summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp1
-rw-r--r--libkdepim/ksyncmanager.cpp4
2 files changed, 4 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index b56f1f9..04051a2 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -2961,773 +2961,774 @@ void CalendarView::action_mail()
2961 } 2961 }
2962 2962
2963 mailobject.emailEvent(anEvent); 2963 mailobject.emailEvent(anEvent);
2964#endif 2964#endif
2965} 2965}
2966 2966
2967 2967
2968void CalendarView::schedule_publish(Incidence *incidence) 2968void CalendarView::schedule_publish(Incidence *incidence)
2969{ 2969{
2970 Event *event = 0; 2970 Event *event = 0;
2971 Todo *todo = 0; 2971 Todo *todo = 0;
2972 2972
2973 if (incidence == 0) { 2973 if (incidence == 0) {
2974 incidence = mViewManager->currentView()->selectedIncidences().first(); 2974 incidence = mViewManager->currentView()->selectedIncidences().first();
2975 if (incidence == 0) { 2975 if (incidence == 0) {
2976 incidence = mTodoList->selectedIncidences().first(); 2976 incidence = mTodoList->selectedIncidences().first();
2977 } 2977 }
2978 } 2978 }
2979 if ( incidence && incidence->type() == "Event" ) { 2979 if ( incidence && incidence->type() == "Event" ) {
2980 event = static_cast<Event *>(incidence); 2980 event = static_cast<Event *>(incidence);
2981 } else { 2981 } else {
2982 if ( incidence && incidence->type() == "Todo" ) { 2982 if ( incidence && incidence->type() == "Todo" ) {
2983 todo = static_cast<Todo *>(incidence); 2983 todo = static_cast<Todo *>(incidence);
2984 } 2984 }
2985 } 2985 }
2986 2986
2987 if (!event && !todo) { 2987 if (!event && !todo) {
2988 KMessageBox::sorry(this,i18n("No event selected.")); 2988 KMessageBox::sorry(this,i18n("No event selected."));
2989 return; 2989 return;
2990 } 2990 }
2991 2991
2992 PublishDialog *publishdlg = new PublishDialog(); 2992 PublishDialog *publishdlg = new PublishDialog();
2993 if (incidence->attendeeCount()>0) { 2993 if (incidence->attendeeCount()>0) {
2994 QPtrList<Attendee> attendees = incidence->attendees(); 2994 QPtrList<Attendee> attendees = incidence->attendees();
2995 attendees.first(); 2995 attendees.first();
2996 while ( attendees.current()!=0 ) { 2996 while ( attendees.current()!=0 ) {
2997 publishdlg->addAttendee(attendees.current()); 2997 publishdlg->addAttendee(attendees.current());
2998 attendees.next(); 2998 attendees.next();
2999 } 2999 }
3000 } 3000 }
3001 bool send = true; 3001 bool send = true;
3002 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3002 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3003 if ( publishdlg->exec() != QDialog::Accepted ) 3003 if ( publishdlg->exec() != QDialog::Accepted )
3004 send = false; 3004 send = false;
3005 } 3005 }
3006 if ( send ) { 3006 if ( send ) {
3007 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3007 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3008 if ( event ) { 3008 if ( event ) {
3009 Event *ev = new Event(*event); 3009 Event *ev = new Event(*event);
3010 ev->registerObserver(0); 3010 ev->registerObserver(0);
3011 ev->clearAttendees(); 3011 ev->clearAttendees();
3012 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3012 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3013 delete(ev); 3013 delete(ev);
3014 } 3014 }
3015 } else { 3015 } else {
3016 if ( todo ) { 3016 if ( todo ) {
3017 Todo *ev = new Todo(*todo); 3017 Todo *ev = new Todo(*todo);
3018 ev->registerObserver(0); 3018 ev->registerObserver(0);
3019 ev->clearAttendees(); 3019 ev->clearAttendees();
3020 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3020 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3021 delete(ev); 3021 delete(ev);
3022 } 3022 }
3023 } 3023 }
3024 } 3024 }
3025 } 3025 }
3026 delete publishdlg; 3026 delete publishdlg;
3027} 3027}
3028 3028
3029void CalendarView::schedule_request(Incidence *incidence) 3029void CalendarView::schedule_request(Incidence *incidence)
3030{ 3030{
3031 schedule(Scheduler::Request,incidence); 3031 schedule(Scheduler::Request,incidence);
3032} 3032}
3033 3033
3034void CalendarView::schedule_refresh(Incidence *incidence) 3034void CalendarView::schedule_refresh(Incidence *incidence)
3035{ 3035{
3036 schedule(Scheduler::Refresh,incidence); 3036 schedule(Scheduler::Refresh,incidence);
3037} 3037}
3038 3038
3039void CalendarView::schedule_cancel(Incidence *incidence) 3039void CalendarView::schedule_cancel(Incidence *incidence)
3040{ 3040{
3041 schedule(Scheduler::Cancel,incidence); 3041 schedule(Scheduler::Cancel,incidence);
3042} 3042}
3043 3043
3044void CalendarView::schedule_add(Incidence *incidence) 3044void CalendarView::schedule_add(Incidence *incidence)
3045{ 3045{
3046 schedule(Scheduler::Add,incidence); 3046 schedule(Scheduler::Add,incidence);
3047} 3047}
3048 3048
3049void CalendarView::schedule_reply(Incidence *incidence) 3049void CalendarView::schedule_reply(Incidence *incidence)
3050{ 3050{
3051 schedule(Scheduler::Reply,incidence); 3051 schedule(Scheduler::Reply,incidence);
3052} 3052}
3053 3053
3054void CalendarView::schedule_counter(Incidence *incidence) 3054void CalendarView::schedule_counter(Incidence *incidence)
3055{ 3055{
3056 schedule(Scheduler::Counter,incidence); 3056 schedule(Scheduler::Counter,incidence);
3057} 3057}
3058 3058
3059void CalendarView::schedule_declinecounter(Incidence *incidence) 3059void CalendarView::schedule_declinecounter(Incidence *incidence)
3060{ 3060{
3061 schedule(Scheduler::Declinecounter,incidence); 3061 schedule(Scheduler::Declinecounter,incidence);
3062} 3062}
3063 3063
3064void CalendarView::schedule_publish_freebusy(int daysToPublish) 3064void CalendarView::schedule_publish_freebusy(int daysToPublish)
3065{ 3065{
3066 QDateTime start = QDateTime::currentDateTime(); 3066 QDateTime start = QDateTime::currentDateTime();
3067 QDateTime end = start.addDays(daysToPublish); 3067 QDateTime end = start.addDays(daysToPublish);
3068 3068
3069 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 3069 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3070 freebusy->setOrganizer(KOPrefs::instance()->email()); 3070 freebusy->setOrganizer(KOPrefs::instance()->email());
3071 3071
3072 3072
3073 PublishDialog *publishdlg = new PublishDialog(); 3073 PublishDialog *publishdlg = new PublishDialog();
3074 if ( publishdlg->exec() == QDialog::Accepted ) { 3074 if ( publishdlg->exec() == QDialog::Accepted ) {
3075 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3075 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3076 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 3076 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3077 delete(freebusy); 3077 delete(freebusy);
3078 } 3078 }
3079 } 3079 }
3080 delete publishdlg; 3080 delete publishdlg;
3081} 3081}
3082 3082
3083void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 3083void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3084{ 3084{
3085 Event *event = 0; 3085 Event *event = 0;
3086 Todo *todo = 0; 3086 Todo *todo = 0;
3087 3087
3088 if (incidence == 0) { 3088 if (incidence == 0) {
3089 incidence = mViewManager->currentView()->selectedIncidences().first(); 3089 incidence = mViewManager->currentView()->selectedIncidences().first();
3090 if (incidence == 0) { 3090 if (incidence == 0) {
3091 incidence = mTodoList->selectedIncidences().first(); 3091 incidence = mTodoList->selectedIncidences().first();
3092 } 3092 }
3093 } 3093 }
3094 if ( incidence && incidence->type() == "Event" ) { 3094 if ( incidence && incidence->type() == "Event" ) {
3095 event = static_cast<Event *>(incidence); 3095 event = static_cast<Event *>(incidence);
3096 } 3096 }
3097 if ( incidence && incidence->type() == "Todo" ) { 3097 if ( incidence && incidence->type() == "Todo" ) {
3098 todo = static_cast<Todo *>(incidence); 3098 todo = static_cast<Todo *>(incidence);
3099 } 3099 }
3100 3100
3101 if (!event && !todo) { 3101 if (!event && !todo) {
3102 KMessageBox::sorry(this,i18n("No event selected.")); 3102 KMessageBox::sorry(this,i18n("No event selected."));
3103 return; 3103 return;
3104 } 3104 }
3105 3105
3106 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 3106 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
3107 KMessageBox::sorry(this,i18n("The event has no attendees.")); 3107 KMessageBox::sorry(this,i18n("The event has no attendees."));
3108 return; 3108 return;
3109 } 3109 }
3110 3110
3111 Event *ev = 0; 3111 Event *ev = 0;
3112 if (event) ev = new Event(*event); 3112 if (event) ev = new Event(*event);
3113 Todo *to = 0; 3113 Todo *to = 0;
3114 if (todo) to = new Todo(*todo); 3114 if (todo) to = new Todo(*todo);
3115 3115
3116 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 3116 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
3117 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 3117 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
3118 if (!me) { 3118 if (!me) {
3119 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 3119 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
3120 return; 3120 return;
3121 } 3121 }
3122 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 3122 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
3123 StatusDialog *statdlg = new StatusDialog(this); 3123 StatusDialog *statdlg = new StatusDialog(this);
3124 if (!statdlg->exec()==QDialog::Accepted) return; 3124 if (!statdlg->exec()==QDialog::Accepted) return;
3125 me->setStatus( statdlg->status() ); 3125 me->setStatus( statdlg->status() );
3126 delete(statdlg); 3126 delete(statdlg);
3127 } 3127 }
3128 Attendee *menew = new Attendee(*me); 3128 Attendee *menew = new Attendee(*me);
3129 if (ev) { 3129 if (ev) {
3130 ev->clearAttendees(); 3130 ev->clearAttendees();
3131 ev->addAttendee(menew,false); 3131 ev->addAttendee(menew,false);
3132 } else { 3132 } else {
3133 if (to) { 3133 if (to) {
3134 todo->clearAttendees(); 3134 todo->clearAttendees();
3135 todo->addAttendee(menew,false); 3135 todo->addAttendee(menew,false);
3136 } 3136 }
3137 } 3137 }
3138 } 3138 }
3139 3139
3140 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3140 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3141 if (ev) { 3141 if (ev) {
3142 if ( !dlg->addMessage(ev,method) ) delete(ev); 3142 if ( !dlg->addMessage(ev,method) ) delete(ev);
3143 } else { 3143 } else {
3144 if (to) { 3144 if (to) {
3145 if ( !dlg->addMessage(to,method) ) delete(to); 3145 if ( !dlg->addMessage(to,method) ) delete(to);
3146 } 3146 }
3147 } 3147 }
3148} 3148}
3149 3149
3150void CalendarView::openAddressbook() 3150void CalendarView::openAddressbook()
3151{ 3151{
3152 KRun::runCommand("kaddressbook"); 3152 KRun::runCommand("kaddressbook");
3153} 3153}
3154 3154
3155void CalendarView::setModified(bool modified) 3155void CalendarView::setModified(bool modified)
3156{ 3156{
3157 if ( modified ) 3157 if ( modified )
3158 emit signalmodified(); 3158 emit signalmodified();
3159 if (mModified != modified) { 3159 if (mModified != modified) {
3160 mModified = modified; 3160 mModified = modified;
3161 emit modifiedChanged(mModified); 3161 emit modifiedChanged(mModified);
3162 } 3162 }
3163} 3163}
3164 3164
3165bool CalendarView::isReadOnly() 3165bool CalendarView::isReadOnly()
3166{ 3166{
3167 return mReadOnly; 3167 return mReadOnly;
3168} 3168}
3169 3169
3170void CalendarView::setReadOnly(bool readOnly) 3170void CalendarView::setReadOnly(bool readOnly)
3171{ 3171{
3172 if (mReadOnly != readOnly) { 3172 if (mReadOnly != readOnly) {
3173 mReadOnly = readOnly; 3173 mReadOnly = readOnly;
3174 emit readOnlyChanged(mReadOnly); 3174 emit readOnlyChanged(mReadOnly);
3175 } 3175 }
3176} 3176}
3177 3177
3178bool CalendarView::isModified() 3178bool CalendarView::isModified()
3179{ 3179{
3180 return mModified; 3180 return mModified;
3181} 3181}
3182 3182
3183void CalendarView::printSetup() 3183void CalendarView::printSetup()
3184{ 3184{
3185#ifndef KORG_NOPRINTER 3185#ifndef KORG_NOPRINTER
3186 createPrinter(); 3186 createPrinter();
3187 3187
3188 mCalPrinter->setupPrinter(); 3188 mCalPrinter->setupPrinter();
3189#endif 3189#endif
3190} 3190}
3191 3191
3192void CalendarView::print() 3192void CalendarView::print()
3193{ 3193{
3194#ifndef KORG_NOPRINTER 3194#ifndef KORG_NOPRINTER
3195 createPrinter(); 3195 createPrinter();
3196 3196
3197 DateList tmpDateList = mNavigator->selectedDates(); 3197 DateList tmpDateList = mNavigator->selectedDates();
3198 mCalPrinter->print(CalPrinter::Month, 3198 mCalPrinter->print(CalPrinter::Month,
3199 tmpDateList.first(), tmpDateList.last()); 3199 tmpDateList.first(), tmpDateList.last());
3200#endif 3200#endif
3201} 3201}
3202 3202
3203void CalendarView::printPreview() 3203void CalendarView::printPreview()
3204{ 3204{
3205#ifndef KORG_NOPRINTER 3205#ifndef KORG_NOPRINTER
3206 kdDebug() << "CalendarView::printPreview()" << endl; 3206 kdDebug() << "CalendarView::printPreview()" << endl;
3207 3207
3208 createPrinter(); 3208 createPrinter();
3209 3209
3210 DateList tmpDateList = mNavigator->selectedDates(); 3210 DateList tmpDateList = mNavigator->selectedDates();
3211 3211
3212 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 3212 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
3213 tmpDateList.last()); 3213 tmpDateList.last());
3214#endif 3214#endif
3215} 3215}
3216 3216
3217void CalendarView::exportICalendar() 3217void CalendarView::exportICalendar()
3218{ 3218{
3219 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 3219 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
3220 3220
3221 // Force correct extension 3221 // Force correct extension
3222 if (filename.right(4) != ".ics") filename += ".ics"; 3222 if (filename.right(4) != ".ics") filename += ".ics";
3223 3223
3224 FileStorage storage( mCalendar, filename, new ICalFormat() ); 3224 FileStorage storage( mCalendar, filename, new ICalFormat() );
3225 storage.save(); 3225 storage.save();
3226} 3226}
3227 3227
3228bool CalendarView::exportVCalendar( QString filename ) 3228bool CalendarView::exportVCalendar( QString filename )
3229{ 3229{
3230 if (mCalendar->journals().count() > 0) { 3230 if (mCalendar->journals().count() > 0) {
3231 int result = KMessageBox::warningContinueCancel(this, 3231 int result = KMessageBox::warningContinueCancel(this,
3232 i18n("The journal entries can not be\nexported to a vCalendar file."), 3232 i18n("The journal entries can not be\nexported to a vCalendar file."),
3233 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 3233 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
3234 true); 3234 true);
3235 if (result != KMessageBox::Continue) return false; 3235 if (result != KMessageBox::Continue) return false;
3236 } 3236 }
3237 3237
3238 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 3238 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
3239 3239
3240 // Force correct extension 3240 // Force correct extension
3241 if (filename.right(4) != ".vcs") filename += ".vcs"; 3241 if (filename.right(4) != ".vcs") filename += ".vcs";
3242 3242
3243 FileStorage storage( mCalendar, filename, new VCalFormat ); 3243 FileStorage storage( mCalendar, filename, new VCalFormat );
3244 return storage.save(); 3244 return storage.save();
3245 3245
3246} 3246}
3247 3247
3248void CalendarView::eventUpdated(Incidence *) 3248void CalendarView::eventUpdated(Incidence *)
3249{ 3249{
3250 setModified(); 3250 setModified();
3251 // Don't call updateView here. The code, which has caused the update of the 3251 // Don't call updateView here. The code, which has caused the update of the
3252 // event is responsible for updating the view. 3252 // event is responsible for updating the view.
3253 // updateView(); 3253 // updateView();
3254} 3254}
3255 3255
3256void CalendarView::adaptNavigationUnits() 3256void CalendarView::adaptNavigationUnits()
3257{ 3257{
3258 if (mViewManager->currentView()->isEventView()) { 3258 if (mViewManager->currentView()->isEventView()) {
3259 int days = mViewManager->currentView()->currentDateCount(); 3259 int days = mViewManager->currentView()->currentDateCount();
3260 if (days == 1) { 3260 if (days == 1) {
3261 emit changeNavStringPrev(i18n("&Previous Day")); 3261 emit changeNavStringPrev(i18n("&Previous Day"));
3262 emit changeNavStringNext(i18n("&Next Day")); 3262 emit changeNavStringNext(i18n("&Next Day"));
3263 } else { 3263 } else {
3264 emit changeNavStringPrev(i18n("&Previous Week")); 3264 emit changeNavStringPrev(i18n("&Previous Week"));
3265 emit changeNavStringNext(i18n("&Next Week")); 3265 emit changeNavStringNext(i18n("&Next Week"));
3266 } 3266 }
3267 } 3267 }
3268} 3268}
3269 3269
3270void CalendarView::processMainViewSelection( Incidence *incidence ) 3270void CalendarView::processMainViewSelection( Incidence *incidence )
3271{ 3271{
3272 if ( incidence ) mTodoList->clearSelection(); 3272 if ( incidence ) mTodoList->clearSelection();
3273 processIncidenceSelection( incidence ); 3273 processIncidenceSelection( incidence );
3274} 3274}
3275 3275
3276void CalendarView::processTodoListSelection( Incidence *incidence ) 3276void CalendarView::processTodoListSelection( Incidence *incidence )
3277{ 3277{
3278 if ( incidence && mViewManager->currentView() ) { 3278 if ( incidence && mViewManager->currentView() ) {
3279 mViewManager->currentView()->clearSelection(); 3279 mViewManager->currentView()->clearSelection();
3280 } 3280 }
3281 processIncidenceSelection( incidence ); 3281 processIncidenceSelection( incidence );
3282} 3282}
3283 3283
3284void CalendarView::processIncidenceSelection( Incidence *incidence ) 3284void CalendarView::processIncidenceSelection( Incidence *incidence )
3285{ 3285{
3286 if ( incidence == mSelectedIncidence ) return; 3286 if ( incidence == mSelectedIncidence ) return;
3287 3287
3288 mSelectedIncidence = incidence; 3288 mSelectedIncidence = incidence;
3289 3289
3290 emit incidenceSelected( mSelectedIncidence ); 3290 emit incidenceSelected( mSelectedIncidence );
3291 3291
3292 if ( incidence && incidence->type() == "Event" ) { 3292 if ( incidence && incidence->type() == "Event" ) {
3293 Event *event = static_cast<Event *>( incidence ); 3293 Event *event = static_cast<Event *>( incidence );
3294 if ( event->organizer() == KOPrefs::instance()->email() ) { 3294 if ( event->organizer() == KOPrefs::instance()->email() ) {
3295 emit organizerEventsSelected( true ); 3295 emit organizerEventsSelected( true );
3296 } else { 3296 } else {
3297 emit organizerEventsSelected(false); 3297 emit organizerEventsSelected(false);
3298 } 3298 }
3299 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3299 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3300 KOPrefs::instance()->email() ) ) { 3300 KOPrefs::instance()->email() ) ) {
3301 emit groupEventsSelected( true ); 3301 emit groupEventsSelected( true );
3302 } else { 3302 } else {
3303 emit groupEventsSelected(false); 3303 emit groupEventsSelected(false);
3304 } 3304 }
3305 return; 3305 return;
3306 } else { 3306 } else {
3307 if ( incidence && incidence->type() == "Todo" ) { 3307 if ( incidence && incidence->type() == "Todo" ) {
3308 emit todoSelected( true ); 3308 emit todoSelected( true );
3309 Todo *event = static_cast<Todo *>( incidence ); 3309 Todo *event = static_cast<Todo *>( incidence );
3310 if ( event->organizer() == KOPrefs::instance()->email() ) { 3310 if ( event->organizer() == KOPrefs::instance()->email() ) {
3311 emit organizerEventsSelected( true ); 3311 emit organizerEventsSelected( true );
3312 } else { 3312 } else {
3313 emit organizerEventsSelected(false); 3313 emit organizerEventsSelected(false);
3314 } 3314 }
3315 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3315 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3316 KOPrefs::instance()->email() ) ) { 3316 KOPrefs::instance()->email() ) ) {
3317 emit groupEventsSelected( true ); 3317 emit groupEventsSelected( true );
3318 } else { 3318 } else {
3319 emit groupEventsSelected(false); 3319 emit groupEventsSelected(false);
3320 } 3320 }
3321 return; 3321 return;
3322 } else { 3322 } else {
3323 emit todoSelected( false ); 3323 emit todoSelected( false );
3324 emit organizerEventsSelected(false); 3324 emit organizerEventsSelected(false);
3325 emit groupEventsSelected(false); 3325 emit groupEventsSelected(false);
3326 } 3326 }
3327 return; 3327 return;
3328 } 3328 }
3329 3329
3330 /* if ( incidence && incidence->type() == "Todo" ) { 3330 /* if ( incidence && incidence->type() == "Todo" ) {
3331 emit todoSelected( true ); 3331 emit todoSelected( true );
3332 } else { 3332 } else {
3333 emit todoSelected( false ); 3333 emit todoSelected( false );
3334 }*/ 3334 }*/
3335} 3335}
3336 3336
3337 3337
3338void CalendarView::checkClipboard() 3338void CalendarView::checkClipboard()
3339{ 3339{
3340#ifndef KORG_NODND 3340#ifndef KORG_NODND
3341 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 3341 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
3342 emit pasteEnabled(true); 3342 emit pasteEnabled(true);
3343 } else { 3343 } else {
3344 emit pasteEnabled(false); 3344 emit pasteEnabled(false);
3345 } 3345 }
3346#endif 3346#endif
3347} 3347}
3348 3348
3349void CalendarView::showDates(const DateList &selectedDates) 3349void CalendarView::showDates(const DateList &selectedDates)
3350{ 3350{
3351 // kdDebug() << "CalendarView::selectDates()" << endl; 3351 // kdDebug() << "CalendarView::selectDates()" << endl;
3352 3352
3353 if ( mViewManager->currentView() ) { 3353 if ( mViewManager->currentView() ) {
3354 updateView( selectedDates.first(), selectedDates.last() ); 3354 updateView( selectedDates.first(), selectedDates.last() );
3355 } else { 3355 } else {
3356 mViewManager->showAgendaView(); 3356 mViewManager->showAgendaView();
3357 } 3357 }
3358 3358
3359 QString selDates; 3359 QString selDates;
3360 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true); 3360 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true);
3361 if (selectedDates.first() < selectedDates.last() ) 3361 if (selectedDates.first() < selectedDates.last() )
3362 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 3362 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
3363 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 3363 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
3364 3364
3365} 3365}
3366 3366
3367QPtrList<CalFilter> CalendarView::filters() 3367QPtrList<CalFilter> CalendarView::filters()
3368{ 3368{
3369 return mFilters; 3369 return mFilters;
3370 3370
3371} 3371}
3372void CalendarView::editFilters() 3372void CalendarView::editFilters()
3373{ 3373{
3374 // kdDebug() << "CalendarView::editFilters()" << endl; 3374 // kdDebug() << "CalendarView::editFilters()" << endl;
3375 3375
3376 CalFilter *filter = mFilters.first(); 3376 CalFilter *filter = mFilters.first();
3377 while(filter) { 3377 while(filter) {
3378 kdDebug() << " Filter: " << filter->name() << endl; 3378 kdDebug() << " Filter: " << filter->name() << endl;
3379 filter = mFilters.next(); 3379 filter = mFilters.next();
3380 } 3380 }
3381 3381
3382 mDialogManager->showFilterEditDialog(&mFilters); 3382 mDialogManager->showFilterEditDialog(&mFilters);
3383} 3383}
3384void CalendarView::toggleFilter() 3384void CalendarView::toggleFilter()
3385{ 3385{
3386 showFilter(! mFilterView->isVisible()); 3386 showFilter(! mFilterView->isVisible());
3387} 3387}
3388 3388
3389KOFilterView *CalendarView::filterView() 3389KOFilterView *CalendarView::filterView()
3390{ 3390{
3391 return mFilterView; 3391 return mFilterView;
3392} 3392}
3393void CalendarView::selectFilter( int fil ) 3393void CalendarView::selectFilter( int fil )
3394{ 3394{
3395 mFilterView->setSelectedFilter( fil ); 3395 mFilterView->setSelectedFilter( fil );
3396} 3396}
3397void CalendarView::showFilter(bool visible) 3397void CalendarView::showFilter(bool visible)
3398{ 3398{
3399 if (visible) mFilterView->show(); 3399 if (visible) mFilterView->show();
3400 else mFilterView->hide(); 3400 else mFilterView->hide();
3401} 3401}
3402void CalendarView::toggleFilerEnabled( ) 3402void CalendarView::toggleFilerEnabled( )
3403{ 3403{
3404 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 3404 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
3405 if ( !mFilterView->filtersEnabled() ) 3405 if ( !mFilterView->filtersEnabled() )
3406 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 3406 topLevelWidget()->setCaption( i18n("Filter disabled ") );
3407 3407
3408} 3408}
3409void CalendarView::updateFilter() 3409void CalendarView::updateFilter()
3410{ 3410{
3411 CalFilter *filter = mFilterView->selectedFilter(); 3411 CalFilter *filter = mFilterView->selectedFilter();
3412 if (filter) { 3412 if (filter) {
3413 if (mFilterView->filtersEnabled()) { 3413 if (mFilterView->filtersEnabled()) {
3414 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() ); 3414 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() );
3415 filter->setEnabled(true); 3415 filter->setEnabled(true);
3416 } 3416 }
3417 else filter->setEnabled(false); 3417 else filter->setEnabled(false);
3418 mCalendar->setFilter(filter); 3418 mCalendar->setFilter(filter);
3419 updateView(); 3419 updateView();
3420 } 3420 }
3421} 3421}
3422 3422
3423void CalendarView::filterEdited() 3423void CalendarView::filterEdited()
3424{ 3424{
3425 mFilterView->updateFilters(); 3425 mFilterView->updateFilters();
3426 updateFilter(); 3426 updateFilter();
3427 writeSettings(); 3427 writeSettings();
3428} 3428}
3429 3429
3430 3430
3431void CalendarView::takeOverEvent() 3431void CalendarView::takeOverEvent()
3432{ 3432{
3433 Incidence *incidence = currentSelection(); 3433 Incidence *incidence = currentSelection();
3434 3434
3435 if (!incidence) return; 3435 if (!incidence) return;
3436 3436
3437 incidence->setOrganizer(KOPrefs::instance()->email()); 3437 incidence->setOrganizer(KOPrefs::instance()->email());
3438 incidence->recreate(); 3438 incidence->recreate();
3439 incidence->setReadOnly(false); 3439 incidence->setReadOnly(false);
3440 3440
3441 updateView(); 3441 updateView();
3442} 3442}
3443 3443
3444void CalendarView::takeOverCalendar() 3444void CalendarView::takeOverCalendar()
3445{ 3445{
3446 // TODO: Create Calendar::allIncidences() function and use it here 3446 // TODO: Create Calendar::allIncidences() function and use it here
3447 3447
3448 QPtrList<Event> events = mCalendar->events(); 3448 QPtrList<Event> events = mCalendar->events();
3449 for(uint i=0; i<events.count(); ++i) { 3449 for(uint i=0; i<events.count(); ++i) {
3450 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 3450 events.at(i)->setOrganizer(KOPrefs::instance()->email());
3451 events.at(i)->recreate(); 3451 events.at(i)->recreate();
3452 events.at(i)->setReadOnly(false); 3452 events.at(i)->setReadOnly(false);
3453 } 3453 }
3454 3454
3455 QPtrList<Todo> todos = mCalendar->todos(); 3455 QPtrList<Todo> todos = mCalendar->todos();
3456 for(uint i=0; i<todos.count(); ++i) { 3456 for(uint i=0; i<todos.count(); ++i) {
3457 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 3457 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
3458 todos.at(i)->recreate(); 3458 todos.at(i)->recreate();
3459 todos.at(i)->setReadOnly(false); 3459 todos.at(i)->setReadOnly(false);
3460 } 3460 }
3461 3461
3462 QPtrList<Journal> journals = mCalendar->journals(); 3462 QPtrList<Journal> journals = mCalendar->journals();
3463 for(uint i=0; i<journals.count(); ++i) { 3463 for(uint i=0; i<journals.count(); ++i) {
3464 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 3464 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
3465 journals.at(i)->recreate(); 3465 journals.at(i)->recreate();
3466 journals.at(i)->setReadOnly(false); 3466 journals.at(i)->setReadOnly(false);
3467 } 3467 }
3468 3468
3469 updateView(); 3469 updateView();
3470} 3470}
3471 3471
3472void CalendarView::showIntro() 3472void CalendarView::showIntro()
3473{ 3473{
3474 kdDebug() << "To be implemented." << endl; 3474 kdDebug() << "To be implemented." << endl;
3475} 3475}
3476 3476
3477QWidgetStack *CalendarView::viewStack() 3477QWidgetStack *CalendarView::viewStack()
3478{ 3478{
3479 return mRightFrame; 3479 return mRightFrame;
3480} 3480}
3481 3481
3482QWidget *CalendarView::leftFrame() 3482QWidget *CalendarView::leftFrame()
3483{ 3483{
3484 return mLeftFrame; 3484 return mLeftFrame;
3485} 3485}
3486 3486
3487DateNavigator *CalendarView::dateNavigator() 3487DateNavigator *CalendarView::dateNavigator()
3488{ 3488{
3489 return mNavigator; 3489 return mNavigator;
3490} 3490}
3491 3491
3492KDateNavigator* CalendarView::dateNavigatorWidget() 3492KDateNavigator* CalendarView::dateNavigatorWidget()
3493{ 3493{
3494 return mDateNavigator; 3494 return mDateNavigator;
3495} 3495}
3496void CalendarView::toggleDateNavigatorWidget() 3496void CalendarView::toggleDateNavigatorWidget()
3497{ 3497{
3498 if (mDateNavigator->isVisible()) 3498 if (mDateNavigator->isVisible())
3499 mDateNavigator->hide(); 3499 mDateNavigator->hide();
3500 else 3500 else
3501 mDateNavigator->show(); 3501 mDateNavigator->show();
3502} 3502}
3503void CalendarView::addView(KOrg::BaseView *view) 3503void CalendarView::addView(KOrg::BaseView *view)
3504{ 3504{
3505 mViewManager->addView(view); 3505 mViewManager->addView(view);
3506} 3506}
3507 3507
3508void CalendarView::showView(KOrg::BaseView *view) 3508void CalendarView::showView(KOrg::BaseView *view)
3509{ 3509{
3510 mViewManager->showView(view, mLeftFrame->isVisible()); 3510 mViewManager->showView(view, mLeftFrame->isVisible());
3511} 3511}
3512 3512
3513Incidence *CalendarView::currentSelection() 3513Incidence *CalendarView::currentSelection()
3514{ 3514{
3515 return mViewManager->currentSelection(); 3515 return mViewManager->currentSelection();
3516} 3516}
3517void CalendarView::toggleAllDaySize() 3517void CalendarView::toggleAllDaySize()
3518{ 3518{
3519 /* 3519 /*
3520 if ( KOPrefs::instance()->mAllDaySize > 47 ) 3520 if ( KOPrefs::instance()->mAllDaySize > 47 )
3521 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 3521 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
3522 else 3522 else
3523 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 3523 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
3524 */ 3524 */
3525 viewManager()->agendaView()->toggleAllDay(); 3525 viewManager()->agendaView()->toggleAllDay();
3526} 3526}
3527void CalendarView::toggleExpand() 3527void CalendarView::toggleExpand()
3528{ 3528{
3529 // if ( mLeftFrame->isHidden() ) { 3529 // if ( mLeftFrame->isHidden() ) {
3530 // mLeftFrame->show(); 3530 // mLeftFrame->show();
3531 // emit calendarViewExpanded( false ); 3531 // emit calendarViewExpanded( false );
3532 // } else { 3532 // } else {
3533 // mLeftFrame->hide(); 3533 // mLeftFrame->hide();
3534 // emit calendarViewExpanded( true ); 3534 // emit calendarViewExpanded( true );
3535 // } 3535 // }
3536 3536
3537 globalFlagBlockAgenda = 1; 3537 globalFlagBlockAgenda = 1;
3538 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 3538 emit calendarViewExpanded( !mLeftFrame->isHidden() );
3539 globalFlagBlockAgenda = 5; 3539 globalFlagBlockAgenda = 5;
3540 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 3540 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
3541 //mViewManager->showView( 0, true ); 3541 //mViewManager->showView( 0, true );
3542} 3542}
3543 3543
3544void CalendarView::calendarModified( bool modified, Calendar * ) 3544void CalendarView::calendarModified( bool modified, Calendar * )
3545{ 3545{
3546 setModified( modified ); 3546 setModified( modified );
3547} 3547}
3548 3548
3549Todo *CalendarView::selectedTodo() 3549Todo *CalendarView::selectedTodo()
3550{ 3550{
3551 Incidence *incidence = currentSelection(); 3551 Incidence *incidence = currentSelection();
3552 if ( incidence && incidence->type() == "Todo" ) { 3552 if ( incidence && incidence->type() == "Todo" ) {
3553 return static_cast<Todo *>( incidence ); 3553 return static_cast<Todo *>( incidence );
3554 } 3554 }
3555 3555
3556 incidence = mTodoList->selectedIncidences().first(); 3556 incidence = mTodoList->selectedIncidences().first();
3557 if ( incidence && incidence->type() == "Todo" ) { 3557 if ( incidence && incidence->type() == "Todo" ) {
3558 return static_cast<Todo *>( incidence ); 3558 return static_cast<Todo *>( incidence );
3559 } 3559 }
3560 3560
3561 return 0; 3561 return 0;
3562} 3562}
3563 3563
3564void CalendarView::dialogClosing(Incidence *in) 3564void CalendarView::dialogClosing(Incidence *in)
3565{ 3565{
3566 // mDialogList.remove(in); 3566 // mDialogList.remove(in);
3567} 3567}
3568 3568
3569void CalendarView::showIncidence() 3569void CalendarView::showIncidence()
3570{ 3570{
3571 Incidence *incidence = currentSelection(); 3571 Incidence *incidence = currentSelection();
3572 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3572 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3573 if ( incidence ) { 3573 if ( incidence ) {
3574 ShowIncidenceVisitor v; 3574 ShowIncidenceVisitor v;
3575 v.act( incidence, this ); 3575 v.act( incidence, this );
3576 } 3576 }
3577} 3577}
3578void CalendarView::editIncidenceDescription() 3578void CalendarView::editIncidenceDescription()
3579{ 3579{
3580 mFlagEditDescription = true; 3580 mFlagEditDescription = true;
3581 editIncidence(); 3581 editIncidence();
3582 mFlagEditDescription = false; 3582 mFlagEditDescription = false;
3583} 3583}
3584void CalendarView::editIncidence() 3584void CalendarView::editIncidence()
3585{ 3585{
3586 // qDebug("editIncidence() "); 3586 // qDebug("editIncidence() ");
3587 Incidence *incidence = currentSelection(); 3587 Incidence *incidence = currentSelection();
3588 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3588 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3589 if ( incidence ) { 3589 if ( incidence ) {
3590 EditIncidenceVisitor v; 3590 EditIncidenceVisitor v;
3591 v.act( incidence, this ); 3591 v.act( incidence, this );
3592 } 3592 }
3593} 3593}
3594 3594
3595void CalendarView::deleteIncidence() 3595void CalendarView::deleteIncidence()
3596{ 3596{
3597 Incidence *incidence = currentSelection(); 3597 Incidence *incidence = currentSelection();
3598 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3598 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3599 if ( incidence ) { 3599 if ( incidence ) {
3600 deleteIncidence(incidence); 3600 deleteIncidence(incidence);
3601 } 3601 }
3602} 3602}
3603 3603
3604void CalendarView::showIncidence(Incidence *incidence) 3604void CalendarView::showIncidence(Incidence *incidence)
3605{ 3605{
3606 if ( incidence ) { 3606 if ( incidence ) {
3607 ShowIncidenceVisitor v; 3607 ShowIncidenceVisitor v;
3608 v.act( incidence, this ); 3608 v.act( incidence, this );
3609 } 3609 }
3610} 3610}
3611 3611
3612void CalendarView::editIncidence(Incidence *incidence) 3612void CalendarView::editIncidence(Incidence *incidence)
3613{ 3613{
3614 if ( incidence ) { 3614 if ( incidence ) {
3615 3615
3616 EditIncidenceVisitor v; 3616 EditIncidenceVisitor v;
3617 v.act( incidence, this ); 3617 v.act( incidence, this );
3618 3618
3619 } 3619 }
3620} 3620}
3621 3621
3622void CalendarView::deleteIncidence(Incidence *incidence) 3622void CalendarView::deleteIncidence(Incidence *incidence)
3623{ 3623{
3624 //qDebug(" CalendarView::deleteIncidence "); 3624 //qDebug(" CalendarView::deleteIncidence ");
3625 if ( incidence ) { 3625 if ( incidence ) {
3626 DeleteIncidenceVisitor v; 3626 DeleteIncidenceVisitor v;
3627 v.act( incidence, this ); 3627 v.act( incidence, this );
3628 } 3628 }
3629} 3629}
3630 3630
3631 3631
3632void CalendarView::lookForOutgoingMessages() 3632void CalendarView::lookForOutgoingMessages()
3633{ 3633{
3634 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 3634 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
3635 ogd->loadMessages(); 3635 ogd->loadMessages();
3636} 3636}
3637 3637
3638void CalendarView::lookForIncomingMessages() 3638void CalendarView::lookForIncomingMessages()
3639{ 3639{
3640 IncomingDialog *icd = mDialogManager->incomingDialog(); 3640 IncomingDialog *icd = mDialogManager->incomingDialog();
3641 icd->retrieve(); 3641 icd->retrieve();
3642} 3642}
3643 3643
3644bool CalendarView::removeCompletedSubTodos( Todo* t ) 3644bool CalendarView::removeCompletedSubTodos( Todo* t )
3645{ 3645{
3646 bool deleteTodo = true; 3646 bool deleteTodo = true;
3647 QPtrList<Incidence> subTodos; 3647 QPtrList<Incidence> subTodos;
3648 Incidence *aTodo; 3648 Incidence *aTodo;
3649 subTodos = t->relations(); 3649 subTodos = t->relations();
3650 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 3650 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
3651 if (! removeCompletedSubTodos( (Todo*) aTodo )) 3651 if (! removeCompletedSubTodos( (Todo*) aTodo ))
3652 deleteTodo = false; 3652 deleteTodo = false;
3653 } 3653 }
3654 if ( deleteTodo ) { 3654 if ( deleteTodo ) {
3655 if ( t->isCompleted() ) { 3655 if ( t->isCompleted() ) {
3656 checkExternalId( t ); 3656 checkExternalId( t );
3657 mCalendar->deleteTodo( t ); 3657 mCalendar->deleteTodo( t );
3658 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 3658 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
3659 } 3659 }
3660 else 3660 else
3661 deleteTodo = false; 3661 deleteTodo = false;
3662 } 3662 }
3663 return deleteTodo; 3663 return deleteTodo;
3664 3664
3665} 3665}
3666void CalendarView::purgeCompleted() 3666void CalendarView::purgeCompleted()
3667{ 3667{
3668 int result = KMessageBox::warningContinueCancel(this, 3668 int result = KMessageBox::warningContinueCancel(this,
3669 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge")); 3669 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge"));
3670 3670
3671 if (result == KMessageBox::Continue) { 3671 if (result == KMessageBox::Continue) {
3672 3672
3673 QPtrList<Todo> todoCal; 3673 QPtrList<Todo> todoCal;
3674 QPtrList<Todo> rootTodos; 3674 QPtrList<Todo> rootTodos;
3675 //QPtrList<Incidence> rel; 3675 //QPtrList<Incidence> rel;
3676 Todo *aTodo;//, *rTodo; 3676 Todo *aTodo;//, *rTodo;
3677 Incidence *rIncidence; 3677 Incidence *rIncidence;
3678 bool childDelete = false; 3678 bool childDelete = false;
3679 bool deletedOne = true; 3679 bool deletedOne = true;
3680 todoCal = calendar()->todos(); 3680 todoCal = calendar()->todos();
3681 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 3681 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
3682 if ( !aTodo->relatedTo() ) 3682 if ( !aTodo->relatedTo() )
3683 rootTodos.append( aTodo ); 3683 rootTodos.append( aTodo );
3684 } 3684 }
3685 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 3685 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
3686 removeCompletedSubTodos( aTodo ); 3686 removeCompletedSubTodos( aTodo );
3687 } 3687 }
3688 3688
3689 updateView(); 3689 updateView();
3690 } 3690 }
3691} 3691}
3692 3692
3693void CalendarView::slotCalendarChanged() 3693void CalendarView::slotCalendarChanged()
3694{ 3694{
3695 ; 3695 ;
3696} 3696}
3697 3697
3698NavigatorBar *CalendarView::navigatorBar() 3698NavigatorBar *CalendarView::navigatorBar()
3699{ 3699{
3700 return mNavigatorBar; 3700 return mNavigatorBar;
3701} 3701}
3702 3702
3703 3703
3704 3704
3705void CalendarView::keyPressEvent ( QKeyEvent *e) 3705void CalendarView::keyPressEvent ( QKeyEvent *e)
3706{ 3706{
3707 //qDebug(" alendarView::keyPressEvent "); 3707 //qDebug(" alendarView::keyPressEvent ");
3708 e->ignore(); 3708 e->ignore();
3709} 3709}
3710 3710
3711 3711
3712bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) 3712bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
3713{ 3713{
3714 // mSyncManager = manager; 3714 // mSyncManager = manager;
3715 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3715 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3716 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3716 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3717 return syncCalendar( filename, mode ); 3717 return syncCalendar( filename, mode );
3718} 3718}
3719bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 3719bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
3720{ 3720{
3721 //mSyncManager = manager; 3721 //mSyncManager = manager;
3722 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3722 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3723 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3723 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3724 if ( resource == "sharp" ) 3724 if ( resource == "sharp" )
3725 syncExternal( 0 ); 3725 syncExternal( 0 );
3726 if ( resource == "phone" ) 3726 if ( resource == "phone" )
3727 syncExternal( 1 ); 3727 syncExternal( 1 );
3728 // pending setmodified 3728 // pending setmodified
3729 return true;
3729} 3730}
3730void CalendarView::setSyncManager(KSyncManager* manager) 3731void CalendarView::setSyncManager(KSyncManager* manager)
3731{ 3732{
3732 mSyncManager = manager; 3733 mSyncManager = manager;
3733} 3734}
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 01309d5..b3e266a 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -392,783 +392,785 @@ void KSyncManager::multiSync( bool askforPrefs )
392 edit_sync_options(); 392 edit_sync_options();
393 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; 393 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs;
394 } 394 }
395 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); 395 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") );
396 qApp->processEvents(); 396 qApp->processEvents();
397 int num = ringSync() ; 397 int num = ringSync() ;
398 if ( num > 1 ) 398 if ( num > 1 )
399 ringSync(); 399 ringSync();
400 setBlockSave(false); 400 setBlockSave(false);
401 if ( num ) 401 if ( num )
402 emit save(); 402 emit save();
403 if ( num ) 403 if ( num )
404 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); 404 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) );
405 else 405 else
406 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 406 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
407 return; 407 return;
408} 408}
409 409
410int KSyncManager::ringSync() 410int KSyncManager::ringSync()
411{ 411{
412 int syncedProfiles = 0; 412 int syncedProfiles = 0;
413 unsigned int i; 413 unsigned int i;
414 QTime timer; 414 QTime timer;
415 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 415 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
416 QStringList syncProfileNames = mSyncProfileNames; 416 QStringList syncProfileNames = mSyncProfileNames;
417 KSyncProfile* temp = new KSyncProfile (); 417 KSyncProfile* temp = new KSyncProfile ();
418 mAskForPreferences = false; 418 mAskForPreferences = false;
419 for ( i = 0; i < syncProfileNames.count(); ++i ) { 419 for ( i = 0; i < syncProfileNames.count(); ++i ) {
420 mCurrentSyncProfile = i; 420 mCurrentSyncProfile = i;
421 temp->setName(syncProfileNames[mCurrentSyncProfile]); 421 temp->setName(syncProfileNames[mCurrentSyncProfile]);
422 temp->readConfig(&config); 422 temp->readConfig(&config);
423 423
424 QString includeInRingSync; 424 QString includeInRingSync;
425 switch(mTargetApp) 425 switch(mTargetApp)
426 { 426 {
427 case (KAPI): 427 case (KAPI):
428 includeInRingSync = temp->getIncludeInRingSyncAB(); 428 includeInRingSync = temp->getIncludeInRingSyncAB();
429 break; 429 break;
430 case (KOPI): 430 case (KOPI):
431 includeInRingSync = temp->getIncludeInRingSync(); 431 includeInRingSync = temp->getIncludeInRingSync();
432 break; 432 break;
433 case (PWMPI): 433 case (PWMPI):
434 includeInRingSync = temp->getIncludeInRingSyncPWM(); 434 includeInRingSync = temp->getIncludeInRingSyncPWM();
435 break; 435 break;
436 default: 436 default:
437 qDebug("KSyncManager::ringSync: invalid apptype selected"); 437 qDebug("KSyncManager::ringSync: invalid apptype selected");
438 break; 438 break;
439 439
440 } 440 }
441 441
442 442
443 if ( includeInRingSync && ( i < 1 || i > 2 )) { 443 if ( includeInRingSync && ( i < 1 || i > 2 )) {
444 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 444 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
445 ++syncedProfiles; 445 ++syncedProfiles;
446 // mAskForPreferences = temp->getAskForPreferences(); 446 // mAskForPreferences = temp->getAskForPreferences();
447 mWriteBackFile = temp->getWriteBackFile(); 447 mWriteBackFile = temp->getWriteBackFile();
448 mWriteBackExistingOnly = temp->getWriteBackExisting(); 448 mWriteBackExistingOnly = temp->getWriteBackExisting();
449 mWriteBackInFuture = 0; 449 mWriteBackInFuture = 0;
450 if ( temp->getWriteBackFuture() ) 450 if ( temp->getWriteBackFuture() )
451 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 451 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
452 mShowSyncSummary = false; 452 mShowSyncSummary = false;
453 mCurrentSyncDevice = syncProfileNames[i] ; 453 mCurrentSyncDevice = syncProfileNames[i] ;
454 mCurrentSyncName = mLocalMachineName; 454 mCurrentSyncName = mLocalMachineName;
455 if ( i == 0 ) { 455 if ( i == 0 ) {
456 syncSharp(); 456 syncSharp();
457 } else { 457 } else {
458 if ( temp->getIsLocalFileSync() ) { 458 if ( temp->getIsLocalFileSync() ) {
459 switch(mTargetApp) 459 switch(mTargetApp)
460 { 460 {
461 case (KAPI): 461 case (KAPI):
462 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 462 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
463 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 463 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
464 break; 464 break;
465 case (KOPI): 465 case (KOPI):
466 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 466 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
467 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 467 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
468 break; 468 break;
469 case (PWMPI): 469 case (PWMPI):
470 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 470 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
471 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 471 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
472 break; 472 break;
473 default: 473 default:
474 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 474 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
475 break; 475 break;
476 } 476 }
477 } else { 477 } else {
478 if ( temp->getIsPhoneSync() ) { 478 if ( temp->getIsPhoneSync() ) {
479 mPhoneDevice = temp->getPhoneDevice( ) ; 479 mPhoneDevice = temp->getPhoneDevice( ) ;
480 mPhoneConnection = temp->getPhoneConnection( ); 480 mPhoneConnection = temp->getPhoneConnection( );
481 mPhoneModel = temp->getPhoneModel( ); 481 mPhoneModel = temp->getPhoneModel( );
482 syncPhone(); 482 syncPhone();
483 } else if ( temp->getIsPiSync() ) { 483 } else if ( temp->getIsPiSync() ) {
484 if ( mTargetApp == KAPI ) { 484 if ( mTargetApp == KAPI ) {
485 mPassWordPiSync = temp->getRemotePwAB(); 485 mPassWordPiSync = temp->getRemotePwAB();
486 mActiveSyncPort = temp->getRemotePortAB(); 486 mActiveSyncPort = temp->getRemotePortAB();
487 mActiveSyncIP = temp->getRemoteIPAB(); 487 mActiveSyncIP = temp->getRemoteIPAB();
488 } else if ( mTargetApp == KOPI ) { 488 } else if ( mTargetApp == KOPI ) {
489 mPassWordPiSync = temp->getRemotePw(); 489 mPassWordPiSync = temp->getRemotePw();
490 mActiveSyncPort = temp->getRemotePort(); 490 mActiveSyncPort = temp->getRemotePort();
491 mActiveSyncIP = temp->getRemoteIP(); 491 mActiveSyncIP = temp->getRemoteIP();
492 } else { 492 } else {
493 mPassWordPiSync = temp->getRemotePwPWM(); 493 mPassWordPiSync = temp->getRemotePwPWM();
494 mActiveSyncPort = temp->getRemotePortPWM(); 494 mActiveSyncPort = temp->getRemotePortPWM();
495 mActiveSyncIP = temp->getRemoteIPPWM(); 495 mActiveSyncIP = temp->getRemoteIPPWM();
496 } 496 }
497 syncPi(); 497 syncPi();
498 } else 498 } else
499 syncRemote( temp, false ); 499 syncRemote( temp, false );
500 500
501 } 501 }
502 } 502 }
503 timer.start(); 503 timer.start();
504 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); 504 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") );
505 while ( timer.elapsed () < 2000 ) { 505 while ( timer.elapsed () < 2000 ) {
506 qApp->processEvents(); 506 qApp->processEvents();
507#ifndef _WIN32_ 507#ifndef _WIN32_
508 sleep (1); 508 sleep (1);
509#endif 509#endif
510 } 510 }
511 511
512 } 512 }
513 513
514 } 514 }
515 delete temp; 515 delete temp;
516 return syncedProfiles; 516 return syncedProfiles;
517} 517}
518 518
519void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) 519void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
520{ 520{
521 QString question; 521 QString question;
522 if ( ask ) { 522 if ( ask ) {
523 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 523 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
524 if ( QMessageBox::information( mParent, i18n("Sync"), 524 if ( QMessageBox::information( mParent, i18n("Sync"),
525 question, 525 question,
526 i18n("Yes"), i18n("No"), 526 i18n("Yes"), i18n("No"),
527 0, 0 ) != 0 ) 527 0, 0 ) != 0 )
528 return; 528 return;
529 } 529 }
530 530
531 QString preCommand; 531 QString preCommand;
532 QString localTempFile; 532 QString localTempFile;
533 QString postCommand; 533 QString postCommand;
534 534
535 switch(mTargetApp) 535 switch(mTargetApp)
536 { 536 {
537 case (KAPI): 537 case (KAPI):
538 preCommand = prof->getPreSyncCommandAB(); 538 preCommand = prof->getPreSyncCommandAB();
539 postCommand = prof->getPostSyncCommandAB(); 539 postCommand = prof->getPostSyncCommandAB();
540 localTempFile = prof->getLocalTempFileAB(); 540 localTempFile = prof->getLocalTempFileAB();
541 break; 541 break;
542 case (KOPI): 542 case (KOPI):
543 preCommand = prof->getPreSyncCommand(); 543 preCommand = prof->getPreSyncCommand();
544 postCommand = prof->getPostSyncCommand(); 544 postCommand = prof->getPostSyncCommand();
545 localTempFile = prof->getLocalTempFile(); 545 localTempFile = prof->getLocalTempFile();
546 break; 546 break;
547 case (PWMPI): 547 case (PWMPI):
548 preCommand = prof->getPreSyncCommandPWM(); 548 preCommand = prof->getPreSyncCommandPWM();
549 postCommand = prof->getPostSyncCommandPWM(); 549 postCommand = prof->getPostSyncCommandPWM();
550 localTempFile = prof->getLocalTempFilePWM(); 550 localTempFile = prof->getLocalTempFilePWM();
551 break; 551 break;
552 default: 552 default:
553 qDebug("KSyncManager::syncRemote: invalid apptype selected"); 553 qDebug("KSyncManager::syncRemote: invalid apptype selected");
554 break; 554 break;
555 } 555 }
556 556
557 557
558 int fi; 558 int fi;
559 if ( (fi = preCommand.find("$PWD$")) > 0 ) { 559 if ( (fi = preCommand.find("$PWD$")) > 0 ) {
560 QString pwd = getPassword(); 560 QString pwd = getPassword();
561 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); 561 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
562 562
563 } 563 }
564 int maxlen = 30; 564 int maxlen = 30;
565 if ( QApplication::desktop()->width() > 320 ) 565 if ( QApplication::desktop()->width() > 320 )
566 maxlen += 25; 566 maxlen += 25;
567 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); 567 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) );
568 int fileSize = 0; 568 int fileSize = 0;
569 int result = system ( preCommand ); 569 int result = system ( preCommand );
570 // 0 : okay 570 // 0 : okay
571 // 256: no such file or dir 571 // 256: no such file or dir
572 // 572 //
573 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 573 qDebug("KO: Remote copy result(0 = okay): %d ",result );
574 if ( result != 0 ) { 574 if ( result != 0 ) {
575 unsigned int len = maxlen; 575 unsigned int len = maxlen;
576 while ( len < preCommand.length() ) { 576 while ( len < preCommand.length() ) {
577 preCommand.insert( len , "\n" ); 577 preCommand.insert( len , "\n" );
578 len += maxlen +2; 578 len += maxlen +2;
579 } 579 }
580 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 (preCommand) ; 580 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 (preCommand) ;
581 QMessageBox::information( mParent, i18n("Sync - ERROR"), 581 QMessageBox::information( mParent, i18n("Sync - ERROR"),
582 question, 582 question,
583 i18n("Okay!")) ; 583 i18n("Okay!")) ;
584 mParent->topLevelWidget()->setCaption ("KDE-Pim"); 584 mParent->topLevelWidget()->setCaption ("KDE-Pim");
585 return; 585 return;
586 } 586 }
587 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); 587 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) );
588 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 588 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
589 589
590 if ( syncWithFile( localTempFile, true ) ) { 590 if ( syncWithFile( localTempFile, true ) ) {
591 591
592 if ( mWriteBackFile ) { 592 if ( mWriteBackFile ) {
593 int fi; 593 int fi;
594 if ( (fi = postCommand.find("$PWD$")) > 0 ) { 594 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
595 QString pwd = getPassword(); 595 QString pwd = getPassword();
596 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); 596 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
597 597
598 } 598 }
599 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); 599 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
600 result = system ( postCommand ); 600 result = system ( postCommand );
601 qDebug("Writing back file result: %d ", result); 601 qDebug("Writing back file result: %d ", result);
602 if ( result != 0 ) { 602 if ( result != 0 ) {
603 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 603 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
604 return; 604 return;
605 } else { 605 } else {
606 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 606 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
607 } 607 }
608 } 608 }
609 } 609 }
610 return; 610 return;
611} 611}
612 612
613void KSyncManager::edit_sync_options() 613void KSyncManager::edit_sync_options()
614{ 614{
615 //mDialogManager->showSyncOptions(); 615 //mDialogManager->showSyncOptions();
616 //mSyncAlgoPrefs 616 //mSyncAlgoPrefs
617 QDialog dia( mParent, "dia", true ); 617 QDialog dia( mParent, "dia", true );
618 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 618 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
619 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 619 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
620 QVBoxLayout lay ( &dia ); 620 QVBoxLayout lay ( &dia );
621 lay.setSpacing( 2 ); 621 lay.setSpacing( 2 );
622 lay.setMargin( 3 ); 622 lay.setMargin( 3 );
623 lay.addWidget(&gr); 623 lay.addWidget(&gr);
624 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 624 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
625 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 625 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
626 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 626 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
627 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 627 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
628 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 628 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
629 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 629 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
630 //QRadioButton both( i18n("Take both on conflict"), &gr ); 630 //QRadioButton both( i18n("Take both on conflict"), &gr );
631 QPushButton pb ( "OK", &dia); 631 QPushButton pb ( "OK", &dia);
632 lay.addWidget( &pb ); 632 lay.addWidget( &pb );
633 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 633 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
634 switch ( mSyncAlgoPrefs ) { 634 switch ( mSyncAlgoPrefs ) {
635 case 0: 635 case 0:
636 loc.setChecked( true); 636 loc.setChecked( true);
637 break; 637 break;
638 case 1: 638 case 1:
639 rem.setChecked( true ); 639 rem.setChecked( true );
640 break; 640 break;
641 case 2: 641 case 2:
642 newest.setChecked( true); 642 newest.setChecked( true);
643 break; 643 break;
644 case 3: 644 case 3:
645 ask.setChecked( true); 645 ask.setChecked( true);
646 break; 646 break;
647 case 4: 647 case 4:
648 f_loc.setChecked( true); 648 f_loc.setChecked( true);
649 break; 649 break;
650 case 5: 650 case 5:
651 f_rem.setChecked( true); 651 f_rem.setChecked( true);
652 break; 652 break;
653 case 6: 653 case 6:
654 // both.setChecked( true); 654 // both.setChecked( true);
655 break; 655 break;
656 default: 656 default:
657 break; 657 break;
658 } 658 }
659 if ( dia.exec() ) { 659 if ( dia.exec() ) {
660 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 660 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
661 } 661 }
662 662
663 663
664} 664}
665 665
666QString KSyncManager::getPassword( ) 666QString KSyncManager::getPassword( )
667{ 667{
668 QString retfile = ""; 668 QString retfile = "";
669 QDialog dia ( mParent, "input-dialog", true ); 669 QDialog dia ( mParent, "input-dialog", true );
670 QLineEdit lab ( &dia ); 670 QLineEdit lab ( &dia );
671 lab.setEchoMode( QLineEdit::Password ); 671 lab.setEchoMode( QLineEdit::Password );
672 QVBoxLayout lay( &dia ); 672 QVBoxLayout lay( &dia );
673 lay.setMargin(7); 673 lay.setMargin(7);
674 lay.setSpacing(7); 674 lay.setSpacing(7);
675 lay.addWidget( &lab); 675 lay.addWidget( &lab);
676 dia.setFixedSize( 230,50 ); 676 dia.setFixedSize( 230,50 );
677 dia.setCaption( i18n("Enter password") ); 677 dia.setCaption( i18n("Enter password") );
678 QPushButton pb ( "OK", &dia); 678 QPushButton pb ( "OK", &dia);
679 lay.addWidget( &pb ); 679 lay.addWidget( &pb );
680 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 680 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
681 dia.show(); 681 dia.show();
682 int res = dia.exec(); 682 int res = dia.exec();
683 if ( res ) 683 if ( res )
684 retfile = lab.text(); 684 retfile = lab.text();
685 dia.hide(); 685 dia.hide();
686 qApp->processEvents(); 686 qApp->processEvents();
687 return retfile; 687 return retfile;
688 688
689} 689}
690 690
691 691
692void KSyncManager::confSync() 692void KSyncManager::confSync()
693{ 693{
694 static KSyncPrefsDialog* sp = 0; 694 static KSyncPrefsDialog* sp = 0;
695 if ( ! sp ) { 695 if ( ! sp ) {
696 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 696 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
697 } 697 }
698 sp->usrReadConfig(); 698 sp->usrReadConfig();
699#ifndef DESKTOP_VERSION 699#ifndef DESKTOP_VERSION
700 sp->showMaximized(); 700 sp->showMaximized();
701#else 701#else
702 sp->show(); 702 sp->show();
703#endif 703#endif
704 sp->exec(); 704 sp->exec();
705 mSyncProfileNames = sp->getSyncProfileNames(); 705 mSyncProfileNames = sp->getSyncProfileNames();
706 mLocalMachineName = sp->getLocalMachineName (); 706 mLocalMachineName = sp->getLocalMachineName ();
707 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 707 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
708} 708}
709 709
710void KSyncManager::syncSharp() 710void KSyncManager::syncSharp()
711{ 711{
712 712
713 if ( ! syncExternalApplication("sharp") ) 713 if ( ! syncExternalApplication("sharp") )
714 qDebug("ERROR sync sharp ");; 714 qDebug("ERROR sync sharp ");;
715} 715}
716 716
717bool KSyncManager::syncExternalApplication(QString resource) 717bool KSyncManager::syncExternalApplication(QString resource)
718{ 718{
719 719
720 emit save(); 720 emit save();
721 721
722 if ( mAskForPreferences ) 722 if ( mAskForPreferences )
723 edit_sync_options(); 723 edit_sync_options();
724 724
725 qDebug("sync %s", resource.latin1()); 725 qDebug("sync %s", resource.latin1());
726 726
727 bool syncOK = mImplementation->syncExternal(this, resource); 727 bool syncOK = mImplementation->syncExternal(this, resource);
728 728
729 return syncOK; 729 return syncOK;
730 730
731} 731}
732 732
733void KSyncManager::syncPhone() 733void KSyncManager::syncPhone()
734{ 734{
735 735
736 syncExternalApplication("phone"); 736 syncExternalApplication("phone");
737 737
738} 738}
739 739
740void KSyncManager::showProgressBar(int percentage, QString caption, int total) 740void KSyncManager::showProgressBar(int percentage, QString caption, int total)
741{ 741{
742 if (!bar->isVisible()) 742 if (!bar->isVisible())
743 { 743 {
744 bar->setCaption (caption); 744 bar->setCaption (caption);
745 bar->setTotalSteps ( total ) ; 745 bar->setTotalSteps ( total ) ;
746 746
747 bar->show(); 747 bar->show();
748 } 748 }
749 749
750 bar->setProgress( percentage ); 750 bar->setProgress( percentage );
751} 751}
752 752
753void KSyncManager::hideProgressBar() 753void KSyncManager::hideProgressBar()
754{ 754{
755 bar->hide(); 755 bar->hide();
756} 756}
757 757
758bool KSyncManager::isProgressBarCanceled() 758bool KSyncManager::isProgressBarCanceled()
759{ 759{
760 return !bar->isVisible(); 760 return !bar->isVisible();
761} 761}
762 762
763QString KSyncManager::syncFileName() 763QString KSyncManager::syncFileName()
764{ 764{
765 765
766 QString fn = "tempfile"; 766 QString fn = "tempfile";
767 switch(mTargetApp) 767 switch(mTargetApp)
768 { 768 {
769 case (KAPI): 769 case (KAPI):
770 fn = "tempsyncab.vcf"; 770 fn = "tempsyncab.vcf";
771 break; 771 break;
772 case (KOPI): 772 case (KOPI):
773 fn = "tempsynccal.ics"; 773 fn = "tempsynccal.ics";
774 break; 774 break;
775 case (PWMPI): 775 case (PWMPI):
776 fn = "tempsyncpw.pwm"; 776 fn = "tempsyncpw.pwm";
777 break; 777 break;
778 default: 778 default:
779 break; 779 break;
780 } 780 }
781#ifdef _WIN32_ 781#ifdef _WIN32_
782 return locateLocal( "tmp", fn ); 782 return locateLocal( "tmp", fn );
783#else 783#else
784 return (QString( "/tmp/" )+ fn ); 784 return (QString( "/tmp/" )+ fn );
785#endif 785#endif
786} 786}
787 787
788 788
789void KSyncManager::syncPi() 789void KSyncManager::syncPi()
790{ 790{
791 qApp->processEvents(); 791 qApp->processEvents();
792 bool ok; 792 bool ok;
793 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 793 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
794 if ( ! ok ) { 794 if ( ! ok ) {
795 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 795 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
796 return; 796 return;
797 } 797 }
798 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); 798 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
799 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 799 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
800 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); 800 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") );
801 commandSocket->readFile( syncFileName() ); 801 commandSocket->readFile( syncFileName() );
802} 802}
803 803
804void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 804void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
805{ 805{
806 qDebug("MainWindow::deleteCommandSocket %d", state); 806 qDebug("MainWindow::deleteCommandSocket %d", state);
807 807
808 //enum { success, errorW, errorR, quiet }; 808 //enum { success, errorW, errorR, quiet };
809 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { 809 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
810 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 810 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
811 delete s; 811 delete s;
812 if ( state == KCommandSocket::errorR ) { 812 if ( state == KCommandSocket::errorR ) {
813 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 813 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
814 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 814 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
815 commandSocket->sendStop(); 815 commandSocket->sendStop();
816 } 816 }
817 return; 817 return;
818 818
819 } else if ( state == KCommandSocket::errorW ) { 819 } else if ( state == KCommandSocket::errorW ) {
820 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 820 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
821 821
822 } else if ( state == KCommandSocket::successR ) { 822 } else if ( state == KCommandSocket::successR ) {
823 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 823 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
824 824
825 } else if ( state == KCommandSocket::successW ) { 825 } else if ( state == KCommandSocket::successW ) {
826 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 826 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
827 } 827 }
828 828
829 delete s; 829 delete s;
830} 830}
831 831
832void KSyncManager::readFileFromSocket() 832void KSyncManager::readFileFromSocket()
833{ 833{
834 QString fileName = syncFileName(); 834 QString fileName = syncFileName();
835 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 835 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
836 if ( ! syncWithFile( fileName , true ) ) { 836 if ( ! syncWithFile( fileName , true ) ) {
837 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 837 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
838 qDebug("Syncing failed "); 838 qDebug("Syncing failed ");
839 return; 839 return;
840 } 840 }
841 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 841 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
842 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 842 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
843 if ( mWriteBackFile ) 843 if ( mWriteBackFile )
844 commandSocket->writeFile( fileName ); 844 commandSocket->writeFile( fileName );
845 else { 845 else {
846 commandSocket->sendStop(); 846 commandSocket->sendStop();
847 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 847 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
848 } 848 }
849} 849}
850 850
851KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 851KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
852{ 852{
853 mPassWord = pw; 853 mPassWord = pw;
854 mSocket = 0; 854 mSocket = 0;
855 mSyncActionDialog = 0; 855 mSyncActionDialog = 0;
856 blockRC = false; 856 blockRC = false;
857}; 857};
858 858
859void KServerSocket::newConnection ( int socket ) 859void KServerSocket::newConnection ( int socket )
860{ 860{
861 // qDebug("KServerSocket:New connection %d ", socket); 861 // qDebug("KServerSocket:New connection %d ", socket);
862 if ( mSocket ) { 862 if ( mSocket ) {
863 qDebug("KServerSocket::newConnection Socket deleted! "); 863 qDebug("KServerSocket::newConnection Socket deleted! ");
864 delete mSocket; 864 delete mSocket;
865 mSocket = 0; 865 mSocket = 0;
866 } 866 }
867 mSocket = new QSocket( this ); 867 mSocket = new QSocket( this );
868 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 868 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
869 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 869 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
870 mSocket->setSocket( socket ); 870 mSocket->setSocket( socket );
871} 871}
872 872
873void KServerSocket::discardClient() 873void KServerSocket::discardClient()
874{ 874{
875 //qDebug(" KServerSocket::discardClient()"); 875 //qDebug(" KServerSocket::discardClient()");
876 if ( mSocket ) { 876 if ( mSocket ) {
877 delete mSocket; 877 delete mSocket;
878 mSocket = 0; 878 mSocket = 0;
879 } 879 }
880 //emit endConnect(); 880 //emit endConnect();
881} 881}
882void KServerSocket::readClient() 882void KServerSocket::readClient()
883{ 883{
884 if ( blockRC ) 884 if ( blockRC )
885 return; 885 return;
886 if ( mSocket == 0 ) { 886 if ( mSocket == 0 ) {
887 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 887 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
888 return; 888 return;
889 } 889 }
890 qDebug("KServerSocket readClient()"); 890 qDebug("KServerSocket readClient()");
891 if ( mSocket->canReadLine() ) { 891 if ( mSocket->canReadLine() ) {
892 QString line = mSocket->readLine(); 892 QString line = mSocket->readLine();
893 qDebug("KServerSocket readline: %s ", line.latin1()); 893 qDebug("KServerSocket readline: %s ", line.latin1());
894 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 894 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
895 if ( tokens[0] == "GET" ) { 895 if ( tokens[0] == "GET" ) {
896 if ( tokens[1] == mPassWord ) 896 if ( tokens[1] == mPassWord )
897 //emit sendFile( mSocket ); 897 //emit sendFile( mSocket );
898 send_file(); 898 send_file();
899 else { 899 else {
900 KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); 900 KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password"));
901 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 901 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
902 } 902 }
903 } 903 }
904 if ( tokens[0] == "PUT" ) { 904 if ( tokens[0] == "PUT" ) {
905 if ( tokens[1] == mPassWord ) { 905 if ( tokens[1] == mPassWord ) {
906 //emit getFile( mSocket ); 906 //emit getFile( mSocket );
907 blockRC = true; 907 blockRC = true;
908 get_file(); 908 get_file();
909 } 909 }
910 else { 910 else {
911 KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); 911 KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password"));
912 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 912 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
913 } 913 }
914 } 914 }
915 if ( tokens[0] == "STOP" ) { 915 if ( tokens[0] == "STOP" ) {
916 //emit endConnect(); 916 //emit endConnect();
917 end_connect(); 917 end_connect();
918 } 918 }
919 } 919 }
920} 920}
921void KServerSocket::end_connect() 921void KServerSocket::end_connect()
922{ 922{
923 delete mSyncActionDialog; 923 delete mSyncActionDialog;
924 mSyncActionDialog = 0; 924 mSyncActionDialog = 0;
925} 925}
926void KServerSocket::send_file() 926void KServerSocket::send_file()
927{ 927{
928 //qDebug("MainWindow::sendFile(QSocket* s) "); 928 //qDebug("MainWindow::sendFile(QSocket* s) ");
929 if ( mSyncActionDialog ) 929 if ( mSyncActionDialog )
930 delete mSyncActionDialog; 930 delete mSyncActionDialog;
931 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 931 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
932 mSyncActionDialog->setCaption(i18n("Received sync request")); 932 mSyncActionDialog->setCaption(i18n("Received sync request"));
933 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 933 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
934 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 934 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
935 lay->addWidget( label); 935 lay->addWidget( label);
936 lay->setMargin(7); 936 lay->setMargin(7);
937 lay->setSpacing(7); 937 lay->setSpacing(7);
938 mSyncActionDialog->setFixedSize( 230, 120); 938 mSyncActionDialog->setFixedSize( 230, 120);
939 mSyncActionDialog->show(); 939 mSyncActionDialog->show();
940 mSyncActionDialog->raise(); 940 mSyncActionDialog->raise();
941 qDebug("KSS::saving ... "); 941 qDebug("KSS::saving ... ");
942 emit request_file(); 942 emit request_file();
943 qApp->processEvents(); 943 qApp->processEvents();
944 QString fileName = mFileName; 944 QString fileName = mFileName;
945 QFile file( fileName ); 945 QFile file( fileName );
946 if (!file.open( IO_ReadOnly ) ) { 946 if (!file.open( IO_ReadOnly ) ) {
947 delete mSyncActionDialog; 947 delete mSyncActionDialog;
948 mSyncActionDialog = 0; 948 mSyncActionDialog = 0;
949 qDebug("KSS::error open file "); 949 qDebug("KSS::error open file ");
950 mSocket->close(); 950 mSocket->close();
951 if ( mSocket->state() == QSocket::Idle ) 951 if ( mSocket->state() == QSocket::Idle )
952 QTimer::singleShot( 10, this , SLOT ( discardClient())); 952 QTimer::singleShot( 10, this , SLOT ( discardClient()));
953 return ; 953 return ;
954 954
955 } 955 }
956 mSyncActionDialog->setCaption( i18n("Sending file...") ); 956 mSyncActionDialog->setCaption( i18n("Sending file...") );
957 QTextStream ts( &file ); 957 QTextStream ts( &file );
958 ts.setEncoding( QTextStream::Latin1 ); 958 ts.setEncoding( QTextStream::Latin1 );
959 959
960 QTextStream os( mSocket ); 960 QTextStream os( mSocket );
961 os.setEncoding( QTextStream::Latin1 ); 961 os.setEncoding( QTextStream::Latin1 );
962 while ( ! ts.atEnd() ) { 962 while ( ! ts.atEnd() ) {
963 os << ts.readLine() << "\n"; 963 os << ts.readLine() << "\n";
964 } 964 }
965 //os << ts.read(); 965 //os << ts.read();
966 file.close(); 966 file.close();
967 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 967 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
968 mSocket->close(); 968 mSocket->close();
969 if ( mSocket->state() == QSocket::Idle ) 969 if ( mSocket->state() == QSocket::Idle )
970 QTimer::singleShot( 10, this , SLOT ( discardClient())); 970 QTimer::singleShot( 10, this , SLOT ( discardClient()));
971} 971}
972void KServerSocket::get_file() 972void KServerSocket::get_file()
973{ 973{
974 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 974 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
975 975
976 piTime.start(); 976 piTime.start();
977 piFileString = ""; 977 piFileString = "";
978 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 978 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
979} 979}
980 980
981 981
982void KServerSocket::readBackFileFromSocket() 982void KServerSocket::readBackFileFromSocket()
983{ 983{
984 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 984 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
985 while ( mSocket->canReadLine () ) { 985 while ( mSocket->canReadLine () ) {
986 piTime.restart(); 986 piTime.restart();
987 QString line = mSocket->readLine (); 987 QString line = mSocket->readLine ();
988 piFileString += line; 988 piFileString += line;
989 //qDebug("readline: %s ", line.latin1()); 989 //qDebug("readline: %s ", line.latin1());
990 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 990 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
991 991
992 } 992 }
993 if ( piTime.elapsed () < 3000 ) { 993 if ( piTime.elapsed () < 3000 ) {
994 // wait for more 994 // wait for more
995 //qDebug("waitformore "); 995 //qDebug("waitformore ");
996 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 996 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
997 return; 997 return;
998 } 998 }
999 QString fileName = mFileName; 999 QString fileName = mFileName;
1000 QFile file ( fileName ); 1000 QFile file ( fileName );
1001 if (!file.open( IO_WriteOnly ) ) { 1001 if (!file.open( IO_WriteOnly ) ) {
1002 delete mSyncActionDialog; 1002 delete mSyncActionDialog;
1003 mSyncActionDialog = 0; 1003 mSyncActionDialog = 0;
1004 qDebug("error open cal file "); 1004 qDebug("error open cal file ");
1005 piFileString = ""; 1005 piFileString = "";
1006 emit file_received( false ); 1006 emit file_received( false );
1007 blockRC = false; 1007 blockRC = false;
1008 return ; 1008 return ;
1009 1009
1010 } 1010 }
1011 1011
1012 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1012 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1013 QTextStream ts ( &file ); 1013 QTextStream ts ( &file );
1014 ts.setEncoding( QTextStream::Latin1 ); 1014 ts.setEncoding( QTextStream::Latin1 );
1015 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1015 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1016 ts << piFileString; 1016 ts << piFileString;
1017 mSocket->close(); 1017 mSocket->close();
1018 if ( mSocket->state() == QSocket::Idle ) 1018 if ( mSocket->state() == QSocket::Idle )
1019 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1019 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1020 file.close(); 1020 file.close();
1021 delete mSyncActionDialog; 1021 delete mSyncActionDialog;
1022 mSyncActionDialog = 0; 1022 mSyncActionDialog = 0;
1023 piFileString = ""; 1023 piFileString = "";
1024 blockRC = false; 1024 blockRC = false;
1025 emit file_received( true ); 1025 emit file_received( true );
1026 1026
1027} 1027}
1028 1028
1029KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 1029KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
1030{ 1030{
1031 mPassWord = password; 1031 mPassWord = password;
1032 mSocket = 0; 1032 mSocket = 0;
1033 mPort = port; 1033 mPort = port;
1034 mHost = host; 1034 mHost = host;
1035 1035
1036 mRetVal = quiet; 1036 mRetVal = quiet;
1037 mTimerSocket = new QTimer ( this ); 1037 mTimerSocket = new QTimer ( this );
1038 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 1038 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
1039} 1039}
1040void KCommandSocket::readFile( QString fn ) 1040void KCommandSocket::readFile( QString fn )
1041{ 1041{
1042 if ( !mSocket ) { 1042 if ( !mSocket ) {
1043 mSocket = new QSocket( this ); 1043 mSocket = new QSocket( this );
1044 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1044 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1045 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1045 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1046 } 1046 }
1047 mFileString = ""; 1047 mFileString = "";
1048 mFileName = fn; 1048 mFileName = fn;
1049 mFirst = true; 1049 mFirst = true;
1050 mSocket->connectToHost( mHost, mPort ); 1050 mSocket->connectToHost( mHost, mPort );
1051 QTextStream os( mSocket ); 1051 QTextStream os( mSocket );
1052 os.setEncoding( QTextStream::Latin1 ); 1052 os.setEncoding( QTextStream::Latin1 );
1053 os << "GET " << mPassWord << "\r\n"; 1053 os << "GET " << mPassWord << "\r\n";
1054 mTimerSocket->start( 10000 ); 1054 mTimerSocket->start( 10000 );
1055} 1055}
1056 1056
1057void KCommandSocket::writeFile( QString fileName ) 1057void KCommandSocket::writeFile( QString fileName )
1058{ 1058{
1059 if ( !mSocket ) { 1059 if ( !mSocket ) {
1060 mSocket = new QSocket( this ); 1060 mSocket = new QSocket( this );
1061 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1061 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1062 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1062 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1063 } 1063 }
1064 mFileName = fileName ; 1064 mFileName = fileName ;
1065 mSocket->connectToHost( mHost, mPort ); 1065 mSocket->connectToHost( mHost, mPort );
1066} 1066}
1067void KCommandSocket::writeFileToSocket() 1067void KCommandSocket::writeFileToSocket()
1068{ 1068{
1069 QFile file2( mFileName ); 1069 QFile file2( mFileName );
1070 if (!file2.open( IO_ReadOnly ) ) { 1070 if (!file2.open( IO_ReadOnly ) ) {
1071 mRetVal= errorW; 1071 mRetVal= errorW;
1072 mSocket->close(); 1072 mSocket->close();
1073 if ( mSocket->state() == QSocket::Idle ) 1073 if ( mSocket->state() == QSocket::Idle )
1074 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1074 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1075 return ; 1075 return ;
1076 } 1076 }
1077 QTextStream ts2( &file2 ); 1077 QTextStream ts2( &file2 );
1078 ts2.setEncoding( QTextStream::Latin1 ); 1078 ts2.setEncoding( QTextStream::Latin1 );
1079 QTextStream os2( mSocket ); 1079 QTextStream os2( mSocket );
1080 os2.setEncoding( QTextStream::Latin1 ); 1080 os2.setEncoding( QTextStream::Latin1 );
1081 os2 << "PUT " << mPassWord << "\r\n";; 1081 os2 << "PUT " << mPassWord << "\r\n";;
1082 while ( ! ts2.atEnd() ) { 1082 while ( ! ts2.atEnd() ) {
1083 os2 << ts2.readLine() << "\n"; 1083 os2 << ts2.readLine() << "\n";
1084 } 1084 }
1085 mRetVal= successW; 1085 mRetVal= successW;
1086 file2.close(); 1086 file2.close();
1087 mSocket->close(); 1087 mSocket->close();
1088 if ( mSocket->state() == QSocket::Idle ) 1088 if ( mSocket->state() == QSocket::Idle )
1089 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1089 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1090} 1090}
1091void KCommandSocket::sendStop() 1091void KCommandSocket::sendStop()
1092{ 1092{
1093 if ( !mSocket ) { 1093 if ( !mSocket ) {
1094 mSocket = new QSocket( this ); 1094 mSocket = new QSocket( this );
1095 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1095 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1096 } 1096 }
1097 mSocket->connectToHost( mHost, mPort ); 1097 mSocket->connectToHost( mHost, mPort );
1098 QTextStream os2( mSocket ); 1098 QTextStream os2( mSocket );
1099 os2.setEncoding( QTextStream::Latin1 ); 1099 os2.setEncoding( QTextStream::Latin1 );
1100 os2 << "STOP\r\n"; 1100 os2 << "STOP\r\n";
1101 mSocket->close(); 1101 mSocket->close();
1102 if ( mSocket->state() == QSocket::Idle ) 1102 if ( mSocket->state() == QSocket::Idle )
1103 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1103 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1104} 1104}
1105 1105
1106void KCommandSocket::startReadFileFromSocket() 1106void KCommandSocket::startReadFileFromSocket()
1107{ 1107{
1108 if ( ! mFirst ) 1108 if ( ! mFirst )
1109 return; 1109 return;
1110 mFirst = false; 1110 mFirst = false;
1111 mTimerSocket->stop(); 1111 mTimerSocket->stop();
1112 mFileString = ""; 1112 mFileString = "";
1113 mTime.start(); 1113 mTime.start();
1114 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1114 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1115 1115
1116} 1116}
1117void KCommandSocket::readFileFromSocket() 1117void KCommandSocket::readFileFromSocket()
1118{ 1118{
1119 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1119 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1120 while ( mSocket->canReadLine () ) { 1120 while ( mSocket->canReadLine () ) {
1121 mTime.restart(); 1121 mTime.restart();
1122 QString line = mSocket->readLine (); 1122 QString line = mSocket->readLine ();
1123 mFileString += line; 1123 mFileString += line;
1124 //qDebug("readline: %s ", line.latin1()); 1124 //qDebug("readline: %s ", line.latin1());
1125 } 1125 }
1126 if ( mTime.elapsed () < 3000 ) { 1126 if ( mTime.elapsed () < 3000 ) {
1127 // wait for more 1127 // wait for more
1128 //qDebug("waitformore "); 1128 //qDebug("waitformore ");
1129 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1129 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1130 return; 1130 return;
1131 } 1131 }
1132 QString fileName = mFileName; 1132 QString fileName = mFileName;
1133 QFile file ( fileName ); 1133 QFile file ( fileName );
1134 if (!file.open( IO_WriteOnly ) ) { 1134 if (!file.open( IO_WriteOnly ) ) {
1135 mFileString = ""; 1135 mFileString = "";
1136 mRetVal = errorR; 1136 mRetVal = errorR;
1137 qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); 1137 qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
1138 deleteSocket(); 1138 deleteSocket();
1139 return ; 1139 return ;
1140 1140
1141 } 1141 }
1142 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1142 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1143 QTextStream ts ( &file ); 1143 QTextStream ts ( &file );
1144 ts.setEncoding( QTextStream::Latin1 ); 1144 ts.setEncoding( QTextStream::Latin1 );
1145 ts << mFileString; 1145 ts << mFileString;
1146 file.close(); 1146 file.close();
1147 mFileString = ""; 1147 mFileString = "";
1148 mRetVal = successR; 1148 mRetVal = successR;
1149 mSocket->close(); 1149 mSocket->close();
1150 // if state is not idle, deleteSocket(); is called via 1150 // if state is not idle, deleteSocket(); is called via
1151 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1151 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1152 if ( mSocket->state() == QSocket::Idle ) 1152 if ( mSocket->state() == QSocket::Idle )
1153 deleteSocket(); 1153 deleteSocket();
1154} 1154}
1155 1155
1156void KCommandSocket::deleteSocket() 1156void KCommandSocket::deleteSocket()
1157{ 1157{
1158 if ( mTimerSocket->isActive () ) { 1158 if ( mTimerSocket->isActive () ) {
1159 mTimerSocket->stop(); 1159 mTimerSocket->stop();
1160 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? "));
1161 mRetVal = errorTO; 1160 mRetVal = errorTO;
1162 if ( mSocket ) { 1161 if ( mSocket ) {
1163 mSocket->close(); 1162 mSocket->close();
1164 if ( mSocket->state() == QSocket::Idle ) 1163 if ( mSocket->state() == QSocket::Idle )
1165 deleteSocket(); 1164 deleteSocket();
1166 return; 1165 return;
1167 } 1166 }
1168 } 1167 }
1169 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1168 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1170 if ( mSocket) 1169 if ( mSocket)
1171 delete mSocket; 1170 delete mSocket;
1172 mSocket = 0; 1171 mSocket = 0;
1172 if ( mRetVal == errorTO)
1173 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? "));
1174
1173 emit commandFinished( this, mRetVal ); 1175 emit commandFinished( this, mRetVal );
1174} 1176}