author | zautrix <zautrix> | 2004-09-18 08:51:10 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-18 08:51:10 (UTC) |
commit | 4ec7c78ebd2c5a79ff224e9b07d9a3164f7fe602 (patch) (unidiff) | |
tree | 0beaebd8819f1fc4a36fb8fc115ff97ac43c3db3 | |
parent | 983b010853dfadfec3638e2afd90e522985f67fb (diff) | |
download | kdepimpi-4ec7c78ebd2c5a79ff224e9b07d9a3164f7fe602.zip kdepimpi-4ec7c78ebd2c5a79ff224e9b07d9a3164f7fe602.tar.gz kdepimpi-4ec7c78ebd2c5a79ff224e9b07d9a3164f7fe602.tar.bz2 |
more AB sync
-rw-r--r-- | kaddressbook/kabcore.cpp | 293 |
1 files changed, 277 insertions, 16 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index e912941..1196360 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -1750,863 +1750,1124 @@ void KABCore::initActions() | |||
1750 | // KDE uses a XML format to plug the actions, but we work her without this overhead. | 1750 | // KDE uses a XML format to plug the actions, but we work her without this overhead. |
1751 | void KABCore::addActionsManually() | 1751 | void KABCore::addActionsManually() |
1752 | { | 1752 | { |
1753 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); | 1753 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); |
1754 | 1754 | ||
1755 | #ifdef KAB_EMBEDDED | 1755 | #ifdef KAB_EMBEDDED |
1756 | QPopupMenu *fileMenu = new QPopupMenu( this ); | 1756 | QPopupMenu *fileMenu = new QPopupMenu( this ); |
1757 | QPopupMenu *editMenu = new QPopupMenu( this ); | 1757 | QPopupMenu *editMenu = new QPopupMenu( this ); |
1758 | QPopupMenu *helpMenu = new QPopupMenu( this ); | 1758 | QPopupMenu *helpMenu = new QPopupMenu( this ); |
1759 | 1759 | ||
1760 | KToolBar* tb = mMainWindow->toolBar(); | 1760 | KToolBar* tb = mMainWindow->toolBar(); |
1761 | 1761 | ||
1762 | #ifdef DESKTOP_VERSION | 1762 | #ifdef DESKTOP_VERSION |
1763 | QMenuBar* mb = mMainWindow->menuBar(); | 1763 | QMenuBar* mb = mMainWindow->menuBar(); |
1764 | 1764 | ||
1765 | //US setup menubar. | 1765 | //US setup menubar. |
1766 | //Disable the following block if you do not want to have a menubar. | 1766 | //Disable the following block if you do not want to have a menubar. |
1767 | mb->insertItem( "&File", fileMenu ); | 1767 | mb->insertItem( "&File", fileMenu ); |
1768 | mb->insertItem( "&Edit", editMenu ); | 1768 | mb->insertItem( "&Edit", editMenu ); |
1769 | mb->insertItem( "&View", viewMenu ); | 1769 | mb->insertItem( "&View", viewMenu ); |
1770 | mb->insertItem( "&Settings", settingsMenu ); | 1770 | mb->insertItem( "&Settings", settingsMenu ); |
1771 | mb->insertItem( i18n("Synchronize"), syncMenu ); | 1771 | mb->insertItem( i18n("Synchronize"), syncMenu ); |
1772 | mb->insertItem( "&Change selected", changeMenu ); | 1772 | mb->insertItem( "&Change selected", changeMenu ); |
1773 | mb->insertItem( "&Help", helpMenu ); | 1773 | mb->insertItem( "&Help", helpMenu ); |
1774 | mIncSearchWidget = new IncSearchWidget( tb ); | 1774 | mIncSearchWidget = new IncSearchWidget( tb ); |
1775 | // tb->insertWidget(-1, 0, mIncSearchWidget); | 1775 | // tb->insertWidget(-1, 0, mIncSearchWidget); |
1776 | 1776 | ||
1777 | #else | 1777 | #else |
1778 | //US setup toolbar | 1778 | //US setup toolbar |
1779 | QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); | 1779 | QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); |
1780 | QPopupMenu *popupBarTB = new QPopupMenu( this ); | 1780 | QPopupMenu *popupBarTB = new QPopupMenu( this ); |
1781 | menuBarTB->insertItem( "ME", popupBarTB); | 1781 | menuBarTB->insertItem( "ME", popupBarTB); |
1782 | tb->insertWidget(-1, 0, menuBarTB); | 1782 | tb->insertWidget(-1, 0, menuBarTB); |
1783 | mIncSearchWidget = new IncSearchWidget( tb ); | 1783 | mIncSearchWidget = new IncSearchWidget( tb ); |
1784 | 1784 | ||
1785 | tb->enableMoving(false); | 1785 | tb->enableMoving(false); |
1786 | popupBarTB->insertItem( "&File", fileMenu ); | 1786 | popupBarTB->insertItem( "&File", fileMenu ); |
1787 | popupBarTB->insertItem( "&Edit", editMenu ); | 1787 | popupBarTB->insertItem( "&Edit", editMenu ); |
1788 | popupBarTB->insertItem( "&View", viewMenu ); | 1788 | popupBarTB->insertItem( "&View", viewMenu ); |
1789 | popupBarTB->insertItem( "&Settings", settingsMenu ); | 1789 | popupBarTB->insertItem( "&Settings", settingsMenu ); |
1790 | popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); | 1790 | popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); |
1791 | mViewManager->getFilterAction()->plug ( popupBarTB); | 1791 | mViewManager->getFilterAction()->plug ( popupBarTB); |
1792 | popupBarTB->insertItem( "&Change selected", changeMenu ); | 1792 | popupBarTB->insertItem( "&Change selected", changeMenu ); |
1793 | popupBarTB->insertItem( "&Help", helpMenu ); | 1793 | popupBarTB->insertItem( "&Help", helpMenu ); |
1794 | if (QApplication::desktop()->width() > 320 ) { | 1794 | if (QApplication::desktop()->width() > 320 ) { |
1795 | // mViewManager->getFilterAction()->plug ( tb); | 1795 | // mViewManager->getFilterAction()->plug ( tb); |
1796 | } | 1796 | } |
1797 | #endif | 1797 | #endif |
1798 | // mActionQuit->plug ( mMainWindow->toolBar()); | 1798 | // mActionQuit->plug ( mMainWindow->toolBar()); |
1799 | 1799 | ||
1800 | 1800 | ||
1801 | 1801 | ||
1802 | //US Now connect the actions with the menue entries. | 1802 | //US Now connect the actions with the menue entries. |
1803 | mActionPrint->plug( fileMenu ); | 1803 | mActionPrint->plug( fileMenu ); |
1804 | mActionMail->plug( fileMenu ); | 1804 | mActionMail->plug( fileMenu ); |
1805 | fileMenu->insertSeparator(); | 1805 | fileMenu->insertSeparator(); |
1806 | 1806 | ||
1807 | mActionNewContact->plug( fileMenu ); | 1807 | mActionNewContact->plug( fileMenu ); |
1808 | mActionNewContact->plug( tb ); | 1808 | mActionNewContact->plug( tb ); |
1809 | 1809 | ||
1810 | mActionEditAddressee->plug( fileMenu ); | 1810 | mActionEditAddressee->plug( fileMenu ); |
1811 | if ((KGlobal::getDesktopSize() > KGlobal::Small ) || | 1811 | if ((KGlobal::getDesktopSize() > KGlobal::Small ) || |
1812 | (!KABPrefs::instance()->mMultipleViewsAtOnce )) | 1812 | (!KABPrefs::instance()->mMultipleViewsAtOnce )) |
1813 | mActionEditAddressee->plug( tb ); | 1813 | mActionEditAddressee->plug( tb ); |
1814 | 1814 | ||
1815 | fileMenu->insertSeparator(); | 1815 | fileMenu->insertSeparator(); |
1816 | mActionSave->plug( fileMenu ); | 1816 | mActionSave->plug( fileMenu ); |
1817 | fileMenu->insertItem( "&Import", ImportMenu ); | 1817 | fileMenu->insertItem( "&Import", ImportMenu ); |
1818 | fileMenu->insertItem( "&Export", ExportMenu ); | 1818 | fileMenu->insertItem( "&Export", ExportMenu ); |
1819 | fileMenu->insertSeparator(); | 1819 | fileMenu->insertSeparator(); |
1820 | mActionMailVCard->plug( fileMenu ); | 1820 | mActionMailVCard->plug( fileMenu ); |
1821 | #ifndef DESKTOP_VERSION | 1821 | #ifndef DESKTOP_VERSION |
1822 | if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); | 1822 | if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); |
1823 | if ( Ir::supported() ) mActionBeam->plug(fileMenu ); | 1823 | if ( Ir::supported() ) mActionBeam->plug(fileMenu ); |
1824 | #endif | 1824 | #endif |
1825 | fileMenu->insertSeparator(); | 1825 | fileMenu->insertSeparator(); |
1826 | mActionQuit->plug( fileMenu ); | 1826 | mActionQuit->plug( fileMenu ); |
1827 | #ifdef _WIN32_ | 1827 | #ifdef _WIN32_ |
1828 | mActionImportOL->plug( ImportMenu ); | 1828 | mActionImportOL->plug( ImportMenu ); |
1829 | #endif | 1829 | #endif |
1830 | // edit menu | 1830 | // edit menu |
1831 | mActionUndo->plug( editMenu ); | 1831 | mActionUndo->plug( editMenu ); |
1832 | mActionRedo->plug( editMenu ); | 1832 | mActionRedo->plug( editMenu ); |
1833 | editMenu->insertSeparator(); | 1833 | editMenu->insertSeparator(); |
1834 | mActionCut->plug( editMenu ); | 1834 | mActionCut->plug( editMenu ); |
1835 | mActionCopy->plug( editMenu ); | 1835 | mActionCopy->plug( editMenu ); |
1836 | mActionPaste->plug( editMenu ); | 1836 | mActionPaste->plug( editMenu ); |
1837 | mActionDelete->plug( editMenu ); | 1837 | mActionDelete->plug( editMenu ); |
1838 | editMenu->insertSeparator(); | 1838 | editMenu->insertSeparator(); |
1839 | mActionSelectAll->plug( editMenu ); | 1839 | mActionSelectAll->plug( editMenu ); |
1840 | 1840 | ||
1841 | mActionRemoveVoice->plug( changeMenu ); | 1841 | mActionRemoveVoice->plug( changeMenu ); |
1842 | // settings menu | 1842 | // settings menu |
1843 | //US special menuentry to configure the addressbook resources. On KDE | 1843 | //US special menuentry to configure the addressbook resources. On KDE |
1844 | // you do that through the control center !!! | 1844 | // you do that through the control center !!! |
1845 | mActionConfigResources->plug( settingsMenu ); | 1845 | mActionConfigResources->plug( settingsMenu ); |
1846 | settingsMenu->insertSeparator(); | 1846 | settingsMenu->insertSeparator(); |
1847 | 1847 | ||
1848 | mActionConfigKAddressbook->plug( settingsMenu ); | 1848 | mActionConfigKAddressbook->plug( settingsMenu ); |
1849 | 1849 | ||
1850 | if ( mIsPart ) { | 1850 | if ( mIsPart ) { |
1851 | mActionConfigShortcuts->plug( settingsMenu ); | 1851 | mActionConfigShortcuts->plug( settingsMenu ); |
1852 | mActionConfigureToolbars->plug( settingsMenu ); | 1852 | mActionConfigureToolbars->plug( settingsMenu ); |
1853 | 1853 | ||
1854 | } else { | 1854 | } else { |
1855 | mActionKeyBindings->plug( settingsMenu ); | 1855 | mActionKeyBindings->plug( settingsMenu ); |
1856 | } | 1856 | } |
1857 | 1857 | ||
1858 | settingsMenu->insertSeparator(); | 1858 | settingsMenu->insertSeparator(); |
1859 | 1859 | ||
1860 | mActionJumpBar->plug( settingsMenu ); | 1860 | mActionJumpBar->plug( settingsMenu ); |
1861 | mActionDetails->plug( settingsMenu ); | 1861 | mActionDetails->plug( settingsMenu ); |
1862 | if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) | 1862 | if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) |
1863 | mActionDetails->plug( tb ); | 1863 | mActionDetails->plug( tb ); |
1864 | settingsMenu->insertSeparator(); | 1864 | settingsMenu->insertSeparator(); |
1865 | 1865 | ||
1866 | mActionWhoAmI->plug( settingsMenu ); | 1866 | mActionWhoAmI->plug( settingsMenu ); |
1867 | mActionCategories->plug( settingsMenu ); | 1867 | mActionCategories->plug( settingsMenu ); |
1868 | 1868 | ||
1869 | mActionLicence->plug( helpMenu ); | 1869 | mActionLicence->plug( helpMenu ); |
1870 | mActionFaq->plug( helpMenu ); | 1870 | mActionFaq->plug( helpMenu ); |
1871 | mActionAboutKAddressbook->plug( helpMenu ); | 1871 | mActionAboutKAddressbook->plug( helpMenu ); |
1872 | 1872 | ||
1873 | if (KGlobal::getDesktopSize() > KGlobal::Small ) { | 1873 | if (KGlobal::getDesktopSize() > KGlobal::Small ) { |
1874 | 1874 | ||
1875 | mActionSave->plug( tb ); | 1875 | mActionSave->plug( tb ); |
1876 | mViewManager->getFilterAction()->plug ( tb); | 1876 | mViewManager->getFilterAction()->plug ( tb); |
1877 | if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { | 1877 | if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { |
1878 | mActionUndo->plug( tb ); | 1878 | mActionUndo->plug( tb ); |
1879 | mActionDelete->plug( tb ); | 1879 | mActionDelete->plug( tb ); |
1880 | mActionRedo->plug( tb ); | 1880 | mActionRedo->plug( tb ); |
1881 | } | 1881 | } |
1882 | } | 1882 | } |
1883 | //mActionQuit->plug ( tb ); | 1883 | //mActionQuit->plug ( tb ); |
1884 | // tb->insertWidget(-1, 0, mIncSearchWidget, 6); | 1884 | // tb->insertWidget(-1, 0, mIncSearchWidget, 6); |
1885 | 1885 | ||
1886 | //US link the searchwidget first to this. | 1886 | //US link the searchwidget first to this. |
1887 | // The real linkage to the toolbar happens later. | 1887 | // The real linkage to the toolbar happens later. |
1888 | //US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); | 1888 | //US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); |
1889 | //US tb->insertItem( mIncSearchWidget ); | 1889 | //US tb->insertItem( mIncSearchWidget ); |
1890 | /*US | 1890 | /*US |
1891 | mIncSearchWidget = new IncSearchWidget( tb ); | 1891 | mIncSearchWidget = new IncSearchWidget( tb ); |
1892 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), | 1892 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), |
1893 | SLOT( incrementalSearch( const QString& ) ) ); | 1893 | SLOT( incrementalSearch( const QString& ) ) ); |
1894 | 1894 | ||
1895 | mJumpButtonBar = new JumpButtonBar( this, this ); | 1895 | mJumpButtonBar = new JumpButtonBar( this, this ); |
1896 | 1896 | ||
1897 | //US topLayout->addWidget( mJumpButtonBar ); | 1897 | //US topLayout->addWidget( mJumpButtonBar ); |
1898 | this->layout()->add( mJumpButtonBar ); | 1898 | this->layout()->add( mJumpButtonBar ); |
1899 | */ | 1899 | */ |
1900 | 1900 | ||
1901 | #endif //KAB_EMBEDDED | 1901 | #endif //KAB_EMBEDDED |
1902 | 1902 | ||
1903 | connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) ); | 1903 | connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) ); |
1904 | fillSyncMenu(); | 1904 | fillSyncMenu(); |
1905 | 1905 | ||
1906 | } | 1906 | } |
1907 | void KABCore::showLicence() | 1907 | void KABCore::showLicence() |
1908 | { | 1908 | { |
1909 | KApplication::showLicence(); | 1909 | KApplication::showLicence(); |
1910 | } | 1910 | } |
1911 | void KABCore::removeVoice() | 1911 | void KABCore::removeVoice() |
1912 | { | 1912 | { |
1913 | if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) | 1913 | if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) |
1914 | return; | 1914 | return; |
1915 | KABC::Addressee::List list = mViewManager->selectedAddressees(); | 1915 | KABC::Addressee::List list = mViewManager->selectedAddressees(); |
1916 | KABC::Addressee::List::Iterator it; | 1916 | KABC::Addressee::List::Iterator it; |
1917 | for ( it = list.begin(); it != list.end(); ++it ) { | 1917 | for ( it = list.begin(); it != list.end(); ++it ) { |
1918 | PhoneNumber::List phoneNumbers = (*it).phoneNumbers(); | 1918 | PhoneNumber::List phoneNumbers = (*it).phoneNumbers(); |
1919 | PhoneNumber::List::Iterator phoneIt; | 1919 | PhoneNumber::List::Iterator phoneIt; |
1920 | bool found = false; | 1920 | bool found = false; |
1921 | for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { | 1921 | for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { |
1922 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found | 1922 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found |
1923 | if ((*phoneIt).type() - PhoneNumber::Voice ) { | 1923 | if ((*phoneIt).type() - PhoneNumber::Voice ) { |
1924 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); | 1924 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); |
1925 | (*it).insertPhoneNumber( (*phoneIt) ); | 1925 | (*it).insertPhoneNumber( (*phoneIt) ); |
1926 | found = true; | 1926 | found = true; |
1927 | } | 1927 | } |
1928 | } | 1928 | } |
1929 | 1929 | ||
1930 | } | 1930 | } |
1931 | if ( found ) | 1931 | if ( found ) |
1932 | contactModified((*it) ); | 1932 | contactModified((*it) ); |
1933 | } | 1933 | } |
1934 | } | 1934 | } |
1935 | 1935 | ||
1936 | 1936 | ||
1937 | 1937 | ||
1938 | void KABCore::clipboardDataChanged() | 1938 | void KABCore::clipboardDataChanged() |
1939 | { | 1939 | { |
1940 | 1940 | ||
1941 | if ( mReadWrite ) | 1941 | if ( mReadWrite ) |
1942 | mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); | 1942 | mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); |
1943 | 1943 | ||
1944 | } | 1944 | } |
1945 | 1945 | ||
1946 | void KABCore::updateActionMenu() | 1946 | void KABCore::updateActionMenu() |
1947 | { | 1947 | { |
1948 | UndoStack *undo = UndoStack::instance(); | 1948 | UndoStack *undo = UndoStack::instance(); |
1949 | RedoStack *redo = RedoStack::instance(); | 1949 | RedoStack *redo = RedoStack::instance(); |
1950 | 1950 | ||
1951 | if ( undo->isEmpty() ) | 1951 | if ( undo->isEmpty() ) |
1952 | mActionUndo->setText( i18n( "Undo" ) ); | 1952 | mActionUndo->setText( i18n( "Undo" ) ); |
1953 | else | 1953 | else |
1954 | mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); | 1954 | mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); |
1955 | 1955 | ||
1956 | mActionUndo->setEnabled( !undo->isEmpty() ); | 1956 | mActionUndo->setEnabled( !undo->isEmpty() ); |
1957 | 1957 | ||
1958 | if ( !redo->top() ) | 1958 | if ( !redo->top() ) |
1959 | mActionRedo->setText( i18n( "Redo" ) ); | 1959 | mActionRedo->setText( i18n( "Redo" ) ); |
1960 | else | 1960 | else |
1961 | mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); | 1961 | mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); |
1962 | 1962 | ||
1963 | mActionRedo->setEnabled( !redo->isEmpty() ); | 1963 | mActionRedo->setEnabled( !redo->isEmpty() ); |
1964 | } | 1964 | } |
1965 | 1965 | ||
1966 | void KABCore::configureKeyBindings() | 1966 | void KABCore::configureKeyBindings() |
1967 | { | 1967 | { |
1968 | #ifndef KAB_EMBEDDED | 1968 | #ifndef KAB_EMBEDDED |
1969 | KKeyDialog::configure( actionCollection(), true ); | 1969 | KKeyDialog::configure( actionCollection(), true ); |
1970 | #else //KAB_EMBEDDED | 1970 | #else //KAB_EMBEDDED |
1971 | qDebug("KABCore::configureKeyBindings() not implemented"); | 1971 | qDebug("KABCore::configureKeyBindings() not implemented"); |
1972 | #endif //KAB_EMBEDDED | 1972 | #endif //KAB_EMBEDDED |
1973 | } | 1973 | } |
1974 | 1974 | ||
1975 | #ifdef KAB_EMBEDDED | 1975 | #ifdef KAB_EMBEDDED |
1976 | void KABCore::configureResources() | 1976 | void KABCore::configureResources() |
1977 | { | 1977 | { |
1978 | KRES::KCMKResources dlg( this, "" , 0 ); | 1978 | KRES::KCMKResources dlg( this, "" , 0 ); |
1979 | 1979 | ||
1980 | if ( !dlg.exec() ) | 1980 | if ( !dlg.exec() ) |
1981 | return; | 1981 | return; |
1982 | KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); | 1982 | KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); |
1983 | } | 1983 | } |
1984 | #endif //KAB_EMBEDDED | 1984 | #endif //KAB_EMBEDDED |
1985 | 1985 | ||
1986 | 1986 | ||
1987 | /* this method will be called through the QCop interface from Ko/Pi to select addresses | 1987 | /* this method will be called through the QCop interface from Ko/Pi to select addresses |
1988 | * for the attendees list of an event. | 1988 | * for the attendees list of an event. |
1989 | */ | 1989 | */ |
1990 | void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) | 1990 | void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) |
1991 | { | 1991 | { |
1992 | QStringList nameList; | 1992 | QStringList nameList; |
1993 | QStringList emailList; | 1993 | QStringList emailList; |
1994 | QStringList uidList; | 1994 | QStringList uidList; |
1995 | 1995 | ||
1996 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); | 1996 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); |
1997 | uint i=0; | 1997 | uint i=0; |
1998 | for (i=0; i < list.count(); i++) | 1998 | for (i=0; i < list.count(); i++) |
1999 | { | 1999 | { |
2000 | nameList.append(list[i].realName()); | 2000 | nameList.append(list[i].realName()); |
2001 | emailList.append(list[i].preferredEmail()); | 2001 | emailList.append(list[i].preferredEmail()); |
2002 | uidList.append(list[i].uid()); | 2002 | uidList.append(list[i].uid()); |
2003 | } | 2003 | } |
2004 | 2004 | ||
2005 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); | 2005 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); |
2006 | 2006 | ||
2007 | } | 2007 | } |
2008 | 2008 | ||
2009 | /* this method will be called through the QCop interface from other apps to show details of a contact. | 2009 | /* this method will be called through the QCop interface from other apps to show details of a contact. |
2010 | */ | 2010 | */ |
2011 | void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) | 2011 | void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) |
2012 | { | 2012 | { |
2013 | qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); | 2013 | qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); |
2014 | 2014 | ||
2015 | QString foundUid = QString::null; | 2015 | QString foundUid = QString::null; |
2016 | if ( ! uid.isEmpty() ) { | 2016 | if ( ! uid.isEmpty() ) { |
2017 | Addressee adrr = mAddressBook->findByUid( uid ); | 2017 | Addressee adrr = mAddressBook->findByUid( uid ); |
2018 | if ( !adrr.isEmpty() ) { | 2018 | if ( !adrr.isEmpty() ) { |
2019 | foundUid = uid; | 2019 | foundUid = uid; |
2020 | } | 2020 | } |
2021 | if ( email == "sendbacklist" ) { | 2021 | if ( email == "sendbacklist" ) { |
2022 | //qDebug("ssssssssssssssssssssssend "); | 2022 | //qDebug("ssssssssssssssssssssssend "); |
2023 | QStringList nameList; | 2023 | QStringList nameList; |
2024 | QStringList emailList; | 2024 | QStringList emailList; |
2025 | QStringList uidList; | 2025 | QStringList uidList; |
2026 | nameList.append(adrr.realName()); | 2026 | nameList.append(adrr.realName()); |
2027 | emailList = adrr.emails(); | 2027 | emailList = adrr.emails(); |
2028 | uidList.append( adrr.preferredEmail()); | 2028 | uidList.append( adrr.preferredEmail()); |
2029 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); | 2029 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); |
2030 | return; | 2030 | return; |
2031 | } | 2031 | } |
2032 | 2032 | ||
2033 | } | 2033 | } |
2034 | 2034 | ||
2035 | if ( email == "sendbacklist" ) | 2035 | if ( email == "sendbacklist" ) |
2036 | return; | 2036 | return; |
2037 | if (foundUid.isEmpty()) | 2037 | if (foundUid.isEmpty()) |
2038 | { | 2038 | { |
2039 | //find the uid of the person first | 2039 | //find the uid of the person first |
2040 | Addressee::List namelist; | 2040 | Addressee::List namelist; |
2041 | Addressee::List emaillist; | 2041 | Addressee::List emaillist; |
2042 | 2042 | ||
2043 | if (!name.isEmpty()) | 2043 | if (!name.isEmpty()) |
2044 | namelist = mAddressBook->findByName( name ); | 2044 | namelist = mAddressBook->findByName( name ); |
2045 | 2045 | ||
2046 | if (!email.isEmpty()) | 2046 | if (!email.isEmpty()) |
2047 | emaillist = mAddressBook->findByEmail( email ); | 2047 | emaillist = mAddressBook->findByEmail( email ); |
2048 | qDebug("count %d %d ", namelist.count(),emaillist.count() ); | 2048 | qDebug("count %d %d ", namelist.count(),emaillist.count() ); |
2049 | //check if we have a match in Namelist and Emaillist | 2049 | //check if we have a match in Namelist and Emaillist |
2050 | if ((namelist.count() == 0) && (emaillist.count() > 0)) { | 2050 | if ((namelist.count() == 0) && (emaillist.count() > 0)) { |
2051 | foundUid = emaillist[0].uid(); | 2051 | foundUid = emaillist[0].uid(); |
2052 | } | 2052 | } |
2053 | else if ((namelist.count() > 0) && (emaillist.count() == 0)) | 2053 | else if ((namelist.count() > 0) && (emaillist.count() == 0)) |
2054 | foundUid = namelist[0].uid(); | 2054 | foundUid = namelist[0].uid(); |
2055 | else | 2055 | else |
2056 | { | 2056 | { |
2057 | for (int i = 0; i < namelist.count(); i++) | 2057 | for (int i = 0; i < namelist.count(); i++) |
2058 | { | 2058 | { |
2059 | for (int j = 0; j < emaillist.count(); j++) | 2059 | for (int j = 0; j < emaillist.count(); j++) |
2060 | { | 2060 | { |
2061 | if (namelist[i] == emaillist[j]) | 2061 | if (namelist[i] == emaillist[j]) |
2062 | { | 2062 | { |
2063 | foundUid = namelist[i].uid(); | 2063 | foundUid = namelist[i].uid(); |
2064 | } | 2064 | } |
2065 | } | 2065 | } |
2066 | } | 2066 | } |
2067 | } | 2067 | } |
2068 | } | 2068 | } |
2069 | else | 2069 | else |
2070 | { | 2070 | { |
2071 | foundUid = uid; | 2071 | foundUid = uid; |
2072 | } | 2072 | } |
2073 | 2073 | ||
2074 | if (!foundUid.isEmpty()) | 2074 | if (!foundUid.isEmpty()) |
2075 | { | 2075 | { |
2076 | 2076 | ||
2077 | // raise Ka/Pi if it is in the background | 2077 | // raise Ka/Pi if it is in the background |
2078 | #ifndef DESKTOP_VERSION | 2078 | #ifndef DESKTOP_VERSION |
2079 | #ifndef KORG_NODCOP | 2079 | #ifndef KORG_NODCOP |
2080 | //QCopEnvelope e("QPE/Application/kapi", "raise()"); | 2080 | //QCopEnvelope e("QPE/Application/kapi", "raise()"); |
2081 | #endif | 2081 | #endif |
2082 | #endif | 2082 | #endif |
2083 | 2083 | ||
2084 | mMainWindow->showMaximized(); | 2084 | mMainWindow->showMaximized(); |
2085 | mMainWindow-> raise(); | 2085 | mMainWindow-> raise(); |
2086 | 2086 | ||
2087 | mViewManager->setSelected( "", false); | 2087 | mViewManager->setSelected( "", false); |
2088 | mViewManager->refreshView( "" ); | 2088 | mViewManager->refreshView( "" ); |
2089 | mViewManager->setSelected( foundUid, true ); | 2089 | mViewManager->setSelected( foundUid, true ); |
2090 | mViewManager->refreshView( foundUid ); | 2090 | mViewManager->refreshView( foundUid ); |
2091 | 2091 | ||
2092 | if ( !mMultipleViewsAtOnce ) | 2092 | if ( !mMultipleViewsAtOnce ) |
2093 | { | 2093 | { |
2094 | setDetailsVisible( true ); | 2094 | setDetailsVisible( true ); |
2095 | mActionDetails->setChecked(true); | 2095 | mActionDetails->setChecked(true); |
2096 | } | 2096 | } |
2097 | } | 2097 | } |
2098 | } | 2098 | } |
2099 | 2099 | ||
2100 | 2100 | ||
2101 | void KABCore::faq() | 2101 | void KABCore::faq() |
2102 | { | 2102 | { |
2103 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); | 2103 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); |
2104 | } | 2104 | } |
2105 | 2105 | ||
2106 | 2106 | ||
2107 | void KABCore::fillSyncMenu() | 2107 | void KABCore::fillSyncMenu() |
2108 | { | 2108 | { |
2109 | if ( syncMenu->count() ) | 2109 | if ( syncMenu->count() ) |
2110 | syncMenu->clear(); | 2110 | syncMenu->clear(); |
2111 | syncMenu->insertItem( i18n("Configure..."), 0 ); | 2111 | syncMenu->insertItem( i18n("Configure..."), 0 ); |
2112 | syncMenu->insertSeparator(); | 2112 | syncMenu->insertSeparator(); |
2113 | syncMenu->insertItem( i18n("Multiple sync"), 1 ); | 2113 | syncMenu->insertItem( i18n("Multiple sync"), 1 ); |
2114 | syncMenu->insertSeparator(); | 2114 | syncMenu->insertSeparator(); |
2115 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 2115 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
2116 | config.setGroup("General"); | 2116 | config.setGroup("General"); |
2117 | QStringList prof = config.readListEntry("SyncProfileNames"); | 2117 | QStringList prof = config.readListEntry("SyncProfileNames"); |
2118 | KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 2118 | KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
2119 | if ( prof.count() < 3 ) { | 2119 | if ( prof.count() < 3 ) { |
2120 | prof.clear(); | 2120 | prof.clear(); |
2121 | prof << i18n("Sharp_DTM"); | 2121 | prof << i18n("Sharp_DTM"); |
2122 | prof << i18n("Local_file"); | 2122 | prof << i18n("Local_file"); |
2123 | prof << i18n("Last_file"); | 2123 | prof << i18n("Last_file"); |
2124 | KSyncProfile* temp = new KSyncProfile (); | 2124 | KSyncProfile* temp = new KSyncProfile (); |
2125 | temp->setName( prof[0] ); | 2125 | temp->setName( prof[0] ); |
2126 | temp->writeConfig(&config); | 2126 | temp->writeConfig(&config); |
2127 | temp->setName( prof[1] ); | 2127 | temp->setName( prof[1] ); |
2128 | temp->writeConfig(&config); | 2128 | temp->writeConfig(&config); |
2129 | temp->setName( prof[2] ); | 2129 | temp->setName( prof[2] ); |
2130 | temp->writeConfig(&config); | 2130 | temp->writeConfig(&config); |
2131 | config.setGroup("General"); | 2131 | config.setGroup("General"); |
2132 | config.writeEntry("SyncProfileNames",prof); | 2132 | config.writeEntry("SyncProfileNames",prof); |
2133 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); | 2133 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); |
2134 | config.sync(); | 2134 | config.sync(); |
2135 | delete temp; | 2135 | delete temp; |
2136 | } | 2136 | } |
2137 | KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 2137 | KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
2138 | KABPrefs::instance()->mSyncProfileNames = prof; | 2138 | KABPrefs::instance()->mSyncProfileNames = prof; |
2139 | int i; | 2139 | int i; |
2140 | for ( i = 0; i < prof.count(); ++i ) { | 2140 | for ( i = 0; i < prof.count(); ++i ) { |
2141 | 2141 | ||
2142 | syncMenu->insertItem( prof[i], 1000+i ); | 2142 | syncMenu->insertItem( prof[i], 1000+i ); |
2143 | if ( i == 2 ) | 2143 | if ( i == 2 ) |
2144 | syncMenu->insertSeparator(); | 2144 | syncMenu->insertSeparator(); |
2145 | } | 2145 | } |
2146 | QDir app_dir; | 2146 | QDir app_dir; |
2147 | if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | 2147 | if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { |
2148 | syncMenu->setItemEnabled( false , 1000 ); | 2148 | syncMenu->setItemEnabled( false , 1000 ); |
2149 | } | 2149 | } |
2150 | //probaly useless | 2150 | //probaly useless |
2151 | //mView->setupExternSyncProfiles(); | 2151 | //mView->setupExternSyncProfiles(); |
2152 | } | 2152 | } |
2153 | void KABCore::slotSyncMenu( int action ) | 2153 | void KABCore::slotSyncMenu( int action ) |
2154 | { | 2154 | { |
2155 | //qDebug("syncaction %d ", action); | 2155 | //qDebug("syncaction %d ", action); |
2156 | if ( action == 0 ) { | 2156 | if ( action == 0 ) { |
2157 | 2157 | ||
2158 | // seems to be a Qt2 event handling bug | 2158 | // seems to be a Qt2 event handling bug |
2159 | // syncmenu.clear causes a segfault at first time | 2159 | // syncmenu.clear causes a segfault at first time |
2160 | // when we call it after the main event loop, it is ok | 2160 | // when we call it after the main event loop, it is ok |
2161 | // same behaviour when calling OM/Pi via QCOP for the first time | 2161 | // same behaviour when calling OM/Pi via QCOP for the first time |
2162 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | 2162 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); |
2163 | //confSync(); | 2163 | //confSync(); |
2164 | 2164 | ||
2165 | return; | 2165 | return; |
2166 | } | 2166 | } |
2167 | if ( action == 1 ) { | 2167 | if ( action == 1 ) { |
2168 | multiSync( true ); | 2168 | multiSync( true ); |
2169 | return; | 2169 | return; |
2170 | } | 2170 | } |
2171 | 2171 | ||
2172 | if (mBlockSaveFlag) | 2172 | if (mBlockSaveFlag) |
2173 | return; | 2173 | return; |
2174 | mBlockSaveFlag = true; | 2174 | mBlockSaveFlag = true; |
2175 | mCurrentSyncProfile = action - 1000 ; | 2175 | mCurrentSyncProfile = action - 1000 ; |
2176 | mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ; | 2176 | mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ; |
2177 | mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ; | 2177 | mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ; |
2178 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 2178 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
2179 | KSyncProfile* temp = new KSyncProfile (); | 2179 | KSyncProfile* temp = new KSyncProfile (); |
2180 | temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 2180 | temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
2181 | temp->readConfig(&config); | 2181 | temp->readConfig(&config); |
2182 | KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); | 2182 | KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); |
2183 | KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); | 2183 | KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); |
2184 | KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); | 2184 | KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); |
2185 | KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); | 2185 | KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); |
2186 | KABPrefs::instance()->mWriteBackInFuture = 0; | 2186 | KABPrefs::instance()->mWriteBackInFuture = 0; |
2187 | if ( temp->getWriteBackFuture() ) | 2187 | if ( temp->getWriteBackFuture() ) |
2188 | KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 2188 | KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
2189 | KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); | 2189 | KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); |
2190 | if ( action == 1000 ) { | 2190 | if ( action == 1000 ) { |
2191 | syncSharp(); | 2191 | syncSharp(); |
2192 | 2192 | ||
2193 | } else if ( action == 1001 ) { | 2193 | } else if ( action == 1001 ) { |
2194 | syncLocalFile(); | 2194 | syncLocalFile(); |
2195 | 2195 | ||
2196 | } else if ( action == 1002 ) { | 2196 | } else if ( action == 1002 ) { |
2197 | quickSyncLocalFile(); | 2197 | quickSyncLocalFile(); |
2198 | 2198 | ||
2199 | } else if ( action >= 1003 ) { | 2199 | } else if ( action >= 1003 ) { |
2200 | if ( temp->getIsLocalFileSync() ) { | 2200 | if ( temp->getIsLocalFileSync() ) { |
2201 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 2201 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
2202 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 2202 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
2203 | } else { | 2203 | } else { |
2204 | if ( temp->getIsPhoneSync() ) { | 2204 | if ( temp->getIsPhoneSync() ) { |
2205 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; | 2205 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; |
2206 | KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); | 2206 | KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); |
2207 | KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); | 2207 | KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); |
2208 | syncPhone(); | 2208 | syncPhone(); |
2209 | } else | 2209 | } else |
2210 | syncRemote( temp ); | 2210 | syncRemote( temp ); |
2211 | 2211 | ||
2212 | } | 2212 | } |
2213 | } | 2213 | } |
2214 | delete temp; | 2214 | delete temp; |
2215 | mBlockSaveFlag = false; | 2215 | mBlockSaveFlag = false; |
2216 | } | 2216 | } |
2217 | 2217 | ||
2218 | void KABCore::syncLocalFile() | 2218 | void KABCore::syncLocalFile() |
2219 | { | 2219 | { |
2220 | 2220 | ||
2221 | QString fn =KABPrefs::instance()->mLastSyncedLocalFile; | 2221 | QString fn =KABPrefs::instance()->mLastSyncedLocalFile; |
2222 | 2222 | ||
2223 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); | 2223 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); |
2224 | if ( fn == "" ) | 2224 | if ( fn == "" ) |
2225 | return; | 2225 | return; |
2226 | if ( syncWithFile( fn, false ) ) { | 2226 | if ( syncWithFile( fn, false ) ) { |
2227 | qDebug("syncLocalFile() successful "); | 2227 | qDebug("syncLocalFile() successful "); |
2228 | } | 2228 | } |
2229 | 2229 | ||
2230 | } | 2230 | } |
2231 | bool KABCore::syncWithFile( QString fn , bool quick ) | 2231 | bool KABCore::syncWithFile( QString fn , bool quick ) |
2232 | { | 2232 | { |
2233 | bool ret = false; | 2233 | bool ret = false; |
2234 | QFileInfo info; | 2234 | QFileInfo info; |
2235 | info.setFile( fn ); | 2235 | info.setFile( fn ); |
2236 | QString mess; | 2236 | QString mess; |
2237 | bool loadbup = true; | 2237 | bool loadbup = true; |
2238 | if ( !info. exists() ) { | 2238 | if ( !info. exists() ) { |
2239 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 2239 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
2240 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | 2240 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), |
2241 | mess ); | 2241 | mess ); |
2242 | return ret; | 2242 | return ret; |
2243 | } | 2243 | } |
2244 | int result = 0; | 2244 | int result = 0; |
2245 | if ( !quick ) { | 2245 | if ( !quick ) { |
2246 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 2246 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
2247 | result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | 2247 | result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), |
2248 | mess, | 2248 | mess, |
2249 | i18n("Sync"), i18n("Cancel"), 0, | 2249 | i18n("Sync"), i18n("Cancel"), 0, |
2250 | 0, 1 ); | 2250 | 0, 1 ); |
2251 | if ( result ) | 2251 | if ( result ) |
2252 | return false; | 2252 | return false; |
2253 | } | 2253 | } |
2254 | if ( KABPrefs::instance()->mAskForPreferences ) | 2254 | if ( KABPrefs::instance()->mAskForPreferences ) |
2255 | edit_sync_options(); | 2255 | edit_sync_options(); |
2256 | if ( result == 0 ) { | 2256 | if ( result == 0 ) { |
2257 | //qDebug("Now sycing ... "); | 2257 | //qDebug("Now sycing ... "); |
2258 | if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) ) | 2258 | if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) ) |
2259 | setCaption( i18n("Synchronization successful") ); | 2259 | setCaption( i18n("Synchronization successful") ); |
2260 | else | 2260 | else |
2261 | setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); | 2261 | setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); |
2262 | if ( ! quick ) | 2262 | if ( ! quick ) |
2263 | KABPrefs::instance()->mLastSyncedLocalFile = fn; | 2263 | KABPrefs::instance()->mLastSyncedLocalFile = fn; |
2264 | setModified(); | 2264 | setModified(); |
2265 | } | 2265 | } |
2266 | return ret; | 2266 | return ret; |
2267 | } | 2267 | } |
2268 | void KABCore::quickSyncLocalFile() | 2268 | void KABCore::quickSyncLocalFile() |
2269 | { | 2269 | { |
2270 | 2270 | ||
2271 | if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) { | 2271 | if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) { |
2272 | qDebug("quick syncLocalFile() successful "); | 2272 | qDebug("quick syncLocalFile() successful "); |
2273 | 2273 | ||
2274 | } | 2274 | } |
2275 | } | 2275 | } |
2276 | void KABCore::multiSync( bool askforPrefs ) | 2276 | void KABCore::multiSync( bool askforPrefs ) |
2277 | { | 2277 | { |
2278 | if (mBlockSaveFlag) | 2278 | if (mBlockSaveFlag) |
2279 | return; | 2279 | return; |
2280 | mBlockSaveFlag = true; | 2280 | mBlockSaveFlag = true; |
2281 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | 2281 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); |
2282 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), | 2282 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), |
2283 | question, | 2283 | question, |
2284 | i18n("Yes"), i18n("No"), | 2284 | i18n("Yes"), i18n("No"), |
2285 | 0, 0 ) != 0 ) { | 2285 | 0, 0 ) != 0 ) { |
2286 | mBlockSaveFlag = false; | 2286 | mBlockSaveFlag = false; |
2287 | setCaption(i18n("Aborted! Nothing synced!")); | 2287 | setCaption(i18n("Aborted! Nothing synced!")); |
2288 | return; | 2288 | return; |
2289 | } | 2289 | } |
2290 | mCurrentSyncDevice = i18n("Multiple profiles") ; | 2290 | mCurrentSyncDevice = i18n("Multiple profiles") ; |
2291 | KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs; | 2291 | KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs; |
2292 | if ( askforPrefs ) { | 2292 | if ( askforPrefs ) { |
2293 | edit_sync_options(); | 2293 | edit_sync_options(); |
2294 | KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs; | 2294 | KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs; |
2295 | } | 2295 | } |
2296 | setCaption(i18n("Multiple sync started.") ); | 2296 | setCaption(i18n("Multiple sync started.") ); |
2297 | qApp->processEvents(); | 2297 | qApp->processEvents(); |
2298 | int num = ringSync() ; | 2298 | int num = ringSync() ; |
2299 | if ( num > 1 ) | 2299 | if ( num > 1 ) |
2300 | ringSync(); | 2300 | ringSync(); |
2301 | mBlockSaveFlag = false; | 2301 | mBlockSaveFlag = false; |
2302 | if ( num ) | 2302 | if ( num ) |
2303 | save(); | 2303 | save(); |
2304 | if ( num ) | 2304 | if ( num ) |
2305 | setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); | 2305 | setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); |
2306 | else | 2306 | else |
2307 | setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 2307 | setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
2308 | return; | 2308 | return; |
2309 | } | 2309 | } |
2310 | int KABCore::ringSync() | 2310 | int KABCore::ringSync() |
2311 | { | 2311 | { |
2312 | int syncedProfiles = 0; | 2312 | int syncedProfiles = 0; |
2313 | int i; | 2313 | int i; |
2314 | QTime timer; | 2314 | QTime timer; |
2315 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 2315 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
2316 | QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames; | 2316 | QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames; |
2317 | KSyncProfile* temp = new KSyncProfile (); | 2317 | KSyncProfile* temp = new KSyncProfile (); |
2318 | KABPrefs::instance()->mAskForPreferences = false; | 2318 | KABPrefs::instance()->mAskForPreferences = false; |
2319 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | 2319 | for ( i = 0; i < syncProfileNames.count(); ++i ) { |
2320 | mCurrentSyncProfile = i; | 2320 | mCurrentSyncProfile = i; |
2321 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 2321 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
2322 | temp->readConfig(&config); | 2322 | temp->readConfig(&config); |
2323 | if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { | 2323 | if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { |
2324 | setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | 2324 | setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); |
2325 | ++syncedProfiles; | 2325 | ++syncedProfiles; |
2326 | // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); | 2326 | // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); |
2327 | KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); | 2327 | KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); |
2328 | KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); | 2328 | KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); |
2329 | KABPrefs::instance()->mWriteBackInFuture = 0; | 2329 | KABPrefs::instance()->mWriteBackInFuture = 0; |
2330 | if ( temp->getWriteBackFuture() ) | 2330 | if ( temp->getWriteBackFuture() ) |
2331 | KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 2331 | KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
2332 | KABPrefs::instance()->mShowSyncSummary = false; | 2332 | KABPrefs::instance()->mShowSyncSummary = false; |
2333 | mCurrentSyncDevice = syncProfileNames[i] ; | 2333 | mCurrentSyncDevice = syncProfileNames[i] ; |
2334 | mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; | 2334 | mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; |
2335 | if ( i == 0 ) { | 2335 | if ( i == 0 ) { |
2336 | syncSharp(); | 2336 | syncSharp(); |
2337 | } else { | 2337 | } else { |
2338 | if ( temp->getIsLocalFileSync() ) { | 2338 | if ( temp->getIsLocalFileSync() ) { |
2339 | if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) | 2339 | if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) |
2340 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 2340 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
2341 | } else { | 2341 | } else { |
2342 | if ( temp->getIsPhoneSync() ) { | 2342 | if ( temp->getIsPhoneSync() ) { |
2343 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; | 2343 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; |
2344 | KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); | 2344 | KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); |
2345 | KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); | 2345 | KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); |
2346 | syncPhone(); | 2346 | syncPhone(); |
2347 | } else | 2347 | } else |
2348 | syncRemote( temp, false ); | 2348 | syncRemote( temp, false ); |
2349 | 2349 | ||
2350 | } | 2350 | } |
2351 | } | 2351 | } |
2352 | timer.start(); | 2352 | timer.start(); |
2353 | setCaption(i18n("Multiple sync in progress ... please wait!") ); | 2353 | setCaption(i18n("Multiple sync in progress ... please wait!") ); |
2354 | while ( timer.elapsed () < 2000 ) { | 2354 | while ( timer.elapsed () < 2000 ) { |
2355 | qApp->processEvents(); | 2355 | qApp->processEvents(); |
2356 | #ifndef _WIN32_ | 2356 | #ifndef _WIN32_ |
2357 | sleep (1); | 2357 | sleep (1); |
2358 | #endif | 2358 | #endif |
2359 | } | 2359 | } |
2360 | 2360 | ||
2361 | } | 2361 | } |
2362 | 2362 | ||
2363 | } | 2363 | } |
2364 | delete temp; | 2364 | delete temp; |
2365 | return syncedProfiles; | 2365 | return syncedProfiles; |
2366 | } | 2366 | } |
2367 | 2367 | ||
2368 | void KABCore::syncRemote( KSyncProfile* prof, bool ask) | 2368 | void KABCore::syncRemote( KSyncProfile* prof, bool ask) |
2369 | { | 2369 | { |
2370 | QString question; | 2370 | QString question; |
2371 | if ( ask ) { | 2371 | if ( ask ) { |
2372 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 2372 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
2373 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), | 2373 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), |
2374 | question, | 2374 | question, |
2375 | i18n("Yes"), i18n("No"), | 2375 | i18n("Yes"), i18n("No"), |
2376 | 0, 0 ) != 0 ) | 2376 | 0, 0 ) != 0 ) |
2377 | return; | 2377 | return; |
2378 | } | 2378 | } |
2379 | QString command = prof->getPreSyncCommandAB(); | 2379 | QString command = prof->getPreSyncCommandAB(); |
2380 | int fi; | 2380 | int fi; |
2381 | if ( (fi = command.find("$PWD$")) > 0 ) { | 2381 | if ( (fi = command.find("$PWD$")) > 0 ) { |
2382 | QString pwd = getPassword(); | 2382 | QString pwd = getPassword(); |
2383 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | 2383 | command = command.left( fi )+ pwd + command.mid( fi+5 ); |
2384 | 2384 | ||
2385 | } | 2385 | } |
2386 | int maxlen = 30; | 2386 | int maxlen = 30; |
2387 | if ( QApplication::desktop()->width() > 320 ) | 2387 | if ( QApplication::desktop()->width() > 320 ) |
2388 | maxlen += 25; | 2388 | maxlen += 25; |
2389 | setCaption ( i18n( "Copy remote file to local machine..." ) ); | 2389 | setCaption ( i18n( "Copy remote file to local machine..." ) ); |
2390 | int fileSize = 0; | 2390 | int fileSize = 0; |
2391 | int result = system ( command ); | 2391 | int result = system ( command ); |
2392 | // 0 : okay | 2392 | // 0 : okay |
2393 | // 256: no such file or dir | 2393 | // 256: no such file or dir |
2394 | // | 2394 | // |
2395 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); | 2395 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); |
2396 | if ( result != 0 ) { | 2396 | if ( result != 0 ) { |
2397 | int len = maxlen; | 2397 | int len = maxlen; |
2398 | while ( len < command.length() ) { | 2398 | while ( len < command.length() ) { |
2399 | command.insert( len , "\n" ); | 2399 | command.insert( len , "\n" ); |
2400 | len += maxlen +2; | 2400 | len += maxlen +2; |
2401 | } | 2401 | } |
2402 | 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) ; | 2402 | 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) ; |
2403 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), | 2403 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), |
2404 | question, | 2404 | question, |
2405 | i18n("Okay!")) ; | 2405 | i18n("Okay!")) ; |
2406 | setCaption ("KO/Pi"); | 2406 | setCaption ("KO/Pi"); |
2407 | return; | 2407 | return; |
2408 | } | 2408 | } |
2409 | setCaption ( i18n( "Copying succeed." ) ); | 2409 | setCaption ( i18n( "Copying succeed." ) ); |
2410 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 2410 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
2411 | if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { | 2411 | if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { |
2412 | // Event* e = mView->getLastSyncEvent(); | 2412 | // Event* e = mView->getLastSyncEvent(); |
2413 | // e->setReadOnly( false ); | 2413 | // e->setReadOnly( false ); |
2414 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 2414 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
2415 | // e->setReadOnly( true ); | 2415 | // e->setReadOnly( true ); |
2416 | if ( KABPrefs::instance()->mWriteBackFile ) { | 2416 | if ( KABPrefs::instance()->mWriteBackFile ) { |
2417 | command = prof->getPostSyncCommandAB(); | 2417 | command = prof->getPostSyncCommandAB(); |
2418 | int fi; | 2418 | int fi; |
2419 | if ( (fi = command.find("$PWD$")) > 0 ) { | 2419 | if ( (fi = command.find("$PWD$")) > 0 ) { |
2420 | QString pwd = getPassword(); | 2420 | QString pwd = getPassword(); |
2421 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | 2421 | command = command.left( fi )+ pwd + command.mid( fi+5 ); |
2422 | 2422 | ||
2423 | } | 2423 | } |
2424 | setCaption ( i18n( "Writing back file ..." ) ); | 2424 | setCaption ( i18n( "Writing back file ..." ) ); |
2425 | result = system ( command ); | 2425 | result = system ( command ); |
2426 | qDebug("KO: Writing back file result: %d ", result); | 2426 | qDebug("KO: Writing back file result: %d ", result); |
2427 | if ( result != 0 ) { | 2427 | if ( result != 0 ) { |
2428 | setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 2428 | setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
2429 | return; | 2429 | return; |
2430 | } else { | 2430 | } else { |
2431 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 2431 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
2432 | } | 2432 | } |
2433 | } | 2433 | } |
2434 | } | 2434 | } |
2435 | return; | 2435 | return; |
2436 | } | 2436 | } |
2437 | #include <qpushbutton.h> | 2437 | #include <qpushbutton.h> |
2438 | #include <qradiobutton.h> | 2438 | #include <qradiobutton.h> |
2439 | #include <qbuttongroup.h> | 2439 | #include <qbuttongroup.h> |
2440 | void KABCore::edit_sync_options() | 2440 | void KABCore::edit_sync_options() |
2441 | { | 2441 | { |
2442 | //mDialogManager->showSyncOptions(); | 2442 | //mDialogManager->showSyncOptions(); |
2443 | //KABPrefs::instance()->mSyncAlgoPrefs | 2443 | //KABPrefs::instance()->mSyncAlgoPrefs |
2444 | QDialog dia( this, "dia", true ); | 2444 | QDialog dia( this, "dia", true ); |
2445 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 2445 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
2446 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 2446 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
2447 | QVBoxLayout lay ( &dia ); | 2447 | QVBoxLayout lay ( &dia ); |
2448 | lay.setSpacing( 2 ); | 2448 | lay.setSpacing( 2 ); |
2449 | lay.setMargin( 3 ); | 2449 | lay.setMargin( 3 ); |
2450 | lay.addWidget(&gr); | 2450 | lay.addWidget(&gr); |
2451 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 2451 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
2452 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 2452 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
2453 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 2453 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
2454 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 2454 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
2455 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 2455 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
2456 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 2456 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
2457 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 2457 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
2458 | QPushButton pb ( "OK", &dia); | 2458 | QPushButton pb ( "OK", &dia); |
2459 | lay.addWidget( &pb ); | 2459 | lay.addWidget( &pb ); |
2460 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 2460 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
2461 | switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { | 2461 | switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { |
2462 | case 0: | 2462 | case 0: |
2463 | loc.setChecked( true); | 2463 | loc.setChecked( true); |
2464 | break; | 2464 | break; |
2465 | case 1: | 2465 | case 1: |
2466 | rem.setChecked( true ); | 2466 | rem.setChecked( true ); |
2467 | break; | 2467 | break; |
2468 | case 2: | 2468 | case 2: |
2469 | newest.setChecked( true); | 2469 | newest.setChecked( true); |
2470 | break; | 2470 | break; |
2471 | case 3: | 2471 | case 3: |
2472 | ask.setChecked( true); | 2472 | ask.setChecked( true); |
2473 | break; | 2473 | break; |
2474 | case 4: | 2474 | case 4: |
2475 | f_loc.setChecked( true); | 2475 | f_loc.setChecked( true); |
2476 | break; | 2476 | break; |
2477 | case 5: | 2477 | case 5: |
2478 | f_rem.setChecked( true); | 2478 | f_rem.setChecked( true); |
2479 | break; | 2479 | break; |
2480 | case 6: | 2480 | case 6: |
2481 | // both.setChecked( true); | 2481 | // both.setChecked( true); |
2482 | break; | 2482 | break; |
2483 | default: | 2483 | default: |
2484 | break; | 2484 | break; |
2485 | } | 2485 | } |
2486 | if ( dia.exec() ) { | 2486 | if ( dia.exec() ) { |
2487 | KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | 2487 | KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; |
2488 | } | 2488 | } |
2489 | 2489 | ||
2490 | 2490 | ||
2491 | } | 2491 | } |
2492 | QString KABCore::getPassword( ) | 2492 | QString KABCore::getPassword( ) |
2493 | { | 2493 | { |
2494 | QString retfile = ""; | 2494 | QString retfile = ""; |
2495 | QDialog dia ( this, "input-dialog", true ); | 2495 | QDialog dia ( this, "input-dialog", true ); |
2496 | QLineEdit lab ( &dia ); | 2496 | QLineEdit lab ( &dia ); |
2497 | lab.setEchoMode( QLineEdit::Password ); | 2497 | lab.setEchoMode( QLineEdit::Password ); |
2498 | QVBoxLayout lay( &dia ); | 2498 | QVBoxLayout lay( &dia ); |
2499 | lay.setMargin(7); | 2499 | lay.setMargin(7); |
2500 | lay.setSpacing(7); | 2500 | lay.setSpacing(7); |
2501 | lay.addWidget( &lab); | 2501 | lay.addWidget( &lab); |
2502 | dia.setFixedSize( 230,50 ); | 2502 | dia.setFixedSize( 230,50 ); |
2503 | dia.setCaption( i18n("Enter password") ); | 2503 | dia.setCaption( i18n("Enter password") ); |
2504 | QPushButton pb ( "OK", &dia); | 2504 | QPushButton pb ( "OK", &dia); |
2505 | lay.addWidget( &pb ); | 2505 | lay.addWidget( &pb ); |
2506 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 2506 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
2507 | dia.show(); | 2507 | dia.show(); |
2508 | int res = dia.exec(); | 2508 | int res = dia.exec(); |
2509 | if ( res ) | 2509 | if ( res ) |
2510 | retfile = lab.text(); | 2510 | retfile = lab.text(); |
2511 | dia.hide(); | 2511 | dia.hide(); |
2512 | qApp->processEvents(); | 2512 | qApp->processEvents(); |
2513 | return retfile; | 2513 | return retfile; |
2514 | 2514 | ||
2515 | } | 2515 | } |
2516 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) | 2516 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) |
2517 | { | 2517 | { |
2518 | 2518 | #if 0 | |
2519 | bool syncOK = true; | ||
2520 | int addedAddressee = 0; | ||
2521 | int addedAddresseeR = 0; | ||
2522 | int deletedAddresseeR = 0; | ||
2523 | int deletedAddresseeL = 0; | ||
2524 | int changedLocal = 0; | ||
2525 | int changedRemote = 0; | ||
2526 | //QPtrList<Addressee> el = local->rawAddressees(); | ||
2527 | Addressee* addresseeR; | ||
2528 | QString uid; | ||
2529 | int take; | ||
2530 | Addressee* addresseeL; | ||
2531 | Addressee* addresseeRSync; | ||
2532 | Addressee* addresseeLSync; | ||
2533 | QPtrList<Addressee> addresseeRSyncSharp = remote->getExternLastSyncAddressees(); | ||
2534 | QPtrList<Addressee> addresseeLSyncSharp = local->getExternLastSyncAddressees(); | ||
2535 | bool fullDateRange = false; | ||
2536 | local->resetTempSyncStat(); | ||
2537 | mLastCalendarSync = QDateTime::currentDateTime(); | ||
2538 | QDateTime modifiedCalendar = mLastCalendarSync;; | ||
2539 | addresseeLSync = getLastSyncAddressee(); | ||
2540 | addresseeR = remote->addressee("last-syncAddressee-"+mCurrentSyncName ); | ||
2541 | if ( addresseeR ) { | ||
2542 | addresseeRSync = (Addressee*) addresseeR->clone(); | ||
2543 | remote->deleteAddressee(addresseeR ); | ||
2544 | |||
2545 | } else { | ||
2546 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | ||
2547 | addresseeRSync = (Addressee*)addresseeLSync->clone(); | ||
2548 | } else { | ||
2549 | fullDateRange = true; | ||
2550 | addresseeRSync = new Addressee(); | ||
2551 | addresseeRSync->setSummary(mCurrentSyncName + i18n(" - sync addressee")); | ||
2552 | addresseeRSync->setUid("last-syncAddressee-"+mCurrentSyncName ); | ||
2553 | addresseeRSync->setDtStart( mLastCalendarSync ); | ||
2554 | addresseeRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | ||
2555 | addresseeRSync->setCategories( i18n("SyncAddressee") ); | ||
2556 | } | ||
2557 | } | ||
2558 | if ( addresseeLSync->dtStart() == mLastCalendarSync ) | ||
2559 | fullDateRange = true; | ||
2560 | |||
2561 | if ( ! fullDateRange ) { | ||
2562 | if ( addresseeLSync->dtStart() != addresseeRSync->dtStart() ) { | ||
2563 | |||
2564 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | ||
2565 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | ||
2566 | fullDateRange = true; | ||
2567 | } | ||
2568 | } | ||
2569 | if ( fullDateRange ) | ||
2570 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); | ||
2571 | else | ||
2572 | mLastCalendarSync = addresseeLSync->dtStart(); | ||
2573 | // for resyncing if own file has changed | ||
2574 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | ||
2575 | mLastCalendarSync = loadedFileVersion; | ||
2576 | qDebug("setting mLastCalendarSync "); | ||
2577 | } | ||
2578 | //qDebug("*************************** "); | ||
2579 | qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); | ||
2580 | QPtrList<Incidence> er = remote->rawIncidences(); | ||
2581 | Incidence* inR = er.first(); | ||
2582 | Incidence* inL; | ||
2583 | QProgressBar bar( er.count(),0 ); | ||
2584 | bar.setCaption (i18n("Syncing - close to abort!") ); | ||
2585 | |||
2586 | int w = 300; | ||
2587 | if ( QApplication::desktop()->width() < 320 ) | ||
2588 | w = 220; | ||
2589 | int h = bar.sizeHint().height() ; | ||
2590 | int dw = QApplication::desktop()->width(); | ||
2591 | int dh = QApplication::desktop()->height(); | ||
2592 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
2593 | bar.show(); | ||
2594 | int modulo = (er.count()/10)+1; | ||
2595 | int incCounter = 0; | ||
2596 | while ( inR ) { | ||
2597 | if ( ! bar.isVisible() ) | ||
2598 | return false; | ||
2599 | if ( incCounter % modulo == 0 ) | ||
2600 | bar.setProgress( incCounter ); | ||
2601 | ++incCounter; | ||
2602 | uid = inR->uid(); | ||
2603 | bool skipIncidence = false; | ||
2604 | if ( uid.left(15) == QString("last-syncAddressee-") ) | ||
2605 | skipIncidence = true; | ||
2606 | QString idS; | ||
2607 | qApp->processAddressees(); | ||
2608 | if ( !skipIncidence ) { | ||
2609 | inL = local->incidence( uid ); | ||
2610 | if ( inL ) { // maybe conflict - same uid in both calendars | ||
2611 | int maxrev = inL->revision(); | ||
2612 | if ( maxrev < inR->revision() ) | ||
2613 | maxrev = inR->revision(); | ||
2614 | if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) { | ||
2615 | //qDebug("take %d %s ", take, inL->summary().latin1()); | ||
2616 | if ( take == 3 ) | ||
2617 | return false; | ||
2618 | if ( take == 1 ) {// take local | ||
2619 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | ||
2620 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | ||
2621 | else | ||
2622 | idS = inR->IDStr(); | ||
2623 | remote->deleteIncidence( inR ); | ||
2624 | if ( inL->revision() < maxrev ) | ||
2625 | inL->setRevision( maxrev ); | ||
2626 | inR = inL->clone(); | ||
2627 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | ||
2628 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) | ||
2629 | inR->setIDStr( idS ); | ||
2630 | remote->addIncidence( inR ); | ||
2631 | ++changedRemote; | ||
2632 | } else { | ||
2633 | if ( inR->revision() < maxrev ) | ||
2634 | inR->setRevision( maxrev ); | ||
2635 | idS = inL->IDStr(); | ||
2636 | local->deleteIncidence( inL ); | ||
2637 | inL = inR->clone(); | ||
2638 | inL->setIDStr( idS ); | ||
2639 | local->addIncidence( inL ); | ||
2640 | ++changedLocal; | ||
2641 | } | ||
2642 | } | ||
2643 | } else { // no conflict | ||
2644 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | ||
2645 | QString des = addresseeLSync->description(); | ||
2646 | QString pref = "e"; | ||
2647 | if ( inR->type() == "Todo" ) | ||
2648 | pref = "t"; | ||
2649 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | ||
2650 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | ||
2651 | //remote->deleteIncidence( inR ); | ||
2652 | ++deletedAddresseeR; | ||
2653 | } else { | ||
2654 | inR->setLastModified( modifiedCalendar ); | ||
2655 | inL = inR->clone(); | ||
2656 | local->addIncidence( inL ); | ||
2657 | ++addedAddressee; | ||
2658 | } | ||
2659 | } else { | ||
2660 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | ||
2661 | inR->setLastModified( modifiedCalendar ); | ||
2662 | local->addIncidence( inR->clone() ); | ||
2663 | ++addedAddressee; | ||
2664 | } else { | ||
2665 | checkExternSyncAddressee(addresseeRSyncSharp, inR); | ||
2666 | remote->deleteIncidence( inR ); | ||
2667 | ++deletedAddresseeR; | ||
2668 | } | ||
2669 | } | ||
2670 | } | ||
2671 | } | ||
2672 | inR = er.next(); | ||
2673 | } | ||
2674 | QPtrList<Incidence> el = local->rawIncidences(); | ||
2675 | inL = el.first(); | ||
2676 | modulo = (el.count()/10)+1; | ||
2677 | bar.setCaption (i18n("Add / remove addressees") ); | ||
2678 | bar.setTotalSteps ( el.count() ) ; | ||
2679 | bar.show(); | ||
2680 | incCounter = 0; | ||
2681 | |||
2682 | while ( inL ) { | ||
2683 | |||
2684 | qApp->processAddressees(); | ||
2685 | if ( ! bar.isVisible() ) | ||
2686 | return false; | ||
2687 | if ( incCounter % modulo == 0 ) | ||
2688 | bar.setProgress( incCounter ); | ||
2689 | ++incCounter; | ||
2690 | uid = inL->uid(); | ||
2691 | bool skipIncidence = false; | ||
2692 | if ( uid.left(15) == QString("last-syncAddressee-") ) | ||
2693 | skipIncidence = true; | ||
2694 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) | ||
2695 | skipIncidence = true; | ||
2696 | if ( !skipIncidence ) { | ||
2697 | inR = remote->incidence( uid ); | ||
2698 | if ( ! inR ) { | ||
2699 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | ||
2700 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | ||
2701 | checkExternSyncAddressee(addresseeLSyncSharp, inL); | ||
2702 | local->deleteIncidence( inL ); | ||
2703 | ++deletedAddresseeL; | ||
2704 | } else { | ||
2705 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | ||
2706 | inL->removeID(mCurrentSyncDevice ); | ||
2707 | ++addedAddresseeR; | ||
2708 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); | ||
2709 | inL->setLastModified( modifiedCalendar ); | ||
2710 | inR = inL->clone(); | ||
2711 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | ||
2712 | remote->addIncidence( inR ); | ||
2713 | } | ||
2714 | } | ||
2715 | } else { | ||
2716 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | ||
2717 | checkExternSyncAddressee(addresseeLSyncSharp, inL); | ||
2718 | local->deleteIncidence( inL ); | ||
2719 | ++deletedAddresseeL; | ||
2720 | } else { | ||
2721 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | ||
2722 | ++addedAddresseeR; | ||
2723 | inL->setLastModified( modifiedCalendar ); | ||
2724 | remote->addIncidence( inL->clone() ); | ||
2725 | } | ||
2726 | } | ||
2727 | } | ||
2728 | } | ||
2729 | } | ||
2730 | inL = el.next(); | ||
2731 | } | ||
2732 | int delFut = 0; | ||
2733 | if ( KOPrefs::instance()->mWriteBackInFuture ) { | ||
2734 | er = remote->rawIncidences(); | ||
2735 | inR = er.first(); | ||
2736 | QDateTime dt; | ||
2737 | QDateTime cur = QDateTime::currentDateTime(); | ||
2738 | QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); | ||
2739 | while ( inR ) { | ||
2740 | if ( inR->type() == "Todo" ) { | ||
2741 | Todo * t = (Todo*)inR; | ||
2742 | if ( t->hasDueDate() ) | ||
2743 | dt = t->dtDue(); | ||
2744 | else | ||
2745 | dt = cur.addSecs( 62 ); | ||
2746 | } | ||
2747 | else if (inR->type() == "Addressee" ) { | ||
2748 | bool ok; | ||
2749 | dt = inR->getNextOccurence( cur, &ok ); | ||
2750 | if ( !ok ) | ||
2751 | dt = cur.addSecs( -62 ); | ||
2752 | } | ||
2753 | else | ||
2754 | dt = inR->dtStart(); | ||
2755 | if ( dt < cur || dt > end ) { | ||
2756 | remote->deleteIncidence( inR ); | ||
2757 | ++delFut; | ||
2758 | } | ||
2759 | inR = er.next(); | ||
2760 | } | ||
2761 | } | ||
2762 | bar.hide(); | ||
2763 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); | ||
2764 | addresseeLSync->setReadOnly( false ); | ||
2765 | addresseeLSync->setDtStart( mLastCalendarSync ); | ||
2766 | addresseeRSync->setDtStart( mLastCalendarSync ); | ||
2767 | addresseeLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | ||
2768 | addresseeRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | ||
2769 | addresseeRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; | ||
2770 | addresseeLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); | ||
2771 | addresseeLSync->setReadOnly( true ); | ||
2772 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | ||
2773 | remote->addAddressee( addresseeRSync ); | ||
2774 | QString mes; | ||
2775 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); | ||
2776 | QString delmess; | ||
2777 | if ( delFut ) { | ||
2778 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); | ||
2779 | mes += delmess; | ||
2780 | } | ||
2781 | if ( KOPrefs::instance()->mShowSyncSummary ) { | ||
2782 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); | ||
2783 | } | ||
2784 | qDebug( mes ); | ||
2785 | mCalendar->checkAlarmForIncidence( 0, true ); | ||
2786 | return syncOK; | ||
2787 | #endif | ||
2788 | return false; | ||
2519 | } | 2789 | } |
2520 | bool KABCore::syncAB(QString filename, int mode) | 2790 | bool KABCore::syncAB(QString filename, int mode) |
2521 | { | 2791 | { |
2522 | 2792 | ||
2523 | 2793 | //pending prepare addresseeview for output | |
2524 | 2794 | //pending detect, if remote file has REV field. if not switch to external sync | |
2525 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2795 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2526 | AddressBook abLocal(filename,"syncContact"); | 2796 | AddressBook abLocal(filename,"syncContact"); |
2527 | bool syncOK = false; | 2797 | bool syncOK = false; |
2528 | if ( abLocal.load() ) { | 2798 | if ( abLocal.load() ) { |
2529 | qDebug("AB loaded %s mode %d",filename.latin1(), mode ); | 2799 | qDebug("AB loaded %s mode %d",filename.latin1(), mode ); |
2530 | AddressBook::Iterator it; | 2800 | AddressBook::Iterator it; |
2531 | QStringList vcards; | 2801 | QStringList vcards; |
2532 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2802 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2533 | qDebug("Name %s ", (*it).familyName().latin1()); | 2803 | qDebug("Name %s ", (*it).familyName().latin1()); |
2534 | } | 2804 | } |
2535 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2805 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2536 | if ( syncOK ) { | 2806 | if ( syncOK ) { |
2537 | if ( KABPrefs::instance()->mWriteBackFile ) | 2807 | if ( KABPrefs::instance()->mWriteBackFile ) |
2538 | { | 2808 | { |
2809 | qDebug("saving remote AB "); | ||
2539 | abLocal.saveAB(); | 2810 | abLocal.saveAB(); |
2540 | } | 2811 | } |
2541 | } | 2812 | } |
2542 | setModified(); | 2813 | setModified(); |
2543 | 2814 | ||
2544 | } | 2815 | } |
2545 | if ( syncOK ) | 2816 | if ( syncOK ) |
2546 | ;//updateView(); | 2817 | mViewManager->refreshView(); |
2547 | return syncOK; | 2818 | return syncOK; |
2548 | #if 0 | 2819 | #if 0 |
2549 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2820 | |
2550 | CalendarLocal* calendar = new CalendarLocal(); | ||
2551 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | ||
2552 | FileStorage* storage = new FileStorage( calendar ); | ||
2553 | bool syncOK = false; | ||
2554 | storage->setFileName( filename ); | ||
2555 | // qDebug("loading ... "); | ||
2556 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { | 2821 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { |
2557 | getEventViewerDialog()->setSyncMode( true ); | 2822 | getEventViewerDialog()->setSyncMode( true ); |
2558 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 2823 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
2559 | getEventViewerDialog()->setSyncMode( false ); | 2824 | getEventViewerDialog()->setSyncMode( false ); |
2560 | if ( syncOK ) { | 2825 | if ( syncOK ) { |
2561 | if ( KOPrefs::instance()->mWriteBackFile ) | 2826 | if ( KOPrefs::instance()->mWriteBackFile ) |
2562 | { | 2827 | { |
2563 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 2828 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
2564 | storage->save(); | 2829 | storage->save(); |
2565 | } | 2830 | } |
2566 | } | 2831 | } |
2567 | setModified(); | 2832 | setModified(); |
2568 | } | 2833 | } |
2569 | delete storage; | 2834 | |
2570 | delete calendar; | ||
2571 | if ( syncOK ) | ||
2572 | updateView(); | ||
2573 | return syncOK; | ||
2574 | #endif | 2835 | #endif |
2575 | } | 2836 | } |
2576 | 2837 | ||
2577 | 2838 | ||
2578 | void KABCore::confSync() | 2839 | void KABCore::confSync() |
2579 | { | 2840 | { |
2580 | static KSyncPrefsDialog* sp = 0; | 2841 | static KSyncPrefsDialog* sp = 0; |
2581 | if ( ! sp ) { | 2842 | if ( ! sp ) { |
2582 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); | 2843 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); |
2583 | } | 2844 | } |
2584 | sp->usrReadConfig(); | 2845 | sp->usrReadConfig(); |
2585 | #ifndef DESKTOP_VERSION | 2846 | #ifndef DESKTOP_VERSION |
2586 | sp->showMaximized(); | 2847 | sp->showMaximized(); |
2587 | #else | 2848 | #else |
2588 | sp->show(); | 2849 | sp->show(); |
2589 | #endif | 2850 | #endif |
2590 | sp->exec(); | 2851 | sp->exec(); |
2591 | KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); | 2852 | KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); |
2592 | KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); | 2853 | KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); |
2593 | fillSyncMenu(); | 2854 | fillSyncMenu(); |
2594 | } | 2855 | } |
2595 | void KABCore::syncSharp() | 2856 | void KABCore::syncSharp() |
2596 | { | 2857 | { |
2597 | if ( mModified ) | 2858 | if ( mModified ) |
2598 | save(); | 2859 | save(); |
2599 | qDebug("pending syncSharp() "); | 2860 | qDebug("pending syncSharp() "); |
2600 | //mView->syncSharp(); | 2861 | //mView->syncSharp(); |
2601 | setModified(); | 2862 | setModified(); |
2602 | 2863 | ||
2603 | } | 2864 | } |
2604 | void KABCore::syncPhone() | 2865 | void KABCore::syncPhone() |
2605 | { | 2866 | { |
2606 | if ( mModified ) | 2867 | if ( mModified ) |
2607 | save(); | 2868 | save(); |
2608 | qDebug("pending syncPhone(); "); | 2869 | qDebug("pending syncPhone(); "); |
2609 | //mView->syncPhone(); | 2870 | //mView->syncPhone(); |
2610 | setModified(); | 2871 | setModified(); |
2611 | 2872 | ||
2612 | } | 2873 | } |