author | zautrix <zautrix> | 2004-10-04 10:38:45 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-04 10:38:45 (UTC) |
commit | 01b5806c61deb8368f8f454fdec1c4767c73a840 (patch) (unidiff) | |
tree | f2546296a50444d02d2a74f6bf55fd57b0504ebc | |
parent | 743f44c45534a6e1df17ddc7b5f3c62b73921455 (diff) | |
download | kdepimpi-01b5806c61deb8368f8f454fdec1c4767c73a840.zip kdepimpi-01b5806c61deb8368f8f454fdec1c4767c73a840.tar.gz kdepimpi-01b5806c61deb8368f8f454fdec1c4767c73a840.tar.bz2 |
sync fixes
-rw-r--r-- | korganizer/mainwindow.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index 8e2f956..10cb2a2 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp | |||
@@ -1607,996 +1607,998 @@ void MainWindow::keyPressEvent ( QKeyEvent * e ) | |||
1607 | break; | 1607 | break; |
1608 | case Qt::Key_Plus: | 1608 | case Qt::Key_Plus: |
1609 | size = p->mHourSize +2; | 1609 | size = p->mHourSize +2; |
1610 | if ( size <= 18 ) | 1610 | if ( size <= 18 ) |
1611 | configureAgenda( size ); | 1611 | configureAgenda( size ); |
1612 | break; | 1612 | break; |
1613 | case Qt::Key_Minus: | 1613 | case Qt::Key_Minus: |
1614 | size = p->mHourSize - 2; | 1614 | size = p->mHourSize - 2; |
1615 | if ( size >= 4 ) | 1615 | if ( size >= 4 ) |
1616 | configureAgenda( size ); | 1616 | configureAgenda( size ); |
1617 | break; | 1617 | break; |
1618 | 1618 | ||
1619 | 1619 | ||
1620 | default: | 1620 | default: |
1621 | e->ignore(); | 1621 | e->ignore(); |
1622 | } | 1622 | } |
1623 | if ( pro > 0 ) { | 1623 | if ( pro > 0 ) { |
1624 | mView->selectFilter( pro-1 ); | 1624 | mView->selectFilter( pro-1 ); |
1625 | } | 1625 | } |
1626 | if ( showSelectedDates ) { | 1626 | if ( showSelectedDates ) { |
1627 | ;// setCaptionToDates(); | 1627 | ;// setCaptionToDates(); |
1628 | } | 1628 | } |
1629 | 1629 | ||
1630 | } | 1630 | } |
1631 | 1631 | ||
1632 | void MainWindow::fillFilterMenu() | 1632 | void MainWindow::fillFilterMenu() |
1633 | { | 1633 | { |
1634 | selectFilterMenu->clear(); | 1634 | selectFilterMenu->clear(); |
1635 | bool disable = false; | 1635 | bool disable = false; |
1636 | if ( mView->filterView()->filtersEnabled() ) { | 1636 | if ( mView->filterView()->filtersEnabled() ) { |
1637 | selectFilterMenu->insertItem(i18n ( "Turn filter off" ), 0 ); | 1637 | selectFilterMenu->insertItem(i18n ( "Turn filter off" ), 0 ); |
1638 | } | 1638 | } |
1639 | else { | 1639 | else { |
1640 | selectFilterMenu->insertItem(i18n ( "Turn filter on" ), 0 ); | 1640 | selectFilterMenu->insertItem(i18n ( "Turn filter on" ), 0 ); |
1641 | disable = true; | 1641 | disable = true; |
1642 | } | 1642 | } |
1643 | selectFilterMenu->insertSeparator(); | 1643 | selectFilterMenu->insertSeparator(); |
1644 | QPtrList<CalFilter> fili = mView->filters(); | 1644 | QPtrList<CalFilter> fili = mView->filters(); |
1645 | CalFilter *curfilter = mView->filterView()->selectedFilter(); | 1645 | CalFilter *curfilter = mView->filterView()->selectedFilter(); |
1646 | CalFilter *filter = fili.first(); | 1646 | CalFilter *filter = fili.first(); |
1647 | int iii = 1; | 1647 | int iii = 1; |
1648 | while(filter) { | 1648 | while(filter) { |
1649 | selectFilterMenu->insertItem( filter->name(), iii ); | 1649 | selectFilterMenu->insertItem( filter->name(), iii ); |
1650 | if ( filter == curfilter) | 1650 | if ( filter == curfilter) |
1651 | selectFilterMenu->setItemChecked( iii, true ); | 1651 | selectFilterMenu->setItemChecked( iii, true ); |
1652 | if ( disable ) | 1652 | if ( disable ) |
1653 | selectFilterMenu->setItemEnabled( iii, false ); | 1653 | selectFilterMenu->setItemEnabled( iii, false ); |
1654 | filter = fili.next(); | 1654 | filter = fili.next(); |
1655 | ++iii; | 1655 | ++iii; |
1656 | } | 1656 | } |
1657 | } | 1657 | } |
1658 | void MainWindow::selectFilter( int fil ) | 1658 | void MainWindow::selectFilter( int fil ) |
1659 | { | 1659 | { |
1660 | if ( fil == 0 ) { | 1660 | if ( fil == 0 ) { |
1661 | mView->toggleFilerEnabled( ); | 1661 | mView->toggleFilerEnabled( ); |
1662 | } else { | 1662 | } else { |
1663 | mView->selectFilter( fil-1 ); | 1663 | mView->selectFilter( fil-1 ); |
1664 | } | 1664 | } |
1665 | } | 1665 | } |
1666 | void MainWindow::configureToolBar( int item ) | 1666 | void MainWindow::configureToolBar( int item ) |
1667 | { | 1667 | { |
1668 | 1668 | ||
1669 | configureToolBarMenu->setItemChecked( item, !configureToolBarMenu-> isItemChecked ( item ) ); | 1669 | configureToolBarMenu->setItemChecked( item, !configureToolBarMenu-> isItemChecked ( item ) ); |
1670 | KOPrefs *p = KOPrefs::instance(); | 1670 | KOPrefs *p = KOPrefs::instance(); |
1671 | p-> mShowIconStretch= configureToolBarMenu->isItemChecked( 5 ); | 1671 | p-> mShowIconStretch= configureToolBarMenu->isItemChecked( 5 ); |
1672 | p-> mShowIconNewEvent= configureToolBarMenu->isItemChecked( 10 ); | 1672 | p-> mShowIconNewEvent= configureToolBarMenu->isItemChecked( 10 ); |
1673 | p->mShowIconNewTodo = configureToolBarMenu->isItemChecked( 20 ); | 1673 | p->mShowIconNewTodo = configureToolBarMenu->isItemChecked( 20 ); |
1674 | p-> mShowIconSearch= configureToolBarMenu->isItemChecked( 120 ); | 1674 | p-> mShowIconSearch= configureToolBarMenu->isItemChecked( 120 ); |
1675 | p-> mShowIconList= configureToolBarMenu->isItemChecked( 30 ); | 1675 | p-> mShowIconList= configureToolBarMenu->isItemChecked( 30 ); |
1676 | p-> mShowIconDay1= configureToolBarMenu->isItemChecked( 40 ); | 1676 | p-> mShowIconDay1= configureToolBarMenu->isItemChecked( 40 ); |
1677 | p-> mShowIconDay5= configureToolBarMenu->isItemChecked( 50 ); | 1677 | p-> mShowIconDay5= configureToolBarMenu->isItemChecked( 50 ); |
1678 | p-> mShowIconDay7= configureToolBarMenu->isItemChecked( 60 ); | 1678 | p-> mShowIconDay7= configureToolBarMenu->isItemChecked( 60 ); |
1679 | p-> mShowIconMonth= configureToolBarMenu->isItemChecked( 70 ); | 1679 | p-> mShowIconMonth= configureToolBarMenu->isItemChecked( 70 ); |
1680 | p-> mShowIconTodoview= configureToolBarMenu->isItemChecked( 80 ); | 1680 | p-> mShowIconTodoview= configureToolBarMenu->isItemChecked( 80 ); |
1681 | p-> mShowIconBackFast= configureToolBarMenu->isItemChecked( 200 ); | 1681 | p-> mShowIconBackFast= configureToolBarMenu->isItemChecked( 200 ); |
1682 | p-> mShowIconBack = configureToolBarMenu->isItemChecked( 210 ); | 1682 | p-> mShowIconBack = configureToolBarMenu->isItemChecked( 210 ); |
1683 | p-> mShowIconToday= configureToolBarMenu->isItemChecked( 130 ); | 1683 | p-> mShowIconToday= configureToolBarMenu->isItemChecked( 130 ); |
1684 | p-> mShowIconForward= configureToolBarMenu->isItemChecked( 220 ); | 1684 | p-> mShowIconForward= configureToolBarMenu->isItemChecked( 220 ); |
1685 | p-> mShowIconForwardFast= configureToolBarMenu->isItemChecked( 230 ); | 1685 | p-> mShowIconForwardFast= configureToolBarMenu->isItemChecked( 230 ); |
1686 | p-> mShowIconNextDays= configureToolBarMenu->isItemChecked( 100 ); | 1686 | p-> mShowIconNextDays= configureToolBarMenu->isItemChecked( 100 ); |
1687 | p-> mShowIconNext= configureToolBarMenu->isItemChecked( 110 ); | 1687 | p-> mShowIconNext= configureToolBarMenu->isItemChecked( 110 ); |
1688 | p-> mShowIconJournal= configureToolBarMenu->isItemChecked( 90 ); | 1688 | p-> mShowIconJournal= configureToolBarMenu->isItemChecked( 90 ); |
1689 | p-> mShowIconWhatsThis= configureToolBarMenu->isItemChecked( 300 ); | 1689 | p-> mShowIconWhatsThis= configureToolBarMenu->isItemChecked( 300 ); |
1690 | // initActions(); | 1690 | // initActions(); |
1691 | } | 1691 | } |
1692 | 1692 | ||
1693 | void MainWindow::setCaptionToDates() | 1693 | void MainWindow::setCaptionToDates() |
1694 | { | 1694 | { |
1695 | QString selDates; | 1695 | QString selDates; |
1696 | selDates = KGlobal::locale()->formatDate(mView->startDate(), true); | 1696 | selDates = KGlobal::locale()->formatDate(mView->startDate(), true); |
1697 | if (mView->startDate() < mView->endDate() ) | 1697 | if (mView->startDate() < mView->endDate() ) |
1698 | selDates += " - " + KGlobal::locale()->formatDate(mView->endDate(), true); | 1698 | selDates += " - " + KGlobal::locale()->formatDate(mView->endDate(), true); |
1699 | setCaption( i18n("Dates: ") + selDates ); | 1699 | setCaption( i18n("Dates: ") + selDates ); |
1700 | 1700 | ||
1701 | } | 1701 | } |
1702 | // parameter item == 0: reinit | 1702 | // parameter item == 0: reinit |
1703 | void MainWindow::configureAgenda( int item ) | 1703 | void MainWindow::configureAgenda( int item ) |
1704 | { | 1704 | { |
1705 | 1705 | ||
1706 | KOPrefs *p = KOPrefs::instance(); | 1706 | KOPrefs *p = KOPrefs::instance(); |
1707 | 1707 | ||
1708 | int i; | 1708 | int i; |
1709 | if ( item == 1 ) { | 1709 | if ( item == 1 ) { |
1710 | mView->toggleAllDaySize(); | 1710 | mView->toggleAllDaySize(); |
1711 | return; | 1711 | return; |
1712 | } | 1712 | } |
1713 | // do not allow 4 for widgets higher than 480 | 1713 | // do not allow 4 for widgets higher than 480 |
1714 | // if ( QApplication::desktop()->height() > 480 ) { | 1714 | // if ( QApplication::desktop()->height() > 480 ) { |
1715 | // if ( item == 4 ) | 1715 | // if ( item == 4 ) |
1716 | // item = 6; | 1716 | // item = 6; |
1717 | // } | 1717 | // } |
1718 | for ( i = 4; i <= 18; i= i+2 ) | 1718 | for ( i = 4; i <= 18; i= i+2 ) |
1719 | configureAgendaMenu->setItemChecked( i, false ); | 1719 | configureAgendaMenu->setItemChecked( i, false ); |
1720 | configureAgendaMenu->setItemChecked( item, true ); | 1720 | configureAgendaMenu->setItemChecked( item, true ); |
1721 | if ( p->mHourSize == item ) | 1721 | if ( p->mHourSize == item ) |
1722 | return; | 1722 | return; |
1723 | p->mHourSize=item; | 1723 | p->mHourSize=item; |
1724 | mView->viewManager()->agendaView()->updateConfig(); | 1724 | mView->viewManager()->agendaView()->updateConfig(); |
1725 | } | 1725 | } |
1726 | 1726 | ||
1727 | void MainWindow::saveCalendar() | 1727 | void MainWindow::saveCalendar() |
1728 | { | 1728 | { |
1729 | QString fn = KOPrefs::instance()->mLastSaveFile; | 1729 | QString fn = KOPrefs::instance()->mLastSaveFile; |
1730 | fn = KFileDialog::getSaveFileName( fn, i18n("Save backup filename"), this ); | 1730 | fn = KFileDialog::getSaveFileName( fn, i18n("Save backup filename"), this ); |
1731 | 1731 | ||
1732 | if ( fn == "" ) | 1732 | if ( fn == "" ) |
1733 | return; | 1733 | return; |
1734 | QFileInfo info; | 1734 | QFileInfo info; |
1735 | info.setFile( fn ); | 1735 | info.setFile( fn ); |
1736 | QString mes; | 1736 | QString mes; |
1737 | bool createbup = true; | 1737 | bool createbup = true; |
1738 | if ( info. exists() ) { | 1738 | if ( info. exists() ) { |
1739 | mes = i18n("Backup file\nalready exists!\nOld backup file from:\n%1\nOverwrite?\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )) ; | 1739 | mes = i18n("Backup file\nalready exists!\nOld backup file from:\n%1\nOverwrite?\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )) ; |
1740 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, | 1740 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, |
1741 | i18n("Overwrite!"), i18n("Cancel"), 0, | 1741 | i18n("Overwrite!"), i18n("Cancel"), 0, |
1742 | 0, 1 ); | 1742 | 0, 1 ); |
1743 | if ( result != 0 ) { | 1743 | if ( result != 0 ) { |
1744 | createbup = false; | 1744 | createbup = false; |
1745 | } | 1745 | } |
1746 | } | 1746 | } |
1747 | if ( createbup ) { | 1747 | if ( createbup ) { |
1748 | mView->saveCalendar( fn ); | 1748 | mView->saveCalendar( fn ); |
1749 | mes = i18n("KO/Pi:Saved %1").arg(fn); | 1749 | mes = i18n("KO/Pi:Saved %1").arg(fn); |
1750 | KOPrefs::instance()->mLastSaveFile = fn; | 1750 | KOPrefs::instance()->mLastSaveFile = fn; |
1751 | setCaption(mes); | 1751 | setCaption(mes); |
1752 | } | 1752 | } |
1753 | } | 1753 | } |
1754 | void MainWindow::loadCalendar() | 1754 | void MainWindow::loadCalendar() |
1755 | { | 1755 | { |
1756 | 1756 | ||
1757 | QString fn = KOPrefs::instance()->mLastLoadFile; | 1757 | QString fn = KOPrefs::instance()->mLastLoadFile; |
1758 | fn = KFileDialog::getOpenFileName( fn, i18n("Load backup filename"), this ); | 1758 | fn = KFileDialog::getOpenFileName( fn, i18n("Load backup filename"), this ); |
1759 | 1759 | ||
1760 | if ( fn == "" ) | 1760 | if ( fn == "" ) |
1761 | return; | 1761 | return; |
1762 | QFileInfo info; | 1762 | QFileInfo info; |
1763 | info.setFile( fn ); | 1763 | info.setFile( fn ); |
1764 | QString mess; | 1764 | QString mess; |
1765 | bool loadbup = true; | 1765 | bool loadbup = true; |
1766 | if ( info. exists() ) { | 1766 | if ( info. exists() ) { |
1767 | mess = i18n("Backup file from:\n%1\nLoading backup\nfile will delete\nyour current Data!\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 1767 | mess = i18n("Backup file from:\n%1\nLoading backup\nfile will delete\nyour current Data!\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
1768 | int result = QMessageBox::warning( this, "KO/Pi: Warning!", | 1768 | int result = QMessageBox::warning( this, "KO/Pi: Warning!", |
1769 | mess, | 1769 | mess, |
1770 | i18n("Load!"), i18n("Cancel"), 0, | 1770 | i18n("Load!"), i18n("Cancel"), 0, |
1771 | 0, 1 ); | 1771 | 0, 1 ); |
1772 | if ( result != 0 ) { | 1772 | if ( result != 0 ) { |
1773 | loadbup = false; | 1773 | loadbup = false; |
1774 | } | 1774 | } |
1775 | } else { | 1775 | } else { |
1776 | QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | 1776 | QMessageBox::warning( this, i18n("KO/Pi: Warning!"), |
1777 | i18n("Backup file\ndoes not exist!\nNothing loaded!"), 0, 0, | 1777 | i18n("Backup file\ndoes not exist!\nNothing loaded!"), 0, 0, |
1778 | 0, 1 ); | 1778 | 0, 1 ); |
1779 | 1779 | ||
1780 | return; | 1780 | return; |
1781 | } | 1781 | } |
1782 | if ( loadbup ) { | 1782 | if ( loadbup ) { |
1783 | mView->openCalendar( fn ); | 1783 | mView->openCalendar( fn ); |
1784 | KOPrefs::instance()->mLastLoadFile = fn; | 1784 | KOPrefs::instance()->mLastLoadFile = fn; |
1785 | mess = i18n("KO/Pi:Loaded %1").arg(fn) ; | 1785 | mess = i18n("KO/Pi:Loaded %1").arg(fn) ; |
1786 | setCaption(mess); | 1786 | setCaption(mess); |
1787 | } | 1787 | } |
1788 | 1788 | ||
1789 | } | 1789 | } |
1790 | void MainWindow::quickImportIcal() | 1790 | void MainWindow::quickImportIcal() |
1791 | { | 1791 | { |
1792 | importFile( KOPrefs::instance()->mLastImportFile, false ); | 1792 | importFile( KOPrefs::instance()->mLastImportFile, false ); |
1793 | } | 1793 | } |
1794 | void MainWindow::importFile( QString fn, bool quick ) | 1794 | void MainWindow::importFile( QString fn, bool quick ) |
1795 | { | 1795 | { |
1796 | QFileInfo info; | 1796 | QFileInfo info; |
1797 | info.setFile( fn ); | 1797 | info.setFile( fn ); |
1798 | QString mess; | 1798 | QString mess; |
1799 | bool loadbup = true; | 1799 | bool loadbup = true; |
1800 | if ( !info. exists() ) { | 1800 | if ( !info. exists() ) { |
1801 | mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30)); | 1801 | mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30)); |
1802 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | 1802 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), |
1803 | mess ); | 1803 | mess ); |
1804 | return; | 1804 | return; |
1805 | } | 1805 | } |
1806 | int result = 0; | 1806 | int result = 0; |
1807 | if ( !quick ) { | 1807 | if ( !quick ) { |
1808 | mess = i18n( "Import file \n...%1\nfrom:\n%2\nDuplicated entries\nwill not be imported!\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 1808 | mess = i18n( "Import file \n...%1\nfrom:\n%2\nDuplicated entries\nwill not be imported!\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
1809 | result = QMessageBox::warning( this, "KO/Pi: Warning!", | 1809 | result = QMessageBox::warning( this, "KO/Pi: Warning!", |
1810 | mess, | 1810 | mess, |
1811 | "Import", "Cancel", 0, | 1811 | "Import", "Cancel", 0, |
1812 | 0, 1 ); | 1812 | 0, 1 ); |
1813 | } | 1813 | } |
1814 | if ( result == 0 ) { | 1814 | if ( result == 0 ) { |
1815 | if ( mView->openCalendar( fn, true )) { | 1815 | if ( mView->openCalendar( fn, true )) { |
1816 | KOPrefs::instance()->mLastImportFile = fn; | 1816 | KOPrefs::instance()->mLastImportFile = fn; |
1817 | setCaption(i18n("Imported file successfully")); | 1817 | setCaption(i18n("Imported file successfully")); |
1818 | } else { | 1818 | } else { |
1819 | setCaption(i18n("Error importing file")); | 1819 | setCaption(i18n("Error importing file")); |
1820 | } | 1820 | } |
1821 | } | 1821 | } |
1822 | } | 1822 | } |
1823 | 1823 | ||
1824 | void MainWindow::importIcal() | 1824 | void MainWindow::importIcal() |
1825 | { | 1825 | { |
1826 | 1826 | ||
1827 | QString fn =KOPrefs::instance()->mLastImportFile; | 1827 | QString fn =KOPrefs::instance()->mLastImportFile; |
1828 | 1828 | ||
1829 | fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this ); | 1829 | fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this ); |
1830 | if ( fn == "" ) | 1830 | if ( fn == "" ) |
1831 | return; | 1831 | return; |
1832 | importFile( fn, true ); | 1832 | importFile( fn, true ); |
1833 | 1833 | ||
1834 | } | 1834 | } |
1835 | 1835 | ||
1836 | void MainWindow::exportVCalendar() | 1836 | void MainWindow::exportVCalendar() |
1837 | { | 1837 | { |
1838 | QString fn = KOPrefs::instance()->mLastVcalFile; | 1838 | QString fn = KOPrefs::instance()->mLastVcalFile; |
1839 | fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this ); | 1839 | fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this ); |
1840 | if ( fn == "" ) | 1840 | if ( fn == "" ) |
1841 | return; | 1841 | return; |
1842 | QFileInfo info; | 1842 | QFileInfo info; |
1843 | info.setFile( fn ); | 1843 | info.setFile( fn ); |
1844 | QString mes; | 1844 | QString mes; |
1845 | bool createbup = true; | 1845 | bool createbup = true; |
1846 | if ( info. exists() ) { | 1846 | if ( info. exists() ) { |
1847 | mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); | 1847 | mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); |
1848 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, | 1848 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, |
1849 | i18n("Overwrite!"), i18n("Cancel"), 0, | 1849 | i18n("Overwrite!"), i18n("Cancel"), 0, |
1850 | 0, 1 ); | 1850 | 0, 1 ); |
1851 | if ( result != 0 ) { | 1851 | if ( result != 0 ) { |
1852 | createbup = false; | 1852 | createbup = false; |
1853 | } | 1853 | } |
1854 | } | 1854 | } |
1855 | if ( createbup ) { | 1855 | if ( createbup ) { |
1856 | if ( mView->exportVCalendar( fn ) ) { | 1856 | if ( mView->exportVCalendar( fn ) ) { |
1857 | KOPrefs::instance()->mLastVcalFile = fn; | 1857 | KOPrefs::instance()->mLastVcalFile = fn; |
1858 | if ( fn.length() > 20 ) | 1858 | if ( fn.length() > 20 ) |
1859 | mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ; | 1859 | mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ; |
1860 | else | 1860 | else |
1861 | mes = i18n("KO/Pi:Exported to %1").arg(fn ); | 1861 | mes = i18n("KO/Pi:Exported to %1").arg(fn ); |
1862 | setCaption(mes); | 1862 | setCaption(mes); |
1863 | } | 1863 | } |
1864 | } | 1864 | } |
1865 | 1865 | ||
1866 | } | 1866 | } |
1867 | QString MainWindow::getPassword( ) | 1867 | QString MainWindow::getPassword( ) |
1868 | { | 1868 | { |
1869 | QString retfile = ""; | 1869 | QString retfile = ""; |
1870 | QDialog dia ( this, "input-dialog", true ); | 1870 | QDialog dia ( this, "input-dialog", true ); |
1871 | QLineEdit lab ( &dia ); | 1871 | QLineEdit lab ( &dia ); |
1872 | lab.setEchoMode( QLineEdit::Password ); | 1872 | lab.setEchoMode( QLineEdit::Password ); |
1873 | QVBoxLayout lay( &dia ); | 1873 | QVBoxLayout lay( &dia ); |
1874 | lay.setMargin(7); | 1874 | lay.setMargin(7); |
1875 | lay.setSpacing(7); | 1875 | lay.setSpacing(7); |
1876 | lay.addWidget( &lab); | 1876 | lay.addWidget( &lab); |
1877 | dia.setFixedSize( 230,50 ); | 1877 | dia.setFixedSize( 230,50 ); |
1878 | dia.setCaption( i18n("Enter password") ); | 1878 | dia.setCaption( i18n("Enter password") ); |
1879 | QPushButton pb ( "OK", &dia); | 1879 | QPushButton pb ( "OK", &dia); |
1880 | lay.addWidget( &pb ); | 1880 | lay.addWidget( &pb ); |
1881 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 1881 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
1882 | dia.show(); | 1882 | dia.show(); |
1883 | int res = dia.exec(); | 1883 | int res = dia.exec(); |
1884 | if ( res ) | 1884 | if ( res ) |
1885 | retfile = lab.text(); | 1885 | retfile = lab.text(); |
1886 | dia.hide(); | 1886 | dia.hide(); |
1887 | qApp->processEvents(); | 1887 | qApp->processEvents(); |
1888 | return retfile; | 1888 | return retfile; |
1889 | 1889 | ||
1890 | } | 1890 | } |
1891 | 1891 | ||
1892 | void MainWindow::enableQuick() | 1892 | void MainWindow::enableQuick() |
1893 | { | 1893 | { |
1894 | QString passWordPiSync = "bhdrvmk"; | 1894 | QString passWordPiSync = "bhdrvmk"; |
1895 | QString retfile = ""; | 1895 | QString retfile = ""; |
1896 | QDialog dia ( this, "input-dialog", true ); | 1896 | QDialog dia ( this, "input-dialog", true ); |
1897 | QLineEdit lab ( &dia ); | 1897 | QLineEdit lab ( &dia ); |
1898 | QVBoxLayout lay( &dia ); | 1898 | QVBoxLayout lay( &dia ); |
1899 | lab.setText( KOPrefs::instance()->mPassiveSyncPort ); | 1899 | lab.setText( KOPrefs::instance()->mPassiveSyncPort ); |
1900 | lay.setMargin(7); | 1900 | lay.setMargin(7); |
1901 | lay.setSpacing(7); | 1901 | lay.setSpacing(7); |
1902 | QLabel label ( i18n("Port number (Default: 9197)"), &dia ); | 1902 | QLabel label ( i18n("Port number (Default: 9197)"), &dia ); |
1903 | lay.addWidget( &label); | 1903 | lay.addWidget( &label); |
1904 | lay.addWidget( &lab); | 1904 | lay.addWidget( &lab); |
1905 | 1905 | ||
1906 | QLineEdit lepw ( &dia ); | 1906 | QLineEdit lepw ( &dia ); |
1907 | lepw.setText( "abc" ); | 1907 | lepw.setText( "abc" ); |
1908 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 1908 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
1909 | lay.addWidget( &label2); | 1909 | lay.addWidget( &label2); |
1910 | lay.addWidget( &lepw); | 1910 | lay.addWidget( &lepw); |
1911 | dia.setFixedSize( 230,80 ); | 1911 | dia.setFixedSize( 230,80 ); |
1912 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 1912 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
1913 | QPushButton pb ( "OK", &dia); | 1913 | QPushButton pb ( "OK", &dia); |
1914 | lay.addWidget( &pb ); | 1914 | lay.addWidget( &pb ); |
1915 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 1915 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
1916 | dia.show(); | 1916 | dia.show(); |
1917 | int res = dia.exec(); | 1917 | int res = dia.exec(); |
1918 | if ( res ) | 1918 | if ( res ) |
1919 | retfile = lab.text(); | 1919 | retfile = lab.text(); |
1920 | else | 1920 | else |
1921 | return; | 1921 | return; |
1922 | dia.hide(); | 1922 | dia.hide(); |
1923 | passWordPiSync = lepw.text(); | 1923 | passWordPiSync = lepw.text(); |
1924 | qApp->processEvents(); | 1924 | qApp->processEvents(); |
1925 | KOPrefs::instance()->mPassiveSyncPort = retfile; | 1925 | KOPrefs::instance()->mPassiveSyncPort = retfile; |
1926 | bool ok; | 1926 | bool ok; |
1927 | Q_UINT16 port = retfile.toUInt(&ok); | 1927 | Q_UINT16 port = retfile.toUInt(&ok); |
1928 | if ( ! ok ) { | 1928 | if ( ! ok ) { |
1929 | KMessageBox::information( this, i18n("No valid port")); | 1929 | KMessageBox::information( this, i18n("No valid port")); |
1930 | return; | 1930 | return; |
1931 | } | 1931 | } |
1932 | qDebug("port %d ", port); | 1932 | qDebug("port %d ", port); |
1933 | mServerSocket = new KServerSocket ( passWordPiSync, port ,1 ); | 1933 | mServerSocket = new KServerSocket ( passWordPiSync, port ,1 ); |
1934 | qDebug("connected "); | 1934 | qDebug("connected "); |
1935 | if ( !mServerSocket->ok() ) { | 1935 | if ( !mServerSocket->ok() ) { |
1936 | qWarning("Failed to bind to port %d", port); | 1936 | qWarning("Failed to bind to port %d", port); |
1937 | delete mServerSocket; | 1937 | delete mServerSocket; |
1938 | mServerSocket = 0; | 1938 | mServerSocket = 0; |
1939 | return; | 1939 | return; |
1940 | } | 1940 | } |
1941 | connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) ); | 1941 | connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) ); |
1942 | connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) ); | 1942 | connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) ); |
1943 | } | 1943 | } |
1944 | void MainWindow::sendFile(QSocket* socket) | 1944 | void MainWindow::sendFile(QSocket* socket) |
1945 | { | 1945 | { |
1946 | setCaption( i18n("Received request for file") ); | 1946 | setCaption( i18n("Received request for file") ); |
1947 | qDebug("MainWindow::sendFile(QSocket* s) "); | 1947 | qDebug("MainWindow::sendFile(QSocket* s) "); |
1948 | if ( mSyncActionDialog ) | 1948 | if ( mSyncActionDialog ) |
1949 | delete mSyncActionDialog; | 1949 | delete mSyncActionDialog; |
1950 | mSyncActionDialog = new QDialog ( this, "input-dialog", true ); | 1950 | mSyncActionDialog = new QDialog ( this, "input-dialog", true ); |
1951 | mSyncActionDialog->setCaption(i18n("KO/Pi - WARNING")); | 1951 | mSyncActionDialog->setCaption(i18n("KO/Pi - WARNING")); |
1952 | QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use\nthis application!\n"), mSyncActionDialog ); | 1952 | QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use\nthis application!\n"), mSyncActionDialog ); |
1953 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 1953 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
1954 | lay->addWidget( label); | 1954 | lay->addWidget( label); |
1955 | lay->setMargin(7); | 1955 | lay->setMargin(7); |
1956 | lay->setSpacing(7); | 1956 | lay->setSpacing(7); |
1957 | mSyncActionDialog->setFixedSize( 200,100 ); | 1957 | mSyncActionDialog->setFixedSize( 200,100 ); |
1958 | mSyncActionDialog->show(); | 1958 | mSyncActionDialog->show(); |
1959 | qDebug("saving ... "); | 1959 | qDebug("saving ... "); |
1960 | save(); | 1960 | save(); |
1961 | qApp->processEvents(); | 1961 | qApp->processEvents(); |
1962 | QString fileName = defaultFileName(); | 1962 | QString fileName = defaultFileName(); |
1963 | QFile file( fileName ); | 1963 | QFile file( fileName ); |
1964 | if (!file.open( IO_ReadOnly ) ) { | 1964 | if (!file.open( IO_ReadOnly ) ) { |
1965 | setCaption( i18n("Error open file") ); | 1965 | setCaption( i18n("Error open file") ); |
1966 | delete mSyncActionDialog; | 1966 | delete mSyncActionDialog; |
1967 | mSyncActionDialog = 0; | 1967 | mSyncActionDialog = 0; |
1968 | qDebug("error open cal file "); | 1968 | qDebug("error open cal file "); |
1969 | return ; | 1969 | return ; |
1970 | 1970 | ||
1971 | } | 1971 | } |
1972 | setCaption( i18n("Sending file...") ); | 1972 | setCaption( i18n("Sending file...") ); |
1973 | QTextStream ts( &file ); | 1973 | QTextStream ts( &file ); |
1974 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 1974 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
1975 | QTextStream os( socket ); | 1975 | QTextStream os( socket ); |
1976 | os.setCodec( QTextCodec::codecForName("utf8") ); | 1976 | os.setCodec( QTextCodec::codecForName("utf8") ); |
1977 | //os.setEncoding( QTextStream::UnicodeUTF8 ); | 1977 | //os.setEncoding( QTextStream::UnicodeUTF8 ); |
1978 | while ( ! ts.atEnd() ) { | 1978 | while ( ! ts.atEnd() ) { |
1979 | os << ts.readLine() << "\n"; | 1979 | os << ts.readLine() << "\n"; |
1980 | } | 1980 | } |
1981 | //os << ts.read(); | 1981 | //os << ts.read(); |
1982 | socket->close(); | 1982 | socket->close(); |
1983 | file.close(); | 1983 | file.close(); |
1984 | setCaption( i18n("File sent. Waiting to get back synced file") ); | 1984 | setCaption( i18n("File sent. Waiting to get back synced file") ); |
1985 | qDebug("file sent "); | 1985 | qDebug("file sent "); |
1986 | } | 1986 | } |
1987 | void MainWindow::getFile(QSocket* socket) | 1987 | void MainWindow::getFile(QSocket* socket) |
1988 | { | 1988 | { |
1989 | setCaption( i18n("Receiving synced file...") ); | 1989 | setCaption( i18n("Receiving synced file...") ); |
1990 | 1990 | ||
1991 | piTime.start(); | 1991 | piTime.start(); |
1992 | piSocket = socket; | 1992 | piSocket = socket; |
1993 | piFileString = ""; | 1993 | piFileString = ""; |
1994 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 1994 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
1995 | 1995 | ||
1996 | 1996 | ||
1997 | } | 1997 | } |
1998 | void MainWindow::readBackFileFromSocket() | 1998 | void MainWindow::readBackFileFromSocket() |
1999 | { | 1999 | { |
2000 | qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 2000 | qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
2001 | while ( piSocket->canReadLine () ) { | 2001 | while ( piSocket->canReadLine () ) { |
2002 | piTime.restart(); | 2002 | piTime.restart(); |
2003 | QString line = piSocket->readLine (); | 2003 | QString line = piSocket->readLine (); |
2004 | piFileString += line; | 2004 | piFileString += line; |
2005 | qDebug("readline: %s ", line.latin1()); | 2005 | qDebug("readline: %s ", line.latin1()); |
2006 | setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | 2006 | setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); |
2007 | 2007 | ||
2008 | } | 2008 | } |
2009 | if ( piTime.elapsed () < 3000 ) { | 2009 | if ( piTime.elapsed () < 3000 ) { |
2010 | // wait for more | 2010 | // wait for more |
2011 | qDebug("waitformore "); | 2011 | qDebug("waitformore "); |
2012 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | 2012 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); |
2013 | return; | 2013 | return; |
2014 | } | 2014 | } |
2015 | QString fileName = defaultFileName(); | 2015 | QString fileName = defaultFileName(); |
2016 | QFile file ( fileName ); | 2016 | QFile file ( fileName ); |
2017 | if (!file.open( IO_WriteOnly ) ) { | 2017 | if (!file.open( IO_WriteOnly ) ) { |
2018 | setCaption( i18n("Error open file for writing!") ); | 2018 | setCaption( i18n("Error open file for writing!") ); |
2019 | delete mSyncActionDialog; | 2019 | delete mSyncActionDialog; |
2020 | mSyncActionDialog = 0; | 2020 | mSyncActionDialog = 0; |
2021 | qDebug("error open cal file "); | 2021 | qDebug("error open cal file "); |
2022 | piFileString = ""; | 2022 | piFileString = ""; |
2023 | return ; | 2023 | return ; |
2024 | 2024 | ||
2025 | } | 2025 | } |
2026 | 2026 | ||
2027 | mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 2027 | mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
2028 | QTextStream ts ( &file ); | 2028 | QTextStream ts ( &file ); |
2029 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 2029 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
2030 | qDebug("finish "); | 2030 | qDebug("finish "); |
2031 | setCaption( i18n("Writing file to disk...") ); | 2031 | setCaption( i18n("Writing file to disk...") ); |
2032 | ts << piFileString; | 2032 | ts << piFileString; |
2033 | setCaption( i18n("File received - reloading calendar...") ); | 2033 | setCaption( i18n("File received - reloading calendar...") ); |
2034 | piSocket->close(); | 2034 | piSocket->close(); |
2035 | file.close(); | 2035 | file.close(); |
2036 | mView->watchSavedFile(); | 2036 | mView->watchSavedFile(); |
2037 | mView->openCalendar( defaultFileName() ); | 2037 | mView->openCalendar( defaultFileName() ); |
2038 | setCaption( i18n("Pi-Sync successful!") ); | 2038 | setCaption( i18n("Pi-Sync successful!") ); |
2039 | delete mSyncActionDialog; | 2039 | delete mSyncActionDialog; |
2040 | mSyncActionDialog = 0; | 2040 | mSyncActionDialog = 0; |
2041 | piFileString = ""; | 2041 | piFileString = ""; |
2042 | 2042 | ||
2043 | 2043 | ||
2044 | } | 2044 | } |
2045 | void MainWindow::endConnect() | 2045 | void MainWindow::endConnect() |
2046 | { | 2046 | { |
2047 | setCaption( i18n("No file received - syncing successful") ); | 2047 | setCaption( i18n("No file received - syncing successful") ); |
2048 | delete mSyncActionDialog; | 2048 | delete mSyncActionDialog; |
2049 | mSyncActionDialog = 0; | 2049 | mSyncActionDialog = 0; |
2050 | } | 2050 | } |
2051 | void MainWindow::performQuick() | 2051 | void MainWindow::performQuick() |
2052 | { | 2052 | { |
2053 | 2053 | ||
2054 | setCaption( i18n("Please input connection settings") ); | 2054 | setCaption( i18n("Please input connection settings") ); |
2055 | QString retfile = ""; | 2055 | QString retfile = ""; |
2056 | QDialog dia ( this, "input-dialog", true ); | 2056 | QDialog dia ( this, "input-dialog", true ); |
2057 | QLineEdit lab ( &dia ); | 2057 | QLineEdit lab ( &dia ); |
2058 | QVBoxLayout lay( &dia ); | 2058 | QVBoxLayout lay( &dia ); |
2059 | QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia ); | 2059 | QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia ); |
2060 | lay.addWidget( &label); | 2060 | lay.addWidget( &label); |
2061 | lab.setText( KOPrefs::instance()->mActiveSyncIP ); | 2061 | lab.setText( KOPrefs::instance()->mActiveSyncIP ); |
2062 | lay.setMargin(7); | 2062 | lay.setMargin(7); |
2063 | lay.setSpacing(7); | 2063 | lay.setSpacing(7); |
2064 | lay.addWidget( &lab); | 2064 | lay.addWidget( &lab); |
2065 | QLabel label2 ( i18n("Port number (Default: 9197)"), &dia ); | 2065 | QLabel label2 ( i18n("Port number (Default: 9197)"), &dia ); |
2066 | lay.addWidget( &label2); | 2066 | lay.addWidget( &label2); |
2067 | QLineEdit lab2 ( &dia ); | 2067 | QLineEdit lab2 ( &dia ); |
2068 | lab2.setText( KOPrefs::instance()->mActiveSyncPort ); | 2068 | lab2.setText( KOPrefs::instance()->mActiveSyncPort ); |
2069 | lay.addWidget( &lab2); | 2069 | lay.addWidget( &lab2); |
2070 | 2070 | ||
2071 | QLineEdit lepw ( &dia ); | 2071 | QLineEdit lepw ( &dia ); |
2072 | lepw.setText( mPassWordPiSync ); | 2072 | lepw.setText( mPassWordPiSync ); |
2073 | QLabel label3 ( i18n("Password to enable\naccess to remote:"), &dia ); | 2073 | QLabel label3 ( i18n("Password to enable\naccess to remote:"), &dia ); |
2074 | lay.addWidget( &label3); | 2074 | lay.addWidget( &label3); |
2075 | lay.addWidget( &lepw); | 2075 | lay.addWidget( &lepw); |
2076 | 2076 | ||
2077 | dia.setFixedSize( 230,200 ); | 2077 | dia.setFixedSize( 230,200 ); |
2078 | dia.setCaption( i18n("Enter port for Pi-Sync ") ); | 2078 | dia.setCaption( i18n("Enter port for Pi-Sync ") ); |
2079 | QPushButton pb ( "OK", &dia); | 2079 | QPushButton pb ( "OK", &dia); |
2080 | lay.addWidget( &pb ); | 2080 | lay.addWidget( &pb ); |
2081 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 2081 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
2082 | dia.show(); | 2082 | dia.show(); |
2083 | int res = dia.exec(); | 2083 | int res = dia.exec(); |
2084 | if ( !res ) { | 2084 | if ( !res ) { |
2085 | setCaption( i18n("Syncing cancelled!") ); | 2085 | setCaption( i18n("Syncing cancelled!") ); |
2086 | return; | 2086 | return; |
2087 | } | 2087 | } |
2088 | mPassWordPiSync = lepw.text(); | 2088 | mPassWordPiSync = lepw.text(); |
2089 | dia.hide(); | 2089 | dia.hide(); |
2090 | KOPrefs::instance()->mActiveSyncPort = lab2.text(); | 2090 | KOPrefs::instance()->mActiveSyncPort = lab2.text(); |
2091 | KOPrefs::instance()->mActiveSyncIP = lab.text(); | 2091 | KOPrefs::instance()->mActiveSyncIP = lab.text(); |
2092 | qApp->processEvents(); | 2092 | qApp->processEvents(); |
2093 | performQuickQuick(); | 2093 | performQuickQuick(); |
2094 | } | 2094 | } |
2095 | 2095 | ||
2096 | void MainWindow::performQuickQuick() | 2096 | void MainWindow::performQuickQuick() |
2097 | { | 2097 | { |
2098 | // setCaption( i18n("") ); | 2098 | // setCaption( i18n("") ); |
2099 | 2099 | ||
2100 | bool ok; | 2100 | bool ok; |
2101 | Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok); | 2101 | Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok); |
2102 | if ( ! ok ) { | 2102 | if ( ! ok ) { |
2103 | setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 2103 | setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
2104 | return; | 2104 | return; |
2105 | } | 2105 | } |
2106 | if ( !mCommandSocket ) { | 2106 | if ( !mCommandSocket ) { |
2107 | mCommandSocket = new QSocket( this ); | 2107 | mCommandSocket = new QSocket( this ); |
2108 | // delete mCommandSocket; | 2108 | // delete mCommandSocket; |
2109 | //mCommandSocket = new QSocket( this ); | 2109 | //mCommandSocket = new QSocket( this ); |
2110 | connect( mCommandSocket, SIGNAL(readyRead()), this, SLOT(readFileFromSocket()) ); | 2110 | connect( mCommandSocket, SIGNAL(readyRead()), this, SLOT(readFileFromSocket()) ); |
2111 | connect( mCommandSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocket()) ); | 2111 | connect( mCommandSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocket()) ); |
2112 | } | 2112 | } |
2113 | QString host = KOPrefs::instance()->mActiveSyncIP; | 2113 | QString host = KOPrefs::instance()->mActiveSyncIP; |
2114 | mCommandSocket->connectToHost( host, port ); | 2114 | mCommandSocket->connectToHost( host, port ); |
2115 | QTextStream os( mCommandSocket ); | 2115 | QTextStream os( mCommandSocket ); |
2116 | os.setEncoding( QTextStream::UnicodeUTF8 ); | 2116 | os.setEncoding( QTextStream::UnicodeUTF8 ); |
2117 | os << "GET " << mPassWordPiSync << "\r\n"; | 2117 | os << "GET " << mPassWordPiSync << "\r\n"; |
2118 | setCaption( i18n("Sending request for remote file ...") ); | 2118 | setCaption( i18n("Sending request for remote file ...") ); |
2119 | mTimerCommandSocket->start( 15000 ); | 2119 | mTimerCommandSocket->start( 10000 ); |
2120 | 2120 | ||
2121 | } | 2121 | } |
2122 | void MainWindow::deleteCommandSocket() | 2122 | void MainWindow::deleteCommandSocket() |
2123 | { | 2123 | { |
2124 | if ( !mCommandSocket) | 2124 | if ( !mCommandSocket) |
2125 | return; | 2125 | return; |
2126 | if ( mTimerCommandSocket->isActive () ) { | 2126 | if ( mTimerCommandSocket->isActive () ) { |
2127 | KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out ")); | 2127 | KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out ")); |
2128 | mTimerCommandSocket->stop(); | 2128 | mTimerCommandSocket->stop(); |
2129 | } | 2129 | } |
2130 | //KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocket ")); | ||
2130 | qDebug("MainWindow::deletemCommandSocket() "); | 2131 | qDebug("MainWindow::deletemCommandSocket() "); |
2131 | delete mCommandSocket; | 2132 | delete mCommandSocket; |
2132 | mCommandSocket = 0; | 2133 | mCommandSocket = 0; |
2133 | } | 2134 | } |
2134 | void MainWindow::deleteCommandSocketFinish() | 2135 | void MainWindow::deleteCommandSocketFinish() |
2135 | { | 2136 | { |
2136 | if ( ! mCommandSocketFinish) | 2137 | if ( ! mCommandSocketFinish) |
2137 | return; | 2138 | return; |
2138 | //KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() ")); | 2139 | // KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() ")); |
2139 | qDebug("MainWindow::deletemCommandSocketFinish() "); | 2140 | qDebug("MainWindow::deletemCommandSocketFinish() "); |
2140 | delete mCommandSocketFinish; | 2141 | delete mCommandSocketFinish; |
2141 | mCommandSocketFinish = 0; | 2142 | mCommandSocketFinish = 0; |
2142 | } | 2143 | } |
2143 | void MainWindow::readFileFromSocket() | 2144 | void MainWindow::readFileFromSocket() |
2144 | { | 2145 | { |
2145 | mTimerCommandSocket->stop(); | 2146 | mTimerCommandSocket->stop(); |
2146 | setCaption( i18n("Receiving remote file ...") ); | 2147 | setCaption( i18n("Receiving remote file ...") ); |
2147 | qDebug("MainWindow::readFileFromSocket() "); | 2148 | qDebug("MainWindow::readFileFromSocket() "); |
2148 | QString fileName; | 2149 | QString fileName; |
2149 | #ifdef _WIN32_ | 2150 | #ifdef _WIN32_ |
2150 | fileName = defaultFileName() +"sync"; | 2151 | fileName = defaultFileName() +"sync"; |
2151 | #else | 2152 | #else |
2152 | fileName = "/tmp/kopitempfile.ics"; | 2153 | fileName = "/tmp/kopitempfile.ics"; |
2153 | #endif | 2154 | #endif |
2154 | QFile file( fileName ); | 2155 | QFile file( fileName ); |
2155 | if (!file.open( IO_WriteOnly ) ) { | 2156 | if (!file.open( IO_WriteOnly ) ) { |
2156 | setCaption( i18n("Error: Cannot open temp file for write.") ); | 2157 | setCaption( i18n("Error: Cannot open temp file for write.") ); |
2157 | qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); | 2158 | qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); |
2158 | return ; | 2159 | return ; |
2159 | } | 2160 | } |
2160 | 2161 | ||
2161 | //QTextStream os2( mCommandSocket ); | 2162 | //QTextStream os2( mCommandSocket ); |
2162 | //os2.setEncoding( QTextStream::UnicodeUTF8 ); | 2163 | //os2.setEncoding( QTextStream::UnicodeUTF8 ); |
2163 | 2164 | ||
2164 | QTextStream ts( &file ); | 2165 | QTextStream ts( &file ); |
2165 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 2166 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
2166 | bool first = true; | 2167 | bool first = true; |
2167 | while ( mCommandSocket->canReadLine () || first) { | 2168 | while ( mCommandSocket->canReadLine () || first) { |
2168 | first = false; | 2169 | first = false; |
2169 | while ( mCommandSocket->canReadLine () ) { | 2170 | while ( mCommandSocket->canReadLine () ) { |
2170 | ts << mCommandSocket->readLine (); | 2171 | ts << mCommandSocket->readLine (); |
2171 | } | 2172 | } |
2172 | QTime ti; | 2173 | QTime ti; |
2173 | ti.start(); | 2174 | ti.start(); |
2174 | while ( ti.elapsed () < 5000 && !mCommandSocket->canReadLine () ) { | 2175 | while ( ti.elapsed () < 3000 && !mCommandSocket->canReadLine () ) { |
2175 | qApp->processEvents(); | 2176 | qApp->processEvents(); |
2176 | qDebug("waiting2 %d ",ti.elapsed () ); | 2177 | qDebug("waiting2 %d ",ti.elapsed () ); |
2177 | if ( !mCommandSocket->canReadLine () ) | 2178 | if ( !mCommandSocket->canReadLine () ) |
2178 | mCommandSocket->waitForMore ( 100 ); | 2179 | mCommandSocket->waitForMore ( 100 ); |
2179 | } | 2180 | } |
2180 | //mCommandSocket->waitForMore ( 5000 ); | 2181 | //mCommandSocket->waitForMore ( 5000 ); |
2181 | } | 2182 | } |
2182 | file.close(); | 2183 | file.close(); |
2183 | mCommandSocket->close(); | 2184 | mCommandSocket->close(); |
2184 | if ( mCommandSocket->state() == QSocket::Idle ) | 2185 | if ( mCommandSocket->state() == QSocket::Idle ) |
2185 | deleteCommandSocket(); | 2186 | deleteCommandSocket(); |
2186 | // pending: deleting after signal SIGNAL(delayedCloseFinished()) | 2187 | // pending: deleting after signal SIGNAL(delayedCloseFinished()) |
2187 | //delete mCommandSocket; | 2188 | //delete mCommandSocket; |
2188 | setCaption( i18n("Remote file saved to temp file.") ); | 2189 | setCaption( i18n("Remote file saved to temp file.") ); |
2189 | //mCommandSocket = 0; | 2190 | //mCommandSocket = 0; |
2190 | mCurrentSyncProfile = 2 ; // last file | 2191 | mCurrentSyncProfile = 2 ; // last file |
2191 | mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); | 2192 | mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); |
2192 | mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); | 2193 | mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); |
2193 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 2194 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
2194 | KSyncProfile* temp = new KSyncProfile (); | 2195 | KSyncProfile* temp = new KSyncProfile (); |
2195 | temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 2196 | temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
2196 | temp->readConfig(&config); | 2197 | temp->readConfig(&config); |
2197 | KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); | 2198 | KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); |
2198 | KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); | 2199 | KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); |
2199 | KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); | 2200 | KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); |
2200 | KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); | 2201 | KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); |
2201 | KOPrefs::instance()->mWriteBackInFuture = 0; | 2202 | KOPrefs::instance()->mWriteBackInFuture = 0; |
2202 | if ( temp->getWriteBackFuture() ) | 2203 | if ( temp->getWriteBackFuture() ) |
2203 | KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 2204 | KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
2204 | KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); | 2205 | KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); |
2205 | delete temp; | 2206 | delete temp; |
2206 | setCaption( i18n("Remote file saved to temp file.") ); | 2207 | setCaption( i18n("Remote file saved to temp file.") ); |
2207 | if ( ! syncWithFile( fileName , true ) ) { | 2208 | if ( ! syncWithFile( fileName , true ) ) { |
2208 | setCaption( i18n("Syncing failed.") ); | 2209 | setCaption( i18n("Syncing failed.") ); |
2209 | qDebug("Syncing failed "); | 2210 | qDebug("Syncing failed "); |
2210 | return; | 2211 | return; |
2211 | } | 2212 | } |
2212 | 2213 | ||
2213 | if ( !mCommandSocketFinish ) { | 2214 | if ( !mCommandSocketFinish ) { |
2214 | mCommandSocketFinish = new QSocket( this ); | 2215 | mCommandSocketFinish = new QSocket( this ); |
2215 | connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) ); | 2216 | connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) ); |
2216 | } | 2217 | } |
2217 | mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); | 2218 | mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); |
2218 | 2219 | ||
2219 | // pending connect signals connected () and error to new slots | 2220 | // pending connect signals connected () and error to new slots |
2220 | QString host = KOPrefs::instance()->mActiveSyncIP; | 2221 | QString host = KOPrefs::instance()->mActiveSyncIP; |
2221 | QFile file2( fileName ); | 2222 | QFile file2( fileName ); |
2222 | if (!file2.open( IO_ReadOnly ) ) { | 2223 | if (!file2.open( IO_ReadOnly ) ) { |
2223 | setCaption( i18n("Error: Cannot open temp file for read.") ); | 2224 | setCaption( i18n("Error: Cannot open temp file for read.") ); |
2224 | qDebug("error open cal file "); | 2225 | qDebug("error open cal file "); |
2225 | return ; | 2226 | return ; |
2226 | 2227 | ||
2227 | } | 2228 | } |
2228 | setCaption( i18n("Sending back synced file...") ); | ||
2229 | QTextStream ts2( &file2 ); | 2229 | QTextStream ts2( &file2 ); |
2230 | ts2.setCodec( QTextCodec::codecForName("utf8") ); | 2230 | ts2.setCodec( QTextCodec::codecForName("utf8") ); |
2231 | QTextStream os2( mCommandSocketFinish ); | 2231 | QTextStream os2( mCommandSocketFinish ); |
2232 | os2.setCodec( QTextCodec::codecForName("utf8") ); | 2232 | os2.setCodec( QTextCodec::codecForName("utf8") ); |
2233 | //os.setEncoding( QTextStream::UnicodeUTF8 ); | 2233 | //os.setEncoding( QTextStream::UnicodeUTF8 ); |
2234 | if ( KOPrefs::instance()->mWriteBackFile ) { | 2234 | if ( KOPrefs::instance()->mWriteBackFile ) { |
2235 | setCaption( i18n("Sending back synced file...") ); | ||
2235 | os2 << "PUT " << mPassWordPiSync << "\r\n";; | 2236 | os2 << "PUT " << mPassWordPiSync << "\r\n";; |
2236 | while ( ! ts2.atEnd() ) { | 2237 | while ( ! ts2.atEnd() ) { |
2237 | os2 << ts2.readLine() << "\n"; | 2238 | os2 << ts2.readLine() << "\n"; |
2238 | } | 2239 | } |
2239 | } else { | 2240 | } else { |
2240 | os2 << "STOP\r\n"; | 2241 | os2 << "STOP\r\n"; |
2241 | } | 2242 | } |
2242 | mCommandSocketFinish->close(); | 2243 | mCommandSocketFinish->close(); |
2243 | if ( mCommandSocketFinish->state() == QSocket::Idle ) | 2244 | if ( mCommandSocketFinish->state() == QSocket::Idle ) |
2244 | deleteCommandSocketFinish(); | 2245 | QTimer::singleShot( 10, this , SLOT ( deleteCommandSocketFinish())); |
2245 | file.close(); | 2246 | file.close(); |
2246 | qDebug("Syncing succesful! "); | 2247 | qDebug("Syncing succesful! "); |
2247 | setCaption( i18n("Pi-Sync succesful!") ); | 2248 | setCaption( i18n("Pi-Sync succesful!") ); |
2248 | 2249 | ||
2250 | // KMessageBox::information( 0, i18n(" Pi-Sync succesful! ")); | ||
2249 | 2251 | ||
2250 | } | 2252 | } |
2251 | 2253 | ||
2252 | void MainWindow::syncLocalFile() | 2254 | void MainWindow::syncLocalFile() |
2253 | { | 2255 | { |
2254 | 2256 | ||
2255 | QString fn =KOPrefs::instance()->mLastSyncedLocalFile; | 2257 | QString fn =KOPrefs::instance()->mLastSyncedLocalFile; |
2256 | 2258 | ||
2257 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); | 2259 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); |
2258 | if ( fn == "" ) | 2260 | if ( fn == "" ) |
2259 | return; | 2261 | return; |
2260 | //mView->setSyncDevice("local-file" ); | 2262 | //mView->setSyncDevice("local-file" ); |
2261 | if ( syncWithFile( fn, false ) ) { | 2263 | if ( syncWithFile( fn, false ) ) { |
2262 | // Event* e = mView->getLastSyncEvent(); | 2264 | // Event* e = mView->getLastSyncEvent(); |
2263 | // e->setReadOnly( false ); | 2265 | // e->setReadOnly( false ); |
2264 | // e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); | 2266 | // e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); |
2265 | // e->setReadOnly( true ); | 2267 | // e->setReadOnly( true ); |
2266 | } | 2268 | } |
2267 | 2269 | ||
2268 | } | 2270 | } |
2269 | 2271 | ||
2270 | bool MainWindow::syncWithFile( QString fn , bool quick ) | 2272 | bool MainWindow::syncWithFile( QString fn , bool quick ) |
2271 | { | 2273 | { |
2272 | bool ret = false; | 2274 | bool ret = false; |
2273 | QFileInfo info; | 2275 | QFileInfo info; |
2274 | info.setFile( fn ); | 2276 | info.setFile( fn ); |
2275 | QString mess; | 2277 | QString mess; |
2276 | bool loadbup = true; | 2278 | bool loadbup = true; |
2277 | if ( !info. exists() ) { | 2279 | if ( !info. exists() ) { |
2278 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 2280 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
2279 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | 2281 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), |
2280 | mess ); | 2282 | mess ); |
2281 | return ret; | 2283 | return ret; |
2282 | } | 2284 | } |
2283 | int result = 0; | 2285 | int result = 0; |
2284 | if ( !quick ) { | 2286 | if ( !quick ) { |
2285 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 2287 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
2286 | result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | 2288 | result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), |
2287 | mess, | 2289 | mess, |
2288 | i18n("Sync"), i18n("Cancel"), 0, | 2290 | i18n("Sync"), i18n("Cancel"), 0, |
2289 | 0, 1 ); | 2291 | 0, 1 ); |
2290 | if ( result ) | 2292 | if ( result ) |
2291 | return false; | 2293 | return false; |
2292 | } | 2294 | } |
2293 | if ( KOPrefs::instance()->mAskForPreferences ) | 2295 | if ( KOPrefs::instance()->mAskForPreferences ) |
2294 | mView->edit_sync_options(); | 2296 | mView->edit_sync_options(); |
2295 | if ( result == 0 ) { | 2297 | if ( result == 0 ) { |
2296 | //qDebug("Now sycing ... "); | 2298 | //qDebug("Now sycing ... "); |
2297 | if ( ret = mView->syncCalendar( fn, KOPrefs::instance()->mSyncAlgoPrefs ) ) | 2299 | if ( ret = mView->syncCalendar( fn, KOPrefs::instance()->mSyncAlgoPrefs ) ) |
2298 | setCaption( i18n("Synchronization successful") ); | 2300 | setCaption( i18n("Synchronization successful") ); |
2299 | else | 2301 | else |
2300 | setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); | 2302 | setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); |
2301 | if ( ! quick ) | 2303 | if ( ! quick ) |
2302 | KOPrefs::instance()->mLastSyncedLocalFile = fn; | 2304 | KOPrefs::instance()->mLastSyncedLocalFile = fn; |
2303 | slotModifiedChanged( true ); | 2305 | slotModifiedChanged( true ); |
2304 | } | 2306 | } |
2305 | return ret; | 2307 | return ret; |
2306 | } | 2308 | } |
2307 | void MainWindow::quickSyncLocalFile() | 2309 | void MainWindow::quickSyncLocalFile() |
2308 | { | 2310 | { |
2309 | //mView->setSyncDevice("local-file" ); | 2311 | //mView->setSyncDevice("local-file" ); |
2310 | //qDebug("quickSyncLocalFile() "); | 2312 | //qDebug("quickSyncLocalFile() "); |
2311 | if ( syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false ) ) { | 2313 | if ( syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false ) ) { |
2312 | // Event* e = mView->getLastSyncEvent(); | 2314 | // Event* e = mView->getLastSyncEvent(); |
2313 | // e->setReadOnly( false ); | 2315 | // e->setReadOnly( false ); |
2314 | // e->setLocation( i18n("Quick with file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); | 2316 | // e->setLocation( i18n("Quick with file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); |
2315 | // e->setReadOnly( true ); | 2317 | // e->setReadOnly( true ); |
2316 | 2318 | ||
2317 | } | 2319 | } |
2318 | } | 2320 | } |
2319 | 2321 | ||
2320 | void MainWindow::confSync() | 2322 | void MainWindow::confSync() |
2321 | { | 2323 | { |
2322 | mView->confSync(); | 2324 | mView->confSync(); |
2323 | fillSyncMenu(); | 2325 | fillSyncMenu(); |
2324 | } | 2326 | } |
2325 | void MainWindow::syncRemote( KSyncProfile* prof, bool ask) | 2327 | void MainWindow::syncRemote( KSyncProfile* prof, bool ask) |
2326 | { | 2328 | { |
2327 | QString question; | 2329 | QString question; |
2328 | if ( ask ) { | 2330 | if ( ask ) { |
2329 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 2331 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
2330 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), | 2332 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), |
2331 | question, | 2333 | question, |
2332 | i18n("Yes"), i18n("No"), | 2334 | i18n("Yes"), i18n("No"), |
2333 | 0, 0 ) != 0 ) | 2335 | 0, 0 ) != 0 ) |
2334 | return; | 2336 | return; |
2335 | } | 2337 | } |
2336 | QString command = prof->getPreSyncCommand(); | 2338 | QString command = prof->getPreSyncCommand(); |
2337 | int fi; | 2339 | int fi; |
2338 | if ( (fi = command.find("$PWD$")) > 0 ) { | 2340 | if ( (fi = command.find("$PWD$")) > 0 ) { |
2339 | QString pwd = getPassword(); | 2341 | QString pwd = getPassword(); |
2340 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | 2342 | command = command.left( fi )+ pwd + command.mid( fi+5 ); |
2341 | 2343 | ||
2342 | } | 2344 | } |
2343 | int maxlen = 30; | 2345 | int maxlen = 30; |
2344 | if ( QApplication::desktop()->width() > 320 ) | 2346 | if ( QApplication::desktop()->width() > 320 ) |
2345 | maxlen += 25; | 2347 | maxlen += 25; |
2346 | setCaption ( i18n( "Copy remote file to local machine..." ) ); | 2348 | setCaption ( i18n( "Copy remote file to local machine..." ) ); |
2347 | int fileSize = 0; | 2349 | int fileSize = 0; |
2348 | int result = system ( command ); | 2350 | int result = system ( command ); |
2349 | // 0 : okay | 2351 | // 0 : okay |
2350 | // 256: no such file or dir | 2352 | // 256: no such file or dir |
2351 | // | 2353 | // |
2352 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); | 2354 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); |
2353 | if ( result != 0 ) { | 2355 | if ( result != 0 ) { |
2354 | int len = maxlen; | 2356 | int len = maxlen; |
2355 | while ( len < command.length() ) { | 2357 | while ( len < command.length() ) { |
2356 | command.insert( len , "\n" ); | 2358 | command.insert( len , "\n" ); |
2357 | len += maxlen +2; | 2359 | len += maxlen +2; |
2358 | } | 2360 | } |
2359 | question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; | 2361 | question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; |
2360 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), | 2362 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), |
2361 | question, | 2363 | question, |
2362 | i18n("Okay!")) ; | 2364 | i18n("Okay!")) ; |
2363 | setCaption ("KO/Pi"); | 2365 | setCaption ("KO/Pi"); |
2364 | return; | 2366 | return; |
2365 | } | 2367 | } |
2366 | setCaption ( i18n( "Copying succeed." ) ); | 2368 | setCaption ( i18n( "Copying succeed." ) ); |
2367 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 2369 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
2368 | if ( syncWithFile( prof->getLocalTempFile(), true ) ) { | 2370 | if ( syncWithFile( prof->getLocalTempFile(), true ) ) { |
2369 | // Event* e = mView->getLastSyncEvent(); | 2371 | // Event* e = mView->getLastSyncEvent(); |
2370 | // e->setReadOnly( false ); | 2372 | // e->setReadOnly( false ); |
2371 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 2373 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
2372 | // e->setReadOnly( true ); | 2374 | // e->setReadOnly( true ); |
2373 | if ( KOPrefs::instance()->mWriteBackFile ) { | 2375 | if ( KOPrefs::instance()->mWriteBackFile ) { |
2374 | command = prof->getPostSyncCommand(); | 2376 | command = prof->getPostSyncCommand(); |
2375 | int fi; | 2377 | int fi; |
2376 | if ( (fi = command.find("$PWD$")) > 0 ) { | 2378 | if ( (fi = command.find("$PWD$")) > 0 ) { |
2377 | QString pwd = getPassword(); | 2379 | QString pwd = getPassword(); |
2378 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | 2380 | command = command.left( fi )+ pwd + command.mid( fi+5 ); |
2379 | 2381 | ||
2380 | } | 2382 | } |
2381 | setCaption ( i18n( "Writing back file ..." ) ); | 2383 | setCaption ( i18n( "Writing back file ..." ) ); |
2382 | result = system ( command ); | 2384 | result = system ( command ); |
2383 | qDebug("KO: Writing back file result: %d ", result); | 2385 | qDebug("KO: Writing back file result: %d ", result); |
2384 | if ( result != 0 ) { | 2386 | if ( result != 0 ) { |
2385 | setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 2387 | setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
2386 | return; | 2388 | return; |
2387 | } else { | 2389 | } else { |
2388 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 2390 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
2389 | } | 2391 | } |
2390 | } | 2392 | } |
2391 | } | 2393 | } |
2392 | return; | 2394 | return; |
2393 | } | 2395 | } |
2394 | void MainWindow::syncSSH() | 2396 | void MainWindow::syncSSH() |
2395 | { | 2397 | { |
2396 | // not used anymore | 2398 | // not used anymore |
2397 | QTime timer; | 2399 | QTime timer; |
2398 | timer.start(); | 2400 | timer.start(); |
2399 | //qDebug("MainWindow::syncssh() "); | 2401 | //qDebug("MainWindow::syncssh() "); |
2400 | KOPrefs *p = KOPrefs::instance(); | 2402 | KOPrefs *p = KOPrefs::instance(); |
2401 | QString localFile = p->mLocalTempFile; | 2403 | QString localFile = p->mLocalTempFile; |
2402 | QString remoteIP = p->mRemoteIP; | 2404 | QString remoteIP = p->mRemoteIP; |
2403 | QString remoteUser = p->mRemoteUser; | 2405 | QString remoteUser = p->mRemoteUser; |
2404 | QString remoteFile = p->mRemoteFile; | 2406 | QString remoteFile = p->mRemoteFile; |
2405 | if ( p->mUsePassWd && p->mRemotePassWd.length() > 0 ) | 2407 | if ( p->mUsePassWd && p->mRemotePassWd.length() > 0 ) |
2406 | remoteUser += ":" + p->mRemotePassWd; | 2408 | remoteUser += ":" + p->mRemotePassWd; |
2407 | 2409 | ||
2408 | QString question = i18n("Do you really want\nto remote sync?\n \n") + | 2410 | QString question = i18n("Do you really want\nto remote sync?\n \n") + |
2409 | i18n("IP: " ) +remoteIP +"\n" + | 2411 | i18n("IP: " ) +remoteIP +"\n" + |
2410 | i18n("User: " ) + remoteUser +"\n" ; | 2412 | i18n("User: " ) + remoteUser +"\n" ; |
2411 | int maxlen = 30; | 2413 | int maxlen = 30; |
2412 | if ( QApplication::desktop()->width() > 320 ) | 2414 | if ( QApplication::desktop()->width() > 320 ) |
2413 | maxlen += 25; | 2415 | maxlen += 25; |
2414 | if ( remoteFile.length() > maxlen ) | 2416 | if ( remoteFile.length() > maxlen ) |
2415 | question += i18n("Remote file:\n..." ) + remoteFile.right(maxlen) +"\n"; | 2417 | question += i18n("Remote file:\n..." ) + remoteFile.right(maxlen) +"\n"; |
2416 | else | 2418 | else |
2417 | question += i18n("Remote file:\n " ) + remoteFile +"\n"; | 2419 | question += i18n("Remote file:\n " ) + remoteFile +"\n"; |
2418 | if ( localFile.length() > maxlen ) | 2420 | if ( localFile.length() > maxlen ) |
2419 | question += i18n("Local temp file:\n..." ) + localFile.right(maxlen) +"\n"; | 2421 | question += i18n("Local temp file:\n..." ) + localFile.right(maxlen) +"\n"; |
2420 | else | 2422 | else |
2421 | question += i18n("Local temp file:\n " ) + localFile +"\n"; | 2423 | question += i18n("Local temp file:\n " ) + localFile +"\n"; |
2422 | 2424 | ||
2423 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), | 2425 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), |
2424 | question, | 2426 | question, |
2425 | i18n("Yes"), i18n("No"), | 2427 | i18n("Yes"), i18n("No"), |
2426 | 0, 0 ) != 0 ) | 2428 | 0, 0 ) != 0 ) |
2427 | return; | 2429 | return; |
2428 | // if ( !p->mUsePassWd ) { | 2430 | // if ( !p->mUsePassWd ) { |
2429 | // QString pass = getPassword(); | 2431 | // QString pass = getPassword(); |
2430 | // if ( pass.length() > 0 ) | 2432 | // if ( pass.length() > 0 ) |
2431 | // remoteUser += ":" + pass; | 2433 | // remoteUser += ":" + pass; |
2432 | // } | 2434 | // } |
2433 | QString command = "scp " + remoteUser + "@" + remoteIP +":" + remoteFile +" " +localFile; | 2435 | QString command = "scp " + remoteUser + "@" + remoteIP +":" + remoteFile +" " +localFile; |
2434 | setCaption ( i18n( "Copy remote file to local machine..." ) ); | 2436 | setCaption ( i18n( "Copy remote file to local machine..." ) ); |
2435 | int fileSize = 0; | 2437 | int fileSize = 0; |
2436 | int result = system ( command ); | 2438 | int result = system ( command ); |
2437 | // 0 : okay | 2439 | // 0 : okay |
2438 | // 256: no such file or dir | 2440 | // 256: no such file or dir |
2439 | // | 2441 | // |
2440 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); | 2442 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); |
2441 | if ( result != 0 ) { | 2443 | if ( result != 0 ) { |
2442 | int len = maxlen; | 2444 | int len = maxlen; |
2443 | while ( len < command.length() ) { | 2445 | while ( len < command.length() ) { |
2444 | command.insert( len , "\n" ); | 2446 | command.insert( len , "\n" ); |
2445 | len += maxlen +2; | 2447 | len += maxlen +2; |
2446 | } | 2448 | } |
2447 | question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; | 2449 | question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; |
2448 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), | 2450 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), |
2449 | question, | 2451 | question, |
2450 | i18n("Okay!")) ; | 2452 | i18n("Okay!")) ; |
2451 | setCaption ("KO/Pi"); | 2453 | setCaption ("KO/Pi"); |
2452 | return; | 2454 | return; |
2453 | } | 2455 | } |
2454 | 2456 | ||
2455 | 2457 | ||
2456 | setCaption ( i18n( "Copying succeed." ) ); | 2458 | setCaption ( i18n( "Copying succeed." ) ); |
2457 | //mView->setSyncDevice("ssh-scp" ); | 2459 | //mView->setSyncDevice("ssh-scp" ); |
2458 | if ( syncWithFile(localFile , true ) ) { | 2460 | if ( syncWithFile(localFile , true ) ) { |
2459 | // Event* e = mView->getLastSyncEvent(); | 2461 | // Event* e = mView->getLastSyncEvent(); |
2460 | // e->setReadOnly( false ); | 2462 | // e->setReadOnly( false ); |
2461 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 2463 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
2462 | // e->setReadOnly( true ); | 2464 | // e->setReadOnly( true ); |
2463 | if ( KOPrefs::instance()->mWriteBackFile ) { | 2465 | if ( KOPrefs::instance()->mWriteBackFile ) { |
2464 | command = "scp " + localFile +" " +remoteUser + "@" + remoteIP +":" + remoteFile ; | 2466 | command = "scp " + localFile +" " +remoteUser + "@" + remoteIP +":" + remoteFile ; |
2465 | setCaption ( i18n( "Writing back file ..." ) ); | 2467 | setCaption ( i18n( "Writing back file ..." ) ); |
2466 | result = system ( command ); | 2468 | result = system ( command ); |
2467 | if ( result != 0 ) { | 2469 | if ( result != 0 ) { |
2468 | int len = maxlen; | 2470 | int len = maxlen; |
2469 | while ( len < command.length() ) { | 2471 | while ( len < command.length() ) { |
2470 | command.insert( len , "\n" ); | 2472 | command.insert( len , "\n" ); |
2471 | len += maxlen +2; | 2473 | len += maxlen +2; |
2472 | } | 2474 | } |
2473 | question = i18n("Sorry, the copy back command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; | 2475 | question = i18n("Sorry, the copy back command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; |
2474 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), | 2476 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), |
2475 | question, | 2477 | question, |
2476 | i18n("Okay!")) ; | 2478 | i18n("Okay!")) ; |
2477 | setCaption ("KO/Pi"); | 2479 | setCaption ("KO/Pi"); |
2478 | return; | 2480 | return; |
2479 | } else { | 2481 | } else { |
2480 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 2482 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
2481 | } | 2483 | } |
2482 | } | 2484 | } |
2483 | } | 2485 | } |
2484 | return; | 2486 | return; |
2485 | #if 0 | 2487 | #if 0 |
2486 | system ("scp zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics /home/polo/Applications/korganizer/z_sync.ics"); | 2488 | system ("scp zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics /home/polo/Applications/korganizer/z_sync.ics"); |
2487 | while ( timer.elapsed() < 5000 ) | 2489 | while ( timer.elapsed() < 5000 ) |
2488 | qApp->processEvents(); | 2490 | qApp->processEvents(); |
2489 | 2491 | ||
2490 | qDebug("MainWindow::merging) "); | 2492 | qDebug("MainWindow::merging) "); |
2491 | mView->syncCalendar( "/home/polo/Applications/korganizer/z_sync.ics", 0 ); | 2493 | mView->syncCalendar( "/home/polo/Applications/korganizer/z_sync.ics", 0 ); |
2492 | while ( mBlockSaveFlag ) | 2494 | while ( mBlockSaveFlag ) |
2493 | qApp->processEvents(); | 2495 | qApp->processEvents(); |
2494 | save(); | 2496 | save(); |
2495 | system ("scp /home/polo/Applications/korganizer/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics"); | 2497 | system ("scp /home/polo/Applications/korganizer/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics"); |
2496 | #endif | 2498 | #endif |
2497 | 2499 | ||
2498 | } | 2500 | } |
2499 | 2501 | ||
2500 | 2502 | ||
2501 | void MainWindow::syncSharp() | 2503 | void MainWindow::syncSharp() |
2502 | { | 2504 | { |
2503 | if ( mCalendarModifiedFlag ) | 2505 | if ( mCalendarModifiedFlag ) |
2504 | save(); | 2506 | save(); |
2505 | mView->syncSharp(); | 2507 | mView->syncSharp(); |
2506 | slotModifiedChanged( true ); | 2508 | slotModifiedChanged( true ); |
2507 | 2509 | ||
2508 | } | 2510 | } |
2509 | void MainWindow::syncPhone() | 2511 | void MainWindow::syncPhone() |
2510 | { | 2512 | { |
2511 | if ( mCalendarModifiedFlag ) | 2513 | if ( mCalendarModifiedFlag ) |
2512 | save(); | 2514 | save(); |
2513 | mView->syncPhone(); | 2515 | mView->syncPhone(); |
2514 | slotModifiedChanged( true ); | 2516 | slotModifiedChanged( true ); |
2515 | 2517 | ||
2516 | } | 2518 | } |
2517 | 2519 | ||
2518 | void MainWindow::printSel( ) | 2520 | void MainWindow::printSel( ) |
2519 | { | 2521 | { |
2520 | mView->viewManager()->agendaView()->agenda()->printSelection(); | 2522 | mView->viewManager()->agendaView()->agenda()->printSelection(); |
2521 | } | 2523 | } |
2522 | 2524 | ||
2523 | void MainWindow::printCal() | 2525 | void MainWindow::printCal() |
2524 | { | 2526 | { |
2525 | mView->print();//mCp->showDialog(); | 2527 | mView->print();//mCp->showDialog(); |
2526 | } | 2528 | } |
2527 | 2529 | ||
2528 | 2530 | ||
2529 | 2531 | ||
2530 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 2532 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
2531 | { | 2533 | { |
2532 | mPassWord = pw; | 2534 | mPassWord = pw; |
2533 | mSocket = 0; | 2535 | mSocket = 0; |
2534 | }; | 2536 | }; |
2535 | 2537 | ||
2536 | void KServerSocket::newConnection ( int socket ) | 2538 | void KServerSocket::newConnection ( int socket ) |
2537 | { | 2539 | { |
2538 | qDebug("KServerSocket:New connection %d ", socket); | 2540 | qDebug("KServerSocket:New connection %d ", socket); |
2539 | if ( mSocket ) { | 2541 | if ( mSocket ) { |
2540 | qDebug("KServerSocket::newConnection Socket deleted! "); | 2542 | qDebug("KServerSocket::newConnection Socket deleted! "); |
2541 | delete mSocket; | 2543 | delete mSocket; |
2542 | mSocket = 0; | 2544 | mSocket = 0; |
2543 | } | 2545 | } |
2544 | mSocket = new QSocket( this ); | 2546 | mSocket = new QSocket( this ); |
2545 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 2547 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
2546 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 2548 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
2547 | mSocket->setSocket( socket ); | 2549 | mSocket->setSocket( socket ); |
2548 | } | 2550 | } |
2549 | 2551 | ||
2550 | void KServerSocket::discardClient() | 2552 | void KServerSocket::discardClient() |
2551 | { | 2553 | { |
2552 | qDebug(" KServerSocket::discardClient()"); | 2554 | qDebug(" KServerSocket::discardClient()"); |
2553 | if ( mSocket ) { | 2555 | if ( mSocket ) { |
2554 | qDebug("delete "); | 2556 | qDebug("delete "); |
2555 | delete mSocket; | 2557 | delete mSocket; |
2556 | mSocket = 0; | 2558 | mSocket = 0; |
2557 | } | 2559 | } |
2558 | //emit endConnect(); | 2560 | //emit endConnect(); |
2559 | } | 2561 | } |
2560 | void KServerSocket::readClient() | 2562 | void KServerSocket::readClient() |
2561 | { | 2563 | { |
2562 | if ( mSocket == 0 ) { | 2564 | if ( mSocket == 0 ) { |
2563 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); | 2565 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); |
2564 | return; | 2566 | return; |
2565 | } | 2567 | } |
2566 | qDebug("KServerSocket readClient()"); | 2568 | qDebug("KServerSocket readClient()"); |
2567 | if ( mSocket->canReadLine() ) { | 2569 | if ( mSocket->canReadLine() ) { |
2568 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), mSocket->readLine() ); | 2570 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), mSocket->readLine() ); |
2569 | qDebug("KServerSocket socket->canReadLine()"); | 2571 | qDebug("KServerSocket socket->canReadLine()"); |
2570 | if ( tokens[0] == "GET" ) { | 2572 | if ( tokens[0] == "GET" ) { |
2571 | if ( tokens[1] == mPassWord ) | 2573 | if ( tokens[1] == mPassWord ) |
2572 | emit sendFile( mSocket ); | 2574 | emit sendFile( mSocket ); |
2573 | else { | 2575 | else { |
2574 | KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); | 2576 | KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); |
2575 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 2577 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
2576 | } | 2578 | } |
2577 | } | 2579 | } |
2578 | if ( tokens[0] == "PUT" ) { | 2580 | if ( tokens[0] == "PUT" ) { |
2579 | if ( tokens[1] == mPassWord ) | 2581 | if ( tokens[1] == mPassWord ) |
2580 | emit getFile( mSocket ); | 2582 | emit getFile( mSocket ); |
2581 | else { | 2583 | else { |
2582 | KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); | 2584 | KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); |
2583 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 2585 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
2584 | } | 2586 | } |
2585 | } | 2587 | } |
2586 | if ( tokens[0] == "STOP" ) { | 2588 | if ( tokens[0] == "STOP" ) { |
2587 | emit endConnect(); | 2589 | emit endConnect(); |
2588 | } | 2590 | } |
2589 | } | 2591 | } |
2590 | } | 2592 | } |
2591 | 2593 | ||
2592 | 2594 | ||
2593 | 2595 | ||
2594 | 2596 | ||
2595 | 2597 | ||
2596 | 2598 | ||
2597 | 2599 | ||
2598 | 2600 | ||
2599 | 2601 | ||
2600 | 2602 | ||
2601 | 2603 | ||
2602 | 2604 | ||