summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-12 00:04:54 (UTC)
committer zautrix <zautrix>2004-09-12 00:04:54 (UTC)
commitd03369e14779dcbedb1e6a8882859664f818f588 (patch) (unidiff)
treedbd76c26ae1b134ebb3497b6b4bdb695ec867be2
parent0a2900e71fd3d80393d67c81aab3aae19d2d680c (diff)
downloadkdepimpi-d03369e14779dcbedb1e6a8882859664f818f588.zip
kdepimpi-d03369e14779dcbedb1e6a8882859664f818f588.tar.gz
kdepimpi-d03369e14779dcbedb1e6a8882859664f818f588.tar.bz2
Fixed seqfault after sync config
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index 9e326a1..d8aa43a 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -790,129 +790,130 @@ void MainWindow::initActions()
790 } 790 }
791 icon = loadPixmap( pathString + "2rightarrowB" ); 791 icon = loadPixmap( pathString + "2rightarrowB" );
792 configureToolBarMenu->insertItem(icon, i18n("Next month"), 230); 792 configureToolBarMenu->insertItem(icon, i18n("Next month"), 230);
793 if (p-> mShowIconForwardFast) { 793 if (p-> mShowIconForwardFast) {
794 action = new QAction( i18n("Next month"), icon, i18n("Next month"),0 , this ); 794 action = new QAction( i18n("Next month"), icon, i18n("Next month"),0 , this );
795 connect( action, SIGNAL( activated() ), 795 connect( action, SIGNAL( activated() ),
796 mView, SLOT( goNextMonth() ) ); 796 mView, SLOT( goNextMonth() ) );
797 action->addTo( iconToolBar ); 797 action->addTo( iconToolBar );
798 } 798 }
799 799
800 800
801 configureToolBarMenu->insertItem(i18n("What's This?"), 300); 801 configureToolBarMenu->insertItem(i18n("What's This?"), 300);
802 802
803 if (p-> mShowIconNewEvent) 803 if (p-> mShowIconNewEvent)
804 configureToolBarMenu->setItemChecked( 10, true ); 804 configureToolBarMenu->setItemChecked( 10, true );
805 if (p->mShowIconNewTodo ) 805 if (p->mShowIconNewTodo )
806 configureToolBarMenu->setItemChecked( 20, true ); 806 configureToolBarMenu->setItemChecked( 20, true );
807 if (p-> mShowIconSearch) 807 if (p-> mShowIconSearch)
808 configureToolBarMenu->setItemChecked( 120, true ); 808 configureToolBarMenu->setItemChecked( 120, true );
809 if (p-> mShowIconList) 809 if (p-> mShowIconList)
810 configureToolBarMenu->setItemChecked( 30, true ); 810 configureToolBarMenu->setItemChecked( 30, true );
811 if (p-> mShowIconDay1) 811 if (p-> mShowIconDay1)
812 configureToolBarMenu->setItemChecked( 40, true ); 812 configureToolBarMenu->setItemChecked( 40, true );
813 if (p-> mShowIconDay5) 813 if (p-> mShowIconDay5)
814 configureToolBarMenu->setItemChecked( 50, true ); 814 configureToolBarMenu->setItemChecked( 50, true );
815 if (p-> mShowIconDay7) 815 if (p-> mShowIconDay7)
816 configureToolBarMenu->setItemChecked( 60, true ); 816 configureToolBarMenu->setItemChecked( 60, true );
817 if (p-> mShowIconMonth) 817 if (p-> mShowIconMonth)
818 configureToolBarMenu->setItemChecked( 70, true ); 818 configureToolBarMenu->setItemChecked( 70, true );
819 if (p-> mShowIconTodoview) 819 if (p-> mShowIconTodoview)
820 configureToolBarMenu->setItemChecked( 80, true ); 820 configureToolBarMenu->setItemChecked( 80, true );
821 if (p-> mShowIconBackFast) 821 if (p-> mShowIconBackFast)
822 configureToolBarMenu->setItemChecked( 200, true ); 822 configureToolBarMenu->setItemChecked( 200, true );
823 if (p-> mShowIconBack) 823 if (p-> mShowIconBack)
824 configureToolBarMenu->setItemChecked( 210, true ); 824 configureToolBarMenu->setItemChecked( 210, true );
825 if (p-> mShowIconToday) 825 if (p-> mShowIconToday)
826 configureToolBarMenu->setItemChecked( 130, true ); 826 configureToolBarMenu->setItemChecked( 130, true );
827 if (p-> mShowIconForward) 827 if (p-> mShowIconForward)
828 configureToolBarMenu->setItemChecked( 220, true ); 828 configureToolBarMenu->setItemChecked( 220, true );
829 if (p-> mShowIconForwardFast) 829 if (p-> mShowIconForwardFast)
830 configureToolBarMenu->setItemChecked( 230, true ); 830 configureToolBarMenu->setItemChecked( 230, true );
831 if (p-> mShowIconNextDays) 831 if (p-> mShowIconNextDays)
832 configureToolBarMenu->setItemChecked( 100, true ); 832 configureToolBarMenu->setItemChecked( 100, true );
833 if (p-> mShowIconNext) 833 if (p-> mShowIconNext)
834 configureToolBarMenu->setItemChecked( 110, true ); 834 configureToolBarMenu->setItemChecked( 110, true );
835 if (p-> mShowIconJournal) 835 if (p-> mShowIconJournal)
836 configureToolBarMenu->setItemChecked( 90, true ); 836 configureToolBarMenu->setItemChecked( 90, true );
837 if (p-> mShowIconWhatsThis) 837 if (p-> mShowIconWhatsThis)
838 configureToolBarMenu->setItemChecked( 300, true ); 838 configureToolBarMenu->setItemChecked( 300, true );
839 839
840 QLabel* dummy = new QLabel( iconToolBar ); 840 QLabel* dummy = new QLabel( iconToolBar );
841 dummy->setBackgroundColor( iconToolBar->backgroundColor() ); 841 dummy->setBackgroundColor( iconToolBar->backgroundColor() );
842 if (!p-> mShowIconStretch) 842 if (!p-> mShowIconStretch)
843 iconToolBar->setStretchableWidget ( dummy ) ; 843 iconToolBar->setStretchableWidget ( dummy ) ;
844 else 844 else
845 configureToolBarMenu->setItemChecked( 5, true ); 845 configureToolBarMenu->setItemChecked( 5, true );
846 if (p-> mShowIconWhatsThis) 846 if (p-> mShowIconWhatsThis)
847 QWhatsThis::whatsThisButton ( iconToolBar ); 847 QWhatsThis::whatsThisButton ( iconToolBar );
848 connect( configureToolBarMenu, SIGNAL( activated( int ) ),this, SLOT(configureToolBar( int ) ) ); 848 connect( configureToolBarMenu, SIGNAL( activated( int ) ),this, SLOT(configureToolBar( int ) ) );
849 configureAgenda( p->mHourSize ); 849 configureAgenda( p->mHourSize );
850 connect( configureAgendaMenu, SIGNAL( activated( int ) ),this, SLOT(configureAgenda( int ) ) ); 850 connect( configureAgendaMenu, SIGNAL( activated( int ) ),this, SLOT(configureAgenda( int ) ) );
851} 851}
852void MainWindow::fillSyncMenu() 852void MainWindow::fillSyncMenu()
853{ 853{
854 syncMenu->clear(); 854 if ( syncMenu->count() )
855 syncMenu->clear();
855 syncMenu->insertItem( i18n("Configure..."), 0 ); 856 syncMenu->insertItem( i18n("Configure..."), 0 );
856 syncMenu->insertSeparator(); 857 syncMenu->insertSeparator();
857 syncMenu->insertItem( i18n("Multiple sync"), 1 ); 858 syncMenu->insertItem( i18n("Multiple sync"), 1 );
858 syncMenu->insertSeparator(); 859 syncMenu->insertSeparator();
859 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 860 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
860 config.setGroup("General"); 861 config.setGroup("General");
861 QStringList prof = config.readListEntry("SyncProfileNames"); 862 QStringList prof = config.readListEntry("SyncProfileNames");
862 KOPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 863 KOPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined");
863 if ( prof.count() < 3 ) { 864 if ( prof.count() < 3 ) {
864 prof.clear(); 865 prof.clear();
865 prof << i18n("Sharp_DTM"); 866 prof << i18n("Sharp_DTM");
866 prof << i18n("Local_file"); 867 prof << i18n("Local_file");
867 prof << i18n("Last_file"); 868 prof << i18n("Last_file");
868 KSyncProfile* temp = new KSyncProfile (); 869 KSyncProfile* temp = new KSyncProfile ();
869 temp->setName( prof[0] ); 870 temp->setName( prof[0] );
870 temp->writeConfig(&config); 871 temp->writeConfig(&config);
871 temp->setName( prof[1] ); 872 temp->setName( prof[1] );
872 temp->writeConfig(&config); 873 temp->writeConfig(&config);
873 temp->setName( prof[2] ); 874 temp->setName( prof[2] );
874 temp->writeConfig(&config); 875 temp->writeConfig(&config);
875 config.setGroup("General"); 876 config.setGroup("General");
876 config.writeEntry("SyncProfileNames",prof); 877 config.writeEntry("SyncProfileNames",prof);
877 config.writeEntry("ExternSyncProfiles","Sharp_DTM"); 878 config.writeEntry("ExternSyncProfiles","Sharp_DTM");
878 config.sync(); 879 config.sync();
879 delete temp; 880 delete temp;
880 } 881 }
881 KOPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 882 KOPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
882 KOPrefs::instance()->mSyncProfileNames = prof; 883 KOPrefs::instance()->mSyncProfileNames = prof;
883 int i; 884 int i;
884 for ( i = 0; i < prof.count(); ++i ) { 885 for ( i = 0; i < prof.count(); ++i ) {
885 886
886 syncMenu->insertItem( prof[i], 1000+i ); 887 syncMenu->insertItem( prof[i], 1000+i );
887 if ( i == 2 ) 888 if ( i == 2 )
888 syncMenu->insertSeparator(); 889 syncMenu->insertSeparator();
889 } 890 }
890 QDir app_dir; 891 QDir app_dir;
891 if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 892 if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
892 syncMenu->setItemEnabled( false , 1000 ); 893 syncMenu->setItemEnabled( false , 1000 );
893 } 894 }
894 mView->setupExternSyncProfiles(); 895 mView->setupExternSyncProfiles();
895} 896}
896 897
897int MainWindow::ringSync() 898int MainWindow::ringSync()
898{ 899{
899 int syncedProfiles = 0; 900 int syncedProfiles = 0;
900 int i; 901 int i;
901 QTime timer; 902 QTime timer;
902 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 903 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
903 QStringList syncProfileNames = KOPrefs::instance()->mSyncProfileNames; 904 QStringList syncProfileNames = KOPrefs::instance()->mSyncProfileNames;
904 KSyncProfile* temp = new KSyncProfile (); 905 KSyncProfile* temp = new KSyncProfile ();
905 KOPrefs::instance()->mAskForPreferences = false; 906 KOPrefs::instance()->mAskForPreferences = false;
906 for ( i = 0; i < syncProfileNames.count(); ++i ) { 907 for ( i = 0; i < syncProfileNames.count(); ++i ) {
907 mCurrentSyncProfile = i; 908 mCurrentSyncProfile = i;
908 temp->setName(syncProfileNames[mCurrentSyncProfile]); 909 temp->setName(syncProfileNames[mCurrentSyncProfile]);
909 temp->readConfig(&config); 910 temp->readConfig(&config);
910 if ( temp->getIncludeInRingSync() && ( i < 1 || i > 2 )) { 911 if ( temp->getIncludeInRingSync() && ( i < 1 || i > 2 )) {
911 setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 912 setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
912 ++syncedProfiles; 913 ++syncedProfiles;
913 // KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); 914 // KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
914 KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); 915 KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
915 KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); 916 KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
916 KOPrefs::instance()->mShowSyncSummary = false; 917 KOPrefs::instance()->mShowSyncSummary = false;
917 mView->setSyncDevice(syncProfileNames[i] ); 918 mView->setSyncDevice(syncProfileNames[i] );
918 mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); 919 mView->setSyncName( KOPrefs::instance()->mLocalMachineName );
@@ -927,129 +928,134 @@ int MainWindow::ringSync()
927 KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; 928 KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
928 KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); 929 KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( );
929 KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); 930 KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
930 syncPhone(); 931 syncPhone();
931 } else 932 } else
932 syncRemote( temp, false ); 933 syncRemote( temp, false );
933 934
934 } 935 }
935 } 936 }
936 timer.start(); 937 timer.start();
937 setCaption(i18n("Multiple sync in progress ... please wait!") ); 938 setCaption(i18n("Multiple sync in progress ... please wait!") );
938 while ( timer.elapsed () < 2000 ) { 939 while ( timer.elapsed () < 2000 ) {
939 qApp->processEvents(); 940 qApp->processEvents();
940#ifndef _WIN32_ 941#ifndef _WIN32_
941 sleep (1); 942 sleep (1);
942#endif 943#endif
943 } 944 }
944 945
945 } 946 }
946 947
947 } 948 }
948 delete temp; 949 delete temp;
949 return syncedProfiles; 950 return syncedProfiles;
950} 951}
951 952
952void MainWindow::multiSync( bool askforPrefs ) 953void MainWindow::multiSync( bool askforPrefs )
953{ 954{
954 if (mBlockSaveFlag) 955 if (mBlockSaveFlag)
955 return; 956 return;
956 mBlockSaveFlag = true; 957 mBlockSaveFlag = true;
957 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 958 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
958 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 959 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
959 question, 960 question,
960 i18n("Yes"), i18n("No"), 961 i18n("Yes"), i18n("No"),
961 0, 0 ) != 0 ) { 962 0, 0 ) != 0 ) {
962 mBlockSaveFlag = false; 963 mBlockSaveFlag = false;
963 setCaption(i18n("Aborted! Nothing synced!")); 964 setCaption(i18n("Aborted! Nothing synced!"));
964 return; 965 return;
965 } 966 }
966 mView->setSyncDevice(i18n("Multiple profiles") ); 967 mView->setSyncDevice(i18n("Multiple profiles") );
967 KOPrefs::instance()->mSyncAlgoPrefs = KOPrefs::instance()->mRingSyncAlgoPrefs; 968 KOPrefs::instance()->mSyncAlgoPrefs = KOPrefs::instance()->mRingSyncAlgoPrefs;
968 if ( askforPrefs ) { 969 if ( askforPrefs ) {
969 mView->edit_sync_options(); 970 mView->edit_sync_options();
970 KOPrefs::instance()->mRingSyncAlgoPrefs = KOPrefs::instance()->mSyncAlgoPrefs; 971 KOPrefs::instance()->mRingSyncAlgoPrefs = KOPrefs::instance()->mSyncAlgoPrefs;
971 } 972 }
972 setCaption(i18n("Multiple sync started.") ); 973 setCaption(i18n("Multiple sync started.") );
973 qApp->processEvents(); 974 qApp->processEvents();
974 int num = ringSync() ; 975 int num = ringSync() ;
975 if ( num > 1 ) 976 if ( num > 1 )
976 ringSync(); 977 ringSync();
977 mBlockSaveFlag = false; 978 mBlockSaveFlag = false;
978 if ( num ) 979 if ( num )
979 save(); 980 save();
980 if ( num ) 981 if ( num )
981 setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); 982 setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) );
982 else 983 else
983 setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 984 setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
984 return; 985 return;
985} 986}
986void MainWindow::slotSyncMenu( int action ) 987void MainWindow::slotSyncMenu( int action )
987{ 988{
988 //qDebug("syncaction %d ", action); 989 //qDebug("syncaction %d ", action);
989 if ( action == 0 ) { 990 if ( action == 0 ) {
990 991
991 confSync(); 992 // seems to be a Qt2 event handling bug
993 // syncmenu.clear causes a segfault at first time
994 // when we call it after the main event loop, it is ok
995 // same behaviour when calling OM/Pi via QCOP for the first time
996 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
997 //confSync();
992 998
993 return; 999 return;
994 } 1000 }
995 if ( action == 1 ) { 1001 if ( action == 1 ) {
996 multiSync( true ); 1002 multiSync( true );
997 return; 1003 return;
998 } 1004 }
999 1005
1000 if (mBlockSaveFlag) 1006 if (mBlockSaveFlag)
1001 return; 1007 return;
1002 mBlockSaveFlag = true; 1008 mBlockSaveFlag = true;
1003 mCurrentSyncProfile = action - 1000 ; 1009 mCurrentSyncProfile = action - 1000 ;
1004 mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); 1010 mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] );
1005 mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); 1011 mView->setSyncName( KOPrefs::instance()->mLocalMachineName );
1006 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 1012 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
1007 KSyncProfile* temp = new KSyncProfile (); 1013 KSyncProfile* temp = new KSyncProfile ();
1008 temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 1014 temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
1009 temp->readConfig(&config); 1015 temp->readConfig(&config);
1010 KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); 1016 KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
1011 KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); 1017 KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs();
1012 KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); 1018 KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
1013 KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); 1019 KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
1014 KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); 1020 KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync();
1015 if ( action == 1000 ) { 1021 if ( action == 1000 ) {
1016 syncSharp(); 1022 syncSharp();
1017 1023
1018 } else if ( action == 1001 ) { 1024 } else if ( action == 1001 ) {
1019 syncLocalFile(); 1025 syncLocalFile();
1020 1026
1021 } else if ( action == 1002 ) { 1027 } else if ( action == 1002 ) {
1022 quickSyncLocalFile(); 1028 quickSyncLocalFile();
1023 1029
1024 } else if ( action >= 1003 ) { 1030 } else if ( action >= 1003 ) {
1025 if ( temp->getIsLocalFileSync() ) { 1031 if ( temp->getIsLocalFileSync() ) {
1026 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 1032 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
1027 KOPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); 1033 KOPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName();
1028 } else { 1034 } else {
1029 if ( temp->getIsPhoneSync() ) { 1035 if ( temp->getIsPhoneSync() ) {
1030 KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; 1036 KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
1031 KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); 1037 KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( );
1032 KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); 1038 KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
1033 syncPhone(); 1039 syncPhone();
1034 } else 1040 } else
1035 syncRemote( temp ); 1041 syncRemote( temp );
1036 1042
1037 } 1043 }
1038 } 1044 }
1039 delete temp; 1045 delete temp;
1040 mBlockSaveFlag = false; 1046 mBlockSaveFlag = false;
1041} 1047}
1042void MainWindow::setDefaultPreferences() 1048void MainWindow::setDefaultPreferences()
1043{ 1049{
1044 KOPrefs *p = KOPrefs::instance(); 1050 KOPrefs *p = KOPrefs::instance();
1045 1051
1046 p->mCompactDialogs = true; 1052 p->mCompactDialogs = true;
1047 p->mConfirm = true; 1053 p->mConfirm = true;
1048 // p->mEnableQuickTodo = false; 1054 // p->mEnableQuickTodo = false;
1049} 1055}
1050 1056
1051QString MainWindow::resourcePath() 1057QString MainWindow::resourcePath()
1052{ 1058{
1053 return KGlobal::iconLoader()->iconPath(); 1059 return KGlobal::iconLoader()->iconPath();
1054} 1060}
1055 1061
@@ -1851,131 +1857,128 @@ void MainWindow::syncLocalFile()
1851 //mView->setSyncDevice("local-file" ); 1857 //mView->setSyncDevice("local-file" );
1852 if ( syncWithFile( fn, false ) ) { 1858 if ( syncWithFile( fn, false ) ) {
1853 // Event* e = mView->getLastSyncEvent(); 1859 // Event* e = mView->getLastSyncEvent();
1854// e->setReadOnly( false ); 1860// e->setReadOnly( false );
1855// e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); 1861// e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile);
1856// e->setReadOnly( true ); 1862// e->setReadOnly( true );
1857 } 1863 }
1858 1864
1859} 1865}
1860 1866
1861bool MainWindow::syncWithFile( QString fn , bool quick ) 1867bool MainWindow::syncWithFile( QString fn , bool quick )
1862{ 1868{
1863 bool ret = false; 1869 bool ret = false;
1864 QFileInfo info; 1870 QFileInfo info;
1865 info.setFile( fn ); 1871 info.setFile( fn );
1866 QString mess; 1872 QString mess;
1867 bool loadbup = true; 1873 bool loadbup = true;
1868 if ( !info. exists() ) { 1874 if ( !info. exists() ) {
1869 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 1875 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
1870 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 1876 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
1871 mess ); 1877 mess );
1872 return ret; 1878 return ret;
1873 } 1879 }
1874 int result = 0; 1880 int result = 0;
1875 if ( !quick ) { 1881 if ( !quick ) {
1876 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 1882 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
1877 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 1883 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
1878 mess, 1884 mess,
1879 i18n("Sync"), i18n("Cancel"), 0, 1885 i18n("Sync"), i18n("Cancel"), 0,
1880 0, 1 ); 1886 0, 1 );
1881 if ( result ) 1887 if ( result )
1882 return false; 1888 return false;
1883 } 1889 }
1884 if ( KOPrefs::instance()->mAskForPreferences ) 1890 if ( KOPrefs::instance()->mAskForPreferences )
1885 mView->edit_sync_options(); 1891 mView->edit_sync_options();
1886 if ( result == 0 ) { 1892 if ( result == 0 ) {
1887 //qDebug("Now sycing ... "); 1893 //qDebug("Now sycing ... ");
1888 if ( ret = mView->syncCalendar( fn, KOPrefs::instance()->mSyncAlgoPrefs ) ) 1894 if ( ret = mView->syncCalendar( fn, KOPrefs::instance()->mSyncAlgoPrefs ) )
1889 setCaption( i18n("Synchronization successful") ); 1895 setCaption( i18n("Synchronization successful") );
1890 else 1896 else
1891 setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 1897 setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
1892 if ( ! quick ) 1898 if ( ! quick )
1893 KOPrefs::instance()->mLastSyncedLocalFile = fn; 1899 KOPrefs::instance()->mLastSyncedLocalFile = fn;
1894 slotModifiedChanged( true ); 1900 slotModifiedChanged( true );
1895 } 1901 }
1896 return ret; 1902 return ret;
1897} 1903}
1898void MainWindow::quickSyncLocalFile() 1904void MainWindow::quickSyncLocalFile()
1899{ 1905{
1900 //mView->setSyncDevice("local-file" ); 1906 //mView->setSyncDevice("local-file" );
1901 //qDebug("quickSyncLocalFile() "); 1907 //qDebug("quickSyncLocalFile() ");
1902 if ( syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false ) ) { 1908 if ( syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false ) ) {
1903 // Event* e = mView->getLastSyncEvent(); 1909 // Event* e = mView->getLastSyncEvent();
1904// e->setReadOnly( false ); 1910// e->setReadOnly( false );
1905// e->setLocation( i18n("Quick with file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); 1911// e->setLocation( i18n("Quick with file: ")+ KOPrefs::instance()->mLastSyncedLocalFile);
1906// e->setReadOnly( true ); 1912// e->setReadOnly( true );
1907 1913
1908 } 1914 }
1909} 1915}
1910 1916
1911void MainWindow::confSync() 1917void MainWindow::confSync()
1912{ 1918{
1913 mView->confSync(); 1919 mView->confSync();
1914 fillSyncMenu(); 1920 fillSyncMenu();
1915 //mView->writeSettings();
1916
1917
1918} 1921}
1919void MainWindow::syncRemote( KSyncProfile* prof, bool ask) 1922void MainWindow::syncRemote( KSyncProfile* prof, bool ask)
1920{ 1923{
1921 QString question; 1924 QString question;
1922 if ( ask ) { 1925 if ( ask ) {
1923 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 1926 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
1924 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 1927 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
1925 question, 1928 question,
1926 i18n("Yes"), i18n("No"), 1929 i18n("Yes"), i18n("No"),
1927 0, 0 ) != 0 ) 1930 0, 0 ) != 0 )
1928 return; 1931 return;
1929 } 1932 }
1930 QString command = prof->getPreSyncCommand(); 1933 QString command = prof->getPreSyncCommand();
1931 int fi; 1934 int fi;
1932 if ( (fi = command.find("$PWD$")) > 0 ) { 1935 if ( (fi = command.find("$PWD$")) > 0 ) {
1933 QString pwd = getPassword(); 1936 QString pwd = getPassword();
1934 command = command.left( fi )+ pwd + command.mid( fi+5 ); 1937 command = command.left( fi )+ pwd + command.mid( fi+5 );
1935 1938
1936 } 1939 }
1937 int maxlen = 30; 1940 int maxlen = 30;
1938 if ( QApplication::desktop()->width() > 320 ) 1941 if ( QApplication::desktop()->width() > 320 )
1939 maxlen += 25; 1942 maxlen += 25;
1940 setCaption ( i18n( "Copy remote file to local machine..." ) ); 1943 setCaption ( i18n( "Copy remote file to local machine..." ) );
1941 int fileSize = 0; 1944 int fileSize = 0;
1942 int result = system ( command ); 1945 int result = system ( command );
1943 // 0 : okay 1946 // 0 : okay
1944 // 256: no such file or dir 1947 // 256: no such file or dir
1945 // 1948 //
1946 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 1949 qDebug("KO: Remote copy result(0 = okay): %d ",result );
1947 if ( result != 0 ) { 1950 if ( result != 0 ) {
1948 int len = maxlen; 1951 int len = maxlen;
1949 while ( len < command.length() ) { 1952 while ( len < command.length() ) {
1950 command.insert( len , "\n" ); 1953 command.insert( len , "\n" );
1951 len += maxlen +2; 1954 len += maxlen +2;
1952 } 1955 }
1953 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) ; 1956 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) ;
1954 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), 1957 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"),
1955 question, 1958 question,
1956 i18n("Okay!")) ; 1959 i18n("Okay!")) ;
1957 setCaption ("KO/Pi"); 1960 setCaption ("KO/Pi");
1958 return; 1961 return;
1959 } 1962 }
1960 setCaption ( i18n( "Copying succeed." ) ); 1963 setCaption ( i18n( "Copying succeed." ) );
1961 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 1964 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
1962 if ( syncWithFile( prof->getLocalTempFile(), true ) ) { 1965 if ( syncWithFile( prof->getLocalTempFile(), true ) ) {
1963// Event* e = mView->getLastSyncEvent(); 1966// Event* e = mView->getLastSyncEvent();
1964// e->setReadOnly( false ); 1967// e->setReadOnly( false );
1965// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 1968// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
1966// e->setReadOnly( true ); 1969// e->setReadOnly( true );
1967 if ( KOPrefs::instance()->mWriteBackFile ) { 1970 if ( KOPrefs::instance()->mWriteBackFile ) {
1968 command = prof->getPostSyncCommand(); 1971 command = prof->getPostSyncCommand();
1969 setCaption ( i18n( "Writing back file ..." ) ); 1972 setCaption ( i18n( "Writing back file ..." ) );
1970 result = system ( command ); 1973 result = system ( command );
1971 qDebug("KO: Writing back file result: %d ", result); 1974 qDebug("KO: Writing back file result: %d ", result);
1972 if ( result != 0 ) { 1975 if ( result != 0 ) {
1973 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 1976 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
1974 return; 1977 return;
1975 } else { 1978 } else {
1976 setCaption ( i18n( "Syncronization sucessfully completed" ) ); 1979 setCaption ( i18n( "Syncronization sucessfully completed" ) );
1977 } 1980 }
1978 } 1981 }
1979 } 1982 }
1980 return; 1983 return;
1981} 1984}