summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-06-07 06:37:42 (UTC)
committer zautrix <zautrix>2005-06-07 06:37:42 (UTC)
commitff8af7ccdd6346bba1cb871c33931352bbafe40e (patch) (unidiff)
tree8a905fe8237cd1be7276b3c5f10479a9efdb6ee5
parent79f58240bc34d20601abe3325e1dc7e76e1ebe39 (diff)
downloadkdepimpi-ff8af7ccdd6346bba1cb871c33931352bbafe40e.zip
kdepimpi-ff8af7ccdd6346bba1cb871c33931352bbafe40e.tar.gz
kdepimpi-ff8af7ccdd6346bba1cb871c33931352bbafe40e.tar.bz2
fixx
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/mainembedded.cpp1
-rw-r--r--korganizer/calendarview.cpp3
2 files changed, 3 insertions, 1 deletions
diff --git a/kaddressbook/mainembedded.cpp b/kaddressbook/mainembedded.cpp
index 50db377..93ba53c 100644
--- a/kaddressbook/mainembedded.cpp
+++ b/kaddressbook/mainembedded.cpp
@@ -1,119 +1,120 @@
1#ifndef DESKTOP_VERSION 1#ifndef DESKTOP_VERSION
2#include <qpe/qpeapplication.h> 2#include <qpe/qpeapplication.h>
3#include <qcopchannel_qws.h> 3#include <qcopchannel_qws.h>
4#include <stdlib.h> 4#include <stdlib.h>
5#else 5#else
6#include <qapplication.h> 6#include <qapplication.h>
7#include <qwindowsstyle.h> 7#include <qwindowsstyle.h>
8#include <qplatinumstyle.h> 8#include <qplatinumstyle.h>
9#include <qmainwindow.h> 9#include <qmainwindow.h>
10#include <qmessagebox.h> 10#include <qmessagebox.h>
11#include <stdlib.h> 11#include <stdlib.h>
12#endif 12#endif
13 13
14#include <qtextcodec.h> 14#include <qtextcodec.h>
15#include <kstandarddirs.h> 15#include <kstandarddirs.h>
16#include <qregexp.h> 16#include <qregexp.h>
17#include <kglobal.h> 17#include <kglobal.h>
18#include <stdio.h> 18#include <stdio.h>
19#include <qdir.h> 19#include <qdir.h>
20#include "kabprefs.h" 20#include "kabprefs.h"
21#include "kaddressbookmain.h" 21#include "kaddressbookmain.h"
22#include "externalapphandler.h" 22#include "externalapphandler.h"
23#include <libkdepim/kpimglobalprefs.h> 23#include <libkdepim/kpimglobalprefs.h>
24void dumpMissing(); 24void dumpMissing();
25int main( int argc, char **argv ) 25int main( int argc, char **argv )
26{ 26{
27#ifndef DESKTOP_VERSION 27#ifndef DESKTOP_VERSION
28 QPEApplication a( argc, argv ); 28 QPEApplication a( argc, argv );
29 a.setKeepRunning (); 29 a.setKeepRunning ();
30#else 30#else
31 QApplication a( argc, argv ); 31 QApplication a( argc, argv );
32 QApplication::setStyle( new QPlatinumStyle ()); 32 QApplication::setStyle( new QPlatinumStyle ());
33#ifdef _WIN32_ 33#ifdef _WIN32_
34 QString hdir ( getenv( "HOME") ); 34 QString hdir ( getenv( "HOME") );
35 if ( hdir.isEmpty() ) { 35 if ( hdir.isEmpty() ) {
36 QString hd ("C:/" ); 36 QString hd ("C:/" );
37 //QMessageBox::information(0,"hh",QDir::homeDirPath()+" xx" +hd ); 37 //QMessageBox::information(0,"hh",QDir::homeDirPath()+" xx" +hd );
38 if ( QDir::homeDirPath().lower() == hd.lower() ) { 38 if ( QDir::homeDirPath().lower() == hd.lower() ) {
39 _putenv( "HOME=C:"); 39 _putenv( "HOME=C:");
40 //QMessageBox::information(0,"hh",QString ( getenv( "HOME") ) ); 40 //QMessageBox::information(0,"hh",QString ( getenv( "HOME") ) );
41 } 41 }
42 } else { 42 } else {
43 QDir app_dir; 43 QDir app_dir;
44 if ( !app_dir.exists(hdir) ) 44 if ( !app_dir.exists(hdir) )
45 app_dir.mkdir (hdir); 45 app_dir.mkdir (hdir);
46 } 46 }
47#endif 47#endif
48#endif 48#endif
49 49
50 bool exitHelp = false; 50 bool exitHelp = false;
51 if ( argc > 1 ) { 51 if ( argc > 1 ) {
52 QString command = argv[1]; 52 QString command = argv[1];
53 if ( command == "-help" ){ 53 if ( command == "-help" ){
54 printf("KA/E command line commands:\n"); 54 printf("KA/E command line commands:\n");
55 printf(" no command: Start KA/E in usual way\n"); 55 printf(" no command: Start KA/E in usual way\n");
56 printf(" -help: This output\n"); 56 printf(" -help: This output\n");
57 printf(" KA/E is exiting now. Bye!\n"); 57 printf(" KA/E is exiting now. Bye!\n");
58 exitHelp = true; 58 exitHelp = true;
59 } 59 }
60 } 60 }
61 if ( ! exitHelp ) { 61 if ( ! exitHelp ) {
62 62
63 KGlobal::setAppName( "kaddressbook" ); 63 KGlobal::setAppName( "kaddressbook" );
64#ifndef DESKTOP_VERSION 64#ifndef DESKTOP_VERSION
65 if ( QApplication::desktop()->width() > 320 ) 65 if ( QApplication::desktop()->width() > 320 )
66 KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/icons22/"); 66 KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/icons22/");
67 else 67 else
68 KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/icons16/"); 68 KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/icons16/");
69#else 69#else
70 QString fileName ; 70 QString fileName ;
71 fileName = qApp->applicationDirPath () + "/kdepim/kaddressbook/icons22/"; 71 fileName = qApp->applicationDirPath () + "/kdepim/kaddressbook/icons22/";
72 KGlobal::iconLoader()->setIconPath(QDir::convertSeparators(fileName)); 72 KGlobal::iconLoader()->setIconPath(QDir::convertSeparators(fileName));
73 QApplication::addLibraryPath ( qApp->applicationDirPath () ); 73 QApplication::addLibraryPath ( qApp->applicationDirPath () );
74 74
75#endif 75#endif
76 KStandardDirs::setAppDir( QDir::convertSeparators(locateLocal("data", "kaddressbook"))); 76 KStandardDirs::setAppDir( QDir::convertSeparators(locateLocal("data", "kaddressbook")));
77 // init language 77 // init language
78 KPimGlobalPrefs::instance()->setGlobalConfig(); 78 KPimGlobalPrefs::instance()->setGlobalConfig();
79 QApplication::setFont( KPimGlobalPrefs::instance()->mApplicationFont ); 79 QApplication::setFont( KPimGlobalPrefs::instance()->mApplicationFont );
80 KAddressBookMain m ; 80 KAddressBookMain m ;
81//US MainWindow m; 81//US MainWindow m;
82#ifndef DESKTOP_VERSION 82#ifndef DESKTOP_VERSION
83 QObject::connect(&a, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & ))); 83 QObject::connect(&a, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & )));
84#endif 84#endif
85 85
86 86
87#ifndef DESKTOP_VERSION 87#ifndef DESKTOP_VERSION
88 a.showMainWidget( &m ); 88 a.showMainWidget( &m );
89 89
90#else 90#else
91 a.setMainWidget( &m ); 91 a.setMainWidget( &m );
92 m.show(); 92 m.show();
93#endif 93#endif
94 a.exec(); 94 a.exec();
95#ifdef DESKTOP_VERSION 95#ifdef DESKTOP_VERSION
96 KConfig *config = KABPrefs::instance()->getConfig(); 96 KConfig *config = KABPrefs::instance()->getConfig();
97 config->setGroup("WidgetLayout"); 97 config->setGroup("WidgetLayout");
98 QStringList list ;//= config->readListEntry("MainLayout"); 98 QStringList list ;//= config->readListEntry("MainLayout");
99 int x,y,w,h; 99 int x,y,w,h;
100 QWidget* wid; 100 QWidget* wid;
101 wid = &m; 101 wid = &m;
102 x = wid->geometry().x(); 102 x = wid->geometry().x();
103 y = wid->geometry().y(); 103 y = wid->geometry().y();
104 w = wid->width(); 104 w = wid->width();
105 h = wid->height(); 105 h = wid->height();
106 list.clear(); 106 list.clear();
107 list << QString::number( x ); 107 list << QString::number( x );
108 list << QString::number( y ); 108 list << QString::number( y );
109 list << QString::number( w ); 109 list << QString::number( w );
110 list << QString::number( h ); 110 list << QString::number( h );
111 config->writeEntry("MainLayout",list ); 111 config->writeEntry("MainLayout",list );
112 config->sync();
112#endif 113#endif
113 dumpMissing(); 114 dumpMissing();
114 115
115 KPimGlobalPrefs::instance()->writeConfig(); 116 KPimGlobalPrefs::instance()->writeConfig();
116 } 117 }
117 qDebug("KA: Bye! "); 118 qDebug("KA: Bye! ");
118} 119}
119 120
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index e13d0be..720ad78 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,4354 +1,4355 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Requires the Qt and KDE widget libraries, available at no cost at 4 Requires the Qt and KDE widget libraries, available at no cost at
5 http://www.troll.no and http://www.kde.org respectively 5 http://www.troll.no and http://www.kde.org respectively
6 6
7 Copyright (c) 1997, 1998, 1999 7 Copyright (c) 1997, 1998, 1999
8 Preston Brown (preton.brown@yale.edu) 8 Preston Brown (preton.brown@yale.edu)
9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) 9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
10 Ian Dawes (iadawes@globalserve.net) 10 Ian Dawes (iadawes@globalserve.net)
11 Laszlo Boloni (boloni@cs.purdue.edu) 11 Laszlo Boloni (boloni@cs.purdue.edu)
12 12
13 Copyright (c) 2000, 2001, 2002 13 Copyright (c) 2000, 2001, 2002
14 Cornelius Schumacher <schumacher@kde.org> 14 Cornelius Schumacher <schumacher@kde.org>
15 15
16 This program is free software; you can redistribute it and/or modify 16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by 17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or 18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version. 19 (at your option) any later version.
20 20
21 This program is distributed in the hope that it will be useful, 21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
24 GNU General Public License for more details. 24 GNU General Public License for more details.
25 25
26 You should have received a copy of the GNU General Public License 26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software 27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qradiobutton.h> 34#include <qradiobutton.h>
35#include <qbuttongroup.h> 35#include <qbuttongroup.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qclipboard.h> 37#include <qclipboard.h>
38#include <qcursor.h> 38#include <qcursor.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qprogressbar.h> 40#include <qprogressbar.h>
41#include <qmultilineedit.h> 41#include <qmultilineedit.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qwidgetstack.h> 43#include <qwidgetstack.h>
44#include <qptrlist.h> 44#include <qptrlist.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qgroupbox.h> 46#include <qgroupbox.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qdir.h> 48#include <qdir.h>
49#ifndef KORG_NOSPLITTER 49#ifndef KORG_NOSPLITTER
50#include <qsplitter.h> 50#include <qsplitter.h>
51#endif 51#endif
52 52
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kdebug.h> 54#include <kdebug.h>
55#include <kstandarddirs.h> 55#include <kstandarddirs.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57#include <kmessagebox.h> 57#include <kmessagebox.h>
58#include <knotifyclient.h> 58#include <knotifyclient.h>
59#include <kconfig.h> 59#include <kconfig.h>
60 60
61#include <libkdepim/ksyncprefsdialog.h> 61#include <libkdepim/ksyncprefsdialog.h>
62#include <krun.h> 62#include <krun.h>
63#include <kdirwatch.h> 63#include <kdirwatch.h>
64#include <libkdepim/kdatepicker.h> 64#include <libkdepim/kdatepicker.h>
65#include <libkdepim/ksyncprofile.h> 65#include <libkdepim/ksyncprofile.h>
66#include <libkdepim/kpimglobalprefs.h> 66#include <libkdepim/kpimglobalprefs.h>
67 67
68#include <libkcal/vcaldrag.h> 68#include <libkcal/vcaldrag.h>
69#include <libkcal/icaldrag.h> 69#include <libkcal/icaldrag.h>
70#include <libkcal/icalformat.h> 70#include <libkcal/icalformat.h>
71#include <libkcal/vcalformat.h> 71#include <libkcal/vcalformat.h>
72#include <libkcal/scheduler.h> 72#include <libkcal/scheduler.h>
73#include <libkcal/calendarlocal.h> 73#include <libkcal/calendarlocal.h>
74#include <libkcal/journal.h> 74#include <libkcal/journal.h>
75#include <libkcal/calfilter.h> 75#include <libkcal/calfilter.h>
76#include <libkcal/attendee.h> 76#include <libkcal/attendee.h>
77#include <libkcal/dndfactory.h> 77#include <libkcal/dndfactory.h>
78#include <libkcal/freebusy.h> 78#include <libkcal/freebusy.h>
79#include <libkcal/filestorage.h> 79#include <libkcal/filestorage.h>
80#include <libkcal/calendarresources.h> 80#include <libkcal/calendarresources.h>
81#include <libkcal/qtopiaformat.h> 81#include <libkcal/qtopiaformat.h>
82#include "../kalarmd/alarmdialog.h" 82#include "../kalarmd/alarmdialog.h"
83 83
84#ifndef DESKTOP_VERSION 84#ifndef DESKTOP_VERSION
85#include <libkcal/sharpformat.h> 85#include <libkcal/sharpformat.h>
86#include <externalapphandler.h> 86#include <externalapphandler.h>
87#endif 87#endif
88#include <libkcal/phoneformat.h> 88#include <libkcal/phoneformat.h>
89#ifndef KORG_NOMAIL 89#ifndef KORG_NOMAIL
90#include "komailclient.h" 90#include "komailclient.h"
91#endif 91#endif
92#ifndef KORG_NOPRINTER 92#ifndef KORG_NOPRINTER
93#include "calprinter.h" 93#include "calprinter.h"
94#endif 94#endif
95#ifndef KORG_NOPLUGINS 95#ifndef KORG_NOPLUGINS
96#include "kocore.h" 96#include "kocore.h"
97#endif 97#endif
98#include "koeventeditor.h" 98#include "koeventeditor.h"
99#include "kotodoeditor.h" 99#include "kotodoeditor.h"
100#include "koprefs.h" 100#include "koprefs.h"
101#include "koeventviewerdialog.h" 101#include "koeventviewerdialog.h"
102#include "publishdialog.h" 102#include "publishdialog.h"
103#include "kofilterview.h" 103#include "kofilterview.h"
104#include "koglobals.h" 104#include "koglobals.h"
105#include "koviewmanager.h" 105#include "koviewmanager.h"
106#include "koagendaview.h" 106#include "koagendaview.h"
107#include "kodialogmanager.h" 107#include "kodialogmanager.h"
108#include "outgoingdialog.h" 108#include "outgoingdialog.h"
109#include "incomingdialog.h" 109#include "incomingdialog.h"
110#include "datenavigatorcontainer.h" 110#include "datenavigatorcontainer.h"
111#include "statusdialog.h" 111#include "statusdialog.h"
112#include "kdatenavigator.h" 112#include "kdatenavigator.h"
113#include "kotodoview.h" 113#include "kotodoview.h"
114#include "datenavigator.h" 114#include "datenavigator.h"
115#include "resourceview.h" 115#include "resourceview.h"
116#include "navigatorbar.h" 116#include "navigatorbar.h"
117#include "searchdialog.h" 117#include "searchdialog.h"
118#include "mainwindow.h" 118#include "mainwindow.h"
119 119
120#include "calendarview.h" 120#include "calendarview.h"
121#ifndef DESKTOP_VERSION 121#ifndef DESKTOP_VERSION
122#include <qtopia/alarmserver.h> 122#include <qtopia/alarmserver.h>
123#endif 123#endif
124#ifndef _WIN32_ 124#ifndef _WIN32_
125#include <stdlib.h> 125#include <stdlib.h>
126#include <stdio.h> 126#include <stdio.h>
127#include <unistd.h> 127#include <unistd.h>
128#else 128#else
129#include <qprocess.h> 129#include <qprocess.h>
130#endif 130#endif
131 131
132#ifdef DESKTOP_VERSION 132#ifdef DESKTOP_VERSION
133#include <kabc/stdaddressbook.h> 133#include <kabc/stdaddressbook.h>
134#endif 134#endif
135using namespace KOrg; 135using namespace KOrg;
136using namespace KCal; 136using namespace KCal;
137extern int globalFlagBlockAgenda; 137extern int globalFlagBlockAgenda;
138extern int globalFlagBlockStartup; 138extern int globalFlagBlockStartup;
139 139
140 140
141MissedAlarmTextBrowser::MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms,QDateTime start ) : QTextBrowser(parent) 141MissedAlarmTextBrowser::MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms,QDateTime start ) : QTextBrowser(parent)
142 142
143{ 143{
144 mAlarms = alarms; 144 mAlarms = alarms;
145 viewport()->setBackgroundColor( QColor( 255, 255, 255 ) ); 145 viewport()->setBackgroundColor( QColor( 255, 255, 255 ) );
146 QString mText = "<table width=\"100%\">\n"; 146 QString mText = "<table width=\"100%\">\n";
147 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; 147 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
148#ifdef DESKTOP_VERSION 148#ifdef DESKTOP_VERSION
149 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>"; 149 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>";
150#else 150#else
151 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h3>"; 151 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h3>";
152#endif 152#endif
153 // mText += "<img src=\""; 153 // mText += "<img src=\"";
154 // mText += ipath; 154 // mText += ipath;
155 // mText += "\">"; 155 // mText += "\">";
156 //mEventDate = QDate::currentDate(); 156 //mEventDate = QDate::currentDate();
157#ifdef DESKTOP_VERSION 157#ifdef DESKTOP_VERSION
158 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h2>"; 158 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h2>";
159#else 159#else
160 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h3>"; 160 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h3>";
161#endif 161#endif
162 //mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>"; 162 //mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>";
163 163
164 Incidence * inc = getNextInc( start ); 164 Incidence * inc = getNextInc( start );
165 int time = 0; 165 int time = 0;
166 //mText += "<table>"; 166 //mText += "<table>";
167 while ( inc ) { 167 while ( inc ) {
168 QDateTime dt ; 168 QDateTime dt ;
169 QString tempText = "<a "; 169 QString tempText = "<a ";
170 bool ok; 170 bool ok;
171 dt = inc->getNextOccurence( start, &ok ); 171 dt = inc->getNextOccurence( start, &ok );
172 if ( !ok ) continue; 172 if ( !ok ) continue;
173 if ( inc->type() == "Event" ) { 173 if ( inc->type() == "Event" ) {
174 tempText += "href=\"event:"; 174 tempText += "href=\"event:";
175 } else if ( inc->type() == "Todo" ) { 175 } else if ( inc->type() == "Todo" ) {
176 tempText += "href=\"todo:"; 176 tempText += "href=\"todo:";
177 } 177 }
178 tempText += inc->uid() + "\">"; 178 tempText += inc->uid() + "\">";
179 if ( inc->type() == "Todo" ) 179 if ( inc->type() == "Todo" )
180 tempText += i18n("Todo: "); 180 tempText += i18n("Todo: ");
181 if ( inc->summary().length() > 0 ) 181 if ( inc->summary().length() > 0 )
182 tempText += inc->summary(); 182 tempText += inc->summary();
183 else 183 else
184 tempText += i18n("-no summary-"); 184 tempText += i18n("-no summary-");
185 QString timestr; 185 QString timestr;
186 if (!inc->doesFloat()) 186 if (!inc->doesFloat())
187 timestr = KGlobal::locale()->formatDateTime( dt, KOPrefs::instance()->mShortDateInViewer) +": "; 187 timestr = KGlobal::locale()->formatDateTime( dt, KOPrefs::instance()->mShortDateInViewer) +": ";
188 else 188 else
189 timestr = KGlobal::locale()->formatDate( dt.date() , KOPrefs::instance()->mShortDateInViewer) +": "; 189 timestr = KGlobal::locale()->formatDate( dt.date() , KOPrefs::instance()->mShortDateInViewer) +": ";
190 if ( dt.date() < QDate::currentDate() && time == 0 ) { 190 if ( dt.date() < QDate::currentDate() && time == 0 ) {
191 mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>"; 191 mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>";
192 mText += "<table>"; 192 mText += "<table>";
193 time = 1; 193 time = 1;
194 } 194 }
195 if ( dt.date() == QDate::currentDate() && time <= 1 ) { 195 if ( dt.date() == QDate::currentDate() && time <= 1 ) {
196 if ( time > 0 ) 196 if ( time > 0 )
197 mText +="</table>"; 197 mText +="</table>";
198 mText += "</td></tr>\n<tr bgcolor=\"#FFDC64\"><td>"; 198 mText += "</td></tr>\n<tr bgcolor=\"#FFDC64\"><td>";
199 mText += "<table>"; 199 mText += "<table>";
200 time = 2; 200 time = 2;
201 201
202 } 202 }
203 if ( dt.date() > QDate::currentDate() && time <= 2 ) { 203 if ( dt.date() > QDate::currentDate() && time <= 2 ) {
204 if ( time > 0 ) 204 if ( time > 0 )
205 mText +="</table>"; 205 mText +="</table>";
206 mText += "</td></tr>\n<tr bgcolor=\"#6AFF6A\"><td>"; 206 mText += "</td></tr>\n<tr bgcolor=\"#6AFF6A\"><td>";
207 mText += "<table>"; 207 mText += "<table>";
208 time = 3; 208 time = 3;
209 } 209 }
210 mText +="<tr><td><b>"; 210 mText +="<tr><td><b>";
211 mText += timestr; 211 mText += timestr;
212 mText += "</b></td><td>"; 212 mText += "</b></td><td>";
213 mText += tempText; 213 mText += tempText;
214 mText += "</td></tr>\n"; 214 mText += "</td></tr>\n";
215 inc = getNextInc( start ); 215 inc = getNextInc( start );
216 } 216 }
217 mText +="</table>"; 217 mText +="</table>";
218 setText( mText ); 218 setText( mText );
219} 219}
220 220
221MissedAlarmTextBrowser::~MissedAlarmTextBrowser() 221MissedAlarmTextBrowser::~MissedAlarmTextBrowser()
222{ 222{
223 //qDebug("delete MissedAlarmTextBrowser::~MissedAlarmTextBrowser() "); 223 //qDebug("delete MissedAlarmTextBrowser::~MissedAlarmTextBrowser() ");
224} 224}
225Incidence * MissedAlarmTextBrowser::getNextInc( QDateTime start ) 225Incidence * MissedAlarmTextBrowser::getNextInc( QDateTime start )
226{ 226{
227 QDateTime dt ; 227 QDateTime dt ;
228 Incidence * retInc; 228 Incidence * retInc;
229 Incidence * inc = mAlarms.first(); 229 Incidence * inc = mAlarms.first();
230 if ( inc == 0 ) 230 if ( inc == 0 )
231 return 0; 231 return 0;
232 bool ok; 232 bool ok;
233 dt = inc->getNextOccurence( start, &ok ); 233 dt = inc->getNextOccurence( start, &ok );
234 if ( ! ok ) return 0; 234 if ( ! ok ) return 0;
235 QDateTime dtn ; 235 QDateTime dtn ;
236 retInc = inc; 236 retInc = inc;
237 inc = mAlarms.next(); 237 inc = mAlarms.next();
238 while ( inc ) { 238 while ( inc ) {
239 dtn = inc->getNextOccurence( start, &ok ); 239 dtn = inc->getNextOccurence( start, &ok );
240 if ( ! ok ) return 0; 240 if ( ! ok ) return 0;
241 if ( dtn < dt ) { 241 if ( dtn < dt ) {
242 dt = dtn; 242 dt = dtn;
243 retInc = inc; 243 retInc = inc;
244 } 244 }
245 inc = mAlarms.next(); 245 inc = mAlarms.next();
246 } 246 }
247 mAlarms.remove( retInc ); 247 mAlarms.remove( retInc );
248 return retInc; 248 return retInc;
249 249
250} 250}
251void MissedAlarmTextBrowser::setSource(const QString & n) 251void MissedAlarmTextBrowser::setSource(const QString & n)
252{ 252{
253 if (n.startsWith("event:")) { 253 if (n.startsWith("event:")) {
254#ifdef DESKTOP_VERSION 254#ifdef DESKTOP_VERSION
255 emit showIncidence(n.mid(8)); 255 emit showIncidence(n.mid(8));
256#else 256#else
257 emit showIncidence(n.mid(6)); 257 emit showIncidence(n.mid(6));
258#endif 258#endif
259 return; 259 return;
260 } else if (n.startsWith("todo:")) { 260 } else if (n.startsWith("todo:")) {
261#ifdef DESKTOP_VERSION 261#ifdef DESKTOP_VERSION
262 emit showIncidence(n.mid(7)); 262 emit showIncidence(n.mid(7));
263#else 263#else
264 emit showIncidence(n.mid(5)); 264 emit showIncidence(n.mid(5));
265#endif 265#endif
266 return; 266 return;
267 } 267 }
268} 268}
269 269
270 270
271class KOBeamPrefs : public QDialog 271class KOBeamPrefs : public QDialog
272{ 272{
273 public: 273 public:
274 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 274 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
275 QDialog( parent, name, true ) 275 QDialog( parent, name, true )
276 { 276 {
277 setCaption( i18n("Beam Options") ); 277 setCaption( i18n("Beam Options") );
278 QVBoxLayout* lay = new QVBoxLayout( this ); 278 QVBoxLayout* lay = new QVBoxLayout( this );
279 lay->setSpacing( 3 ); 279 lay->setSpacing( 3 );
280 lay->setMargin( 3 ); 280 lay->setMargin( 3 );
281 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 281 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
282 lay->addWidget( format ); 282 lay->addWidget( format );
283 format->setExclusive ( true ) ; 283 format->setExclusive ( true ) ;
284 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 284 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
285 lay->addWidget( time ); time->setExclusive ( true ) ; 285 lay->addWidget( time ); time->setExclusive ( true ) ;
286 vcal = new QRadioButton(" vCalendar ", format ); 286 vcal = new QRadioButton(" vCalendar ", format );
287 ical = new QRadioButton(" iCalendar ", format ); 287 ical = new QRadioButton(" iCalendar ", format );
288 vcal->setChecked( true ); 288 vcal->setChecked( true );
289 tz = new QRadioButton(i18n(" With timezone "), time ); 289 tz = new QRadioButton(i18n(" With timezone "), time );
290 local = new QRadioButton(i18n(" Local time "), time ); 290 local = new QRadioButton(i18n(" Local time "), time );
291 tz->setChecked( true ); 291 tz->setChecked( true );
292 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 292 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
293 lay->addWidget( ok ); 293 lay->addWidget( ok );
294 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 294 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
295 lay->addWidget( cancel ); 295 lay->addWidget( cancel );
296 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 296 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
297 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 297 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
298 resize( 200, 200 ); 298 resize( 200, 200 );
299 } 299 }
300 300
301 bool beamVcal() { return vcal->isChecked(); } 301 bool beamVcal() { return vcal->isChecked(); }
302 bool beamLocal() { return local->isChecked(); } 302 bool beamLocal() { return local->isChecked(); }
303private: 303private:
304 QRadioButton* vcal, *ical, *local, *tz; 304 QRadioButton* vcal, *ical, *local, *tz;
305}; 305};
306class KOCatPrefs : public QDialog 306class KOCatPrefs : public QDialog
307{ 307{
308 public: 308 public:
309 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 309 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
310 QDialog( parent, name, true ) 310 QDialog( parent, name, true )
311 { 311 {
312 setCaption( i18n("Manage new Categories") ); 312 setCaption( i18n("Manage new Categories") );
313 QVBoxLayout* lay = new QVBoxLayout( this ); 313 QVBoxLayout* lay = new QVBoxLayout( this );
314 lay->setSpacing( 3 ); 314 lay->setSpacing( 3 );
315 lay->setMargin( 3 ); 315 lay->setMargin( 3 );
316 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); 316 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this );
317 lay->addWidget( lab ); 317 lay->addWidget( lab );
318 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 318 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
319 lay->addWidget( format ); 319 lay->addWidget( format );
320 format->setExclusive ( true ) ; 320 format->setExclusive ( true ) ;
321 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 321 addCatBut = new QRadioButton(i18n("Add to category list"), format );
322 new QRadioButton(i18n("Remove from Events/Todos"), format ); 322 new QRadioButton(i18n("Remove from Events/Todos"), format );
323 addCatBut->setChecked( true ); 323 addCatBut->setChecked( true );
324 QPushButton * ok = new QPushButton( i18n("OK"), this ); 324 QPushButton * ok = new QPushButton( i18n("OK"), this );
325 lay->addWidget( ok ); 325 lay->addWidget( ok );
326 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 326 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
327 lay->addWidget( cancel ); 327 lay->addWidget( cancel );
328 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 328 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
329 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 329 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
330 resize( 200, 200 ); 330 resize( 200, 200 );
331 } 331 }
332 332
333 bool addCat() { return addCatBut->isChecked(); } 333 bool addCat() { return addCatBut->isChecked(); }
334private: 334private:
335 QRadioButton* addCatBut; 335 QRadioButton* addCatBut;
336}; 336};
337 337
338 338
339 339
340CalendarView::CalendarView( CalendarResources *calendar, 340CalendarView::CalendarView( CalendarResources *calendar,
341 QWidget *parent, const char *name ) 341 QWidget *parent, const char *name )
342 : CalendarViewBase( parent, name ), 342 : CalendarViewBase( parent, name ),
343 mCalendar( calendar ), 343 mCalendar( calendar ),
344 mResourceManager( calendar->resourceManager() ) 344 mResourceManager( calendar->resourceManager() )
345{ 345{
346 346
347 mEventEditor = 0; 347 mEventEditor = 0;
348 mTodoEditor = 0; 348 mTodoEditor = 0;
349 349
350 init(); 350 init();
351} 351}
352 352
353CalendarView::CalendarView( Calendar *calendar, 353CalendarView::CalendarView( Calendar *calendar,
354 QWidget *parent, const char *name ) 354 QWidget *parent, const char *name )
355 : CalendarViewBase( parent, name ), 355 : CalendarViewBase( parent, name ),
356 mCalendar( calendar ), 356 mCalendar( calendar ),
357 mResourceManager( 0 ) 357 mResourceManager( 0 )
358{ 358{
359 359
360 mEventEditor = 0; 360 mEventEditor = 0;
361 mTodoEditor = 0; 361 mTodoEditor = 0;
362 init(); 362 init();
363} 363}
364 364
365void CalendarView::init() 365void CalendarView::init()
366{ 366{
367 mNextAlarmDateTime = QDateTime::currentDateTime(); 367 mNextAlarmDateTime = QDateTime::currentDateTime();
368 setFocusPolicy ( NoFocus ); 368 setFocusPolicy ( NoFocus );
369 mViewerCallerIsSearchDialog = false; 369 mViewerCallerIsSearchDialog = false;
370 mBlockShowDates = false; 370 mBlockShowDates = false;
371 beamDialog = new KOBeamPrefs(); 371 beamDialog = new KOBeamPrefs();
372 mDatePickerMode = 0; 372 mDatePickerMode = 0;
373 mCurrentSyncDevice = ""; 373 mCurrentSyncDevice = "";
374 writeLocale(); 374 writeLocale();
375 mViewManager = new KOViewManager( this ); 375 mViewManager = new KOViewManager( this );
376 mDialogManager = new KODialogManager( this ); 376 mDialogManager = new KODialogManager( this );
377 mEventViewerDialog = 0; 377 mEventViewerDialog = 0;
378 mModified = false; 378 mModified = false;
379 mReadOnly = false; 379 mReadOnly = false;
380 mSelectedIncidence = 0; 380 mSelectedIncidence = 0;
381 mCalPrinter = 0; 381 mCalPrinter = 0;
382 mFilters.setAutoDelete(true); 382 mFilters.setAutoDelete(true);
383 383
384 mCalendar->registerObserver( this ); 384 mCalendar->registerObserver( this );
385 // TODO: Make sure that view is updated, when calendar is changed. 385 // TODO: Make sure that view is updated, when calendar is changed.
386 386
387 mStorage = new FileStorage( mCalendar ); 387 mStorage = new FileStorage( mCalendar );
388 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 388 mNavigator = new DateNavigator( this, "datevav", mViewManager );
389 389
390 QBoxLayout *topLayout = (QBoxLayout*)layout(); 390 QBoxLayout *topLayout = (QBoxLayout*)layout();
391#ifndef KORG_NOSPLITTER 391#ifndef KORG_NOSPLITTER
392 // create the main layout frames. 392 // create the main layout frames.
393 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 393 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
394 topLayout->addWidget(mPanner); 394 topLayout->addWidget(mPanner);
395 395
396 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 396 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
397 "CalendarView::LeftFrame"); 397 "CalendarView::LeftFrame");
398 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 398 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
399 399
400 mDateNavigator = new DateNavigatorContainer( mLeftSplitter, 400 mDateNavigator = new DateNavigatorContainer( mLeftSplitter,
401 "CalendarView::DateNavigator" ); 401 "CalendarView::DateNavigator" );
402 402
403 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 403 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
404 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 404 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
405 mTodoList->setNavigator( mNavigator ); 405 mTodoList->setNavigator( mNavigator );
406 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 406 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
407 407
408#ifdef KORG_NORESOURCEVIEW 408#ifdef KORG_NORESOURCEVIEW
409 mResourceView = 0; 409 mResourceView = 0;
410#else 410#else
411 if ( mResourceManager ) { 411 if ( mResourceManager ) {
412 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 412 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
413 mResourceView->updateView(); 413 mResourceView->updateView();
414 connect( mResourceView, SIGNAL( resourcesChanged() ), 414 connect( mResourceView, SIGNAL( resourcesChanged() ),
415 SLOT( updateView() ) ); 415 SLOT( updateView() ) );
416 } else { 416 } else {
417 mResourceView = 0; 417 mResourceView = 0;
418 } 418 }
419#endif 419#endif
420 QWidget *rightBox = new QWidget( mPanner ); 420 QWidget *rightBox = new QWidget( mPanner );
421 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 421 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
422 422
423 mRightFrame = new QWidgetStack( rightBox ); 423 mRightFrame = new QWidgetStack( rightBox );
424 rightLayout->addWidget( mRightFrame, 1 ); 424 rightLayout->addWidget( mRightFrame, 1 );
425 425
426 mLeftFrame = mLeftSplitter; 426 mLeftFrame = mLeftSplitter;
427#else 427#else
428 //QWidget *mainBox = new QWidget( this ); 428 //QWidget *mainBox = new QWidget( this );
429 //QWidget *leftFrame = new QWidget( mainBox ); 429 //QWidget *leftFrame = new QWidget( mainBox );
430 //QBoxLayout * mainBoxLayout; 430 //QBoxLayout * mainBoxLayout;
431 if ( KOPrefs::instance()->mVerticalScreen ) { 431 if ( KOPrefs::instance()->mVerticalScreen ) {
432 //mainBoxLayout = new QVBoxLayout(mainBox); 432 //mainBoxLayout = new QVBoxLayout(mainBox);
433 //leftFrameLayout = new QHBoxLayout(leftFrame ); 433 //leftFrameLayout = new QHBoxLayout(leftFrame );
434 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this ); 434 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this );
435 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 435 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
436 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);; 436 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);;
437 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 437 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
438 } else { 438 } else {
439 //mainBoxLayout = new QHBoxLayout(mainBox); 439 //mainBoxLayout = new QHBoxLayout(mainBox);
440 //leftFrameLayout = new QVBoxLayout(leftFrame ); 440 //leftFrameLayout = new QVBoxLayout(leftFrame );
441 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 441 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
442 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left); 442 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left);
443 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame); 443 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame);
444 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 444 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
445 } 445 }
446 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); 446 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) );
447 //QBoxLayout * leftFrameLayout; 447 //QBoxLayout * leftFrameLayout;
448 topLayout->addWidget( mMainFrame ); 448 topLayout->addWidget( mMainFrame );
449 //mainBoxLayout->addWidget (mLeftFrame); 449 //mainBoxLayout->addWidget (mLeftFrame);
450 mDateNavigator = new DateNavigatorContainer( mLeftFrame, 450 mDateNavigator = new DateNavigatorContainer( mLeftFrame,
451 "CalendarView::DateNavigator" ); 451 "CalendarView::DateNavigator" );
452#if 0 452#if 0
453 // FIXME 453 // FIXME
454 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE, 454 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE,
455 "CalendarView::DateNavigator", QDate::currentDate()); 455 "CalendarView::DateNavigator", QDate::currentDate());
456#endif 456#endif
457 // mDateNavigator->blockSignals( true ); 457 // mDateNavigator->blockSignals( true );
458 //leftFrameLayout->addWidget( mDateNavigator ); 458 //leftFrameLayout->addWidget( mDateNavigator );
459 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall"); 459 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall");
460 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView"); 460 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView");
461 mTodoList->setNavigator( mNavigator ); 461 mTodoList->setNavigator( mNavigator );
462#if 0 462#if 0
463 if ( QApplication::desktop()->width() < 480 ) { 463 if ( QApplication::desktop()->width() < 480 ) {
464 leftFrameLayout->addWidget(mFilterView); 464 leftFrameLayout->addWidget(mFilterView);
465 leftFrameLayout->addWidget(mTodoList, 2 ); 465 leftFrameLayout->addWidget(mTodoList, 2 );
466 466
467 } else { 467 } else {
468 leftFrameLayout->addWidget(mTodoList,2 ); 468 leftFrameLayout->addWidget(mTodoList,2 );
469 leftFrameLayout->addWidget(mFilterView ); 469 leftFrameLayout->addWidget(mFilterView );
470 } 470 }
471#endif 471#endif
472 mFilterView->hide(); 472 mFilterView->hide();
473 QWidget *rightBox = new QWidget( mMainFrame ); 473 QWidget *rightBox = new QWidget( mMainFrame );
474 //mainBoxLayout->addWidget ( rightBox, 10 ); 474 //mainBoxLayout->addWidget ( rightBox, 10 );
475 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 475 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
476 mRightFrame = new QWidgetStack( rightBox ); 476 mRightFrame = new QWidgetStack( rightBox );
477 rightLayout->addWidget( mRightFrame, 10 ); 477 rightLayout->addWidget( mRightFrame, 10 );
478 478
479 //mLeftFrame = (QWidget *)leftFrame; 479 //mLeftFrame = (QWidget *)leftFrame;
480 if ( KOPrefs::instance()->mVerticalScreen ) { 480 if ( KOPrefs::instance()->mVerticalScreen ) {
481 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() ); 481 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() );
482 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() ); 482 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() );
483 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 483 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
484 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 484 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
485 } else { 485 } else {
486 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() ); 486 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() );
487 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 487 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
488 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 488 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
489 } 489 }
490 if ( !KOPrefs::instance()->mShowDateNavigator) 490 if ( !KOPrefs::instance()->mShowDateNavigator)
491 mDateNavigator->hide(); 491 mDateNavigator->hide();
492 //qDebug("Calendarview Size %d %d ", width(), height()); 492 //qDebug("Calendarview Size %d %d ", width(), height());
493#endif 493#endif
494 494
495 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 495 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
496 SLOT( showDates( const KCal::DateList & ) ) ); 496 SLOT( showDates( const KCal::DateList & ) ) );
497 497
498 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 498 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
499 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 499 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
500 500
501 501
502 502
503 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ), 503 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ),
504 mViewManager, SLOT( showMonth( const QDate & ) ) ); 504 mViewManager, SLOT( showMonth( const QDate & ) ) );
505 505
506 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 506 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
507 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 507 mNavigator, SLOT( selectWeek( const QDate & ) ) );
508 508
509 connect( mDateNavigator, SIGNAL( goPrevYear() ), 509 connect( mDateNavigator, SIGNAL( goPrevYear() ),
510 mNavigator, SLOT( selectPreviousYear() ) ); 510 mNavigator, SLOT( selectPreviousYear() ) );
511 connect( mDateNavigator, SIGNAL( goNextYear() ), 511 connect( mDateNavigator, SIGNAL( goNextYear() ),
512 mNavigator, SLOT( selectNextYear() ) ); 512 mNavigator, SLOT( selectNextYear() ) );
513 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 513 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
514 mNavigator, SLOT( selectPreviousMonth() ) ); 514 mNavigator, SLOT( selectPreviousMonth() ) );
515 connect( mDateNavigator, SIGNAL( goNextMonth() ), 515 connect( mDateNavigator, SIGNAL( goNextMonth() ),
516 mNavigator, SLOT( selectNextMonth() ) ); 516 mNavigator, SLOT( selectNextMonth() ) );
517 517
518 connect( mDateNavigator, SIGNAL( goPrevious() ), 518 connect( mDateNavigator, SIGNAL( goPrevious() ),
519 mNavigator, SLOT( selectPrevious() ) ); 519 mNavigator, SLOT( selectPrevious() ) );
520 connect( mDateNavigator, SIGNAL( goNext() ), 520 connect( mDateNavigator, SIGNAL( goNext() ),
521 mNavigator, SLOT( selectNext() ) ); 521 mNavigator, SLOT( selectNext() ) );
522 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 522 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
523 mNavigator, SLOT( slotMonthSelect( int ) ) ); 523 mNavigator, SLOT( slotMonthSelect( int ) ) );
524 524
525 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 525 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
526 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 526 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
527#if 0 527#if 0
528 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ), 528 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ),
529 SLOT( incidenceAdded( Incidence *) ) ); 529 SLOT( incidenceAdded( Incidence *) ) );
530#endif 530#endif
531 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 531 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
532 532
533 connect( this, SIGNAL( configChanged() ), 533 connect( this, SIGNAL( configChanged() ),
534 mDateNavigator, SLOT( updateConfig() ) ); 534 mDateNavigator, SLOT( updateConfig() ) );
535 535
536 connect( mTodoList, SIGNAL( newTodoSignal() ), 536 connect( mTodoList, SIGNAL( newTodoSignal() ),
537 SLOT( newTodo() ) ); 537 SLOT( newTodo() ) );
538 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 538 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
539 SLOT( newSubTodo( Todo * ) ) ); 539 SLOT( newSubTodo( Todo * ) ) );
540 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 540 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
541 SLOT( editTodo( Todo * ) ) ); 541 SLOT( editTodo( Todo * ) ) );
542 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 542 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
543 SLOT( showTodo( Todo *) ) ); 543 SLOT( showTodo( Todo *) ) );
544 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 544 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
545 SLOT( deleteTodo( Todo *) ) ); 545 SLOT( deleteTodo( Todo *) ) );
546 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 546 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
547 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 547 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
548 SLOT( purgeCompleted() ) ); 548 SLOT( purgeCompleted() ) );
549 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 549 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
550 SIGNAL( todoModified( Todo *, int ) ) ); 550 SIGNAL( todoModified( Todo *, int ) ) );
551 551
552 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 552 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
553 this, SLOT ( cloneIncidence( Incidence * ) ) ); 553 this, SLOT ( cloneIncidence( Incidence * ) ) );
554 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 554 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
555 this, SLOT (cancelIncidence( Incidence * ) ) ); 555 this, SLOT (cancelIncidence( Incidence * ) ) );
556 556
557 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 557 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
558 this, SLOT ( moveIncidence( Incidence * ) ) ); 558 this, SLOT ( moveIncidence( Incidence * ) ) );
559 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 559 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
560 this, SLOT ( beamIncidence( Incidence * ) ) ); 560 this, SLOT ( beamIncidence( Incidence * ) ) );
561 561
562 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 562 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
563 this, SLOT ( todo_unsub( Todo * ) ) ); 563 this, SLOT ( todo_unsub( Todo * ) ) );
564 564
565 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 565 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
566 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 566 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
567 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 567 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
568 SLOT( updateTodo( Todo *, int ) ) ); 568 SLOT( updateTodo( Todo *, int ) ) );
569 connect( this, SIGNAL( todoModified( Todo *, int )), this, 569 connect( this, SIGNAL( todoModified( Todo *, int )), this,
570 SLOT( changeTodoDisplay( Todo *, int ) ) ); 570 SLOT( changeTodoDisplay( Todo *, int ) ) );
571 571
572 572
573 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 573 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
574 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 574 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
575 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 575 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
576 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 576 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
577 577
578 578
579 579
580 580
581 581
582 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 582 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
583 SLOT(checkClipboard())); 583 SLOT(checkClipboard()));
584 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 584 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
585 SLOT( processTodoListSelection( Incidence * ) ) ); 585 SLOT( processTodoListSelection( Incidence * ) ) );
586 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 586 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
587 587
588 // kdDebug() << "CalendarView::CalendarView() done" << endl; 588 // kdDebug() << "CalendarView::CalendarView() done" << endl;
589 589
590 mDateFrame = new QVBox(0,0,WType_Popup); 590 mDateFrame = new QVBox(0,0,WType_Popup);
591 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 591 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
592 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 592 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
593 mDateFrame->setLineWidth(3); 593 mDateFrame->setLineWidth(3);
594 mDateFrame->hide(); 594 mDateFrame->hide();
595 mDateFrame->setCaption( i18n( "Pick a date to display")); 595 mDateFrame->setCaption( i18n( "Pick a date to display"));
596 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 596 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
597 597
598 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 598 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
599 599
600 mEventEditor = mDialogManager->getEventEditor(); 600 mEventEditor = mDialogManager->getEventEditor();
601 mTodoEditor = mDialogManager->getTodoEditor(); 601 mTodoEditor = mDialogManager->getTodoEditor();
602 602
603 mFlagEditDescription = false; 603 mFlagEditDescription = false;
604 604
605 mSuspendTimer = new QTimer( this ); 605 mSuspendTimer = new QTimer( this );
606 mAlarmTimer = new QTimer( this ); 606 mAlarmTimer = new QTimer( this );
607 mRecheckAlarmTimer = new QTimer( this ); 607 mRecheckAlarmTimer = new QTimer( this );
608 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 608 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
609 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 609 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
610 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 610 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
611 mAlarmDialog = new AlarmDialog( this ); 611 mAlarmDialog = new AlarmDialog( this );
612 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 612 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
613 mAlarmDialog->setServerNotification( false ); 613 mAlarmDialog->setServerNotification( false );
614 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 614 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
615 615
616 616
617#ifndef DESKTOP_VERSION 617#ifndef DESKTOP_VERSION
618//US listen for arriving address resultsets 618//US listen for arriving address resultsets
619 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 619 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
620 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 620 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
621#endif 621#endif
622 mDateNavigator->setCalendar( mCalendar ); 622 mDateNavigator->setCalendar( mCalendar );
623} 623}
624 624
625 625
626CalendarView::~CalendarView() 626CalendarView::~CalendarView()
627{ 627{
628 // kdDebug() << "~CalendarView()" << endl; 628 // kdDebug() << "~CalendarView()" << endl;
629 //qDebug("CalendarView::~CalendarView() "); 629 //qDebug("CalendarView::~CalendarView() ");
630 delete mDialogManager; 630 delete mDialogManager;
631 delete mViewManager; 631 delete mViewManager;
632 delete mStorage; 632 delete mStorage;
633 delete mDateFrame ; 633 delete mDateFrame ;
634 delete beamDialog; 634 delete beamDialog;
635 delete mEventViewerDialog; 635 delete mEventViewerDialog;
636 //kdDebug() << "~CalendarView() done" << endl; 636 //kdDebug() << "~CalendarView() done" << endl;
637} 637}
638void CalendarView::checkAlarms() 638void CalendarView::checkAlarms()
639{ 639{
640 KConfig *config = KOGlobals::config(); 640 KConfig *config = KOGlobals::config();
641 config->setGroup( "AppRun" ); 641 config->setGroup( "AppRun" );
642 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 642 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
643 int secs = config->readNumEntry( "LatestProgramStop" ) - 30; 643 int secto = dt.secsTo( QDateTime::currentDateTime() );
644 int secs = config->readNumEntry( "LatestProgramStop" , secto) - 30;
644 //secs -= ( 3600 * 24*3 ); // debug only 645 //secs -= ( 3600 * 24*3 ); // debug only
645 QDateTime latest = dt.addSecs ( secs ); 646 QDateTime latest = dt.addSecs ( secs );
646 qDebug("KO: Last termination on %s ", latest.toString().latin1()); 647 qDebug("KO: Last termination on %s ", latest.toString().latin1());
647 QPtrList<Incidence> el = mCalendar->rawIncidences(); 648 QPtrList<Incidence> el = mCalendar->rawIncidences();
648 QPtrList<Incidence> al; 649 QPtrList<Incidence> al;
649 Incidence* inL = el.first(); 650 Incidence* inL = el.first();
650 while ( inL ) { 651 while ( inL ) {
651 bool ok = false; 652 bool ok = false;
652 int offset = 0; 653 int offset = 0;
653 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; 654 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ;
654 if ( ok ) { 655 if ( ok ) {
655 //qDebug("OK %s",next.toString().latin1()); 656 //qDebug("OK %s",next.toString().latin1());
656 if ( next < QDateTime::currentDateTime() ) { 657 if ( next < QDateTime::currentDateTime() ) {
657 al.append( inL ); 658 al.append( inL );
658 //qDebug("found missed alarm: %s ", inL->summary().latin1() ); 659 //qDebug("found missed alarm: %s ", inL->summary().latin1() );
659 } 660 }
660 } 661 }
661 inL = el.next(); 662 inL = el.next();
662 } 663 }
663 if ( al.count() ) { 664 if ( al.count() ) {
664 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop ); 665 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop );
665 dia->setCaption( i18n("KO/Pi: Missing alarms!") ); 666 dia->setCaption( i18n("KO/Pi: Missing alarms!") );
666 QVBoxLayout* lay = new QVBoxLayout( dia ); 667 QVBoxLayout* lay = new QVBoxLayout( dia );
667 lay->setSpacing( 0 ); 668 lay->setSpacing( 0 );
668 lay->setMargin( 0 ); 669 lay->setMargin( 0 );
669 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest ); 670 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest );
670 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 671 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
671 lay->addWidget( matb ); 672 lay->addWidget( matb );
672 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) { 673 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) {
673 int wid = 210; 674 int wid = 210;
674 int x = QApplication::desktop()->width() - wid - 7; 675 int x = QApplication::desktop()->width() - wid - 7;
675 int y = QApplication::desktop()->height() - wid - 70; 676 int y = QApplication::desktop()->height() - wid - 70;
676 dia->setGeometry ( x,y,wid,wid); 677 dia->setGeometry ( x,y,wid,wid);
677 } else { 678 } else {
678 int si = 220; 679 int si = 220;
679 if ( QApplication::desktop()->width() > 470 ) 680 if ( QApplication::desktop()->width() > 470 )
680 si = 400; 681 si = 400;
681 dia->resize(si,si/2); 682 dia->resize(si,si/2);
682 } 683 }
683 dia->setBackgroundColor( QColor( 255, 255, 255 ) ); 684 dia->setBackgroundColor( QColor( 255, 255, 255 ) );
684 dia->show(); 685 dia->show();
685 686
686 } 687 }
687} 688}
688void CalendarView::showDay( QDate d ) 689void CalendarView::showDay( QDate d )
689{ 690{
690 dateNavigator()->blockSignals( true ); 691 dateNavigator()->blockSignals( true );
691 dateNavigator()->selectDate( d ); 692 dateNavigator()->selectDate( d );
692 dateNavigator()->blockSignals( false ); 693 dateNavigator()->blockSignals( false );
693 mViewManager->showDayView(); 694 mViewManager->showDayView();
694 //dateNavigator()->selectDate( d ); 695 //dateNavigator()->selectDate( d );
695} 696}
696void CalendarView::timerAlarm() 697void CalendarView::timerAlarm()
697{ 698{
698 //qDebug("CalendarView::timerAlarm() "); 699 //qDebug("CalendarView::timerAlarm() ");
699 computeAlarm(mAlarmNotification ); 700 computeAlarm(mAlarmNotification );
700} 701}
701 702
702void CalendarView::suspendAlarm() 703void CalendarView::suspendAlarm()
703{ 704{
704 //qDebug(" CalendarView::suspendAlarm() "); 705 //qDebug(" CalendarView::suspendAlarm() ");
705 computeAlarm(mSuspendAlarmNotification ); 706 computeAlarm(mSuspendAlarmNotification );
706 707
707} 708}
708 709
709void CalendarView::startAlarm( QString mess , QString filename) 710void CalendarView::startAlarm( QString mess , QString filename)
710{ 711{
711 712
712 topLevelWidget()->showNormal(); 713 topLevelWidget()->showNormal();
713 topLevelWidget()->setActiveWindow(); 714 topLevelWidget()->setActiveWindow();
714 topLevelWidget()->raise(); 715 topLevelWidget()->raise();
715 716
716 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 717 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
717 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 718 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
718 719
719} 720}
720 721
721void CalendarView::checkNextTimerAlarm() 722void CalendarView::checkNextTimerAlarm()
722{ 723{
723 mCalendar->checkAlarmForIncidence( 0, true ); 724 mCalendar->checkAlarmForIncidence( 0, true );
724} 725}
725 726
726void CalendarView::computeAlarm( QString msg ) 727void CalendarView::computeAlarm( QString msg )
727{ 728{
728 729
729 QString mess = msg; 730 QString mess = msg;
730 QString mAlarmMessage = mess.mid( 9 ); 731 QString mAlarmMessage = mess.mid( 9 );
731 QString filename = MainWindow::resourcePath(); 732 QString filename = MainWindow::resourcePath();
732 filename += "koalarm.wav"; 733 filename += "koalarm.wav";
733 QString tempfilename; 734 QString tempfilename;
734 if ( mess.left( 13 ) == "suspend_alarm") { 735 if ( mess.left( 13 ) == "suspend_alarm") {
735 bool error = false; 736 bool error = false;
736 int len = mess.mid( 13 ).find("+++"); 737 int len = mess.mid( 13 ).find("+++");
737 if ( len < 2 ) 738 if ( len < 2 )
738 error = true; 739 error = true;
739 else { 740 else {
740 tempfilename = mess.mid( 13, len ); 741 tempfilename = mess.mid( 13, len );
741 if ( !QFile::exists( tempfilename ) ) 742 if ( !QFile::exists( tempfilename ) )
742 error = true; 743 error = true;
743 } 744 }
744 if ( ! error ) { 745 if ( ! error ) {
745 filename = tempfilename; 746 filename = tempfilename;
746 } 747 }
747 mAlarmMessage = mess.mid( 13+len+3 ); 748 mAlarmMessage = mess.mid( 13+len+3 );
748 //qDebug("suspend file %s ",tempfilename.latin1() ); 749 //qDebug("suspend file %s ",tempfilename.latin1() );
749 startAlarm( mAlarmMessage, filename); 750 startAlarm( mAlarmMessage, filename);
750 return; 751 return;
751 } 752 }
752 if ( mess.left( 11 ) == "timer_alarm") { 753 if ( mess.left( 11 ) == "timer_alarm") {
753 //mTimerTime = 0; 754 //mTimerTime = 0;
754 startAlarm( mess.mid( 11 ), filename ); 755 startAlarm( mess.mid( 11 ), filename );
755 return; 756 return;
756 } 757 }
757 if ( mess.left( 10 ) == "proc_alarm") { 758 if ( mess.left( 10 ) == "proc_alarm") {
758 bool error = false; 759 bool error = false;
759 int len = mess.mid( 10 ).find("+++"); 760 int len = mess.mid( 10 ).find("+++");
760 if ( len < 2 ) 761 if ( len < 2 )
761 error = true; 762 error = true;
762 else { 763 else {
763 tempfilename = mess.mid( 10, len ); 764 tempfilename = mess.mid( 10, len );
764 if ( !QFile::exists( tempfilename ) ) 765 if ( !QFile::exists( tempfilename ) )
765 error = true; 766 error = true;
766 } 767 }
767 if ( error ) { 768 if ( error ) {
768 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 769 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
769 mAlarmMessage += mess.mid( 10+len+3+9 ); 770 mAlarmMessage += mess.mid( 10+len+3+9 );
770 } else { 771 } else {
771 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 772 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
772 //qDebug("-----system command %s ",tempfilename.latin1() ); 773 //qDebug("-----system command %s ",tempfilename.latin1() );
773#ifndef _WIN32_ 774#ifndef _WIN32_
774 if ( vfork () == 0 ) { 775 if ( vfork () == 0 ) {
775 execl ( tempfilename.latin1(), 0 ); 776 execl ( tempfilename.latin1(), 0 );
776 return; 777 return;
777 } 778 }
778#else 779#else
779 QProcess* p = new QProcess(); 780 QProcess* p = new QProcess();
780 p->addArgument( tempfilename.latin1() ); 781 p->addArgument( tempfilename.latin1() );
781 p->start(); 782 p->start();
782 return; 783 return;
783#endif 784#endif
784 785
785 return; 786 return;
786 } 787 }
787 788
788 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 789 //qDebug("+++++++system command %s ",tempfilename.latin1() );
789 } 790 }
790 if ( mess.left( 11 ) == "audio_alarm") { 791 if ( mess.left( 11 ) == "audio_alarm") {
791 bool error = false; 792 bool error = false;
792 int len = mess.mid( 11 ).find("+++"); 793 int len = mess.mid( 11 ).find("+++");
793 if ( len < 2 ) 794 if ( len < 2 )
794 error = true; 795 error = true;
795 else { 796 else {
796 tempfilename = mess.mid( 11, len ); 797 tempfilename = mess.mid( 11, len );
797 if ( !QFile::exists( tempfilename ) ) 798 if ( !QFile::exists( tempfilename ) )
798 error = true; 799 error = true;
799 } 800 }
800 if ( ! error ) { 801 if ( ! error ) {
801 filename = tempfilename; 802 filename = tempfilename;
802 } 803 }
803 mAlarmMessage = mess.mid( 11+len+3+9 ); 804 mAlarmMessage = mess.mid( 11+len+3+9 );
804 //qDebug("audio file command %s ",tempfilename.latin1() ); 805 //qDebug("audio file command %s ",tempfilename.latin1() );
805 } 806 }
806 if ( mess.left( 9 ) == "cal_alarm") { 807 if ( mess.left( 9 ) == "cal_alarm") {
807 mAlarmMessage = mess.mid( 9 ) ; 808 mAlarmMessage = mess.mid( 9 ) ;
808 } 809 }
809 810
810 startAlarm( mAlarmMessage, filename ); 811 startAlarm( mAlarmMessage, filename );
811 812
812 813
813} 814}
814 815
815void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 816void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
816{ 817{
817 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 818 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
818 819
819 mSuspendAlarmNotification = noti; 820 mSuspendAlarmNotification = noti;
820 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 821 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
821 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 822 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
822 mSuspendTimer->start( ms , true ); 823 mSuspendTimer->start( ms , true );
823 824
824} 825}
825 826
826void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 827void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
827{ 828{
828 mNextAlarmDateTime = qdt; 829 mNextAlarmDateTime = qdt;
829 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 830 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
830 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 831 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
831#ifndef DESKTOP_VERSION 832#ifndef DESKTOP_VERSION
832 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 833 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
833#endif 834#endif
834 return; 835 return;
835 } 836 }
836 int maxSec; 837 int maxSec;
837 //maxSec = 5; //testing only 838 //maxSec = 5; //testing only
838 maxSec = 86400+3600; // one day+1hour 839 maxSec = 86400+3600; // one day+1hour
839 mAlarmNotification = noti; 840 mAlarmNotification = noti;
840 int sec = QDateTime::currentDateTime().secsTo( qdt ); 841 int sec = QDateTime::currentDateTime().secsTo( qdt );
841 if ( sec > maxSec ) { 842 if ( sec > maxSec ) {
842 mRecheckAlarmTimer->start( maxSec * 1000 ); 843 mRecheckAlarmTimer->start( maxSec * 1000 );
843 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 844 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
844 return; 845 return;
845 } else { 846 } else {
846 mRecheckAlarmTimer->stop(); 847 mRecheckAlarmTimer->stop();
847 } 848 }
848 //qDebug("Alarm timer started with secs: %d ", sec); 849 //qDebug("Alarm timer started with secs: %d ", sec);
849 mAlarmTimer->start( sec *1000 , true ); 850 mAlarmTimer->start( sec *1000 , true );
850 851
851} 852}
852// called by mRecheckAlarmTimer to get next alarm 853// called by mRecheckAlarmTimer to get next alarm
853// we need this, because a QTimer has only a max range of 25 days 854// we need this, because a QTimer has only a max range of 25 days
854void CalendarView::recheckTimerAlarm() 855void CalendarView::recheckTimerAlarm()
855{ 856{
856 mAlarmTimer->stop(); 857 mAlarmTimer->stop();
857 mRecheckAlarmTimer->stop(); 858 mRecheckAlarmTimer->stop();
858 mCalendar->checkAlarmForIncidence( 0, true ); 859 mCalendar->checkAlarmForIncidence( 0, true );
859} 860}
860void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 861void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
861{ 862{
862 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 863 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
863 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 864 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
864#ifndef DESKTOP_VERSION 865#ifndef DESKTOP_VERSION
865 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 866 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
866#endif 867#endif
867 return; 868 return;
868 } 869 }
869 mAlarmTimer->stop(); 870 mAlarmTimer->stop();
870} 871}
871void CalendarView::selectWeekNum ( int num ) 872void CalendarView::selectWeekNum ( int num )
872{ 873{
873 dateNavigator()->blockSignals( true ); 874 dateNavigator()->blockSignals( true );
874 dateNavigator()->selectWeek( num ); 875 dateNavigator()->selectWeek( num );
875 dateNavigator()->blockSignals( false ); 876 dateNavigator()->blockSignals( false );
876 mViewManager->showWeekView(); 877 mViewManager->showWeekView();
877} 878}
878KOViewManager *CalendarView::viewManager() 879KOViewManager *CalendarView::viewManager()
879{ 880{
880 return mViewManager; 881 return mViewManager;
881} 882}
882 883
883KODialogManager *CalendarView::dialogManager() 884KODialogManager *CalendarView::dialogManager()
884{ 885{
885 return mDialogManager; 886 return mDialogManager;
886} 887}
887 888
888QDate CalendarView::startDate() 889QDate CalendarView::startDate()
889{ 890{
890 DateList dates = mNavigator->selectedDates(); 891 DateList dates = mNavigator->selectedDates();
891 892
892 return dates.first(); 893 return dates.first();
893} 894}
894 895
895QDate CalendarView::endDate() 896QDate CalendarView::endDate()
896{ 897{
897 DateList dates = mNavigator->selectedDates(); 898 DateList dates = mNavigator->selectedDates();
898 899
899 return dates.last(); 900 return dates.last();
900} 901}
901 902
902 903
903void CalendarView::createPrinter() 904void CalendarView::createPrinter()
904{ 905{
905#ifndef KORG_NOPRINTER 906#ifndef KORG_NOPRINTER
906 if (!mCalPrinter) { 907 if (!mCalPrinter) {
907 mCalPrinter = new CalPrinter(this, mCalendar); 908 mCalPrinter = new CalPrinter(this, mCalendar);
908 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 909 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
909 } 910 }
910#endif 911#endif
911} 912}
912 913
913 914
914//KOPrefs::instance()->mWriteBackFile 915//KOPrefs::instance()->mWriteBackFile
915//KOPrefs::instance()->mWriteBackExistingOnly 916//KOPrefs::instance()->mWriteBackExistingOnly
916 917
917// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 918// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
918// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 919// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
919// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 920// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
920// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 921// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
921// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 922// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
922// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 923// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
923 924
924int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 925int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
925{ 926{
926 927
927 // 0 equal 928 // 0 equal
928 // 1 take local 929 // 1 take local
929 // 2 take remote 930 // 2 take remote
930 // 3 cancel 931 // 3 cancel
931 QDateTime lastSync = mLastCalendarSync; 932 QDateTime lastSync = mLastCalendarSync;
932 QDateTime localMod = local->lastModified(); 933 QDateTime localMod = local->lastModified();
933 QDateTime remoteMod = remote->lastModified(); 934 QDateTime remoteMod = remote->lastModified();
934 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 935 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
935 bool remCh, locCh; 936 bool remCh, locCh;
936 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 937 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
937 //if ( remCh ) 938 //if ( remCh )
938 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 939 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
939 locCh = ( localMod > mLastCalendarSync ); 940 locCh = ( localMod > mLastCalendarSync );
940 if ( !remCh && ! locCh ) { 941 if ( !remCh && ! locCh ) {
941 //qDebug("both not changed "); 942 //qDebug("both not changed ");
942 lastSync = localMod.addDays(1); 943 lastSync = localMod.addDays(1);
943 if ( mode <= SYNC_PREF_ASK ) 944 if ( mode <= SYNC_PREF_ASK )
944 return 0; 945 return 0;
945 } else { 946 } else {
946 if ( locCh ) { 947 if ( locCh ) {
947 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 948 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
948 lastSync = localMod.addDays( -1 ); 949 lastSync = localMod.addDays( -1 );
949 if ( !remCh ) 950 if ( !remCh )
950 remoteMod = ( lastSync.addDays( -1 ) ); 951 remoteMod = ( lastSync.addDays( -1 ) );
951 } else { 952 } else {
952 //qDebug(" not loc changed "); 953 //qDebug(" not loc changed ");
953 lastSync = localMod.addDays( 1 ); 954 lastSync = localMod.addDays( 1 );
954 if ( remCh ) 955 if ( remCh )
955 remoteMod =( lastSync.addDays( 1 ) ); 956 remoteMod =( lastSync.addDays( 1 ) );
956 957
957 } 958 }
958 } 959 }
959 full = true; 960 full = true;
960 if ( mode < SYNC_PREF_ASK ) 961 if ( mode < SYNC_PREF_ASK )
961 mode = SYNC_PREF_ASK; 962 mode = SYNC_PREF_ASK;
962 } else { 963 } else {
963 if ( localMod == remoteMod ) 964 if ( localMod == remoteMod )
964 // if ( local->revision() == remote->revision() ) 965 // if ( local->revision() == remote->revision() )
965 return 0; 966 return 0;
966 967
967 } 968 }
968 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 969 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
969 970
970 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 971 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
971 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 972 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
972 //full = true; //debug only 973 //full = true; //debug only
973 if ( full ) { 974 if ( full ) {
974 bool equ = false; 975 bool equ = false;
975 if ( local->type() == "Event" ) { 976 if ( local->type() == "Event" ) {
976 equ = (*((Event*) local) == *((Event*) remote)); 977 equ = (*((Event*) local) == *((Event*) remote));
977 } 978 }
978 else if ( local->type() =="Todo" ) 979 else if ( local->type() =="Todo" )
979 equ = (*((Todo*) local) == (*(Todo*) remote)); 980 equ = (*((Todo*) local) == (*(Todo*) remote));
980 else if ( local->type() =="Journal" ) 981 else if ( local->type() =="Journal" )
981 equ = (*((Journal*) local) == *((Journal*) remote)); 982 equ = (*((Journal*) local) == *((Journal*) remote));
982 if ( equ ) { 983 if ( equ ) {
983 //qDebug("equal "); 984 //qDebug("equal ");
984 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 985 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
985 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 986 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
986 } 987 }
987 if ( mode < SYNC_PREF_FORCE_LOCAL ) 988 if ( mode < SYNC_PREF_FORCE_LOCAL )
988 return 0; 989 return 0;
989 990
990 }//else //debug only 991 }//else //debug only
991 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 992 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
992 } 993 }
993 int result; 994 int result;
994 bool localIsNew; 995 bool localIsNew;
995 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 996 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
996 997
997 998
998 // ************************************************ 999 // ************************************************
999 // ************************************************ 1000 // ************************************************
1000 // ************************************************ 1001 // ************************************************
1001 // We may have that lastSync > remoteMod AND lastSync > localMod 1002 // We may have that lastSync > remoteMod AND lastSync > localMod
1002 // BUT remoteMod != localMod 1003 // BUT remoteMod != localMod
1003 1004
1004 1005
1005 if ( full && mode < SYNC_PREF_NEWEST ) 1006 if ( full && mode < SYNC_PREF_NEWEST )
1006 mode = SYNC_PREF_ASK; 1007 mode = SYNC_PREF_ASK;
1007 1008
1008 switch( mode ) { 1009 switch( mode ) {
1009 case SYNC_PREF_LOCAL: 1010 case SYNC_PREF_LOCAL:
1010 if ( lastSync > remoteMod ) 1011 if ( lastSync > remoteMod )
1011 return 1; 1012 return 1;
1012 if ( lastSync > localMod ) 1013 if ( lastSync > localMod )
1013 return 2; 1014 return 2;
1014 return 1; 1015 return 1;
1015 break; 1016 break;
1016 case SYNC_PREF_REMOTE: 1017 case SYNC_PREF_REMOTE:
1017 if ( lastSync > localMod ) 1018 if ( lastSync > localMod )
1018 return 2; 1019 return 2;
1019 if ( lastSync > remoteMod ) 1020 if ( lastSync > remoteMod )
1020 return 1; 1021 return 1;
1021 return 2; 1022 return 2;
1022 break; 1023 break;
1023 case SYNC_PREF_NEWEST: 1024 case SYNC_PREF_NEWEST:
1024 if ( localMod >= remoteMod ) 1025 if ( localMod >= remoteMod )
1025 return 1; 1026 return 1;
1026 else 1027 else
1027 return 2; 1028 return 2;
1028 break; 1029 break;
1029 case SYNC_PREF_ASK: 1030 case SYNC_PREF_ASK:
1030 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1031 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1031 if ( lastSync > remoteMod && lastSync > localMod) 1032 if ( lastSync > remoteMod && lastSync > localMod)
1032 return 0; 1033 return 0;
1033 if ( lastSync > remoteMod ) 1034 if ( lastSync > remoteMod )
1034 return 1; 1035 return 1;
1035 if ( lastSync > localMod ) 1036 if ( lastSync > localMod )
1036 return 2; 1037 return 2;
1037 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1038 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1038 localIsNew = localMod >= remoteMod; 1039 localIsNew = localMod >= remoteMod;
1039 if ( localIsNew ) 1040 if ( localIsNew )
1040 getEventViewerDialog()->setColorMode( 1 ); 1041 getEventViewerDialog()->setColorMode( 1 );
1041 else 1042 else
1042 getEventViewerDialog()->setColorMode( 2 ); 1043 getEventViewerDialog()->setColorMode( 2 );
1043 getEventViewerDialog()->setIncidence(local); 1044 getEventViewerDialog()->setIncidence(local);
1044 if ( localIsNew ) 1045 if ( localIsNew )
1045 getEventViewerDialog()->setColorMode( 2 ); 1046 getEventViewerDialog()->setColorMode( 2 );
1046 else 1047 else
1047 getEventViewerDialog()->setColorMode( 1 ); 1048 getEventViewerDialog()->setColorMode( 1 );
1048 getEventViewerDialog()->addIncidence(remote); 1049 getEventViewerDialog()->addIncidence(remote);
1049 getEventViewerDialog()->setColorMode( 0 ); 1050 getEventViewerDialog()->setColorMode( 0 );
1050 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1051 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1051 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1052 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1052 getEventViewerDialog()->showMe(); 1053 getEventViewerDialog()->showMe();
1053 result = getEventViewerDialog()->executeS( localIsNew ); 1054 result = getEventViewerDialog()->executeS( localIsNew );
1054 return result; 1055 return result;
1055 1056
1056 break; 1057 break;
1057 case SYNC_PREF_FORCE_LOCAL: 1058 case SYNC_PREF_FORCE_LOCAL:
1058 return 1; 1059 return 1;
1059 break; 1060 break;
1060 case SYNC_PREF_FORCE_REMOTE: 1061 case SYNC_PREF_FORCE_REMOTE:
1061 return 2; 1062 return 2;
1062 break; 1063 break;
1063 1064
1064 default: 1065 default:
1065 // SYNC_PREF_TAKE_BOTH not implemented 1066 // SYNC_PREF_TAKE_BOTH not implemented
1066 break; 1067 break;
1067 } 1068 }
1068 return 0; 1069 return 0;
1069} 1070}
1070Event* CalendarView::getLastSyncEvent() 1071Event* CalendarView::getLastSyncEvent()
1071{ 1072{
1072 Event* lse; 1073 Event* lse;
1073 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1074 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1074 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1075 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1075 if (!lse) { 1076 if (!lse) {
1076 lse = new Event(); 1077 lse = new Event();
1077 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1078 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1078 QString sum = ""; 1079 QString sum = "";
1079 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1080 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1080 sum = "E: "; 1081 sum = "E: ";
1081 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1082 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1082 lse->setDtStart( mLastCalendarSync ); 1083 lse->setDtStart( mLastCalendarSync );
1083 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1084 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1084 lse->setCategories( i18n("SyncEvent") ); 1085 lse->setCategories( i18n("SyncEvent") );
1085 lse->setReadOnly( true ); 1086 lse->setReadOnly( true );
1086 mCalendar->addEvent( lse ); 1087 mCalendar->addEvent( lse );
1087 } 1088 }
1088 1089
1089 return lse; 1090 return lse;
1090 1091
1091} 1092}
1092 1093
1093// we check, if the to delete event has a id for a profile 1094// we check, if the to delete event has a id for a profile
1094// if yes, we set this id in the profile to delete 1095// if yes, we set this id in the profile to delete
1095void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1096void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1096{ 1097{
1097 if ( lastSync.count() == 0 ) { 1098 if ( lastSync.count() == 0 ) {
1098 //qDebug(" lastSync.count() == 0"); 1099 //qDebug(" lastSync.count() == 0");
1099 return; 1100 return;
1100 } 1101 }
1101 if ( toDelete->type() == "Journal" ) 1102 if ( toDelete->type() == "Journal" )
1102 return; 1103 return;
1103 1104
1104 Event* eve = lastSync.first(); 1105 Event* eve = lastSync.first();
1105 1106
1106 while ( eve ) { 1107 while ( eve ) {
1107 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1108 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1108 if ( !id.isEmpty() ) { 1109 if ( !id.isEmpty() ) {
1109 QString des = eve->description(); 1110 QString des = eve->description();
1110 QString pref = "e"; 1111 QString pref = "e";
1111 if ( toDelete->type() == "Todo" ) 1112 if ( toDelete->type() == "Todo" )
1112 pref = "t"; 1113 pref = "t";
1113 des += pref+ id + ","; 1114 des += pref+ id + ",";
1114 eve->setReadOnly( false ); 1115 eve->setReadOnly( false );
1115 eve->setDescription( des ); 1116 eve->setDescription( des );
1116 //qDebug("setdes %s ", des.latin1()); 1117 //qDebug("setdes %s ", des.latin1());
1117 eve->setReadOnly( true ); 1118 eve->setReadOnly( true );
1118 } 1119 }
1119 eve = lastSync.next(); 1120 eve = lastSync.next();
1120 } 1121 }
1121 1122
1122} 1123}
1123void CalendarView::checkExternalId( Incidence * inc ) 1124void CalendarView::checkExternalId( Incidence * inc )
1124{ 1125{
1125 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1126 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1126 checkExternSyncEvent( lastSync, inc ); 1127 checkExternSyncEvent( lastSync, inc );
1127 1128
1128} 1129}
1129bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1130bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1130{ 1131{
1131 bool syncOK = true; 1132 bool syncOK = true;
1132 int addedEvent = 0; 1133 int addedEvent = 0;
1133 int addedEventR = 0; 1134 int addedEventR = 0;
1134 int deletedEventR = 0; 1135 int deletedEventR = 0;
1135 int deletedEventL = 0; 1136 int deletedEventL = 0;
1136 int changedLocal = 0; 1137 int changedLocal = 0;
1137 int changedRemote = 0; 1138 int changedRemote = 0;
1138 int filteredIN = 0; 1139 int filteredIN = 0;
1139 int filteredOUT = 0; 1140 int filteredOUT = 0;
1140 //QPtrList<Event> el = local->rawEvents(); 1141 //QPtrList<Event> el = local->rawEvents();
1141 Event* eventR; 1142 Event* eventR;
1142 QString uid; 1143 QString uid;
1143 int take; 1144 int take;
1144 Event* eventL; 1145 Event* eventL;
1145 Event* eventRSync; 1146 Event* eventRSync;
1146 Event* eventLSync; 1147 Event* eventLSync;
1147 clearAllViews(); 1148 clearAllViews();
1148 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1149 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1149 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1150 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1150 bool fullDateRange = false; 1151 bool fullDateRange = false;
1151 local->resetTempSyncStat(); 1152 local->resetTempSyncStat();
1152 mLastCalendarSync = QDateTime::currentDateTime(); 1153 mLastCalendarSync = QDateTime::currentDateTime();
1153 if ( mSyncManager->syncWithDesktop() ) { 1154 if ( mSyncManager->syncWithDesktop() ) {
1154 remote->resetPilotStat(1); 1155 remote->resetPilotStat(1);
1155 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1156 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1156 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1157 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1157 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1158 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1158 } else { 1159 } else {
1159 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1160 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1160 } 1161 }
1161 } 1162 }
1162 QDateTime modifiedCalendar = mLastCalendarSync; 1163 QDateTime modifiedCalendar = mLastCalendarSync;
1163 eventLSync = getLastSyncEvent(); 1164 eventLSync = getLastSyncEvent();
1164 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1165 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1165 if ( eventR ) { 1166 if ( eventR ) {
1166 eventRSync = (Event*) eventR->clone(); 1167 eventRSync = (Event*) eventR->clone();
1167 remote->deleteEvent(eventR ); 1168 remote->deleteEvent(eventR );
1168 1169
1169 } else { 1170 } else {
1170 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1171 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1171 eventRSync = (Event*)eventLSync->clone(); 1172 eventRSync = (Event*)eventLSync->clone();
1172 } else { 1173 } else {
1173 fullDateRange = true; 1174 fullDateRange = true;
1174 eventRSync = new Event(); 1175 eventRSync = new Event();
1175 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1176 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1176 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1177 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1177 eventRSync->setDtStart( mLastCalendarSync ); 1178 eventRSync->setDtStart( mLastCalendarSync );
1178 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1179 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1179 eventRSync->setCategories( i18n("SyncEvent") ); 1180 eventRSync->setCategories( i18n("SyncEvent") );
1180 } 1181 }
1181 } 1182 }
1182 if ( eventLSync->dtStart() == mLastCalendarSync ) 1183 if ( eventLSync->dtStart() == mLastCalendarSync )
1183 fullDateRange = true; 1184 fullDateRange = true;
1184 1185
1185 if ( ! fullDateRange ) { 1186 if ( ! fullDateRange ) {
1186 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1187 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1187 1188
1188 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1189 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1189 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1190 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1190 fullDateRange = true; 1191 fullDateRange = true;
1191 } 1192 }
1192 } 1193 }
1193 if ( mSyncManager->syncWithDesktop() ) { 1194 if ( mSyncManager->syncWithDesktop() ) {
1194 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1195 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1195 } 1196 }
1196 if ( fullDateRange ) 1197 if ( fullDateRange )
1197 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1198 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1198 else 1199 else
1199 mLastCalendarSync = eventLSync->dtStart(); 1200 mLastCalendarSync = eventLSync->dtStart();
1200 // for resyncing if own file has changed 1201 // for resyncing if own file has changed
1201 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1202 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1202 mLastCalendarSync = loadedFileVersion; 1203 mLastCalendarSync = loadedFileVersion;
1203 //qDebug("setting mLastCalendarSync "); 1204 //qDebug("setting mLastCalendarSync ");
1204 } 1205 }
1205 //qDebug("*************************** "); 1206 //qDebug("*************************** ");
1206 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1207 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1207 QPtrList<Incidence> er = remote->rawIncidences(); 1208 QPtrList<Incidence> er = remote->rawIncidences();
1208 Incidence* inR = er.first(); 1209 Incidence* inR = er.first();
1209 Incidence* inL; 1210 Incidence* inL;
1210 QProgressBar bar( er.count(),0 ); 1211 QProgressBar bar( er.count(),0 );
1211 bar.setCaption (i18n("Syncing - close to abort!") ); 1212 bar.setCaption (i18n("Syncing - close to abort!") );
1212 1213
1213 // ************** setting up filter ************* 1214 // ************** setting up filter *************
1214 CalFilter *filterIN = 0; 1215 CalFilter *filterIN = 0;
1215 CalFilter *filterOUT = 0; 1216 CalFilter *filterOUT = 0;
1216 CalFilter *filter = mFilters.first(); 1217 CalFilter *filter = mFilters.first();
1217 while(filter) { 1218 while(filter) {
1218 if ( filter->name() == mSyncManager->mFilterInCal ) 1219 if ( filter->name() == mSyncManager->mFilterInCal )
1219 filterIN = filter; 1220 filterIN = filter;
1220 if ( filter->name() == mSyncManager->mFilterOutCal ) 1221 if ( filter->name() == mSyncManager->mFilterOutCal )
1221 filterOUT = filter; 1222 filterOUT = filter;
1222 filter = mFilters.next(); 1223 filter = mFilters.next();
1223 } 1224 }
1224 int w = 300; 1225 int w = 300;
1225 if ( QApplication::desktop()->width() < 320 ) 1226 if ( QApplication::desktop()->width() < 320 )
1226 w = 220; 1227 w = 220;
1227 int h = bar.sizeHint().height() ; 1228 int h = bar.sizeHint().height() ;
1228 int dw = QApplication::desktop()->width(); 1229 int dw = QApplication::desktop()->width();
1229 int dh = QApplication::desktop()->height(); 1230 int dh = QApplication::desktop()->height();
1230 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1231 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1231 bar.show(); 1232 bar.show();
1232 int modulo = (er.count()/10)+1; 1233 int modulo = (er.count()/10)+1;
1233 int incCounter = 0; 1234 int incCounter = 0;
1234 while ( inR ) { 1235 while ( inR ) {
1235 if ( ! bar.isVisible() ) 1236 if ( ! bar.isVisible() )
1236 return false; 1237 return false;
1237 if ( incCounter % modulo == 0 ) 1238 if ( incCounter % modulo == 0 )
1238 bar.setProgress( incCounter ); 1239 bar.setProgress( incCounter );
1239 ++incCounter; 1240 ++incCounter;
1240 uid = inR->uid(); 1241 uid = inR->uid();
1241 bool skipIncidence = false; 1242 bool skipIncidence = false;
1242 if ( uid.left(15) == QString("last-syncEvent-") ) 1243 if ( uid.left(15) == QString("last-syncEvent-") )
1243 skipIncidence = true; 1244 skipIncidence = true;
1244 QString idS; 1245 QString idS;
1245 qApp->processEvents(); 1246 qApp->processEvents();
1246 if ( !skipIncidence ) { 1247 if ( !skipIncidence ) {
1247 inL = local->incidence( uid ); 1248 inL = local->incidence( uid );
1248 if ( inL ) { // maybe conflict - same uid in both calendars 1249 if ( inL ) { // maybe conflict - same uid in both calendars
1249 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1250 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1250 //qDebug("take %d %s ", take, inL->summary().latin1()); 1251 //qDebug("take %d %s ", take, inL->summary().latin1());
1251 if ( take == 3 ) 1252 if ( take == 3 )
1252 return false; 1253 return false;
1253 if ( take == 1 ) {// take local ********************** 1254 if ( take == 1 ) {// take local **********************
1254 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1255 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1255 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1256 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1256 else 1257 else
1257 idS = inR->IDStr(); 1258 idS = inR->IDStr();
1258 remote->deleteIncidence( inR ); 1259 remote->deleteIncidence( inR );
1259 inR = inL->clone(); 1260 inR = inL->clone();
1260 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1261 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1261 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1262 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1262 inR->setIDStr( idS ); 1263 inR->setIDStr( idS );
1263 remote->addIncidence( inR ); 1264 remote->addIncidence( inR );
1264 if ( mSyncManager->syncWithDesktop() ) 1265 if ( mSyncManager->syncWithDesktop() )
1265 inR->setPilotId( 2 ); 1266 inR->setPilotId( 2 );
1266 ++changedRemote; 1267 ++changedRemote;
1267 } else {// take remote ********************** 1268 } else {// take remote **********************
1268 idS = inL->IDStr(); 1269 idS = inL->IDStr();
1269 int pid = inL->pilotId(); 1270 int pid = inL->pilotId();
1270 local->deleteIncidence( inL ); 1271 local->deleteIncidence( inL );
1271 inL = inR->clone(); 1272 inL = inR->clone();
1272 if ( mSyncManager->syncWithDesktop() ) 1273 if ( mSyncManager->syncWithDesktop() )
1273 inL->setPilotId( pid ); 1274 inL->setPilotId( pid );
1274 inL->setIDStr( idS ); 1275 inL->setIDStr( idS );
1275 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1276 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1276 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1277 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1277 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1278 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1278 } 1279 }
1279 local->addIncidence( inL ); 1280 local->addIncidence( inL );
1280 ++changedLocal; 1281 ++changedLocal;
1281 } 1282 }
1282 } 1283 }
1283 } else { // no conflict ********** add or delete remote 1284 } else { // no conflict ********** add or delete remote
1284 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1285 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1285 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1286 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1286 QString des = eventLSync->description(); 1287 QString des = eventLSync->description();
1287 QString pref = "e"; 1288 QString pref = "e";
1288 if ( inR->type() == "Todo" ) 1289 if ( inR->type() == "Todo" )
1289 pref = "t"; 1290 pref = "t";
1290 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1291 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1291 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1292 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1292 //remote->deleteIncidence( inR ); 1293 //remote->deleteIncidence( inR );
1293 ++deletedEventR; 1294 ++deletedEventR;
1294 } else { 1295 } else {
1295 inR->setLastModified( modifiedCalendar ); 1296 inR->setLastModified( modifiedCalendar );
1296 inL = inR->clone(); 1297 inL = inR->clone();
1297 inL->setIDStr( ":" ); 1298 inL->setIDStr( ":" );
1298 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1299 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1299 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1300 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1300 local->addIncidence( inL ); 1301 local->addIncidence( inL );
1301 ++addedEvent; 1302 ++addedEvent;
1302 1303
1303 } 1304 }
1304 } else { 1305 } else {
1305 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1306 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1306 inR->setLastModified( modifiedCalendar ); 1307 inR->setLastModified( modifiedCalendar );
1307 inL = inR->clone(); 1308 inL = inR->clone();
1308 inL->setIDStr( ":" ); 1309 inL->setIDStr( ":" );
1309 local->addIncidence( inL ); 1310 local->addIncidence( inL );
1310 ++addedEvent; 1311 ++addedEvent;
1311 1312
1312 } else { 1313 } else {
1313 checkExternSyncEvent(eventRSyncSharp, inR); 1314 checkExternSyncEvent(eventRSyncSharp, inR);
1314 remote->deleteIncidence( inR ); 1315 remote->deleteIncidence( inR );
1315 ++deletedEventR; 1316 ++deletedEventR;
1316 } 1317 }
1317 } 1318 }
1318 } else { 1319 } else {
1319 ++filteredIN; 1320 ++filteredIN;
1320 } 1321 }
1321 } 1322 }
1322 } 1323 }
1323 inR = er.next(); 1324 inR = er.next();
1324 } 1325 }
1325 QPtrList<Incidence> el = local->rawIncidences(); 1326 QPtrList<Incidence> el = local->rawIncidences();
1326 inL = el.first(); 1327 inL = el.first();
1327 modulo = (el.count()/10)+1; 1328 modulo = (el.count()/10)+1;
1328 bar.setCaption (i18n("Add / remove events") ); 1329 bar.setCaption (i18n("Add / remove events") );
1329 bar.setTotalSteps ( el.count() ) ; 1330 bar.setTotalSteps ( el.count() ) ;
1330 bar.show(); 1331 bar.show();
1331 incCounter = 0; 1332 incCounter = 0;
1332 1333
1333 while ( inL ) { 1334 while ( inL ) {
1334 1335
1335 qApp->processEvents(); 1336 qApp->processEvents();
1336 if ( ! bar.isVisible() ) 1337 if ( ! bar.isVisible() )
1337 return false; 1338 return false;
1338 if ( incCounter % modulo == 0 ) 1339 if ( incCounter % modulo == 0 )
1339 bar.setProgress( incCounter ); 1340 bar.setProgress( incCounter );
1340 ++incCounter; 1341 ++incCounter;
1341 uid = inL->uid(); 1342 uid = inL->uid();
1342 bool skipIncidence = false; 1343 bool skipIncidence = false;
1343 if ( uid.left(15) == QString("last-syncEvent-") ) 1344 if ( uid.left(15) == QString("last-syncEvent-") )
1344 skipIncidence = true; 1345 skipIncidence = true;
1345 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1346 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1346 skipIncidence = true; 1347 skipIncidence = true;
1347 if ( !skipIncidence ) { 1348 if ( !skipIncidence ) {
1348 inR = remote->incidence( uid ); 1349 inR = remote->incidence( uid );
1349 if ( ! inR ) { 1350 if ( ! inR ) {
1350 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1351 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1351 // no conflict ********** add or delete local 1352 // no conflict ********** add or delete local
1352 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1353 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1353 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1354 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1354 checkExternSyncEvent(eventLSyncSharp, inL); 1355 checkExternSyncEvent(eventLSyncSharp, inL);
1355 local->deleteIncidence( inL ); 1356 local->deleteIncidence( inL );
1356 ++deletedEventL; 1357 ++deletedEventL;
1357 } else { 1358 } else {
1358 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1359 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1359 inL->removeID(mCurrentSyncDevice ); 1360 inL->removeID(mCurrentSyncDevice );
1360 ++addedEventR; 1361 ++addedEventR;
1361 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1362 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1362 inL->setLastModified( modifiedCalendar ); 1363 inL->setLastModified( modifiedCalendar );
1363 inR = inL->clone(); 1364 inR = inL->clone();
1364 inR->setIDStr( ":" ); 1365 inR->setIDStr( ":" );
1365 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1366 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1366 remote->addIncidence( inR ); 1367 remote->addIncidence( inR );
1367 } 1368 }
1368 } 1369 }
1369 } else { 1370 } else {
1370 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1371 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1371 checkExternSyncEvent(eventLSyncSharp, inL); 1372 checkExternSyncEvent(eventLSyncSharp, inL);
1372 local->deleteIncidence( inL ); 1373 local->deleteIncidence( inL );
1373 ++deletedEventL; 1374 ++deletedEventL;
1374 } else { 1375 } else {
1375 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1376 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1376 ++addedEventR; 1377 ++addedEventR;
1377 inL->setLastModified( modifiedCalendar ); 1378 inL->setLastModified( modifiedCalendar );
1378 inR = inL->clone(); 1379 inR = inL->clone();
1379 inR->setIDStr( ":" ); 1380 inR->setIDStr( ":" );
1380 remote->addIncidence( inR ); 1381 remote->addIncidence( inR );
1381 } 1382 }
1382 } 1383 }
1383 } 1384 }
1384 } else { 1385 } else {
1385 ++filteredOUT; 1386 ++filteredOUT;
1386 } 1387 }
1387 } 1388 }
1388 } 1389 }
1389 inL = el.next(); 1390 inL = el.next();
1390 } 1391 }
1391 int delFut = 0; 1392 int delFut = 0;
1392 int remRem = 0; 1393 int remRem = 0;
1393 if ( mSyncManager->mWriteBackInFuture ) { 1394 if ( mSyncManager->mWriteBackInFuture ) {
1394 er = remote->rawIncidences(); 1395 er = remote->rawIncidences();
1395 remRem = er.count(); 1396 remRem = er.count();
1396 inR = er.first(); 1397 inR = er.first();
1397 QDateTime dt; 1398 QDateTime dt;
1398 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1399 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1399 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1400 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1400 while ( inR ) { 1401 while ( inR ) {
1401 if ( inR->type() == "Todo" ) { 1402 if ( inR->type() == "Todo" ) {
1402 Todo * t = (Todo*)inR; 1403 Todo * t = (Todo*)inR;
1403 if ( t->hasDueDate() ) 1404 if ( t->hasDueDate() )
1404 dt = t->dtDue(); 1405 dt = t->dtDue();
1405 else 1406 else
1406 dt = cur.addSecs( 62 ); 1407 dt = cur.addSecs( 62 );
1407 } 1408 }
1408 else if (inR->type() == "Event" ) { 1409 else if (inR->type() == "Event" ) {
1409 bool ok; 1410 bool ok;
1410 dt = inR->getNextOccurence( cur, &ok ); 1411 dt = inR->getNextOccurence( cur, &ok );
1411 if ( !ok ) 1412 if ( !ok )
1412 dt = cur.addSecs( -62 ); 1413 dt = cur.addSecs( -62 );
1413 } 1414 }
1414 else 1415 else
1415 dt = inR->dtStart(); 1416 dt = inR->dtStart();
1416 if ( dt < cur || dt > end ) { 1417 if ( dt < cur || dt > end ) {
1417 remote->deleteIncidence( inR ); 1418 remote->deleteIncidence( inR );
1418 ++delFut; 1419 ++delFut;
1419 } 1420 }
1420 inR = er.next(); 1421 inR = er.next();
1421 } 1422 }
1422 } 1423 }
1423 bar.hide(); 1424 bar.hide();
1424 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1425 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1425 eventLSync->setReadOnly( false ); 1426 eventLSync->setReadOnly( false );
1426 eventLSync->setDtStart( mLastCalendarSync ); 1427 eventLSync->setDtStart( mLastCalendarSync );
1427 eventRSync->setDtStart( mLastCalendarSync ); 1428 eventRSync->setDtStart( mLastCalendarSync );
1428 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1429 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1429 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1430 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1430 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1431 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1431 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1432 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1432 eventLSync->setReadOnly( true ); 1433 eventLSync->setReadOnly( true );
1433 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1434 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1434 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1435 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1435 remote->addEvent( eventRSync ); 1436 remote->addEvent( eventRSync );
1436 else 1437 else
1437 delete eventRSync; 1438 delete eventRSync;
1438 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1439 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1439 QString mes; 1440 QString mes;
1440 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); 1441 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT );
1441 QString delmess; 1442 QString delmess;
1442 if ( delFut ) { 1443 if ( delFut ) {
1443 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); 1444 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut);
1444 mes += delmess; 1445 mes += delmess;
1445 } 1446 }
1446 mes = i18n("Local calendar changed!\n") +mes; 1447 mes = i18n("Local calendar changed!\n") +mes;
1447 mCalendar->checkAlarmForIncidence( 0, true ); 1448 mCalendar->checkAlarmForIncidence( 0, true );
1448 qDebug( mes ); 1449 qDebug( mes );
1449 if ( mSyncManager->mShowSyncSummary ) { 1450 if ( mSyncManager->mShowSyncSummary ) {
1450 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1451 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1451 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1452 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1452 qDebug("KO: WB cancelled "); 1453 qDebug("KO: WB cancelled ");
1453 mSyncManager->mWriteBackFile = false; 1454 mSyncManager->mWriteBackFile = false;
1454 return syncOK; 1455 return syncOK;
1455 } 1456 }
1456 } 1457 }
1457 return syncOK; 1458 return syncOK;
1458} 1459}
1459 1460
1460void CalendarView::setSyncDevice( QString s ) 1461void CalendarView::setSyncDevice( QString s )
1461{ 1462{
1462 mCurrentSyncDevice= s; 1463 mCurrentSyncDevice= s;
1463} 1464}
1464void CalendarView::setSyncName( QString s ) 1465void CalendarView::setSyncName( QString s )
1465{ 1466{
1466 mCurrentSyncName= s; 1467 mCurrentSyncName= s;
1467} 1468}
1468bool CalendarView::syncCalendar(QString filename, int mode) 1469bool CalendarView::syncCalendar(QString filename, int mode)
1469{ 1470{
1470 //qDebug("syncCalendar %s ", filename.latin1()); 1471 //qDebug("syncCalendar %s ", filename.latin1());
1471 mGlobalSyncMode = SYNC_MODE_NORMAL; 1472 mGlobalSyncMode = SYNC_MODE_NORMAL;
1472 CalendarLocal* calendar = new CalendarLocal(); 1473 CalendarLocal* calendar = new CalendarLocal();
1473 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1474 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1474 FileStorage* storage = new FileStorage( calendar ); 1475 FileStorage* storage = new FileStorage( calendar );
1475 bool syncOK = false; 1476 bool syncOK = false;
1476 storage->setFileName( filename ); 1477 storage->setFileName( filename );
1477 // qDebug("loading ... "); 1478 // qDebug("loading ... ");
1478 if ( storage->load() ) { 1479 if ( storage->load() ) {
1479 getEventViewerDialog()->setSyncMode( true ); 1480 getEventViewerDialog()->setSyncMode( true );
1480 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1481 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1481 getEventViewerDialog()->setSyncMode( false ); 1482 getEventViewerDialog()->setSyncMode( false );
1482 if ( syncOK ) { 1483 if ( syncOK ) {
1483 if ( mSyncManager->mWriteBackFile ) 1484 if ( mSyncManager->mWriteBackFile )
1484 { 1485 {
1485 storage->setSaveFormat( new ICalFormat() ); 1486 storage->setSaveFormat( new ICalFormat() );
1486 storage->save(); 1487 storage->save();
1487 } 1488 }
1488 } 1489 }
1489 setModified( true ); 1490 setModified( true );
1490 } 1491 }
1491 delete storage; 1492 delete storage;
1492 delete calendar; 1493 delete calendar;
1493 if ( syncOK ) 1494 if ( syncOK )
1494 updateView(); 1495 updateView();
1495 return syncOK; 1496 return syncOK;
1496} 1497}
1497 1498
1498void CalendarView::syncExternal( int mode ) 1499void CalendarView::syncExternal( int mode )
1499{ 1500{
1500 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1501 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1501 1502
1502 qApp->processEvents(); 1503 qApp->processEvents();
1503 CalendarLocal* calendar = new CalendarLocal(); 1504 CalendarLocal* calendar = new CalendarLocal();
1504 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1505 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1505 bool syncOK = false; 1506 bool syncOK = false;
1506 bool loadSuccess = false; 1507 bool loadSuccess = false;
1507 PhoneFormat* phoneFormat = 0; 1508 PhoneFormat* phoneFormat = 0;
1508 emit tempDisableBR(true); 1509 emit tempDisableBR(true);
1509#ifndef DESKTOP_VERSION 1510#ifndef DESKTOP_VERSION
1510 SharpFormat* sharpFormat = 0; 1511 SharpFormat* sharpFormat = 0;
1511 if ( mode == 0 ) { // sharp 1512 if ( mode == 0 ) { // sharp
1512 sharpFormat = new SharpFormat () ; 1513 sharpFormat = new SharpFormat () ;
1513 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1514 loadSuccess = sharpFormat->load( calendar, mCalendar );
1514 1515
1515 } else 1516 } else
1516#endif 1517#endif
1517 if ( mode == 1 ) { // phone 1518 if ( mode == 1 ) { // phone
1518 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1519 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1519 mSyncManager->mPhoneDevice, 1520 mSyncManager->mPhoneDevice,
1520 mSyncManager->mPhoneConnection, 1521 mSyncManager->mPhoneConnection,
1521 mSyncManager->mPhoneModel); 1522 mSyncManager->mPhoneModel);
1522 loadSuccess = phoneFormat->load( calendar,mCalendar); 1523 loadSuccess = phoneFormat->load( calendar,mCalendar);
1523 1524
1524 } else { 1525 } else {
1525 emit tempDisableBR(false); 1526 emit tempDisableBR(false);
1526 return; 1527 return;
1527 } 1528 }
1528 if ( loadSuccess ) { 1529 if ( loadSuccess ) {
1529 getEventViewerDialog()->setSyncMode( true ); 1530 getEventViewerDialog()->setSyncMode( true );
1530 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1531 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1531 getEventViewerDialog()->setSyncMode( false ); 1532 getEventViewerDialog()->setSyncMode( false );
1532 qApp->processEvents(); 1533 qApp->processEvents();
1533 if ( syncOK ) { 1534 if ( syncOK ) {
1534 if ( mSyncManager->mWriteBackFile ) 1535 if ( mSyncManager->mWriteBackFile )
1535 { 1536 {
1536 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1537 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1537 Incidence* inc = iL.first(); 1538 Incidence* inc = iL.first();
1538 if ( phoneFormat ) { 1539 if ( phoneFormat ) {
1539 while ( inc ) { 1540 while ( inc ) {
1540 inc->removeID(mCurrentSyncDevice); 1541 inc->removeID(mCurrentSyncDevice);
1541 inc = iL.next(); 1542 inc = iL.next();
1542 } 1543 }
1543 } 1544 }
1544#ifndef DESKTOP_VERSION 1545#ifndef DESKTOP_VERSION
1545 if ( sharpFormat ) 1546 if ( sharpFormat )
1546 sharpFormat->save(calendar); 1547 sharpFormat->save(calendar);
1547#endif 1548#endif
1548 if ( phoneFormat ) 1549 if ( phoneFormat )
1549 phoneFormat->save(calendar); 1550 phoneFormat->save(calendar);
1550 iL = calendar->rawIncidences(); 1551 iL = calendar->rawIncidences();
1551 inc = iL.first(); 1552 inc = iL.first();
1552 Incidence* loc; 1553 Incidence* loc;
1553 while ( inc ) { 1554 while ( inc ) {
1554 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1555 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1555 loc = mCalendar->incidence(inc->uid() ); 1556 loc = mCalendar->incidence(inc->uid() );
1556 if ( loc ) { 1557 if ( loc ) {
1557 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1558 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1558 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1559 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1559 } 1560 }
1560 } 1561 }
1561 inc = iL.next(); 1562 inc = iL.next();
1562 } 1563 }
1563 Incidence* lse = getLastSyncEvent(); 1564 Incidence* lse = getLastSyncEvent();
1564 if ( lse ) { 1565 if ( lse ) {
1565 lse->setReadOnly( false ); 1566 lse->setReadOnly( false );
1566 lse->setDescription( "" ); 1567 lse->setDescription( "" );
1567 lse->setReadOnly( true ); 1568 lse->setReadOnly( true );
1568 } 1569 }
1569 } 1570 }
1570 } else { 1571 } else {
1571 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1572 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1572 } 1573 }
1573 setModified( true ); 1574 setModified( true );
1574 } else { 1575 } else {
1575 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1576 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1576 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1577 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1577 question, i18n("Ok")) ; 1578 question, i18n("Ok")) ;
1578 1579
1579 } 1580 }
1580 delete calendar; 1581 delete calendar;
1581 updateView(); 1582 updateView();
1582 emit tempDisableBR(false); 1583 emit tempDisableBR(false);
1583 return ;//syncOK; 1584 return ;//syncOK;
1584 1585
1585} 1586}
1586 1587
1587bool CalendarView::importBday() 1588bool CalendarView::importBday()
1588{ 1589{
1589#ifndef KORG_NOKABC 1590#ifndef KORG_NOKABC
1590 1591
1591#ifdef DESKTOP_VERSION 1592#ifdef DESKTOP_VERSION
1592 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1593 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1593 KABC::AddressBook::Iterator it; 1594 KABC::AddressBook::Iterator it;
1594 int count = 0; 1595 int count = 0;
1595 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1596 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1596 ++count; 1597 ++count;
1597 } 1598 }
1598 QProgressBar bar(count,0 ); 1599 QProgressBar bar(count,0 );
1599 int w = 300; 1600 int w = 300;
1600 if ( QApplication::desktop()->width() < 320 ) 1601 if ( QApplication::desktop()->width() < 320 )
1601 w = 220; 1602 w = 220;
1602 int h = bar.sizeHint().height() ; 1603 int h = bar.sizeHint().height() ;
1603 int dw = QApplication::desktop()->width(); 1604 int dw = QApplication::desktop()->width();
1604 int dh = QApplication::desktop()->height(); 1605 int dh = QApplication::desktop()->height();
1605 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1606 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1606 bar.show(); 1607 bar.show();
1607 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1608 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1608 qApp->processEvents(); 1609 qApp->processEvents();
1609 count = 0; 1610 count = 0;
1610 int addCount = 0; 1611 int addCount = 0;
1611 KCal::Attendee* a = 0; 1612 KCal::Attendee* a = 0;
1612 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1613 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1613 if ( ! bar.isVisible() ) 1614 if ( ! bar.isVisible() )
1614 return false; 1615 return false;
1615 bar.setProgress( count++ ); 1616 bar.setProgress( count++ );
1616 qApp->processEvents(); 1617 qApp->processEvents();
1617 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1618 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1618 if ( (*it).birthday().date().isValid() ){ 1619 if ( (*it).birthday().date().isValid() ){
1619 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1620 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1620 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1621 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1621 ++addCount; 1622 ++addCount;
1622 } 1623 }
1623 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1624 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1624 if ( anni.isValid() ){ 1625 if ( anni.isValid() ){
1625 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1626 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1626 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1627 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1627 ++addCount; 1628 ++addCount;
1628 } 1629 }
1629 } 1630 }
1630 updateView(); 1631 updateView();
1631 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1632 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1632#else //DESKTOP_VERSION 1633#else //DESKTOP_VERSION
1633 1634
1634 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1635 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1635 // the result should now arrive through method insertBirthdays 1636 // the result should now arrive through method insertBirthdays
1636 1637
1637#endif //DESKTOP_VERSION 1638#endif //DESKTOP_VERSION
1638 1639
1639#endif //KORG_NOKABC 1640#endif //KORG_NOKABC
1640 1641
1641 1642
1642 return true; 1643 return true;
1643} 1644}
1644 1645
1645// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1646// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1646void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1647void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1647 const QStringList& anniversaryList, const QStringList& realNameList, 1648 const QStringList& anniversaryList, const QStringList& realNameList,
1648 const QStringList& emailList, const QStringList& assembledNameList, 1649 const QStringList& emailList, const QStringList& assembledNameList,
1649 const QStringList& uidList) 1650 const QStringList& uidList)
1650{ 1651{
1651 //qDebug("KO::CalendarView::insertBirthdays"); 1652 //qDebug("KO::CalendarView::insertBirthdays");
1652 if (uid == this->name()) 1653 if (uid == this->name())
1653 { 1654 {
1654 int count = birthdayList.count(); 1655 int count = birthdayList.count();
1655 int addCount = 0; 1656 int addCount = 0;
1656 KCal::Attendee* a = 0; 1657 KCal::Attendee* a = 0;
1657 1658
1658 //qDebug("CalView 1 %i", count); 1659 //qDebug("CalView 1 %i", count);
1659 1660
1660 QProgressBar bar(count,0 ); 1661 QProgressBar bar(count,0 );
1661 int w = 300; 1662 int w = 300;
1662 if ( QApplication::desktop()->width() < 320 ) 1663 if ( QApplication::desktop()->width() < 320 )
1663 w = 220; 1664 w = 220;
1664 int h = bar.sizeHint().height() ; 1665 int h = bar.sizeHint().height() ;
1665 int dw = QApplication::desktop()->width(); 1666 int dw = QApplication::desktop()->width();
1666 int dh = QApplication::desktop()->height(); 1667 int dh = QApplication::desktop()->height();
1667 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1668 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1668 bar.show(); 1669 bar.show();
1669 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1670 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1670 qApp->processEvents(); 1671 qApp->processEvents();
1671 1672
1672 QDate birthday; 1673 QDate birthday;
1673 QDate anniversary; 1674 QDate anniversary;
1674 QString realName; 1675 QString realName;
1675 QString email; 1676 QString email;
1676 QString assembledName; 1677 QString assembledName;
1677 QString uid; 1678 QString uid;
1678 bool ok = true; 1679 bool ok = true;
1679 for ( int i = 0; i < count; i++) 1680 for ( int i = 0; i < count; i++)
1680 { 1681 {
1681 if ( ! bar.isVisible() ) 1682 if ( ! bar.isVisible() )
1682 return; 1683 return;
1683 bar.setProgress( i ); 1684 bar.setProgress( i );
1684 qApp->processEvents(); 1685 qApp->processEvents();
1685 1686
1686 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1687 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1687 if (!ok) { 1688 if (!ok) {
1688 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1689 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1689 } 1690 }
1690 1691
1691 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1692 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1692 if (!ok) { 1693 if (!ok) {
1693 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1694 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1694 } 1695 }
1695 realName = realNameList[i]; 1696 realName = realNameList[i];
1696 email = emailList[i]; 1697 email = emailList[i];
1697 assembledName = assembledNameList[i]; 1698 assembledName = assembledNameList[i];
1698 uid = uidList[i]; 1699 uid = uidList[i];
1699 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); 1700 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() );
1700 1701
1701 if ( birthday.isValid() ){ 1702 if ( birthday.isValid() ){
1702 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1703 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1703 KCal::Attendee::ReqParticipant,uid) ; 1704 KCal::Attendee::ReqParticipant,uid) ;
1704 if ( addAnniversary( birthday, assembledName, a, true ) ) 1705 if ( addAnniversary( birthday, assembledName, a, true ) )
1705 ++addCount; 1706 ++addCount;
1706 } 1707 }
1707 1708
1708 if ( anniversary.isValid() ){ 1709 if ( anniversary.isValid() ){
1709 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1710 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1710 KCal::Attendee::ReqParticipant,uid) ; 1711 KCal::Attendee::ReqParticipant,uid) ;
1711 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1712 if ( addAnniversary( anniversary, assembledName, a, false ) )
1712 ++addCount; 1713 ++addCount;
1713 } 1714 }
1714 } 1715 }
1715 1716
1716 updateView(); 1717 updateView();
1717 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1718 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1718 1719
1719 } 1720 }
1720 1721
1721} 1722}
1722 1723
1723 1724
1724 1725
1725bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1726bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1726{ 1727{
1727 //qDebug("addAnni "); 1728 //qDebug("addAnni ");
1728 Event * ev = new Event(); 1729 Event * ev = new Event();
1729 ev->setOrganizer(KOPrefs::instance()->email()); 1730 ev->setOrganizer(KOPrefs::instance()->email());
1730 if ( a ) { 1731 if ( a ) {
1731 ev->addAttendee( a ); 1732 ev->addAttendee( a );
1732 } 1733 }
1733 QString kind; 1734 QString kind;
1734 if ( birthday ) { 1735 if ( birthday ) {
1735 kind = i18n( "Birthday" ); 1736 kind = i18n( "Birthday" );
1736 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1737 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1737 } 1738 }
1738 else { 1739 else {
1739 kind = i18n( "Anniversary" ); 1740 kind = i18n( "Anniversary" );
1740 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1741 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1741 } 1742 }
1742 ev->setCategories( kind ); 1743 ev->setCategories( kind );
1743 ev->setDtStart( QDateTime(date) ); 1744 ev->setDtStart( QDateTime(date) );
1744 ev->setDtEnd( QDateTime(date) ); 1745 ev->setDtEnd( QDateTime(date) );
1745 ev->setFloats( true ); 1746 ev->setFloats( true );
1746 Recurrence * rec = ev->recurrence(); 1747 Recurrence * rec = ev->recurrence();
1747 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1748 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1748 rec->addYearlyNum( date.month() ); 1749 rec->addYearlyNum( date.month() );
1749 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1750 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1750 delete ev; 1751 delete ev;
1751 return false; 1752 return false;
1752 } 1753 }
1753 return true; 1754 return true;
1754 1755
1755} 1756}
1756bool CalendarView::importQtopia( const QString &categories, 1757bool CalendarView::importQtopia( const QString &categories,
1757 const QString &datebook, 1758 const QString &datebook,
1758 const QString &todolist ) 1759 const QString &todolist )
1759{ 1760{
1760 1761
1761 QtopiaFormat qtopiaFormat; 1762 QtopiaFormat qtopiaFormat;
1762 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1763 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1763 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1764 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1764 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1765 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1765 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1766 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1766 1767
1767 updateView(); 1768 updateView();
1768 return true; 1769 return true;
1769 1770
1770#if 0 1771#if 0
1771 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1772 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1772 mCurrentSyncDevice = "qtopia-XML"; 1773 mCurrentSyncDevice = "qtopia-XML";
1773 if ( mSyncManager->mAskForPreferences ) 1774 if ( mSyncManager->mAskForPreferences )
1774 edit_sync_options(); 1775 edit_sync_options();
1775 qApp->processEvents(); 1776 qApp->processEvents();
1776 CalendarLocal* calendar = new CalendarLocal(); 1777 CalendarLocal* calendar = new CalendarLocal();
1777 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1778 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1778 bool syncOK = false; 1779 bool syncOK = false;
1779 QtopiaFormat qtopiaFormat; 1780 QtopiaFormat qtopiaFormat;
1780 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1781 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1781 bool loadOk = true; 1782 bool loadOk = true;
1782 if ( !categories.isEmpty() ) 1783 if ( !categories.isEmpty() )
1783 loadOk = qtopiaFormat.load( calendar, categories ); 1784 loadOk = qtopiaFormat.load( calendar, categories );
1784 if ( loadOk && !datebook.isEmpty() ) 1785 if ( loadOk && !datebook.isEmpty() )
1785 loadOk = qtopiaFormat.load( calendar, datebook ); 1786 loadOk = qtopiaFormat.load( calendar, datebook );
1786 if ( loadOk && !todolist.isEmpty() ) 1787 if ( loadOk && !todolist.isEmpty() )
1787 loadOk = qtopiaFormat.load( calendar, todolist ); 1788 loadOk = qtopiaFormat.load( calendar, todolist );
1788 1789
1789 if ( loadOk ) { 1790 if ( loadOk ) {
1790 getEventViewerDialog()->setSyncMode( true ); 1791 getEventViewerDialog()->setSyncMode( true );
1791 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1792 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1792 getEventViewerDialog()->setSyncMode( false ); 1793 getEventViewerDialog()->setSyncMode( false );
1793 qApp->processEvents(); 1794 qApp->processEvents();
1794 if ( syncOK ) { 1795 if ( syncOK ) {
1795 if ( mSyncManager->mWriteBackFile ) 1796 if ( mSyncManager->mWriteBackFile )
1796 { 1797 {
1797 // write back XML file 1798 // write back XML file
1798 1799
1799 } 1800 }
1800 setModified( true ); 1801 setModified( true );
1801 } 1802 }
1802 } else { 1803 } else {
1803 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1804 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1804 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1805 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1805 question, i18n("Ok")) ; 1806 question, i18n("Ok")) ;
1806 } 1807 }
1807 delete calendar; 1808 delete calendar;
1808 updateView(); 1809 updateView();
1809 return syncOK; 1810 return syncOK;
1810 1811
1811 1812
1812#endif 1813#endif
1813 1814
1814} 1815}
1815 1816
1816void CalendarView::setSyncEventsReadOnly() 1817void CalendarView::setSyncEventsReadOnly()
1817{ 1818{
1818 Event * ev; 1819 Event * ev;
1819 QPtrList<Event> eL = mCalendar->rawEvents(); 1820 QPtrList<Event> eL = mCalendar->rawEvents();
1820 ev = eL.first(); 1821 ev = eL.first();
1821 while ( ev ) { 1822 while ( ev ) {
1822 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1823 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1823 ev->setReadOnly( true ); 1824 ev->setReadOnly( true );
1824 ev = eL.next(); 1825 ev = eL.next();
1825 } 1826 }
1826} 1827}
1827bool CalendarView::openCalendar(QString filename, bool merge) 1828bool CalendarView::openCalendar(QString filename, bool merge)
1828{ 1829{
1829 1830
1830 if (filename.isEmpty()) { 1831 if (filename.isEmpty()) {
1831 return false; 1832 return false;
1832 } 1833 }
1833 1834
1834 if (!QFile::exists(filename)) { 1835 if (!QFile::exists(filename)) {
1835 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1836 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1836 return false; 1837 return false;
1837 } 1838 }
1838 1839
1839 globalFlagBlockAgenda = 1; 1840 globalFlagBlockAgenda = 1;
1840 clearAllViews(); 1841 clearAllViews();
1841 if (!merge) { 1842 if (!merge) {
1842 mViewManager->setDocumentId( filename ); 1843 mViewManager->setDocumentId( filename );
1843 mCalendar->close(); 1844 mCalendar->close();
1844 } 1845 }
1845 mStorage->setFileName( filename ); 1846 mStorage->setFileName( filename );
1846 1847
1847 if ( mStorage->load() ) { 1848 if ( mStorage->load() ) {
1848 if ( merge ) ;//setModified( true ); 1849 if ( merge ) ;//setModified( true );
1849 else { 1850 else {
1850 //setModified( true ); 1851 //setModified( true );
1851 mViewManager->setDocumentId( filename ); 1852 mViewManager->setDocumentId( filename );
1852 mDialogManager->setDocumentId( filename ); 1853 mDialogManager->setDocumentId( filename );
1853 mTodoList->setDocumentId( filename ); 1854 mTodoList->setDocumentId( filename );
1854 } 1855 }
1855 globalFlagBlockAgenda = 2; 1856 globalFlagBlockAgenda = 2;
1856 // if ( getLastSyncEvent() ) 1857 // if ( getLastSyncEvent() )
1857 // getLastSyncEvent()->setReadOnly( true ); 1858 // getLastSyncEvent()->setReadOnly( true );
1858 mCalendar->reInitAlarmSettings(); 1859 mCalendar->reInitAlarmSettings();
1859 setSyncEventsReadOnly(); 1860 setSyncEventsReadOnly();
1860 updateUnmanagedViews(); 1861 updateUnmanagedViews();
1861 updateView(); 1862 updateView();
1862 if ( filename != MainWindow::defaultFileName() ) { 1863 if ( filename != MainWindow::defaultFileName() ) {
1863 saveCalendar( MainWindow::defaultFileName() ); 1864 saveCalendar( MainWindow::defaultFileName() );
1864 } else { 1865 } else {
1865 QFileInfo finf ( MainWindow::defaultFileName()); 1866 QFileInfo finf ( MainWindow::defaultFileName());
1866 if ( finf.exists() ) { 1867 if ( finf.exists() ) {
1867 setLoadedFileVersion( finf.lastModified () ); 1868 setLoadedFileVersion( finf.lastModified () );
1868 } 1869 }
1869 } 1870 }
1870 return true; 1871 return true;
1871 } else { 1872 } else {
1872 // while failing to load, the calendar object could 1873 // while failing to load, the calendar object could
1873 // have become partially populated. Clear it out. 1874 // have become partially populated. Clear it out.
1874 if ( !merge ) { 1875 if ( !merge ) {
1875 mCalendar->close(); 1876 mCalendar->close();
1876 mViewManager->setDocumentId( filename ); 1877 mViewManager->setDocumentId( filename );
1877 mDialogManager->setDocumentId( filename ); 1878 mDialogManager->setDocumentId( filename );
1878 mTodoList->setDocumentId( filename ); 1879 mTodoList->setDocumentId( filename );
1879 } 1880 }
1880 1881
1881 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1882 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1882 1883
1883 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1884 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1884 globalFlagBlockAgenda = 2; 1885 globalFlagBlockAgenda = 2;
1885 mCalendar->reInitAlarmSettings(); 1886 mCalendar->reInitAlarmSettings();
1886 setSyncEventsReadOnly(); 1887 setSyncEventsReadOnly();
1887 updateUnmanagedViews(); 1888 updateUnmanagedViews();
1888 updateView(); 1889 updateView();
1889 } 1890 }
1890 return false; 1891 return false;
1891} 1892}
1892void CalendarView::showOpenError() 1893void CalendarView::showOpenError()
1893{ 1894{
1894 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1895 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1895} 1896}
1896void CalendarView::setLoadedFileVersion(QDateTime dt) 1897void CalendarView::setLoadedFileVersion(QDateTime dt)
1897{ 1898{
1898 loadedFileVersion = dt; 1899 loadedFileVersion = dt;
1899} 1900}
1900bool CalendarView::checkFileChanged(QString fn) 1901bool CalendarView::checkFileChanged(QString fn)
1901{ 1902{
1902 QFileInfo finf ( fn ); 1903 QFileInfo finf ( fn );
1903 if ( !finf.exists() ) 1904 if ( !finf.exists() )
1904 return true; 1905 return true;
1905 QDateTime dt = finf.lastModified (); 1906 QDateTime dt = finf.lastModified ();
1906 if ( dt <= loadedFileVersion ) 1907 if ( dt <= loadedFileVersion )
1907 return false; 1908 return false;
1908 return true; 1909 return true;
1909 1910
1910} 1911}
1911void CalendarView::watchSavedFile() 1912void CalendarView::watchSavedFile()
1912{ 1913{
1913 QFileInfo finf ( MainWindow::defaultFileName()); 1914 QFileInfo finf ( MainWindow::defaultFileName());
1914 if ( !finf.exists() ) 1915 if ( !finf.exists() )
1915 return; 1916 return;
1916 QDateTime dt = finf.lastModified (); 1917 QDateTime dt = finf.lastModified ();
1917 if ( dt < loadedFileVersion ) { 1918 if ( dt < loadedFileVersion ) {
1918 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1919 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1919 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1920 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1920 return; 1921 return;
1921 } 1922 }
1922 loadedFileVersion = dt; 1923 loadedFileVersion = dt;
1923} 1924}
1924 1925
1925bool CalendarView::checkFileVersion(QString fn) 1926bool CalendarView::checkFileVersion(QString fn)
1926{ 1927{
1927 QFileInfo finf ( fn ); 1928 QFileInfo finf ( fn );
1928 if ( !finf.exists() ) 1929 if ( !finf.exists() )
1929 return true; 1930 return true;
1930 QDateTime dt = finf.lastModified (); 1931 QDateTime dt = finf.lastModified ();
1931 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1932 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1932 //qDebug("file on disk version %s",dt.toString().latin1()); 1933 //qDebug("file on disk version %s",dt.toString().latin1());
1933 if ( dt <= loadedFileVersion ) 1934 if ( dt <= loadedFileVersion )
1934 return true; 1935 return true;
1935 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 1936 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
1936 i18n("KO/Pi Warning"),i18n("Overwrite"), 1937 i18n("KO/Pi Warning"),i18n("Overwrite"),
1937 i18n("Sync+save")); 1938 i18n("Sync+save"));
1938 1939
1939 if ( km == KMessageBox::Cancel ) 1940 if ( km == KMessageBox::Cancel )
1940 return false; 1941 return false;
1941 if ( km == KMessageBox::Yes ) 1942 if ( km == KMessageBox::Yes )
1942 return true; 1943 return true;
1943 1944
1944 setSyncDevice("deleteaftersync" ); 1945 setSyncDevice("deleteaftersync" );
1945 mSyncManager->mAskForPreferences = true; 1946 mSyncManager->mAskForPreferences = true;
1946 mSyncManager->mSyncAlgoPrefs = 3; 1947 mSyncManager->mSyncAlgoPrefs = 3;
1947 mSyncManager->mWriteBackFile = false; 1948 mSyncManager->mWriteBackFile = false;
1948 mSyncManager->mWriteBackExistingOnly = false; 1949 mSyncManager->mWriteBackExistingOnly = false;
1949 mSyncManager->mShowSyncSummary = false; 1950 mSyncManager->mShowSyncSummary = false;
1950 syncCalendar( fn, 3 ); 1951 syncCalendar( fn, 3 );
1951 Event * e = getLastSyncEvent(); 1952 Event * e = getLastSyncEvent();
1952 if ( e ) 1953 if ( e )
1953 deleteEvent ( e ); 1954 deleteEvent ( e );
1954 updateView(); 1955 updateView();
1955 return true; 1956 return true;
1956} 1957}
1957 1958
1958bool CalendarView::saveCalendar( QString filename ) 1959bool CalendarView::saveCalendar( QString filename )
1959{ 1960{
1960 1961
1961 // Store back all unsaved data into calendar object 1962 // Store back all unsaved data into calendar object
1962 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1963 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1963 if ( mViewManager->currentView() ) 1964 if ( mViewManager->currentView() )
1964 mViewManager->currentView()->flushView(); 1965 mViewManager->currentView()->flushView();
1965 1966
1966 1967
1967 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 1968 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
1968 mStorage->setSaveFormat( new ICalFormat() ); 1969 mStorage->setSaveFormat( new ICalFormat() );
1969 mStorage->setFileName( filename ); 1970 mStorage->setFileName( filename );
1970 bool success; 1971 bool success;
1971 success = mStorage->save(); 1972 success = mStorage->save();
1972 if ( !success ) { 1973 if ( !success ) {
1973 return false; 1974 return false;
1974 } 1975 }
1975 if ( filename == MainWindow::defaultFileName() ) { 1976 if ( filename == MainWindow::defaultFileName() ) {
1976 setLoadedFileVersion( lfv ); 1977 setLoadedFileVersion( lfv );
1977 watchSavedFile(); 1978 watchSavedFile();
1978 } 1979 }
1979 return true; 1980 return true;
1980} 1981}
1981 1982
1982void CalendarView::closeCalendar() 1983void CalendarView::closeCalendar()
1983{ 1984{
1984 1985
1985 // child windows no longer valid 1986 // child windows no longer valid
1986 clearAllViews(); 1987 clearAllViews();
1987 emit closingDown(); 1988 emit closingDown();
1988 1989
1989 mCalendar->close(); 1990 mCalendar->close();
1990 setModified(false); 1991 setModified(false);
1991 updateView(); 1992 updateView();
1992} 1993}
1993 1994
1994void CalendarView::archiveCalendar() 1995void CalendarView::archiveCalendar()
1995{ 1996{
1996 mDialogManager->showArchiveDialog(); 1997 mDialogManager->showArchiveDialog();
1997} 1998}
1998 1999
1999 2000
2000void CalendarView::readSettings() 2001void CalendarView::readSettings()
2001{ 2002{
2002 2003
2003 2004
2004 // mViewManager->showAgendaView(); 2005 // mViewManager->showAgendaView();
2005 QString str; 2006 QString str;
2006 //qDebug("CalendarView::readSettings() "); 2007 //qDebug("CalendarView::readSettings() ");
2007 // read settings from the KConfig, supplying reasonable 2008 // read settings from the KConfig, supplying reasonable
2008 // defaults where none are to be found 2009 // defaults where none are to be found
2009 KConfig *config = KOGlobals::config(); 2010 KConfig *config = KOGlobals::config();
2010#ifndef KORG_NOSPLITTER 2011#ifndef KORG_NOSPLITTER
2011 config->setGroup("KOrganizer Geometry"); 2012 config->setGroup("KOrganizer Geometry");
2012 2013
2013 QValueList<int> sizes = config->readIntListEntry("Separator1"); 2014 QValueList<int> sizes = config->readIntListEntry("Separator1");
2014 if (sizes.count() != 2) { 2015 if (sizes.count() != 2) {
2015 sizes << mDateNavigator->minimumSizeHint().width(); 2016 sizes << mDateNavigator->minimumSizeHint().width();
2016 sizes << 300; 2017 sizes << 300;
2017 } 2018 }
2018 mPanner->setSizes(sizes); 2019 mPanner->setSizes(sizes);
2019 2020
2020 sizes = config->readIntListEntry("Separator2"); 2021 sizes = config->readIntListEntry("Separator2");
2021 if ( ( mResourceView && sizes.count() == 4 ) || 2022 if ( ( mResourceView && sizes.count() == 4 ) ||
2022 ( !mResourceView && sizes.count() == 3 ) ) { 2023 ( !mResourceView && sizes.count() == 3 ) ) {
2023 mLeftSplitter->setSizes(sizes); 2024 mLeftSplitter->setSizes(sizes);
2024 } 2025 }
2025#endif 2026#endif
2026 globalFlagBlockAgenda = 1; 2027 globalFlagBlockAgenda = 1;
2027 mViewManager->showAgendaView(); 2028 mViewManager->showAgendaView();
2028 //mViewManager->readSettings( config ); 2029 //mViewManager->readSettings( config );
2029 mTodoList->restoreLayout(config,QString("Todo Layout")); 2030 mTodoList->restoreLayout(config,QString("Todo Layout"));
2030 readFilterSettings(config); 2031 readFilterSettings(config);
2031 2032
2032#ifdef DESKTOP_VERSION 2033#ifdef DESKTOP_VERSION
2033 config->setGroup("WidgetLayout"); 2034 config->setGroup("WidgetLayout");
2034 QStringList list; 2035 QStringList list;
2035 list = config->readListEntry("MainLayout"); 2036 list = config->readListEntry("MainLayout");
2036 int x,y,w,h; 2037 int x,y,w,h;
2037 if ( ! list.isEmpty() ) { 2038 if ( ! list.isEmpty() ) {
2038 x = list[0].toInt(); 2039 x = list[0].toInt();
2039 y = list[1].toInt(); 2040 y = list[1].toInt();
2040 w = list[2].toInt(); 2041 w = list[2].toInt();
2041 h = list[3].toInt(); 2042 h = list[3].toInt();
2042 KApplication::testCoords( &x,&y,&w,&h ); 2043 KApplication::testCoords( &x,&y,&w,&h );
2043 topLevelWidget()->setGeometry(x,y,w,h); 2044 topLevelWidget()->setGeometry(x,y,w,h);
2044 2045
2045 } else { 2046 } else {
2046 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 2047 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
2047 } 2048 }
2048 list = config->readListEntry("EditEventLayout"); 2049 list = config->readListEntry("EditEventLayout");
2049 if ( ! list.isEmpty() ) { 2050 if ( ! list.isEmpty() ) {
2050 x = list[0].toInt(); 2051 x = list[0].toInt();
2051 y = list[1].toInt(); 2052 y = list[1].toInt();
2052 w = list[2].toInt(); 2053 w = list[2].toInt();
2053 h = list[3].toInt(); 2054 h = list[3].toInt();
2054 KApplication::testCoords( &x,&y,&w,&h ); 2055 KApplication::testCoords( &x,&y,&w,&h );
2055 mEventEditor->setGeometry(x,y,w,h); 2056 mEventEditor->setGeometry(x,y,w,h);
2056 2057
2057 } 2058 }
2058 list = config->readListEntry("EditTodoLayout"); 2059 list = config->readListEntry("EditTodoLayout");
2059 if ( ! list.isEmpty() ) { 2060 if ( ! list.isEmpty() ) {
2060 x = list[0].toInt(); 2061 x = list[0].toInt();
2061 y = list[1].toInt(); 2062 y = list[1].toInt();
2062 w = list[2].toInt(); 2063 w = list[2].toInt();
2063 h = list[3].toInt(); 2064 h = list[3].toInt();
2064 KApplication::testCoords( &x,&y,&w,&h ); 2065 KApplication::testCoords( &x,&y,&w,&h );
2065 mTodoEditor->setGeometry(x,y,w,h); 2066 mTodoEditor->setGeometry(x,y,w,h);
2066 2067
2067 } 2068 }
2068 list = config->readListEntry("ViewerLayout"); 2069 list = config->readListEntry("ViewerLayout");
2069 if ( ! list.isEmpty() ) { 2070 if ( ! list.isEmpty() ) {
2070 x = list[0].toInt(); 2071 x = list[0].toInt();
2071 y = list[1].toInt(); 2072 y = list[1].toInt();
2072 w = list[2].toInt(); 2073 w = list[2].toInt();
2073 h = list[3].toInt(); 2074 h = list[3].toInt();
2074 KApplication::testCoords( &x,&y,&w,&h ); 2075 KApplication::testCoords( &x,&y,&w,&h );
2075 getEventViewerDialog()->setGeometry(x,y,w,h); 2076 getEventViewerDialog()->setGeometry(x,y,w,h);
2076 } 2077 }
2077#endif 2078#endif
2078 config->setGroup( "Views" ); 2079 config->setGroup( "Views" );
2079 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 2080 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
2080 2081
2081 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 2082 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
2082 2083
2083 int resetval = 0; 2084 int resetval = 0;
2084 int maxVal = 0; 2085 int maxVal = 0;
2085 if (sizes.count() != 3) { 2086 if (sizes.count() != 3) {
2086 if ( KOPrefs::instance()->mVerticalScreen ) { 2087 if ( KOPrefs::instance()->mVerticalScreen ) {
2087 resetval = mDateNavigator->sizeHint().width()+2; 2088 resetval = mDateNavigator->sizeHint().width()+2;
2088 } else { 2089 } else {
2089 resetval = mDateNavigator->sizeHint().height()+2; 2090 resetval = mDateNavigator->sizeHint().height()+2;
2090 } 2091 }
2091 } 2092 }
2092 if ( resetval ) { 2093 if ( resetval ) {
2093 sizes.clear(); 2094 sizes.clear();
2094 if ( KOPrefs::instance()->mVerticalScreen ) { 2095 if ( KOPrefs::instance()->mVerticalScreen ) {
2095 maxVal = QApplication::desktop()->width() -10; 2096 maxVal = QApplication::desktop()->width() -10;
2096 } else { 2097 } else {
2097 maxVal = QApplication::desktop()->height()-10; 2098 maxVal = QApplication::desktop()->height()-10;
2098 } 2099 }
2099 sizes << resetval; 2100 sizes << resetval;
2100 if ( maxVal < resetval + resetval) 2101 if ( maxVal < resetval + resetval)
2101 resetval = maxVal - resetval; 2102 resetval = maxVal - resetval;
2102 sizes << resetval; 2103 sizes << resetval;
2103 sizes << 100; 2104 sizes << 100;
2104 } 2105 }
2105 mLeftFrame->setSizes(sizes); 2106 mLeftFrame->setSizes(sizes);
2106 sizes = config->readIntListEntry("Main Splitter Frame"); 2107 sizes = config->readIntListEntry("Main Splitter Frame");
2107 resetval = 0; 2108 resetval = 0;
2108 maxVal = 0; 2109 maxVal = 0;
2109 if (sizes.count() != 2) { 2110 if (sizes.count() != 2) {
2110 if ( !KOPrefs::instance()->mVerticalScreen ) { 2111 if ( !KOPrefs::instance()->mVerticalScreen ) {
2111 resetval = mDateNavigator->sizeHint().width()+2; 2112 resetval = mDateNavigator->sizeHint().width()+2;
2112 } else { 2113 } else {
2113 resetval = mDateNavigator->sizeHint().height()+2; 2114 resetval = mDateNavigator->sizeHint().height()+2;
2114 } 2115 }
2115 } 2116 }
2116 if ( resetval ) { 2117 if ( resetval ) {
2117 sizes.clear(); 2118 sizes.clear();
2118 if ( !KOPrefs::instance()->mVerticalScreen ) { 2119 if ( !KOPrefs::instance()->mVerticalScreen ) {
2119 maxVal = QApplication::desktop()->width() -10; 2120 maxVal = QApplication::desktop()->width() -10;
2120 } else { 2121 } else {
2121 maxVal = QApplication::desktop()->height()-10; 2122 maxVal = QApplication::desktop()->height()-10;
2122 } 2123 }
2123 sizes << resetval; 2124 sizes << resetval;
2124 if ( maxVal < resetval + resetval) 2125 if ( maxVal < resetval + resetval)
2125 resetval = maxVal - resetval; 2126 resetval = maxVal - resetval;
2126 sizes << resetval; 2127 sizes << resetval;
2127 } 2128 }
2128 mMainFrame->setSizes(sizes); 2129 mMainFrame->setSizes(sizes);
2129 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 2130 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
2130 else if ( dateCount == 7 ) mNavigator->selectWeek(); 2131 else if ( dateCount == 7 ) mNavigator->selectWeek();
2131 else mNavigator->selectDates( dateCount ); 2132 else mNavigator->selectDates( dateCount );
2132 // mViewManager->readSettings( config ); 2133 // mViewManager->readSettings( config );
2133 updateConfig(); 2134 updateConfig();
2134 globalFlagBlockAgenda = 2; 2135 globalFlagBlockAgenda = 2;
2135 mViewManager->readSettings( config ); 2136 mViewManager->readSettings( config );
2136 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 2137 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
2137} 2138}
2138 2139
2139 2140
2140void CalendarView::writeSettings() 2141void CalendarView::writeSettings()
2141{ 2142{
2142 // kdDebug() << "CalendarView::writeSettings" << endl; 2143 // kdDebug() << "CalendarView::writeSettings" << endl;
2143 2144
2144 KConfig *config = KOGlobals::config(); 2145 KConfig *config = KOGlobals::config();
2145 2146
2146 mViewManager->writeSettings( config ); 2147 mViewManager->writeSettings( config );
2147 mTodoList->saveLayout(config,QString("Todo Layout")); 2148 mTodoList->saveLayout(config,QString("Todo Layout"));
2148 mDialogManager->writeSettings( config ); 2149 mDialogManager->writeSettings( config );
2149 //KOPrefs::instance()->usrWriteConfig(); 2150 //KOPrefs::instance()->usrWriteConfig();
2150 KOPrefs::instance()->writeConfig(); 2151 KOPrefs::instance()->writeConfig();
2151 2152
2152 writeFilterSettings(config); 2153 writeFilterSettings(config);
2153 config->setGroup( "AppRun" ); 2154 config->setGroup( "AppRun" );
2154 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 2155 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
2155 config->writeEntry( "LatestProgramStop", dt.secsTo( QDateTime::currentDateTime() ) ); 2156 config->writeEntry( "LatestProgramStop", dt.secsTo( QDateTime::currentDateTime() ) );
2156 config->setGroup( "Views" ); 2157 config->setGroup( "Views" );
2157 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 2158 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
2158 2159
2159 QValueList<int> listINT = mLeftFrame->sizes(); 2160 QValueList<int> listINT = mLeftFrame->sizes();
2160 config->writeEntry("Left Splitter Frame",listINT); 2161 config->writeEntry("Left Splitter Frame",listINT);
2161 QValueList<int> listINT2 = mMainFrame->sizes(); 2162 QValueList<int> listINT2 = mMainFrame->sizes();
2162 config->writeEntry("Main Splitter Frame",listINT2); 2163 config->writeEntry("Main Splitter Frame",listINT2);
2163#ifdef DESKTOP_VERSION 2164#ifdef DESKTOP_VERSION
2164 config->setGroup("WidgetLayout"); 2165 config->setGroup("WidgetLayout");
2165 QStringList list ;//= config->readListEntry("MainLayout"); 2166 QStringList list ;//= config->readListEntry("MainLayout");
2166 int x,y,w,h; 2167 int x,y,w,h;
2167 QWidget* wid; 2168 QWidget* wid;
2168 wid = topLevelWidget(); 2169 wid = topLevelWidget();
2169 x = wid->geometry().x(); 2170 x = wid->geometry().x();
2170 y = wid->geometry().y(); 2171 y = wid->geometry().y();
2171 w = wid->width(); 2172 w = wid->width();
2172 h = wid->height(); 2173 h = wid->height();
2173 list.clear(); 2174 list.clear();
2174 list << QString::number( x ); 2175 list << QString::number( x );
2175 list << QString::number( y ); 2176 list << QString::number( y );
2176 list << QString::number( w ); 2177 list << QString::number( w );
2177 list << QString::number( h ); 2178 list << QString::number( h );
2178 config->writeEntry("MainLayout",list ); 2179 config->writeEntry("MainLayout",list );
2179 2180
2180 wid = mEventEditor; 2181 wid = mEventEditor;
2181 x = wid->geometry().x(); 2182 x = wid->geometry().x();
2182 y = wid->geometry().y(); 2183 y = wid->geometry().y();
2183 w = wid->width(); 2184 w = wid->width();
2184 h = wid->height(); 2185 h = wid->height();
2185 list.clear(); 2186 list.clear();
2186 list << QString::number( x ); 2187 list << QString::number( x );
2187 list << QString::number( y ); 2188 list << QString::number( y );
2188 list << QString::number( w ); 2189 list << QString::number( w );
2189 list << QString::number( h ); 2190 list << QString::number( h );
2190 config->writeEntry("EditEventLayout",list ); 2191 config->writeEntry("EditEventLayout",list );
2191 2192
2192 wid = mTodoEditor; 2193 wid = mTodoEditor;
2193 x = wid->geometry().x(); 2194 x = wid->geometry().x();
2194 y = wid->geometry().y(); 2195 y = wid->geometry().y();
2195 w = wid->width(); 2196 w = wid->width();
2196 h = wid->height(); 2197 h = wid->height();
2197 list.clear(); 2198 list.clear();
2198 list << QString::number( x ); 2199 list << QString::number( x );
2199 list << QString::number( y ); 2200 list << QString::number( y );
2200 list << QString::number( w ); 2201 list << QString::number( w );
2201 list << QString::number( h ); 2202 list << QString::number( h );
2202 config->writeEntry("EditTodoLayout",list ); 2203 config->writeEntry("EditTodoLayout",list );
2203 wid = getEventViewerDialog(); 2204 wid = getEventViewerDialog();
2204 x = wid->geometry().x(); 2205 x = wid->geometry().x();
2205 y = wid->geometry().y(); 2206 y = wid->geometry().y();
2206 w = wid->width(); 2207 w = wid->width();
2207 h = wid->height(); 2208 h = wid->height();
2208 list.clear(); 2209 list.clear();
2209 list << QString::number( x ); 2210 list << QString::number( x );
2210 list << QString::number( y ); 2211 list << QString::number( y );
2211 list << QString::number( w ); 2212 list << QString::number( w );
2212 list << QString::number( h ); 2213 list << QString::number( h );
2213 config->writeEntry("ViewerLayout",list ); 2214 config->writeEntry("ViewerLayout",list );
2214 wid = mDialogManager->getSearchDialog(); 2215 wid = mDialogManager->getSearchDialog();
2215 if ( wid ) { 2216 if ( wid ) {
2216 x = wid->geometry().x(); 2217 x = wid->geometry().x();
2217 y = wid->geometry().y(); 2218 y = wid->geometry().y();
2218 w = wid->width(); 2219 w = wid->width();
2219 h = wid->height(); 2220 h = wid->height();
2220 list.clear(); 2221 list.clear();
2221 list << QString::number( x ); 2222 list << QString::number( x );
2222 list << QString::number( y ); 2223 list << QString::number( y );
2223 list << QString::number( w ); 2224 list << QString::number( w );
2224 list << QString::number( h ); 2225 list << QString::number( h );
2225 config->writeEntry("SearchLayout",list ); 2226 config->writeEntry("SearchLayout",list );
2226 } 2227 }
2227#endif 2228#endif
2228 2229
2229 2230
2230 config->sync(); 2231 config->sync();
2231} 2232}
2232 2233
2233void CalendarView::readFilterSettings(KConfig *config) 2234void CalendarView::readFilterSettings(KConfig *config)
2234{ 2235{
2235 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2236 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
2236 2237
2237 mFilters.clear(); 2238 mFilters.clear();
2238 2239
2239 config->setGroup("General"); 2240 config->setGroup("General");
2240 QStringList filterList = config->readListEntry("CalendarFilters"); 2241 QStringList filterList = config->readListEntry("CalendarFilters");
2241 2242
2242 QStringList::ConstIterator it = filterList.begin(); 2243 QStringList::ConstIterator it = filterList.begin();
2243 QStringList::ConstIterator end = filterList.end(); 2244 QStringList::ConstIterator end = filterList.end();
2244 while(it != end) { 2245 while(it != end) {
2245 // kdDebug() << " filter: " << (*it) << endl; 2246 // kdDebug() << " filter: " << (*it) << endl;
2246 2247
2247 CalFilter *filter; 2248 CalFilter *filter;
2248 filter = new CalFilter(*it); 2249 filter = new CalFilter(*it);
2249 config->setGroup("Filter_" + (*it).utf8()); 2250 config->setGroup("Filter_" + (*it).utf8());
2250 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 2251 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
2251 filter->setCriteria(config->readNumEntry("Criteria",0)); 2252 filter->setCriteria(config->readNumEntry("Criteria",0));
2252 filter->setCategoryList(config->readListEntry("CategoryList")); 2253 filter->setCategoryList(config->readListEntry("CategoryList"));
2253 mFilters.append(filter); 2254 mFilters.append(filter);
2254 2255
2255 ++it; 2256 ++it;
2256 } 2257 }
2257 2258
2258 if (mFilters.count() == 0) { 2259 if (mFilters.count() == 0) {
2259 CalFilter *filter = new CalFilter(i18n("Default")); 2260 CalFilter *filter = new CalFilter(i18n("Default"));
2260 mFilters.append(filter); 2261 mFilters.append(filter);
2261 } 2262 }
2262 mFilterView->updateFilters(); 2263 mFilterView->updateFilters();
2263 config->setGroup("FilterView"); 2264 config->setGroup("FilterView");
2264 2265
2265 mFilterView->blockSignals(true); 2266 mFilterView->blockSignals(true);
2266 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2267 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2267 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2268 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2268 mFilterView->blockSignals(false); 2269 mFilterView->blockSignals(false);
2269 // We do it manually to avoid it being done twice by the above calls 2270 // We do it manually to avoid it being done twice by the above calls
2270 updateFilter(); 2271 updateFilter();
2271} 2272}
2272 2273
2273void CalendarView::writeFilterSettings(KConfig *config) 2274void CalendarView::writeFilterSettings(KConfig *config)
2274{ 2275{
2275 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2276 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2276 2277
2277 QStringList filterList; 2278 QStringList filterList;
2278 2279
2279 CalFilter *filter = mFilters.first(); 2280 CalFilter *filter = mFilters.first();
2280 while(filter) { 2281 while(filter) {
2281 // kdDebug() << " fn: " << filter->name() << endl; 2282 // kdDebug() << " fn: " << filter->name() << endl;
2282 filterList << filter->name(); 2283 filterList << filter->name();
2283 config->setGroup("Filter_" + filter->name().utf8()); 2284 config->setGroup("Filter_" + filter->name().utf8());
2284 config->writeEntry("Criteria",filter->criteria()); 2285 config->writeEntry("Criteria",filter->criteria());
2285 config->writeEntry("CategoryList",filter->categoryList()); 2286 config->writeEntry("CategoryList",filter->categoryList());
2286 filter = mFilters.next(); 2287 filter = mFilters.next();
2287 } 2288 }
2288 config->setGroup("General"); 2289 config->setGroup("General");
2289 config->writeEntry("CalendarFilters",filterList); 2290 config->writeEntry("CalendarFilters",filterList);
2290 2291
2291 config->setGroup("FilterView"); 2292 config->setGroup("FilterView");
2292 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2293 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2293 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2294 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2294} 2295}
2295 2296
2296 2297
2297void CalendarView::goToday() 2298void CalendarView::goToday()
2298{ 2299{
2299 if ( mViewManager->currentView()->isMonthView() ) 2300 if ( mViewManager->currentView()->isMonthView() )
2300 mNavigator->selectTodayMonth(); 2301 mNavigator->selectTodayMonth();
2301 else 2302 else
2302 mNavigator->selectToday(); 2303 mNavigator->selectToday();
2303} 2304}
2304 2305
2305void CalendarView::goNext() 2306void CalendarView::goNext()
2306{ 2307{
2307 mNavigator->selectNext(); 2308 mNavigator->selectNext();
2308} 2309}
2309 2310
2310void CalendarView::goPrevious() 2311void CalendarView::goPrevious()
2311{ 2312{
2312 mNavigator->selectPrevious(); 2313 mNavigator->selectPrevious();
2313} 2314}
2314void CalendarView::goNextMonth() 2315void CalendarView::goNextMonth()
2315{ 2316{
2316 mNavigator->selectNextMonth(); 2317 mNavigator->selectNextMonth();
2317} 2318}
2318 2319
2319void CalendarView::goPreviousMonth() 2320void CalendarView::goPreviousMonth()
2320{ 2321{
2321 mNavigator->selectPreviousMonth(); 2322 mNavigator->selectPreviousMonth();
2322} 2323}
2323void CalendarView::writeLocale() 2324void CalendarView::writeLocale()
2324{ 2325{
2325 //KPimGlobalPrefs::instance()->setGlobalConfig(); 2326 //KPimGlobalPrefs::instance()->setGlobalConfig();
2326#if 0 2327#if 0
2327 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 2328 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
2328 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 2329 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
2329 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 2330 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
2330 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 2331 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
2331 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 2332 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
2332 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 2333 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
2333 dummy = KOPrefs::instance()->mUserDateFormatShort; 2334 dummy = KOPrefs::instance()->mUserDateFormatShort;
2334 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 2335 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
2335 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 2336 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
2336 KOPrefs::instance()->mDaylightsavingStart, 2337 KOPrefs::instance()->mDaylightsavingStart,
2337 KOPrefs::instance()->mDaylightsavingEnd ); 2338 KOPrefs::instance()->mDaylightsavingEnd );
2338 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId ); 2339 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId );
2339#endif 2340#endif
2340} 2341}
2341void CalendarView::updateConfig() 2342void CalendarView::updateConfig()
2342{ 2343{
2343 writeLocale(); 2344 writeLocale();
2344 if ( KOPrefs::instance()->mUseAppColors ) 2345 if ( KOPrefs::instance()->mUseAppColors )
2345 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2346 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2346 emit configChanged(); 2347 emit configChanged();
2347 mTodoList->updateConfig(); 2348 mTodoList->updateConfig();
2348 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2349 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2349 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2350 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2350 // To make the "fill window" configurations work 2351 // To make the "fill window" configurations work
2351 //mViewManager->raiseCurrentView(); 2352 //mViewManager->raiseCurrentView();
2352} 2353}
2353 2354
2354 2355
2355void CalendarView::eventChanged(Event *event) 2356void CalendarView::eventChanged(Event *event)
2356{ 2357{
2357 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2358 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2358 //updateUnmanagedViews(); 2359 //updateUnmanagedViews();
2359} 2360}
2360 2361
2361void CalendarView::eventAdded(Event *event) 2362void CalendarView::eventAdded(Event *event)
2362{ 2363{
2363 changeEventDisplay(event,KOGlobals::EVENTADDED); 2364 changeEventDisplay(event,KOGlobals::EVENTADDED);
2364} 2365}
2365 2366
2366void CalendarView::eventToBeDeleted(Event *) 2367void CalendarView::eventToBeDeleted(Event *)
2367{ 2368{
2368 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2369 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2369} 2370}
2370 2371
2371void CalendarView::eventDeleted() 2372void CalendarView::eventDeleted()
2372{ 2373{
2373 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2374 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2374} 2375}
2375void CalendarView::changeTodoDisplay(Todo *which, int action) 2376void CalendarView::changeTodoDisplay(Todo *which, int action)
2376{ 2377{
2377 changeIncidenceDisplay((Incidence *)which, action); 2378 changeIncidenceDisplay((Incidence *)which, action);
2378 mDateNavigator->updateView(); //LR 2379 mDateNavigator->updateView(); //LR
2379 //mDialogManager->updateSearchDialog(); 2380 //mDialogManager->updateSearchDialog();
2380 2381
2381 if (which) { 2382 if (which) {
2382 mViewManager->updateWNview(); 2383 mViewManager->updateWNview();
2383 //mTodoList->updateView(); 2384 //mTodoList->updateView();
2384 } 2385 }
2385 2386
2386} 2387}
2387 2388
2388void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2389void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2389{ 2390{
2390 updateUnmanagedViews(); 2391 updateUnmanagedViews();
2391 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2392 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2392 if ( action == KOGlobals::EVENTDELETED ) { //delete 2393 if ( action == KOGlobals::EVENTDELETED ) { //delete
2393 mCalendar->checkAlarmForIncidence( 0, true ); 2394 mCalendar->checkAlarmForIncidence( 0, true );
2394 if ( mEventViewerDialog ) 2395 if ( mEventViewerDialog )
2395 mEventViewerDialog->hide(); 2396 mEventViewerDialog->hide();
2396 } 2397 }
2397 else 2398 else
2398 mCalendar->checkAlarmForIncidence( which , false ); 2399 mCalendar->checkAlarmForIncidence( which , false );
2399} 2400}
2400 2401
2401// most of the changeEventDisplays() right now just call the view's 2402// most of the changeEventDisplays() right now just call the view's
2402// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2403// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2403void CalendarView::changeEventDisplay(Event *which, int action) 2404void CalendarView::changeEventDisplay(Event *which, int action)
2404{ 2405{
2405 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2406 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2406 changeIncidenceDisplay((Incidence *)which, action); 2407 changeIncidenceDisplay((Incidence *)which, action);
2407 mDateNavigator->updateView(); 2408 mDateNavigator->updateView();
2408 //mDialogManager->updateSearchDialog(); 2409 //mDialogManager->updateSearchDialog();
2409 2410
2410 if (which) { 2411 if (which) {
2411 // If there is an event view visible update the display 2412 // If there is an event view visible update the display
2412 mViewManager->currentView()->changeEventDisplay(which,action); 2413 mViewManager->currentView()->changeEventDisplay(which,action);
2413 // TODO: check, if update needed 2414 // TODO: check, if update needed
2414 // if (which->getTodoStatus()) { 2415 // if (which->getTodoStatus()) {
2415 mTodoList->updateView(); 2416 mTodoList->updateView();
2416 // } 2417 // }
2417 } else { 2418 } else {
2418 mViewManager->currentView()->updateView(); 2419 mViewManager->currentView()->updateView();
2419 } 2420 }
2420} 2421}
2421 2422
2422 2423
2423void CalendarView::updateTodoViews() 2424void CalendarView::updateTodoViews()
2424{ 2425{
2425 mTodoList->updateView(); 2426 mTodoList->updateView();
2426 mViewManager->currentView()->updateView(); 2427 mViewManager->currentView()->updateView();
2427 2428
2428} 2429}
2429 2430
2430 2431
2431void CalendarView::updateView(const QDate &start, const QDate &end) 2432void CalendarView::updateView(const QDate &start, const QDate &end)
2432{ 2433{
2433 mTodoList->updateView(); 2434 mTodoList->updateView();
2434 mViewManager->updateView(start, end); 2435 mViewManager->updateView(start, end);
2435 //mDateNavigator->updateView(); 2436 //mDateNavigator->updateView();
2436} 2437}
2437 2438
2438void CalendarView::clearAllViews() 2439void CalendarView::clearAllViews()
2439{ 2440{
2440 mTodoList->clearList(); 2441 mTodoList->clearList();
2441 mViewManager->clearAllViews(); 2442 mViewManager->clearAllViews();
2442 SearchDialog * sd = mDialogManager->getSearchDialog(); 2443 SearchDialog * sd = mDialogManager->getSearchDialog();
2443 if ( sd ) { 2444 if ( sd ) {
2444 KOListView* kol = sd->listview(); 2445 KOListView* kol = sd->listview();
2445 if ( kol ) 2446 if ( kol )
2446 kol->clearList(); 2447 kol->clearList();
2447 } 2448 }
2448} 2449}
2449void CalendarView::updateView() 2450void CalendarView::updateView()
2450{ 2451{
2451 DateList tmpList = mNavigator->selectedDates(); 2452 DateList tmpList = mNavigator->selectedDates();
2452 2453
2453 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2454 if ( KOPrefs::instance()->mHideNonStartedTodos )
2454 mTodoList->updateView(); 2455 mTodoList->updateView();
2455 // We assume that the navigator only selects consecutive days. 2456 // We assume that the navigator only selects consecutive days.
2456 updateView( tmpList.first(), tmpList.last() ); 2457 updateView( tmpList.first(), tmpList.last() );
2457} 2458}
2458 2459
2459void CalendarView::updateUnmanagedViews() 2460void CalendarView::updateUnmanagedViews()
2460{ 2461{
2461 mDateNavigator->updateDayMatrix(); 2462 mDateNavigator->updateDayMatrix();
2462} 2463}
2463 2464
2464int CalendarView::msgItemDelete(const QString name) 2465int CalendarView::msgItemDelete(const QString name)
2465{ 2466{
2466 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 2467 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
2467 i18n("This item will be\npermanently deleted."), 2468 i18n("This item will be\npermanently deleted."),
2468 i18n("KO/Pi Confirmation"),i18n("Delete")); 2469 i18n("KO/Pi Confirmation"),i18n("Delete"));
2469} 2470}
2470 2471
2471 2472
2472void CalendarView::edit_cut() 2473void CalendarView::edit_cut()
2473{ 2474{
2474 Event *anEvent=0; 2475 Event *anEvent=0;
2475 2476
2476 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2477 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2477 2478
2478 if (mViewManager->currentView()->isEventView()) { 2479 if (mViewManager->currentView()->isEventView()) {
2479 if ( incidence && incidence->type() == "Event" ) { 2480 if ( incidence && incidence->type() == "Event" ) {
2480 anEvent = static_cast<Event *>(incidence); 2481 anEvent = static_cast<Event *>(incidence);
2481 } 2482 }
2482 } 2483 }
2483 2484
2484 if (!anEvent) { 2485 if (!anEvent) {
2485 KNotifyClient::beep(); 2486 KNotifyClient::beep();
2486 return; 2487 return;
2487 } 2488 }
2488 DndFactory factory( mCalendar ); 2489 DndFactory factory( mCalendar );
2489 factory.cutIncidence(anEvent); 2490 factory.cutIncidence(anEvent);
2490 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2491 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2491} 2492}
2492 2493
2493void CalendarView::edit_copy() 2494void CalendarView::edit_copy()
2494{ 2495{
2495 Event *anEvent=0; 2496 Event *anEvent=0;
2496 2497
2497 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2498 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2498 2499
2499 if (mViewManager->currentView()->isEventView()) { 2500 if (mViewManager->currentView()->isEventView()) {
2500 if ( incidence && incidence->type() == "Event" ) { 2501 if ( incidence && incidence->type() == "Event" ) {
2501 anEvent = static_cast<Event *>(incidence); 2502 anEvent = static_cast<Event *>(incidence);
2502 } 2503 }
2503 } 2504 }
2504 2505
2505 if (!anEvent) { 2506 if (!anEvent) {
2506 KNotifyClient::beep(); 2507 KNotifyClient::beep();
2507 return; 2508 return;
2508 } 2509 }
2509 DndFactory factory( mCalendar ); 2510 DndFactory factory( mCalendar );
2510 factory.copyIncidence(anEvent); 2511 factory.copyIncidence(anEvent);
2511} 2512}
2512 2513
2513void CalendarView::edit_paste() 2514void CalendarView::edit_paste()
2514{ 2515{
2515 QDate date = mNavigator->selectedDates().first(); 2516 QDate date = mNavigator->selectedDates().first();
2516 2517
2517 DndFactory factory( mCalendar ); 2518 DndFactory factory( mCalendar );
2518 Event *pastedEvent = (Event *)factory.pasteIncidence( date ); 2519 Event *pastedEvent = (Event *)factory.pasteIncidence( date );
2519 2520
2520 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2521 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2521} 2522}
2522 2523
2523void CalendarView::edit_options() 2524void CalendarView::edit_options()
2524{ 2525{
2525 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; 2526 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId;
2526 emit save(); 2527 emit save();
2527 emit saveStopTimer(); 2528 emit saveStopTimer();
2528 mDialogManager->showOptionsDialog(); 2529 mDialogManager->showOptionsDialog();
2529 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { 2530 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) {
2530 emit saveStopTimer(); 2531 emit saveStopTimer();
2531 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto apply timezone changes?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"), 2532 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto apply timezone changes?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"),
2532 i18n("Timezone settings"),i18n("Reload"))) { 2533 i18n("Timezone settings"),i18n("Reload"))) {
2533 qDebug("KO: TZ reload cancelled "); 2534 qDebug("KO: TZ reload cancelled ");
2534 return; 2535 return;
2535 } 2536 }
2536 qDebug("KO: Timezone change "); 2537 qDebug("KO: Timezone change ");
2537 openCalendar( MainWindow::defaultFileName() ); 2538 openCalendar( MainWindow::defaultFileName() );
2538 setModified(true); 2539 setModified(true);
2539 } 2540 }
2540 else 2541 else
2541 qDebug("KO: No tz change "); 2542 qDebug("KO: No tz change ");
2542 2543
2543} 2544}
2544 2545
2545 2546
2546void CalendarView::slotSelectPickerDate( QDate d) 2547void CalendarView::slotSelectPickerDate( QDate d)
2547{ 2548{
2548 mDateFrame->hide(); 2549 mDateFrame->hide();
2549 if ( mDatePickerMode == 1 ) { 2550 if ( mDatePickerMode == 1 ) {
2550 mNavigator->slotDaySelect( d ); 2551 mNavigator->slotDaySelect( d );
2551 } else if ( mDatePickerMode == 2 ) { 2552 } else if ( mDatePickerMode == 2 ) {
2552 if ( mMoveIncidence->type() == "Todo" ) { 2553 if ( mMoveIncidence->type() == "Todo" ) {
2553 Todo * to = (Todo *) mMoveIncidence; 2554 Todo * to = (Todo *) mMoveIncidence;
2554 QTime tim; 2555 QTime tim;
2555 int len = 0; 2556 int len = 0;
2556 if ( to->hasStartDate() && to->hasDueDate() ) 2557 if ( to->hasStartDate() && to->hasDueDate() )
2557 len = to->dtStart().secsTo( to->dtDue()); 2558 len = to->dtStart().secsTo( to->dtDue());
2558 if ( to->hasDueDate() ) 2559 if ( to->hasDueDate() )
2559 tim = to->dtDue().time(); 2560 tim = to->dtDue().time();
2560 else { 2561 else {
2561 tim = QTime ( 0,0,0 ); 2562 tim = QTime ( 0,0,0 );
2562 to->setFloats( true ); 2563 to->setFloats( true );
2563 to->setHasDueDate( true ); 2564 to->setHasDueDate( true );
2564 } 2565 }
2565 QDateTime dt ( d,tim ); 2566 QDateTime dt ( d,tim );
2566 to->setDtDue( dt ); 2567 to->setDtDue( dt );
2567 2568
2568 if ( to->hasStartDate() ) { 2569 if ( to->hasStartDate() ) {
2569 if ( len>0 ) 2570 if ( len>0 )
2570 to->setDtStart(to->dtDue().addSecs( -len )); 2571 to->setDtStart(to->dtDue().addSecs( -len ));
2571 else 2572 else
2572 if (to->dtStart() > to->dtDue() ) 2573 if (to->dtStart() > to->dtDue() )
2573 to->setDtStart(to->dtDue().addDays( -3 )); 2574 to->setDtStart(to->dtDue().addDays( -3 ));
2574 } 2575 }
2575 2576
2576 todoChanged( to ); 2577 todoChanged( to );
2577 } else { 2578 } else {
2578 if ( mMoveIncidence->doesRecur() ) { 2579 if ( mMoveIncidence->doesRecur() ) {
2579#if 0 2580#if 0
2580 // PENDING implement this 2581 // PENDING implement this
2581 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 2582 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
2582 mCalendar()->addIncidence( newInc ); 2583 mCalendar()->addIncidence( newInc );
2583 if ( mMoveIncidence->type() == "Todo" ) 2584 if ( mMoveIncidence->type() == "Todo" )
2584 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 2585 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
2585 else 2586 else
2586 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 2587 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
2587 mMoveIncidence = newInc; 2588 mMoveIncidence = newInc;
2588 2589
2589#endif 2590#endif
2590 } 2591 }
2591 QTime tim = mMoveIncidence->dtStart().time(); 2592 QTime tim = mMoveIncidence->dtStart().time();
2592 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2593 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2593 QDateTime dt ( d,tim ); 2594 QDateTime dt ( d,tim );
2594 mMoveIncidence->setDtStart( dt ); 2595 mMoveIncidence->setDtStart( dt );
2595 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2596 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2596 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2597 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2597 } 2598 }
2598 2599
2599 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2600 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2600 } 2601 }
2601} 2602}
2602 2603
2603void CalendarView::removeCategories() 2604void CalendarView::removeCategories()
2604{ 2605{
2605 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2606 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2606 QStringList catList = KOPrefs::instance()->mCustomCategories; 2607 QStringList catList = KOPrefs::instance()->mCustomCategories;
2607 QStringList catIncList; 2608 QStringList catIncList;
2608 QStringList newCatList; 2609 QStringList newCatList;
2609 Incidence* inc = incList.first(); 2610 Incidence* inc = incList.first();
2610 int i; 2611 int i;
2611 int count = 0; 2612 int count = 0;
2612 while ( inc ) { 2613 while ( inc ) {
2613 newCatList.clear(); 2614 newCatList.clear();
2614 catIncList = inc->categories() ; 2615 catIncList = inc->categories() ;
2615 for( i = 0; i< catIncList.count(); ++i ) { 2616 for( i = 0; i< catIncList.count(); ++i ) {
2616 if ( catList.contains (catIncList[i])) 2617 if ( catList.contains (catIncList[i]))
2617 newCatList.append( catIncList[i] ); 2618 newCatList.append( catIncList[i] );
2618 } 2619 }
2619 newCatList.sort(); 2620 newCatList.sort();
2620 inc->setCategories( newCatList.join(",") ); 2621 inc->setCategories( newCatList.join(",") );
2621 inc = incList.next(); 2622 inc = incList.next();
2622 } 2623 }
2623} 2624}
2624 2625
2625int CalendarView::addCategories() 2626int CalendarView::addCategories()
2626{ 2627{
2627 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2628 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2628 QStringList catList = KOPrefs::instance()->mCustomCategories; 2629 QStringList catList = KOPrefs::instance()->mCustomCategories;
2629 QStringList catIncList; 2630 QStringList catIncList;
2630 Incidence* inc = incList.first(); 2631 Incidence* inc = incList.first();
2631 int i; 2632 int i;
2632 int count = 0; 2633 int count = 0;
2633 while ( inc ) { 2634 while ( inc ) {
2634 catIncList = inc->categories() ; 2635 catIncList = inc->categories() ;
2635 for( i = 0; i< catIncList.count(); ++i ) { 2636 for( i = 0; i< catIncList.count(); ++i ) {
2636 if ( !catList.contains (catIncList[i])) { 2637 if ( !catList.contains (catIncList[i])) {
2637 catList.append( catIncList[i] ); 2638 catList.append( catIncList[i] );
2638 //qDebug("add cat %s ", catIncList[i].latin1()); 2639 //qDebug("add cat %s ", catIncList[i].latin1());
2639 ++count; 2640 ++count;
2640 } 2641 }
2641 } 2642 }
2642 inc = incList.next(); 2643 inc = incList.next();
2643 } 2644 }
2644 catList.sort(); 2645 catList.sort();
2645 KOPrefs::instance()->mCustomCategories = catList; 2646 KOPrefs::instance()->mCustomCategories = catList;
2646 return count; 2647 return count;
2647} 2648}
2648 2649
2649void CalendarView::manageCategories() 2650void CalendarView::manageCategories()
2650{ 2651{
2651 KOCatPrefs* cp = new KOCatPrefs(); 2652 KOCatPrefs* cp = new KOCatPrefs();
2652 cp->show(); 2653 cp->show();
2653 int w =cp->sizeHint().width() ; 2654 int w =cp->sizeHint().width() ;
2654 int h = cp->sizeHint().height() ; 2655 int h = cp->sizeHint().height() ;
2655 int dw = QApplication::desktop()->width(); 2656 int dw = QApplication::desktop()->width();
2656 int dh = QApplication::desktop()->height(); 2657 int dh = QApplication::desktop()->height();
2657 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2658 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2658 if ( !cp->exec() ) { 2659 if ( !cp->exec() ) {
2659 delete cp; 2660 delete cp;
2660 return; 2661 return;
2661 } 2662 }
2662 int count = 0; 2663 int count = 0;
2663 if ( cp->addCat() ) { 2664 if ( cp->addCat() ) {
2664 count = addCategories(); 2665 count = addCategories();
2665 if ( count ) { 2666 if ( count ) {
2666 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2667 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2667 writeSettings(); 2668 writeSettings();
2668 } else 2669 } else
2669 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 2670 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
2670 } else { 2671 } else {
2671 removeCategories(); 2672 removeCategories();
2672 updateView(); 2673 updateView();
2673 } 2674 }
2674 delete cp; 2675 delete cp;
2675} 2676}
2676 2677
2677void CalendarView::beamIncidence(Incidence * Inc) 2678void CalendarView::beamIncidence(Incidence * Inc)
2678{ 2679{
2679 QPtrList<Incidence> delSel ; 2680 QPtrList<Incidence> delSel ;
2680 delSel.append(Inc); 2681 delSel.append(Inc);
2681 beamIncidenceList( delSel ); 2682 beamIncidenceList( delSel );
2682} 2683}
2683void CalendarView::beamCalendar() 2684void CalendarView::beamCalendar()
2684{ 2685{
2685 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2686 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2686 //qDebug("beamCalendar() "); 2687 //qDebug("beamCalendar() ");
2687 beamIncidenceList( delSel ); 2688 beamIncidenceList( delSel );
2688} 2689}
2689void CalendarView::beamFilteredCalendar() 2690void CalendarView::beamFilteredCalendar()
2690{ 2691{
2691 QPtrList<Incidence> delSel = mCalendar->incidences(); 2692 QPtrList<Incidence> delSel = mCalendar->incidences();
2692 //qDebug("beamFilteredCalendar() "); 2693 //qDebug("beamFilteredCalendar() ");
2693 beamIncidenceList( delSel ); 2694 beamIncidenceList( delSel );
2694} 2695}
2695void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2696void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2696{ 2697{
2697 if ( beamDialog->exec () == QDialog::Rejected ) 2698 if ( beamDialog->exec () == QDialog::Rejected )
2698 return; 2699 return;
2699#ifdef DESKTOP_VERSION 2700#ifdef DESKTOP_VERSION
2700 QString fn = locateLocal( "tmp", "kopibeamfile" ); 2701 QString fn = locateLocal( "tmp", "kopibeamfile" );
2701#else 2702#else
2702 QString fn = "/tmp/kopibeamfile"; 2703 QString fn = "/tmp/kopibeamfile";
2703#endif 2704#endif
2704 QString mes; 2705 QString mes;
2705 bool createbup = true; 2706 bool createbup = true;
2706 if ( createbup ) { 2707 if ( createbup ) {
2707 QString description = "\n"; 2708 QString description = "\n";
2708 CalendarLocal* cal = new CalendarLocal(); 2709 CalendarLocal* cal = new CalendarLocal();
2709 if ( beamDialog->beamLocal() ) 2710 if ( beamDialog->beamLocal() )
2710 cal->setLocalTime(); 2711 cal->setLocalTime();
2711 else 2712 else
2712 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2713 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2713 Incidence *incidence = delSel.first(); 2714 Incidence *incidence = delSel.first();
2714 bool addText = false; 2715 bool addText = false;
2715 if ( delSel.count() < 10 ) 2716 if ( delSel.count() < 10 )
2716 addText = true; 2717 addText = true;
2717 else { 2718 else {
2718 description.sprintf(i18n(" %d items?"),delSel.count() ); 2719 description.sprintf(i18n(" %d items?"),delSel.count() );
2719 } 2720 }
2720 while ( incidence ) { 2721 while ( incidence ) {
2721 Incidence *in = incidence->clone(); 2722 Incidence *in = incidence->clone();
2722 if ( ! in->summary().isEmpty() ) { 2723 if ( ! in->summary().isEmpty() ) {
2723 in->setDescription(""); 2724 in->setDescription("");
2724 } else { 2725 } else {
2725 in->setSummary( in->description().left(20)); 2726 in->setSummary( in->description().left(20));
2726 in->setDescription(""); 2727 in->setDescription("");
2727 } 2728 }
2728 if ( addText ) 2729 if ( addText )
2729 description += in->summary() + "\n"; 2730 description += in->summary() + "\n";
2730 cal->addIncidence( in ); 2731 cal->addIncidence( in );
2731 incidence = delSel.next(); 2732 incidence = delSel.next();
2732 } 2733 }
2733 if ( beamDialog->beamVcal() ) { 2734 if ( beamDialog->beamVcal() ) {
2734 fn += ".vcs"; 2735 fn += ".vcs";
2735 FileStorage storage( cal, fn, new VCalFormat ); 2736 FileStorage storage( cal, fn, new VCalFormat );
2736 storage.save(); 2737 storage.save();
2737 } else { 2738 } else {
2738 fn += ".ics"; 2739 fn += ".ics";
2739 FileStorage storage( cal, fn, new ICalFormat( ) ); 2740 FileStorage storage( cal, fn, new ICalFormat( ) );
2740 storage.save(); 2741 storage.save();
2741 } 2742 }
2742 delete cal; 2743 delete cal;
2743 mes = i18n("KO/Pi: Ready for beaming"); 2744 mes = i18n("KO/Pi: Ready for beaming");
2744 topLevelWidget()->setCaption(mes); 2745 topLevelWidget()->setCaption(mes);
2745 KApplication::convert2latin1( fn ); 2746 KApplication::convert2latin1( fn );
2746#ifndef DESKTOP_VERSION 2747#ifndef DESKTOP_VERSION
2747 Ir *ir = new Ir( this ); 2748 Ir *ir = new Ir( this );
2748 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2749 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2749 ir->send( fn, description, "text/x-vCalendar" ); 2750 ir->send( fn, description, "text/x-vCalendar" );
2750#endif 2751#endif
2751 } 2752 }
2752} 2753}
2753void CalendarView::beamDone( Ir *ir ) 2754void CalendarView::beamDone( Ir *ir )
2754{ 2755{
2755#ifndef DESKTOP_VERSION 2756#ifndef DESKTOP_VERSION
2756 delete ir; 2757 delete ir;
2757#endif 2758#endif
2758 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 2759 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
2759 topLevelWidget()->raise(); 2760 topLevelWidget()->raise();
2760} 2761}
2761 2762
2762void CalendarView::moveIncidence(Incidence * inc ) 2763void CalendarView::moveIncidence(Incidence * inc )
2763{ 2764{
2764 if ( !inc ) return; 2765 if ( !inc ) return;
2765 showDatePickerPopup(); 2766 showDatePickerPopup();
2766 mDatePickerMode = 2; 2767 mDatePickerMode = 2;
2767 mMoveIncidence = inc ; 2768 mMoveIncidence = inc ;
2768 QDate da; 2769 QDate da;
2769 if ( mMoveIncidence->type() == "Todo" ) { 2770 if ( mMoveIncidence->type() == "Todo" ) {
2770 Todo * to = (Todo *) mMoveIncidence; 2771 Todo * to = (Todo *) mMoveIncidence;
2771 if ( to->hasDueDate() ) 2772 if ( to->hasDueDate() )
2772 da = to->dtDue().date(); 2773 da = to->dtDue().date();
2773 else 2774 else
2774 da = QDate::currentDate(); 2775 da = QDate::currentDate();
2775 } else { 2776 } else {
2776 da = mMoveIncidence->dtStart().date(); 2777 da = mMoveIncidence->dtStart().date();
2777 } 2778 }
2778 //PENDING set date for recurring incidence to date of recurrence 2779 //PENDING set date for recurring incidence to date of recurrence
2779 //mMoveIncidenceOldDate; 2780 //mMoveIncidenceOldDate;
2780 mDatePicker->setDate( da ); 2781 mDatePicker->setDate( da );
2781} 2782}
2782void CalendarView::showDatePickerPopup() 2783void CalendarView::showDatePickerPopup()
2783{ 2784{
2784 if ( mDateFrame->isVisible() ) 2785 if ( mDateFrame->isVisible() )
2785 mDateFrame->hide(); 2786 mDateFrame->hide();
2786 else { 2787 else {
2787 int offX = 0, offY = 0; 2788 int offX = 0, offY = 0;
2788#ifdef DESKTOP_VERSION 2789#ifdef DESKTOP_VERSION
2789 int w =mDatePicker->sizeHint().width() ; 2790 int w =mDatePicker->sizeHint().width() ;
2790 int h = mDatePicker->sizeHint().height() ; 2791 int h = mDatePicker->sizeHint().height() ;
2791 int dw = topLevelWidget()->width(); 2792 int dw = topLevelWidget()->width();
2792 int dh = topLevelWidget()->height(); 2793 int dh = topLevelWidget()->height();
2793 offX = topLevelWidget()->x(); 2794 offX = topLevelWidget()->x();
2794 offY = topLevelWidget()->y(); 2795 offY = topLevelWidget()->y();
2795#else 2796#else
2796 int w =mDatePicker->sizeHint().width() ; 2797 int w =mDatePicker->sizeHint().width() ;
2797 int h = mDatePicker->sizeHint().height() ; 2798 int h = mDatePicker->sizeHint().height() ;
2798 int dw = QApplication::desktop()->width(); 2799 int dw = QApplication::desktop()->width();
2799 int dh = QApplication::desktop()->height(); 2800 int dh = QApplication::desktop()->height();
2800#endif 2801#endif
2801 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h ); 2802 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h );
2802 mDateFrame->show(); 2803 mDateFrame->show();
2803 } 2804 }
2804} 2805}
2805void CalendarView::showDatePicker( ) 2806void CalendarView::showDatePicker( )
2806{ 2807{
2807 showDatePickerPopup(); 2808 showDatePickerPopup();
2808 mDatePickerMode = 1; 2809 mDatePickerMode = 1;
2809 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2810 mDatePicker->setDate( mNavigator->selectedDates().first() );
2810} 2811}
2811 2812
2812void CalendarView::showEventEditor() 2813void CalendarView::showEventEditor()
2813{ 2814{
2814#ifdef DESKTOP_VERSION 2815#ifdef DESKTOP_VERSION
2815 int x,y,w,h; 2816 int x,y,w,h;
2816 x = mEventEditor->geometry().x(); 2817 x = mEventEditor->geometry().x();
2817 y = mEventEditor->geometry().y(); 2818 y = mEventEditor->geometry().y();
2818 w = mEventEditor->width(); 2819 w = mEventEditor->width();
2819 h = mEventEditor->height(); 2820 h = mEventEditor->height();
2820 mEventEditor->show(); 2821 mEventEditor->show();
2821 mEventEditor->setGeometry(x,y,w,h); 2822 mEventEditor->setGeometry(x,y,w,h);
2822#else 2823#else
2823 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 2824 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
2824 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 2825 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
2825 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 2826 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
2826 qApp->processEvents(); 2827 qApp->processEvents();
2827 delete mEventEditor; 2828 delete mEventEditor;
2828 mEventEditor = mDialogManager->getEventEditor(); 2829 mEventEditor = mDialogManager->getEventEditor();
2829 topLevelWidget()->setCaption( i18n("") ); 2830 topLevelWidget()->setCaption( i18n("") );
2830 } 2831 }
2831 mEventEditor->showMaximized(); 2832 mEventEditor->showMaximized();
2832#endif 2833#endif
2833} 2834}
2834void CalendarView::showTodoEditor() 2835void CalendarView::showTodoEditor()
2835{ 2836{
2836#ifdef DESKTOP_VERSION 2837#ifdef DESKTOP_VERSION
2837 int x,y,w,h; 2838 int x,y,w,h;
2838 x = mTodoEditor->geometry().x(); 2839 x = mTodoEditor->geometry().x();
2839 y = mTodoEditor->geometry().y(); 2840 y = mTodoEditor->geometry().y();
2840 w = mTodoEditor->width(); 2841 w = mTodoEditor->width();
2841 h = mTodoEditor->height(); 2842 h = mTodoEditor->height();
2842 mTodoEditor->show(); 2843 mTodoEditor->show();
2843 mTodoEditor->setGeometry(x,y,w,h); 2844 mTodoEditor->setGeometry(x,y,w,h);
2844#else 2845#else
2845 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 2846 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
2846 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 2847 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
2847 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 2848 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
2848 qApp->processEvents(); 2849 qApp->processEvents();
2849 delete mTodoEditor; 2850 delete mTodoEditor;
2850 mTodoEditor = mDialogManager->getTodoEditor(); 2851 mTodoEditor = mDialogManager->getTodoEditor();
2851 topLevelWidget()->setCaption( i18n("") ); 2852 topLevelWidget()->setCaption( i18n("") );
2852 } 2853 }
2853 mTodoEditor->showMaximized(); 2854 mTodoEditor->showMaximized();
2854#endif 2855#endif
2855} 2856}
2856 2857
2857void CalendarView::cloneIncidence() 2858void CalendarView::cloneIncidence()
2858{ 2859{
2859 Incidence *incidence = currentSelection(); 2860 Incidence *incidence = currentSelection();
2860 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2861 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2861 if ( incidence ) { 2862 if ( incidence ) {
2862 cloneIncidence(incidence); 2863 cloneIncidence(incidence);
2863 } 2864 }
2864} 2865}
2865void CalendarView::moveIncidence() 2866void CalendarView::moveIncidence()
2866{ 2867{
2867 Incidence *incidence = currentSelection(); 2868 Incidence *incidence = currentSelection();
2868 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2869 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2869 if ( incidence ) { 2870 if ( incidence ) {
2870 moveIncidence(incidence); 2871 moveIncidence(incidence);
2871 } 2872 }
2872} 2873}
2873void CalendarView::beamIncidence() 2874void CalendarView::beamIncidence()
2874{ 2875{
2875 Incidence *incidence = currentSelection(); 2876 Incidence *incidence = currentSelection();
2876 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2877 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2877 if ( incidence ) { 2878 if ( incidence ) {
2878 beamIncidence(incidence); 2879 beamIncidence(incidence);
2879 } 2880 }
2880} 2881}
2881void CalendarView::toggleCancelIncidence() 2882void CalendarView::toggleCancelIncidence()
2882{ 2883{
2883 Incidence *incidence = currentSelection(); 2884 Incidence *incidence = currentSelection();
2884 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2885 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2885 if ( incidence ) { 2886 if ( incidence ) {
2886 cancelIncidence(incidence); 2887 cancelIncidence(incidence);
2887 } 2888 }
2888} 2889}
2889 2890
2890 2891
2891void CalendarView::cancelIncidence(Incidence * inc ) 2892void CalendarView::cancelIncidence(Incidence * inc )
2892{ 2893{
2893 inc->setCancelled( ! inc->cancelled() ); 2894 inc->setCancelled( ! inc->cancelled() );
2894 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 2895 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
2895 updateView(); 2896 updateView();
2896} 2897}
2897void CalendarView::cloneIncidence(Incidence * orgInc ) 2898void CalendarView::cloneIncidence(Incidence * orgInc )
2898{ 2899{
2899 Incidence * newInc = orgInc->clone(); 2900 Incidence * newInc = orgInc->clone();
2900 newInc->recreate(); 2901 newInc->recreate();
2901 2902
2902 if ( newInc->type() == "Todo" ) { 2903 if ( newInc->type() == "Todo" ) {
2903 Todo* t = (Todo*) newInc; 2904 Todo* t = (Todo*) newInc;
2904 bool cloneSub = false; 2905 bool cloneSub = false;
2905 if ( orgInc->relations().count() ) { 2906 if ( orgInc->relations().count() ) {
2906 int result = KMessageBox::warningYesNoCancel(this, 2907 int result = KMessageBox::warningYesNoCancel(this,
2907 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( newInc->summary().left ( 25 ) ), 2908 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( newInc->summary().left ( 25 ) ),
2908 i18n("Todo has subtodos"), 2909 i18n("Todo has subtodos"),
2909 i18n("Yes"), 2910 i18n("Yes"),
2910 i18n("No")); 2911 i18n("No"));
2911 2912
2912 if ( result == KMessageBox::Cancel ) { 2913 if ( result == KMessageBox::Cancel ) {
2913 delete t; 2914 delete t;
2914 return; 2915 return;
2915 } 2916 }
2916 if (result == KMessageBox::Yes) cloneSub = true; 2917 if (result == KMessageBox::Yes) cloneSub = true;
2917 } 2918 }
2918 showTodoEditor(); 2919 showTodoEditor();
2919 mTodoEditor->editTodo( t ); 2920 mTodoEditor->editTodo( t );
2920 if ( mTodoEditor->exec() ) { 2921 if ( mTodoEditor->exec() ) {
2921 if ( cloneSub ) { 2922 if ( cloneSub ) {
2922 orgInc->cloneRelations( t ); 2923 orgInc->cloneRelations( t );
2923 mCalendar->addIncidenceBranch( t ); 2924 mCalendar->addIncidenceBranch( t );
2924 updateView(); 2925 updateView();
2925 2926
2926 } else { 2927 } else {
2927 mCalendar->addTodo( t ); 2928 mCalendar->addTodo( t );
2928 updateView(); 2929 updateView();
2929 } 2930 }
2930 } else { 2931 } else {
2931 delete t; 2932 delete t;
2932 } 2933 }
2933 } 2934 }
2934 else { 2935 else {
2935 Event* e = (Event*) newInc; 2936 Event* e = (Event*) newInc;
2936 showEventEditor(); 2937 showEventEditor();
2937 mEventEditor->editEvent( e ); 2938 mEventEditor->editEvent( e );
2938 if ( mEventEditor->exec() ) { 2939 if ( mEventEditor->exec() ) {
2939 mCalendar->addEvent( e ); 2940 mCalendar->addEvent( e );
2940 updateView(); 2941 updateView();
2941 } else { 2942 } else {
2942 delete e; 2943 delete e;
2943 } 2944 }
2944 } 2945 }
2945 setActiveWindow(); 2946 setActiveWindow();
2946} 2947}
2947 2948
2948void CalendarView::newEvent() 2949void CalendarView::newEvent()
2949{ 2950{
2950 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 2951 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
2951 KOAgendaView *aView = mViewManager->agendaView(); 2952 KOAgendaView *aView = mViewManager->agendaView();
2952 if (aView) { 2953 if (aView) {
2953 if (aView->selectionStart().isValid()) { 2954 if (aView->selectionStart().isValid()) {
2954 if (aView->selectedIsAllDay()) { 2955 if (aView->selectedIsAllDay()) {
2955 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 2956 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
2956 } else { 2957 } else {
2957 newEvent(aView->selectionStart(),aView->selectionEnd()); 2958 newEvent(aView->selectionStart(),aView->selectionEnd());
2958 } 2959 }
2959 return; 2960 return;
2960 } 2961 }
2961 } 2962 }
2962 2963
2963 QDate date = mNavigator->selectedDates().first(); 2964 QDate date = mNavigator->selectedDates().first();
2964 QDateTime current = QDateTime::currentDateTime(); 2965 QDateTime current = QDateTime::currentDateTime();
2965 if ( date <= current.date() ) { 2966 if ( date <= current.date() ) {
2966 int hour = current.time().hour() +1; 2967 int hour = current.time().hour() +1;
2967 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 2968 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
2968 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2969 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2969 } else 2970 } else
2970 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 2971 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
2971 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 2972 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
2972 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2973 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2973} 2974}
2974 2975
2975void CalendarView::newEvent(QDateTime fh) 2976void CalendarView::newEvent(QDateTime fh)
2976{ 2977{
2977 newEvent(fh, 2978 newEvent(fh,
2978 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 2979 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
2979} 2980}
2980 2981
2981void CalendarView::newEvent(QDate dt) 2982void CalendarView::newEvent(QDate dt)
2982{ 2983{
2983 newEvent(QDateTime(dt, QTime(0,0,0)), 2984 newEvent(QDateTime(dt, QTime(0,0,0)),
2984 QDateTime(dt, QTime(0,0,0)), true); 2985 QDateTime(dt, QTime(0,0,0)), true);
2985} 2986}
2986void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) 2987void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
2987{ 2988{
2988 newEvent(fromHint, toHint, false); 2989 newEvent(fromHint, toHint, false);
2989} 2990}
2990void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 2991void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
2991{ 2992{
2992 2993
2993 showEventEditor(); 2994 showEventEditor();
2994 mEventEditor->newEvent(fromHint,toHint,allDay); 2995 mEventEditor->newEvent(fromHint,toHint,allDay);
2995 if ( mFilterView->filtersEnabled() ) { 2996 if ( mFilterView->filtersEnabled() ) {
2996 CalFilter *filter = mFilterView->selectedFilter(); 2997 CalFilter *filter = mFilterView->selectedFilter();
2997 if (filter && filter->showCategories()) { 2998 if (filter && filter->showCategories()) {
2998 mEventEditor->setCategories(filter->categoryList().join(",") ); 2999 mEventEditor->setCategories(filter->categoryList().join(",") );
2999 } 3000 }
3000 if ( filter ) 3001 if ( filter )
3001 mEventEditor->setSecrecy( filter->getSecrecy() ); 3002 mEventEditor->setSecrecy( filter->getSecrecy() );
3002 } 3003 }
3003 mEventEditor->exec(); 3004 mEventEditor->exec();
3004 setActiveWindow(); 3005 setActiveWindow();
3005} 3006}
3006void CalendarView::todoAdded(Todo * t) 3007void CalendarView::todoAdded(Todo * t)
3007{ 3008{
3008 3009
3009 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 3010 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
3010 updateTodoViews(); 3011 updateTodoViews();
3011} 3012}
3012void CalendarView::todoChanged(Todo * t) 3013void CalendarView::todoChanged(Todo * t)
3013{ 3014{
3014 emit todoModified( t, 4 ); 3015 emit todoModified( t, 4 );
3015 // updateTodoViews(); 3016 // updateTodoViews();
3016} 3017}
3017void CalendarView::todoToBeDeleted(Todo *) 3018void CalendarView::todoToBeDeleted(Todo *)
3018{ 3019{
3019 //qDebug("todoToBeDeleted(Todo *) "); 3020 //qDebug("todoToBeDeleted(Todo *) ");
3020 updateTodoViews(); 3021 updateTodoViews();
3021} 3022}
3022void CalendarView::todoDeleted() 3023void CalendarView::todoDeleted()
3023{ 3024{
3024 //qDebug(" todoDeleted()"); 3025 //qDebug(" todoDeleted()");
3025 updateTodoViews(); 3026 updateTodoViews();
3026} 3027}
3027 3028
3028 3029
3029void CalendarView::newTodoDateTime( QDateTime dt, bool allday ) 3030void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
3030{ 3031{
3031 showTodoEditor(); 3032 showTodoEditor();
3032 mTodoEditor->newTodo(dt,0,allday); 3033 mTodoEditor->newTodo(dt,0,allday);
3033 if ( mFilterView->filtersEnabled() ) { 3034 if ( mFilterView->filtersEnabled() ) {
3034 CalFilter *filter = mFilterView->selectedFilter(); 3035 CalFilter *filter = mFilterView->selectedFilter();
3035 if (filter && filter->showCategories()) { 3036 if (filter && filter->showCategories()) {
3036 mTodoEditor->setCategories(filter->categoryList().join(",") ); 3037 mTodoEditor->setCategories(filter->categoryList().join(",") );
3037 } 3038 }
3038 if ( filter ) 3039 if ( filter )
3039 mTodoEditor->setSecrecy( filter->getSecrecy() ); 3040 mTodoEditor->setSecrecy( filter->getSecrecy() );
3040 } 3041 }
3041 mTodoEditor->exec(); 3042 mTodoEditor->exec();
3042 setActiveWindow(); 3043 setActiveWindow();
3043} 3044}
3044 3045
3045void CalendarView::newTodo() 3046void CalendarView::newTodo()
3046{ 3047{
3047 newTodoDateTime( QDateTime(),true ); 3048 newTodoDateTime( QDateTime(),true );
3048} 3049}
3049 3050
3050void CalendarView::newSubTodo() 3051void CalendarView::newSubTodo()
3051{ 3052{
3052 Todo *todo = selectedTodo(); 3053 Todo *todo = selectedTodo();
3053 if ( todo ) newSubTodo( todo ); 3054 if ( todo ) newSubTodo( todo );
3054} 3055}
3055 3056
3056void CalendarView::newSubTodo(Todo *parentEvent) 3057void CalendarView::newSubTodo(Todo *parentEvent)
3057{ 3058{
3058 3059
3059 showTodoEditor(); 3060 showTodoEditor();
3060 mTodoEditor->newTodo(QDateTime(),parentEvent,true); 3061 mTodoEditor->newTodo(QDateTime(),parentEvent,true);
3061 mTodoEditor->exec(); 3062 mTodoEditor->exec();
3062 setActiveWindow(); 3063 setActiveWindow();
3063} 3064}
3064 3065
3065void CalendarView::newFloatingEvent() 3066void CalendarView::newFloatingEvent()
3066{ 3067{
3067 DateList tmpList = mNavigator->selectedDates(); 3068 DateList tmpList = mNavigator->selectedDates();
3068 QDate date = tmpList.first(); 3069 QDate date = tmpList.first();
3069 3070
3070 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 3071 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
3071 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 3072 QDateTime( date, QTime( 12, 0, 0 ) ), true );
3072} 3073}
3073 3074
3074 3075
3075void CalendarView::editEvent( Event *event ) 3076void CalendarView::editEvent( Event *event )
3076{ 3077{
3077 3078
3078 if ( !event ) return; 3079 if ( !event ) return;
3079 if ( event->isReadOnly() ) { 3080 if ( event->isReadOnly() ) {
3080 showEvent( event ); 3081 showEvent( event );
3081 return; 3082 return;
3082 } 3083 }
3083 showEventEditor(); 3084 showEventEditor();
3084 mEventEditor->editEvent( event , mFlagEditDescription); 3085 mEventEditor->editEvent( event , mFlagEditDescription);
3085 mEventEditor->exec(); 3086 mEventEditor->exec();
3086 setActiveWindow(); 3087 setActiveWindow();
3087 3088
3088} 3089}
3089void CalendarView::editJournal( Journal *jour ) 3090void CalendarView::editJournal( Journal *jour )
3090{ 3091{
3091 if ( !jour ) return; 3092 if ( !jour ) return;
3092 mDialogManager->hideSearchDialog(); 3093 mDialogManager->hideSearchDialog();
3093 mViewManager->showJournalView(); 3094 mViewManager->showJournalView();
3094 mNavigator->slotDaySelect( jour->dtStart().date() ); 3095 mNavigator->slotDaySelect( jour->dtStart().date() );
3095} 3096}
3096void CalendarView::editTodo( Todo *todo ) 3097void CalendarView::editTodo( Todo *todo )
3097{ 3098{
3098 if ( !todo ) return; 3099 if ( !todo ) return;
3099 3100
3100 if ( todo->isReadOnly() ) { 3101 if ( todo->isReadOnly() ) {
3101 showTodo( todo ); 3102 showTodo( todo );
3102 return; 3103 return;
3103 } 3104 }
3104 showTodoEditor(); 3105 showTodoEditor();
3105 mTodoEditor->editTodo( todo ,mFlagEditDescription); 3106 mTodoEditor->editTodo( todo ,mFlagEditDescription);
3106 mTodoEditor->exec(); 3107 mTodoEditor->exec();
3107 setActiveWindow(); 3108 setActiveWindow();
3108 3109
3109} 3110}
3110 3111
3111KOEventViewerDialog* CalendarView::getEventViewerDialog() 3112KOEventViewerDialog* CalendarView::getEventViewerDialog()
3112{ 3113{
3113 if ( !mEventViewerDialog ) { 3114 if ( !mEventViewerDialog ) {
3114 mEventViewerDialog = new KOEventViewerDialog(0); 3115 mEventViewerDialog = new KOEventViewerDialog(0);
3115 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 3116 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
3116 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 3117 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
3117 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 3118 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
3118 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 3119 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
3119 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 3120 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
3120 viewManager(), SLOT( showAgendaView( bool ) ) ); 3121 viewManager(), SLOT( showAgendaView( bool ) ) );
3121 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()), 3122 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()),
3122 this, SLOT( slotViewerClosed() ) ); 3123 this, SLOT( slotViewerClosed() ) );
3123 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 3124 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
3124 this, SLOT( todoChanged(Todo *) ) ); 3125 this, SLOT( todoChanged(Todo *) ) );
3125 mEventViewerDialog->resize( 640, 480 ); 3126 mEventViewerDialog->resize( 640, 480 );
3126 3127
3127 } 3128 }
3128 return mEventViewerDialog; 3129 return mEventViewerDialog;
3129} 3130}
3130void CalendarView::showEvent(Event *event) 3131void CalendarView::showEvent(Event *event)
3131{ 3132{
3132 getEventViewerDialog()->setEvent(event); 3133 getEventViewerDialog()->setEvent(event);
3133 getEventViewerDialog()->showMe(); 3134 getEventViewerDialog()->showMe();
3134} 3135}
3135 3136
3136void CalendarView::showTodo(Todo *event) 3137void CalendarView::showTodo(Todo *event)
3137{ 3138{
3138 getEventViewerDialog()->setTodo(event); 3139 getEventViewerDialog()->setTodo(event);
3139 getEventViewerDialog()->showMe(); 3140 getEventViewerDialog()->showMe();
3140} 3141}
3141void CalendarView::showJournal( Journal *jour ) 3142void CalendarView::showJournal( Journal *jour )
3142{ 3143{
3143 getEventViewerDialog()->setJournal(jour); 3144 getEventViewerDialog()->setJournal(jour);
3144 getEventViewerDialog()->showMe(); 3145 getEventViewerDialog()->showMe();
3145 3146
3146} 3147}
3147// void CalendarView::todoModified (Todo *event, int changed) 3148// void CalendarView::todoModified (Todo *event, int changed)
3148// { 3149// {
3149// // if (mDialogList.find (event) != mDialogList.end ()) { 3150// // if (mDialogList.find (event) != mDialogList.end ()) {
3150// // kdDebug() << "Todo modified and open" << endl; 3151// // kdDebug() << "Todo modified and open" << endl;
3151// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 3152// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
3152// // temp->modified (changed); 3153// // temp->modified (changed);
3153 3154
3154// // } 3155// // }
3155 3156
3156// mViewManager->updateView(); 3157// mViewManager->updateView();
3157// } 3158// }
3158 3159
3159void CalendarView::appointment_show() 3160void CalendarView::appointment_show()
3160{ 3161{
3161 Event *anEvent = 0; 3162 Event *anEvent = 0;
3162 3163
3163 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3164 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3164 3165
3165 if (mViewManager->currentView()->isEventView()) { 3166 if (mViewManager->currentView()->isEventView()) {
3166 if ( incidence && incidence->type() == "Event" ) { 3167 if ( incidence && incidence->type() == "Event" ) {
3167 anEvent = static_cast<Event *>(incidence); 3168 anEvent = static_cast<Event *>(incidence);
3168 } 3169 }
3169 } 3170 }
3170 3171
3171 if (!anEvent) { 3172 if (!anEvent) {
3172 KNotifyClient::beep(); 3173 KNotifyClient::beep();
3173 return; 3174 return;
3174 } 3175 }
3175 3176
3176 showEvent(anEvent); 3177 showEvent(anEvent);
3177} 3178}
3178 3179
3179void CalendarView::appointment_edit() 3180void CalendarView::appointment_edit()
3180{ 3181{
3181 Event *anEvent = 0; 3182 Event *anEvent = 0;
3182 3183
3183 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3184 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3184 3185
3185 if (mViewManager->currentView()->isEventView()) { 3186 if (mViewManager->currentView()->isEventView()) {
3186 if ( incidence && incidence->type() == "Event" ) { 3187 if ( incidence && incidence->type() == "Event" ) {
3187 anEvent = static_cast<Event *>(incidence); 3188 anEvent = static_cast<Event *>(incidence);
3188 } 3189 }
3189 } 3190 }
3190 3191
3191 if (!anEvent) { 3192 if (!anEvent) {
3192 KNotifyClient::beep(); 3193 KNotifyClient::beep();
3193 return; 3194 return;
3194 } 3195 }
3195 3196
3196 editEvent(anEvent); 3197 editEvent(anEvent);
3197} 3198}
3198 3199
3199void CalendarView::appointment_delete() 3200void CalendarView::appointment_delete()
3200{ 3201{
3201 Event *anEvent = 0; 3202 Event *anEvent = 0;
3202 3203
3203 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3204 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3204 3205
3205 if (mViewManager->currentView()->isEventView()) { 3206 if (mViewManager->currentView()->isEventView()) {
3206 if ( incidence && incidence->type() == "Event" ) { 3207 if ( incidence && incidence->type() == "Event" ) {
3207 anEvent = static_cast<Event *>(incidence); 3208 anEvent = static_cast<Event *>(incidence);
3208 } 3209 }
3209 } 3210 }
3210 3211
3211 if (!anEvent) { 3212 if (!anEvent) {
3212 KNotifyClient::beep(); 3213 KNotifyClient::beep();
3213 return; 3214 return;
3214 } 3215 }
3215 3216
3216 deleteEvent(anEvent); 3217 deleteEvent(anEvent);
3217} 3218}
3218 3219
3219void CalendarView::todo_resub( Todo * parent, Todo * sub ) 3220void CalendarView::todo_resub( Todo * parent, Todo * sub )
3220{ 3221{
3221 if (!sub) return; 3222 if (!sub) return;
3222 if ( sub->relatedTo() == parent ) 3223 if ( sub->relatedTo() == parent )
3223 return; 3224 return;
3224 sub->setRelatedTo(parent); 3225 sub->setRelatedTo(parent);
3225 sub->updated(); 3226 sub->updated();
3226 setModified(true); 3227 setModified(true);
3227 updateView(); 3228 updateView();
3228} 3229}
3229void CalendarView::todo_unsub(Todo *anTodo ) 3230void CalendarView::todo_unsub(Todo *anTodo )
3230{ 3231{
3231 todo_resub( 0, anTodo ); 3232 todo_resub( 0, anTodo );
3232} 3233}
3233 3234
3234void CalendarView::deleteTodo(Todo *todo) 3235void CalendarView::deleteTodo(Todo *todo)
3235{ 3236{
3236 if (!todo) { 3237 if (!todo) {
3237 KNotifyClient::beep(); 3238 KNotifyClient::beep();
3238 return; 3239 return;
3239 } 3240 }
3240 if (KOPrefs::instance()->mConfirm) { 3241 if (KOPrefs::instance()->mConfirm) {
3241 QString text = todo->summary().left(20); 3242 QString text = todo->summary().left(20);
3242 if (!todo->relations().isEmpty()) { 3243 if (!todo->relations().isEmpty()) {
3243 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 3244 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
3244 3245
3245 } 3246 }
3246 switch (msgItemDelete(text)) { 3247 switch (msgItemDelete(text)) {
3247 case KMessageBox::Continue: // OK 3248 case KMessageBox::Continue: // OK
3248 bool deleteT = false; 3249 bool deleteT = false;
3249 if (!todo->relations().isEmpty()) { 3250 if (!todo->relations().isEmpty()) {
3250 deleteT = removeCompletedSubTodos( todo ); 3251 deleteT = removeCompletedSubTodos( todo );
3251 } 3252 }
3252 // deleteT == true: todo already deleted in removeCompletedSubTodos 3253 // deleteT == true: todo already deleted in removeCompletedSubTodos
3253 if ( !deleteT ) { 3254 if ( !deleteT ) {
3254 checkExternalId( todo ); 3255 checkExternalId( todo );
3255 calendar()->deleteTodo(todo); 3256 calendar()->deleteTodo(todo);
3256 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3257 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3257 updateView(); 3258 updateView();
3258 } 3259 }
3259 break; 3260 break;
3260 } // switch 3261 } // switch
3261 } else { 3262 } else {
3262 checkExternalId( todo ); 3263 checkExternalId( todo );
3263 mCalendar->deleteTodo(todo); 3264 mCalendar->deleteTodo(todo);
3264 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3265 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3265 updateView(); 3266 updateView();
3266 } 3267 }
3267 3268
3268 emit updateSearchDialog(); 3269 emit updateSearchDialog();
3269} 3270}
3270void CalendarView::deleteJournal(Journal *jour) 3271void CalendarView::deleteJournal(Journal *jour)
3271{ 3272{
3272 if (!jour) { 3273 if (!jour) {
3273 KNotifyClient::beep(); 3274 KNotifyClient::beep();
3274 return; 3275 return;
3275 } 3276 }
3276 if (KOPrefs::instance()->mConfirm) { 3277 if (KOPrefs::instance()->mConfirm) {
3277 switch (msgItemDelete( jour->description().left(20))) { 3278 switch (msgItemDelete( jour->description().left(20))) {
3278 case KMessageBox::Continue: // OK 3279 case KMessageBox::Continue: // OK
3279 calendar()->deleteJournal(jour); 3280 calendar()->deleteJournal(jour);
3280 updateView(); 3281 updateView();
3281 break; 3282 break;
3282 } // switch 3283 } // switch
3283 } else { 3284 } else {
3284 calendar()->deleteJournal(jour);; 3285 calendar()->deleteJournal(jour);;
3285 updateView(); 3286 updateView();
3286 } 3287 }
3287 emit updateSearchDialog(); 3288 emit updateSearchDialog();
3288} 3289}
3289 3290
3290void CalendarView::deleteEvent(Event *anEvent) 3291void CalendarView::deleteEvent(Event *anEvent)
3291{ 3292{
3292 if (!anEvent) { 3293 if (!anEvent) {
3293 KNotifyClient::beep(); 3294 KNotifyClient::beep();
3294 return; 3295 return;
3295 } 3296 }
3296 3297
3297 if (anEvent->recurrence()->doesRecur()) { 3298 if (anEvent->recurrence()->doesRecur()) {
3298 QDate itemDate = mViewManager->currentSelectionDate(); 3299 QDate itemDate = mViewManager->currentSelectionDate();
3299 int km; 3300 int km;
3300 if (!itemDate.isValid()) { 3301 if (!itemDate.isValid()) {
3301 //kdDebug() << "Date Not Valid" << endl; 3302 //kdDebug() << "Date Not Valid" << endl;
3302 if (KOPrefs::instance()->mConfirm) { 3303 if (KOPrefs::instance()->mConfirm) {
3303 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 3304 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
3304 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 3305 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
3305 i18n("KO/Pi Confirmation"),i18n("Delete All")); 3306 i18n("KO/Pi Confirmation"),i18n("Delete All"));
3306 if ( km == KMessageBox::Continue ) 3307 if ( km == KMessageBox::Continue )
3307 km = KMessageBox::No; // No = all below 3308 km = KMessageBox::No; // No = all below
3308 } else 3309 } else
3309 km = KMessageBox::No; 3310 km = KMessageBox::No;
3310 } else { 3311 } else {
3311 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) + 3312 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) +
3312 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 3313 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
3313 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 3314 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
3314 i18n("KO/Pi Confirmation"),i18n("Current"), 3315 i18n("KO/Pi Confirmation"),i18n("Current"),
3315 i18n("All")); 3316 i18n("All"));
3316 } 3317 }
3317 switch(km) { 3318 switch(km) {
3318 3319
3319 case KMessageBox::No: // Continue // all 3320 case KMessageBox::No: // Continue // all
3320 //qDebug("KMessageBox::No "); 3321 //qDebug("KMessageBox::No ");
3321 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3322 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3322 schedule(Scheduler::Cancel,anEvent); 3323 schedule(Scheduler::Cancel,anEvent);
3323 3324
3324 checkExternalId( anEvent); 3325 checkExternalId( anEvent);
3325 mCalendar->deleteEvent(anEvent); 3326 mCalendar->deleteEvent(anEvent);
3326 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 3327 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
3327 break; 3328 break;
3328 3329
3329 // Disabled because it does not work 3330 // Disabled because it does not work
3330 //#if 0 3331 //#if 0
3331 case KMessageBox::Yes: // just this one 3332 case KMessageBox::Yes: // just this one
3332 //QDate qd = mNavigator->selectedDates().first(); 3333 //QDate qd = mNavigator->selectedDates().first();
3333 //if (!qd.isValid()) { 3334 //if (!qd.isValid()) {
3334 // kdDebug() << "no date selected, or invalid date" << endl; 3335 // kdDebug() << "no date selected, or invalid date" << endl;
3335 // KNotifyClient::beep(); 3336 // KNotifyClient::beep();
3336 // return; 3337 // return;
3337 //} 3338 //}
3338 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 3339 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
3339 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 3340 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
3340 anEvent->addExDate(itemDate); 3341 anEvent->addExDate(itemDate);
3341 int duration = anEvent->recurrence()->duration(); 3342 int duration = anEvent->recurrence()->duration();
3342 if ( duration > 0 ) { 3343 if ( duration > 0 ) {
3343 anEvent->recurrence()->setDuration( duration - 1 ); 3344 anEvent->recurrence()->setDuration( duration - 1 );
3344 } 3345 }
3345 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 3346 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
3346 } 3347 }
3347 break; 3348 break;
3348 //#endif 3349 //#endif
3349 } // switch 3350 } // switch
3350 } else { 3351 } else {
3351 if (KOPrefs::instance()->mConfirm) { 3352 if (KOPrefs::instance()->mConfirm) {
3352 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 3353 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
3353 i18n("\nAre you sure you want\nto delete this event?"), 3354 i18n("\nAre you sure you want\nto delete this event?"),
3354 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 3355 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
3355 case KMessageBox::Continue: // OK 3356 case KMessageBox::Continue: // OK
3356 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3357 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3357 schedule(Scheduler::Cancel,anEvent); 3358 schedule(Scheduler::Cancel,anEvent);
3358 checkExternalId( anEvent); 3359 checkExternalId( anEvent);
3359 mCalendar->deleteEvent(anEvent); 3360 mCalendar->deleteEvent(anEvent);
3360 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3361 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3361 break; 3362 break;
3362 } // switch 3363 } // switch
3363 } else { 3364 } else {
3364 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3365 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3365 schedule(Scheduler::Cancel,anEvent); 3366 schedule(Scheduler::Cancel,anEvent);
3366 checkExternalId( anEvent); 3367 checkExternalId( anEvent);
3367 mCalendar->deleteEvent(anEvent); 3368 mCalendar->deleteEvent(anEvent);
3368 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3369 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3369 } 3370 }
3370 } // if-else 3371 } // if-else
3371 emit updateSearchDialog(); 3372 emit updateSearchDialog();
3372} 3373}
3373 3374
3374bool CalendarView::deleteEvent(const QString &uid) 3375bool CalendarView::deleteEvent(const QString &uid)
3375{ 3376{
3376 Event *ev = mCalendar->event(uid); 3377 Event *ev = mCalendar->event(uid);
3377 if (ev) { 3378 if (ev) {
3378 deleteEvent(ev); 3379 deleteEvent(ev);
3379 return true; 3380 return true;
3380 } else { 3381 } else {
3381 return false; 3382 return false;
3382 } 3383 }
3383} 3384}
3384 3385
3385/*****************************************************************************/ 3386/*****************************************************************************/
3386 3387
3387void CalendarView::action_mail() 3388void CalendarView::action_mail()
3388{ 3389{
3389#ifndef KORG_NOMAIL 3390#ifndef KORG_NOMAIL
3390 KOMailClient mailClient; 3391 KOMailClient mailClient;
3391 3392
3392 Incidence *incidence = currentSelection(); 3393 Incidence *incidence = currentSelection();
3393 3394
3394 if (!incidence) { 3395 if (!incidence) {
3395 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3396 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3396 return; 3397 return;
3397 } 3398 }
3398 if(incidence->attendeeCount() == 0 ) { 3399 if(incidence->attendeeCount() == 0 ) {
3399 KMessageBox::sorry(this, 3400 KMessageBox::sorry(this,
3400 i18n("Can't generate mail:\nNo attendees defined.\n")); 3401 i18n("Can't generate mail:\nNo attendees defined.\n"));
3401 return; 3402 return;
3402 } 3403 }
3403 3404
3404 CalendarLocal cal_tmp; 3405 CalendarLocal cal_tmp;
3405 Event *event = 0; 3406 Event *event = 0;
3406 Event *ev = 0; 3407 Event *ev = 0;
3407 if ( incidence && incidence->type() == "Event" ) { 3408 if ( incidence && incidence->type() == "Event" ) {
3408 event = static_cast<Event *>(incidence); 3409 event = static_cast<Event *>(incidence);
3409 ev = new Event(*event); 3410 ev = new Event(*event);
3410 cal_tmp.addEvent(ev); 3411 cal_tmp.addEvent(ev);
3411 } 3412 }
3412 ICalFormat mForm(); 3413 ICalFormat mForm();
3413 QString attachment = mForm.toString( &cal_tmp ); 3414 QString attachment = mForm.toString( &cal_tmp );
3414 if (ev) delete(ev); 3415 if (ev) delete(ev);
3415 3416
3416 mailClient.mailAttendees(currentSelection(), attachment); 3417 mailClient.mailAttendees(currentSelection(), attachment);
3417 3418
3418#endif 3419#endif
3419 3420
3420#if 0 3421#if 0
3421 Event *anEvent = 0; 3422 Event *anEvent = 0;
3422 if (mViewManager->currentView()->isEventView()) { 3423 if (mViewManager->currentView()->isEventView()) {
3423 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 3424 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
3424 } 3425 }
3425 3426
3426 if (!anEvent) { 3427 if (!anEvent) {
3427 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3428 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3428 return; 3429 return;
3429 } 3430 }
3430 if(anEvent->attendeeCount() == 0 ) { 3431 if(anEvent->attendeeCount() == 0 ) {
3431 KMessageBox::sorry(this, 3432 KMessageBox::sorry(this,
3432 i18n("Can't generate mail:\nNo attendees defined.\n")); 3433 i18n("Can't generate mail:\nNo attendees defined.\n"));
3433 return; 3434 return;
3434 } 3435 }
3435 3436
3436 mailobject.emailEvent(anEvent); 3437 mailobject.emailEvent(anEvent);
3437#endif 3438#endif
3438} 3439}
3439 3440
3440 3441
3441void CalendarView::schedule_publish(Incidence *incidence) 3442void CalendarView::schedule_publish(Incidence *incidence)
3442{ 3443{
3443 Event *event = 0; 3444 Event *event = 0;
3444 Todo *todo = 0; 3445 Todo *todo = 0;
3445 3446
3446 if (incidence == 0) { 3447 if (incidence == 0) {
3447 incidence = mViewManager->currentView()->selectedIncidences().first(); 3448 incidence = mViewManager->currentView()->selectedIncidences().first();
3448 if (incidence == 0) { 3449 if (incidence == 0) {
3449 incidence = mTodoList->selectedIncidences().first(); 3450 incidence = mTodoList->selectedIncidences().first();
3450 } 3451 }
3451 } 3452 }
3452 if ( incidence && incidence->type() == "Event" ) { 3453 if ( incidence && incidence->type() == "Event" ) {
3453 event = static_cast<Event *>(incidence); 3454 event = static_cast<Event *>(incidence);
3454 } else { 3455 } else {
3455 if ( incidence && incidence->type() == "Todo" ) { 3456 if ( incidence && incidence->type() == "Todo" ) {
3456 todo = static_cast<Todo *>(incidence); 3457 todo = static_cast<Todo *>(incidence);
3457 } 3458 }
3458 } 3459 }
3459 3460
3460 if (!event && !todo) { 3461 if (!event && !todo) {
3461 KMessageBox::sorry(this,i18n("No event selected.")); 3462 KMessageBox::sorry(this,i18n("No event selected."));
3462 return; 3463 return;
3463 } 3464 }
3464 3465
3465 PublishDialog *publishdlg = new PublishDialog(); 3466 PublishDialog *publishdlg = new PublishDialog();
3466 if (incidence->attendeeCount()>0) { 3467 if (incidence->attendeeCount()>0) {
3467 QPtrList<Attendee> attendees = incidence->attendees(); 3468 QPtrList<Attendee> attendees = incidence->attendees();
3468 attendees.first(); 3469 attendees.first();
3469 while ( attendees.current()!=0 ) { 3470 while ( attendees.current()!=0 ) {
3470 publishdlg->addAttendee(attendees.current()); 3471 publishdlg->addAttendee(attendees.current());
3471 attendees.next(); 3472 attendees.next();
3472 } 3473 }
3473 } 3474 }
3474 bool send = true; 3475 bool send = true;
3475 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3476 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3476 if ( publishdlg->exec() != QDialog::Accepted ) 3477 if ( publishdlg->exec() != QDialog::Accepted )
3477 send = false; 3478 send = false;
3478 } 3479 }
3479 if ( send ) { 3480 if ( send ) {
3480 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3481 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3481 if ( event ) { 3482 if ( event ) {
3482 Event *ev = new Event(*event); 3483 Event *ev = new Event(*event);
3483 ev->registerObserver(0); 3484 ev->registerObserver(0);
3484 ev->clearAttendees(); 3485 ev->clearAttendees();
3485 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3486 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3486 delete(ev); 3487 delete(ev);
3487 } 3488 }
3488 } else { 3489 } else {
3489 if ( todo ) { 3490 if ( todo ) {
3490 Todo *ev = new Todo(*todo); 3491 Todo *ev = new Todo(*todo);
3491 ev->registerObserver(0); 3492 ev->registerObserver(0);
3492 ev->clearAttendees(); 3493 ev->clearAttendees();
3493 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3494 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3494 delete(ev); 3495 delete(ev);
3495 } 3496 }
3496 } 3497 }
3497 } 3498 }
3498 } 3499 }
3499 delete publishdlg; 3500 delete publishdlg;
3500} 3501}
3501 3502
3502void CalendarView::schedule_request(Incidence *incidence) 3503void CalendarView::schedule_request(Incidence *incidence)
3503{ 3504{
3504 schedule(Scheduler::Request,incidence); 3505 schedule(Scheduler::Request,incidence);
3505} 3506}
3506 3507
3507void CalendarView::schedule_refresh(Incidence *incidence) 3508void CalendarView::schedule_refresh(Incidence *incidence)
3508{ 3509{
3509 schedule(Scheduler::Refresh,incidence); 3510 schedule(Scheduler::Refresh,incidence);
3510} 3511}
3511 3512
3512void CalendarView::schedule_cancel(Incidence *incidence) 3513void CalendarView::schedule_cancel(Incidence *incidence)
3513{ 3514{
3514 schedule(Scheduler::Cancel,incidence); 3515 schedule(Scheduler::Cancel,incidence);
3515} 3516}
3516 3517
3517void CalendarView::schedule_add(Incidence *incidence) 3518void CalendarView::schedule_add(Incidence *incidence)
3518{ 3519{
3519 schedule(Scheduler::Add,incidence); 3520 schedule(Scheduler::Add,incidence);
3520} 3521}
3521 3522
3522void CalendarView::schedule_reply(Incidence *incidence) 3523void CalendarView::schedule_reply(Incidence *incidence)
3523{ 3524{
3524 schedule(Scheduler::Reply,incidence); 3525 schedule(Scheduler::Reply,incidence);
3525} 3526}
3526 3527
3527void CalendarView::schedule_counter(Incidence *incidence) 3528void CalendarView::schedule_counter(Incidence *incidence)
3528{ 3529{
3529 schedule(Scheduler::Counter,incidence); 3530 schedule(Scheduler::Counter,incidence);
3530} 3531}
3531 3532
3532void CalendarView::schedule_declinecounter(Incidence *incidence) 3533void CalendarView::schedule_declinecounter(Incidence *incidence)
3533{ 3534{
3534 schedule(Scheduler::Declinecounter,incidence); 3535 schedule(Scheduler::Declinecounter,incidence);
3535} 3536}
3536 3537
3537void CalendarView::schedule_publish_freebusy(int daysToPublish) 3538void CalendarView::schedule_publish_freebusy(int daysToPublish)
3538{ 3539{
3539 QDateTime start = QDateTime::currentDateTime(); 3540 QDateTime start = QDateTime::currentDateTime();
3540 QDateTime end = start.addDays(daysToPublish); 3541 QDateTime end = start.addDays(daysToPublish);
3541 3542
3542 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 3543 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3543 freebusy->setOrganizer(KOPrefs::instance()->email()); 3544 freebusy->setOrganizer(KOPrefs::instance()->email());
3544 3545
3545 3546
3546 PublishDialog *publishdlg = new PublishDialog(); 3547 PublishDialog *publishdlg = new PublishDialog();
3547 if ( publishdlg->exec() == QDialog::Accepted ) { 3548 if ( publishdlg->exec() == QDialog::Accepted ) {
3548 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3549 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3549 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 3550 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3550 delete(freebusy); 3551 delete(freebusy);
3551 } 3552 }
3552 } 3553 }
3553 delete publishdlg; 3554 delete publishdlg;
3554} 3555}
3555 3556
3556void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 3557void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3557{ 3558{
3558 Event *event = 0; 3559 Event *event = 0;
3559 Todo *todo = 0; 3560 Todo *todo = 0;
3560 3561
3561 if (incidence == 0) { 3562 if (incidence == 0) {
3562 incidence = mViewManager->currentView()->selectedIncidences().first(); 3563 incidence = mViewManager->currentView()->selectedIncidences().first();
3563 if (incidence == 0) { 3564 if (incidence == 0) {
3564 incidence = mTodoList->selectedIncidences().first(); 3565 incidence = mTodoList->selectedIncidences().first();
3565 } 3566 }
3566 } 3567 }
3567 if ( incidence && incidence->type() == "Event" ) { 3568 if ( incidence && incidence->type() == "Event" ) {
3568 event = static_cast<Event *>(incidence); 3569 event = static_cast<Event *>(incidence);
3569 } 3570 }
3570 if ( incidence && incidence->type() == "Todo" ) { 3571 if ( incidence && incidence->type() == "Todo" ) {
3571 todo = static_cast<Todo *>(incidence); 3572 todo = static_cast<Todo *>(incidence);
3572 } 3573 }
3573 3574
3574 if (!event && !todo) { 3575 if (!event && !todo) {
3575 KMessageBox::sorry(this,i18n("No event selected.")); 3576 KMessageBox::sorry(this,i18n("No event selected."));
3576 return; 3577 return;
3577 } 3578 }
3578 3579
3579 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 3580 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
3580 KMessageBox::sorry(this,i18n("The event has no attendees.")); 3581 KMessageBox::sorry(this,i18n("The event has no attendees."));
3581 return; 3582 return;
3582 } 3583 }
3583 3584
3584 Event *ev = 0; 3585 Event *ev = 0;
3585 if (event) ev = new Event(*event); 3586 if (event) ev = new Event(*event);
3586 Todo *to = 0; 3587 Todo *to = 0;
3587 if (todo) to = new Todo(*todo); 3588 if (todo) to = new Todo(*todo);
3588 3589
3589 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 3590 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
3590 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 3591 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
3591 if (!me) { 3592 if (!me) {
3592 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 3593 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
3593 return; 3594 return;
3594 } 3595 }
3595 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 3596 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
3596 StatusDialog *statdlg = new StatusDialog(this); 3597 StatusDialog *statdlg = new StatusDialog(this);
3597 if (!statdlg->exec()==QDialog::Accepted) return; 3598 if (!statdlg->exec()==QDialog::Accepted) return;
3598 me->setStatus( statdlg->status() ); 3599 me->setStatus( statdlg->status() );
3599 delete(statdlg); 3600 delete(statdlg);
3600 } 3601 }
3601 Attendee *menew = new Attendee(*me); 3602 Attendee *menew = new Attendee(*me);
3602 if (ev) { 3603 if (ev) {
3603 ev->clearAttendees(); 3604 ev->clearAttendees();
3604 ev->addAttendee(menew,false); 3605 ev->addAttendee(menew,false);
3605 } else { 3606 } else {
3606 if (to) { 3607 if (to) {
3607 todo->clearAttendees(); 3608 todo->clearAttendees();
3608 todo->addAttendee(menew,false); 3609 todo->addAttendee(menew,false);
3609 } 3610 }
3610 } 3611 }
3611 } 3612 }
3612 3613
3613 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3614 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3614 if (ev) { 3615 if (ev) {
3615 if ( !dlg->addMessage(ev,method) ) delete(ev); 3616 if ( !dlg->addMessage(ev,method) ) delete(ev);
3616 } else { 3617 } else {
3617 if (to) { 3618 if (to) {
3618 if ( !dlg->addMessage(to,method) ) delete(to); 3619 if ( !dlg->addMessage(to,method) ) delete(to);
3619 } 3620 }
3620 } 3621 }
3621} 3622}
3622 3623
3623void CalendarView::openAddressbook() 3624void CalendarView::openAddressbook()
3624{ 3625{
3625 KRun::runCommand("kaddressbook"); 3626 KRun::runCommand("kaddressbook");
3626} 3627}
3627 3628
3628void CalendarView::setModified(bool modified) 3629void CalendarView::setModified(bool modified)
3629{ 3630{
3630 if ( modified ) 3631 if ( modified )
3631 emit signalmodified(); 3632 emit signalmodified();
3632 if (mModified != modified) { 3633 if (mModified != modified) {
3633 mModified = modified; 3634 mModified = modified;
3634 emit modifiedChanged(mModified); 3635 emit modifiedChanged(mModified);
3635 } 3636 }
3636} 3637}
3637 3638
3638bool CalendarView::isReadOnly() 3639bool CalendarView::isReadOnly()
3639{ 3640{
3640 return mReadOnly; 3641 return mReadOnly;
3641} 3642}
3642 3643
3643void CalendarView::setReadOnly(bool readOnly) 3644void CalendarView::setReadOnly(bool readOnly)
3644{ 3645{
3645 if (mReadOnly != readOnly) { 3646 if (mReadOnly != readOnly) {
3646 mReadOnly = readOnly; 3647 mReadOnly = readOnly;
3647 emit readOnlyChanged(mReadOnly); 3648 emit readOnlyChanged(mReadOnly);
3648 } 3649 }
3649} 3650}
3650 3651
3651bool CalendarView::isModified() 3652bool CalendarView::isModified()
3652{ 3653{
3653 return mModified; 3654 return mModified;
3654} 3655}
3655void CalendarView::slotprintSelInc() 3656void CalendarView::slotprintSelInc()
3656{ 3657{
3657 if ( currentSelection() == 0 ) { 3658 if ( currentSelection() == 0 ) {
3658 KMessageBox::sorry(this,i18n("There is nothing selected!")); 3659 KMessageBox::sorry(this,i18n("There is nothing selected!"));
3659 return; 3660 return;
3660 } 3661 }
3661 showIncidence(); 3662 showIncidence();
3662 getEventViewerDialog()->print(); 3663 getEventViewerDialog()->print();
3663 3664
3664} 3665}
3665void CalendarView::printSetup() 3666void CalendarView::printSetup()
3666{ 3667{
3667#ifndef KORG_NOPRINTER 3668#ifndef KORG_NOPRINTER
3668 createPrinter(); 3669 createPrinter();
3669 3670
3670 mCalPrinter->setupPrinter(); 3671 mCalPrinter->setupPrinter();
3671#endif 3672#endif
3672} 3673}
3673 3674
3674void CalendarView::print() 3675void CalendarView::print()
3675{ 3676{
3676#ifndef KORG_NOPRINTER 3677#ifndef KORG_NOPRINTER
3677 createPrinter(); 3678 createPrinter();
3678 3679
3679 DateList tmpDateList = mNavigator->selectedDates(); 3680 DateList tmpDateList = mNavigator->selectedDates();
3680 mCalPrinter->print(CalPrinter::Month, 3681 mCalPrinter->print(CalPrinter::Month,
3681 tmpDateList.first(), tmpDateList.last()); 3682 tmpDateList.first(), tmpDateList.last());
3682#endif 3683#endif
3683} 3684}
3684 3685
3685void CalendarView::printPreview() 3686void CalendarView::printPreview()
3686{ 3687{
3687#ifndef KORG_NOPRINTER 3688#ifndef KORG_NOPRINTER
3688 kdDebug() << "CalendarView::printPreview()" << endl; 3689 kdDebug() << "CalendarView::printPreview()" << endl;
3689 3690
3690 createPrinter(); 3691 createPrinter();
3691 3692
3692 DateList tmpDateList = mNavigator->selectedDates(); 3693 DateList tmpDateList = mNavigator->selectedDates();
3693 3694
3694 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 3695 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
3695 tmpDateList.last()); 3696 tmpDateList.last());
3696#endif 3697#endif
3697} 3698}
3698 3699
3699void CalendarView::exportICalendar() 3700void CalendarView::exportICalendar()
3700{ 3701{
3701 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 3702 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
3702 3703
3703 // Force correct extension 3704 // Force correct extension
3704 if (filename.right(4) != ".ics") filename += ".ics"; 3705 if (filename.right(4) != ".ics") filename += ".ics";
3705 3706
3706 FileStorage storage( mCalendar, filename, new ICalFormat() ); 3707 FileStorage storage( mCalendar, filename, new ICalFormat() );
3707 storage.save(); 3708 storage.save();
3708} 3709}
3709 3710
3710bool CalendarView::exportVCalendar( QString filename ) 3711bool CalendarView::exportVCalendar( QString filename )
3711{ 3712{
3712 if (mCalendar->journals().count() > 0) { 3713 if (mCalendar->journals().count() > 0) {
3713 int result = KMessageBox::warningContinueCancel(this, 3714 int result = KMessageBox::warningContinueCancel(this,
3714 i18n("The journal entries can not be\nexported to a vCalendar file."), 3715 i18n("The journal entries can not be\nexported to a vCalendar file."),
3715 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 3716 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
3716 true); 3717 true);
3717 if (result != KMessageBox::Continue) return false; 3718 if (result != KMessageBox::Continue) return false;
3718 } 3719 }
3719 3720
3720 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 3721 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
3721 3722
3722 // Force correct extension 3723 // Force correct extension
3723 if (filename.right(4) != ".vcs") filename += ".vcs"; 3724 if (filename.right(4) != ".vcs") filename += ".vcs";
3724 3725
3725 FileStorage storage( mCalendar, filename, new VCalFormat ); 3726 FileStorage storage( mCalendar, filename, new VCalFormat );
3726 return storage.save(); 3727 return storage.save();
3727 3728
3728} 3729}
3729 3730
3730void CalendarView::eventUpdated(Incidence *) 3731void CalendarView::eventUpdated(Incidence *)
3731{ 3732{
3732 setModified(); 3733 setModified();
3733 // Don't call updateView here. The code, which has caused the update of the 3734 // Don't call updateView here. The code, which has caused the update of the
3734 // event is responsible for updating the view. 3735 // event is responsible for updating the view.
3735 // updateView(); 3736 // updateView();
3736} 3737}
3737 3738
3738void CalendarView::adaptNavigationUnits() 3739void CalendarView::adaptNavigationUnits()
3739{ 3740{
3740 if (mViewManager->currentView()->isEventView()) { 3741 if (mViewManager->currentView()->isEventView()) {
3741 int days = mViewManager->currentView()->currentDateCount(); 3742 int days = mViewManager->currentView()->currentDateCount();
3742 if (days == 1) { 3743 if (days == 1) {
3743 emit changeNavStringPrev(i18n("&Previous Day")); 3744 emit changeNavStringPrev(i18n("&Previous Day"));
3744 emit changeNavStringNext(i18n("&Next Day")); 3745 emit changeNavStringNext(i18n("&Next Day"));
3745 } else { 3746 } else {
3746 emit changeNavStringPrev(i18n("&Previous Week")); 3747 emit changeNavStringPrev(i18n("&Previous Week"));
3747 emit changeNavStringNext(i18n("&Next Week")); 3748 emit changeNavStringNext(i18n("&Next Week"));
3748 } 3749 }
3749 } 3750 }
3750} 3751}
3751 3752
3752void CalendarView::processMainViewSelection( Incidence *incidence ) 3753void CalendarView::processMainViewSelection( Incidence *incidence )
3753{ 3754{
3754 if ( incidence ) mTodoList->clearSelection(); 3755 if ( incidence ) mTodoList->clearSelection();
3755 processIncidenceSelection( incidence ); 3756 processIncidenceSelection( incidence );
3756} 3757}
3757 3758
3758void CalendarView::processTodoListSelection( Incidence *incidence ) 3759void CalendarView::processTodoListSelection( Incidence *incidence )
3759{ 3760{
3760 if ( incidence && mViewManager->currentView() ) { 3761 if ( incidence && mViewManager->currentView() ) {
3761 mViewManager->currentView()->clearSelection(); 3762 mViewManager->currentView()->clearSelection();
3762 } 3763 }
3763 processIncidenceSelection( incidence ); 3764 processIncidenceSelection( incidence );
3764} 3765}
3765 3766
3766void CalendarView::processIncidenceSelection( Incidence *incidence ) 3767void CalendarView::processIncidenceSelection( Incidence *incidence )
3767{ 3768{
3768 if ( incidence == mSelectedIncidence ) return; 3769 if ( incidence == mSelectedIncidence ) return;
3769 3770
3770 mSelectedIncidence = incidence; 3771 mSelectedIncidence = incidence;
3771 3772
3772 emit incidenceSelected( mSelectedIncidence ); 3773 emit incidenceSelected( mSelectedIncidence );
3773 3774
3774 if ( incidence && incidence->type() == "Event" ) { 3775 if ( incidence && incidence->type() == "Event" ) {
3775 Event *event = static_cast<Event *>( incidence ); 3776 Event *event = static_cast<Event *>( incidence );
3776 if ( event->organizer() == KOPrefs::instance()->email() ) { 3777 if ( event->organizer() == KOPrefs::instance()->email() ) {
3777 emit organizerEventsSelected( true ); 3778 emit organizerEventsSelected( true );
3778 } else { 3779 } else {
3779 emit organizerEventsSelected(false); 3780 emit organizerEventsSelected(false);
3780 } 3781 }
3781 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3782 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3782 KOPrefs::instance()->email() ) ) { 3783 KOPrefs::instance()->email() ) ) {
3783 emit groupEventsSelected( true ); 3784 emit groupEventsSelected( true );
3784 } else { 3785 } else {
3785 emit groupEventsSelected(false); 3786 emit groupEventsSelected(false);
3786 } 3787 }
3787 return; 3788 return;
3788 } else { 3789 } else {
3789 if ( incidence && incidence->type() == "Todo" ) { 3790 if ( incidence && incidence->type() == "Todo" ) {
3790 emit todoSelected( true ); 3791 emit todoSelected( true );
3791 Todo *event = static_cast<Todo *>( incidence ); 3792 Todo *event = static_cast<Todo *>( incidence );
3792 if ( event->organizer() == KOPrefs::instance()->email() ) { 3793 if ( event->organizer() == KOPrefs::instance()->email() ) {
3793 emit organizerEventsSelected( true ); 3794 emit organizerEventsSelected( true );
3794 } else { 3795 } else {
3795 emit organizerEventsSelected(false); 3796 emit organizerEventsSelected(false);
3796 } 3797 }
3797 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3798 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3798 KOPrefs::instance()->email() ) ) { 3799 KOPrefs::instance()->email() ) ) {
3799 emit groupEventsSelected( true ); 3800 emit groupEventsSelected( true );
3800 } else { 3801 } else {
3801 emit groupEventsSelected(false); 3802 emit groupEventsSelected(false);
3802 } 3803 }
3803 return; 3804 return;
3804 } else { 3805 } else {
3805 emit todoSelected( false ); 3806 emit todoSelected( false );
3806 emit organizerEventsSelected(false); 3807 emit organizerEventsSelected(false);
3807 emit groupEventsSelected(false); 3808 emit groupEventsSelected(false);
3808 } 3809 }
3809 return; 3810 return;
3810 } 3811 }
3811 3812
3812 /* if ( incidence && incidence->type() == "Todo" ) { 3813 /* if ( incidence && incidence->type() == "Todo" ) {
3813 emit todoSelected( true ); 3814 emit todoSelected( true );
3814 } else { 3815 } else {
3815 emit todoSelected( false ); 3816 emit todoSelected( false );
3816 }*/ 3817 }*/
3817} 3818}
3818 3819
3819 3820
3820void CalendarView::checkClipboard() 3821void CalendarView::checkClipboard()
3821{ 3822{
3822#ifndef KORG_NODND 3823#ifndef KORG_NODND
3823 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 3824 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
3824 emit pasteEnabled(true); 3825 emit pasteEnabled(true);
3825 } else { 3826 } else {
3826 emit pasteEnabled(false); 3827 emit pasteEnabled(false);
3827 } 3828 }
3828#endif 3829#endif
3829} 3830}
3830 3831
3831void CalendarView::showDates(const DateList &selectedDates) 3832void CalendarView::showDates(const DateList &selectedDates)
3832{ 3833{
3833 // kdDebug() << "CalendarView::selectDates()" << endl; 3834 // kdDebug() << "CalendarView::selectDates()" << endl;
3834 3835
3835 3836
3836 if ( !mBlockShowDates ) { 3837 if ( !mBlockShowDates ) {
3837 if ( mViewManager->currentView() ) { 3838 if ( mViewManager->currentView() ) {
3838 updateView( selectedDates.first(), selectedDates.last() ); 3839 updateView( selectedDates.first(), selectedDates.last() );
3839 } else { 3840 } else {
3840 mViewManager->showAgendaView(); 3841 mViewManager->showAgendaView();
3841 } 3842 }
3842 } 3843 }
3843 3844
3844 QDate date = selectedDates.first(); 3845 QDate date = selectedDates.first();
3845 if ( ! date.isValid() ) { 3846 if ( ! date.isValid() ) {
3846 topLevelWidget()->setCaption(""); 3847 topLevelWidget()->setCaption("");
3847 return; 3848 return;
3848 } 3849 }
3849 3850
3850 QString selDates; 3851 QString selDates;
3851 selDates = KGlobal::locale()->formatDate( date, true); 3852 selDates = KGlobal::locale()->formatDate( date, true);
3852 if (selectedDates.first() < selectedDates.last() ) 3853 if (selectedDates.first() < selectedDates.last() )
3853 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 3854 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
3854 else { 3855 else {
3855 QString addString; 3856 QString addString;
3856 if ( date == QDateTime::currentDateTime().date() ) 3857 if ( date == QDateTime::currentDateTime().date() )
3857 addString = i18n("Today"); 3858 addString = i18n("Today");
3858 else if ( date == QDateTime::currentDateTime().date().addDays(1) ) 3859 else if ( date == QDateTime::currentDateTime().date().addDays(1) )
3859 addString = i18n("Tomorrow"); 3860 addString = i18n("Tomorrow");
3860 else if ( date == QDateTime::currentDateTime().date().addDays(-1) ) 3861 else if ( date == QDateTime::currentDateTime().date().addDays(-1) )
3861 addString = i18n("Yesterday"); 3862 addString = i18n("Yesterday");
3862 else if ( date == QDateTime::currentDateTime().date().addDays(-2) ) 3863 else if ( date == QDateTime::currentDateTime().date().addDays(-2) )
3863 addString = i18n("Day before yesterday"); 3864 addString = i18n("Day before yesterday");
3864 else if ( date == QDateTime::currentDateTime().date().addDays(2) ) 3865 else if ( date == QDateTime::currentDateTime().date().addDays(2) )
3865 addString = i18n("Day after tomorrow"); 3866 addString = i18n("Day after tomorrow");
3866 if ( !addString.isEmpty() ) { 3867 if ( !addString.isEmpty() ) {
3867 topLevelWidget()->setCaption( addString+", " + selDates ); 3868 topLevelWidget()->setCaption( addString+", " + selDates );
3868 return; 3869 return;
3869 } 3870 }
3870 } 3871 }
3871 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 3872 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
3872 3873
3873} 3874}
3874 3875
3875QPtrList<CalFilter> CalendarView::filters() 3876QPtrList<CalFilter> CalendarView::filters()
3876{ 3877{
3877 return mFilters; 3878 return mFilters;
3878 3879
3879} 3880}
3880void CalendarView::editFilters() 3881void CalendarView::editFilters()
3881{ 3882{
3882 // kdDebug() << "CalendarView::editFilters()" << endl; 3883 // kdDebug() << "CalendarView::editFilters()" << endl;
3883 3884
3884 CalFilter *filter = mFilters.first(); 3885 CalFilter *filter = mFilters.first();
3885 while(filter) { 3886 while(filter) {
3886 kdDebug() << " Filter: " << filter->name() << endl; 3887 kdDebug() << " Filter: " << filter->name() << endl;
3887 filter = mFilters.next(); 3888 filter = mFilters.next();
3888 } 3889 }
3889 3890
3890 mDialogManager->showFilterEditDialog(&mFilters); 3891 mDialogManager->showFilterEditDialog(&mFilters);
3891} 3892}
3892void CalendarView::toggleFilter() 3893void CalendarView::toggleFilter()
3893{ 3894{
3894 showFilter(! mFilterView->isVisible()); 3895 showFilter(! mFilterView->isVisible());
3895} 3896}
3896 3897
3897KOFilterView *CalendarView::filterView() 3898KOFilterView *CalendarView::filterView()
3898{ 3899{
3899 return mFilterView; 3900 return mFilterView;
3900} 3901}
3901void CalendarView::selectFilter( int fil ) 3902void CalendarView::selectFilter( int fil )
3902{ 3903{
3903 mFilterView->setSelectedFilter( fil ); 3904 mFilterView->setSelectedFilter( fil );
3904} 3905}
3905void CalendarView::showFilter(bool visible) 3906void CalendarView::showFilter(bool visible)
3906{ 3907{
3907 if (visible) mFilterView->show(); 3908 if (visible) mFilterView->show();
3908 else mFilterView->hide(); 3909 else mFilterView->hide();
3909} 3910}
3910void CalendarView::toggleFilerEnabled( ) 3911void CalendarView::toggleFilerEnabled( )
3911{ 3912{
3912 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 3913 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
3913 if ( !mFilterView->filtersEnabled() ) 3914 if ( !mFilterView->filtersEnabled() )
3914 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 3915 topLevelWidget()->setCaption( i18n("Filter disabled ") );
3915 3916
3916} 3917}
3917void CalendarView::updateFilter() 3918void CalendarView::updateFilter()
3918{ 3919{
3919 CalFilter *filter = mFilterView->selectedFilter(); 3920 CalFilter *filter = mFilterView->selectedFilter();
3920 if (filter) { 3921 if (filter) {
3921 QString mess; 3922 QString mess;
3922 if (mFilterView->filtersEnabled()) { 3923 if (mFilterView->filtersEnabled()) {
3923 mess = i18n("Filter selected: ")+filter->name(); 3924 mess = i18n("Filter selected: ")+filter->name();
3924 filter->setEnabled(true); 3925 filter->setEnabled(true);
3925 } 3926 }
3926 else filter->setEnabled(false); 3927 else filter->setEnabled(false);
3927 mCalendar->setFilter(filter); 3928 mCalendar->setFilter(filter);
3928 updateView(); 3929 updateView();
3929 if ( !mess.isEmpty() ) 3930 if ( !mess.isEmpty() )
3930 topLevelWidget()->setCaption( mess ); 3931 topLevelWidget()->setCaption( mess );
3931 3932
3932 } 3933 }
3933} 3934}
3934 3935
3935void CalendarView::filterEdited() 3936void CalendarView::filterEdited()
3936{ 3937{
3937 mFilterView->updateFilters(); 3938 mFilterView->updateFilters();
3938 updateFilter(); 3939 updateFilter();
3939 writeSettings(); 3940 writeSettings();
3940} 3941}
3941 3942
3942 3943
3943void CalendarView::takeOverEvent() 3944void CalendarView::takeOverEvent()
3944{ 3945{
3945 Incidence *incidence = currentSelection(); 3946 Incidence *incidence = currentSelection();
3946 3947
3947 if (!incidence) return; 3948 if (!incidence) return;
3948 3949
3949 incidence->setOrganizer(KOPrefs::instance()->email()); 3950 incidence->setOrganizer(KOPrefs::instance()->email());
3950 incidence->recreate(); 3951 incidence->recreate();
3951 incidence->setReadOnly(false); 3952 incidence->setReadOnly(false);
3952 3953
3953 updateView(); 3954 updateView();
3954} 3955}
3955 3956
3956void CalendarView::takeOverCalendar() 3957void CalendarView::takeOverCalendar()
3957{ 3958{
3958 // TODO: Create Calendar::allIncidences() function and use it here 3959 // TODO: Create Calendar::allIncidences() function and use it here
3959 3960
3960 clearAllViews(); 3961 clearAllViews();
3961 QPtrList<Event> events = mCalendar->events(); 3962 QPtrList<Event> events = mCalendar->events();
3962 for(uint i=0; i<events.count(); ++i) { 3963 for(uint i=0; i<events.count(); ++i) {
3963 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 3964 events.at(i)->setOrganizer(KOPrefs::instance()->email());
3964 events.at(i)->recreate(); 3965 events.at(i)->recreate();
3965 events.at(i)->setReadOnly(false); 3966 events.at(i)->setReadOnly(false);
3966 } 3967 }
3967 3968
3968 QPtrList<Todo> todos = mCalendar->todos(); 3969 QPtrList<Todo> todos = mCalendar->todos();
3969 for(uint i=0; i<todos.count(); ++i) { 3970 for(uint i=0; i<todos.count(); ++i) {
3970 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 3971 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
3971 todos.at(i)->recreate(); 3972 todos.at(i)->recreate();
3972 todos.at(i)->setReadOnly(false); 3973 todos.at(i)->setReadOnly(false);
3973 } 3974 }
3974 3975
3975 QPtrList<Journal> journals = mCalendar->journals(); 3976 QPtrList<Journal> journals = mCalendar->journals();
3976 for(uint i=0; i<journals.count(); ++i) { 3977 for(uint i=0; i<journals.count(); ++i) {
3977 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 3978 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
3978 journals.at(i)->recreate(); 3979 journals.at(i)->recreate();
3979 journals.at(i)->setReadOnly(false); 3980 journals.at(i)->setReadOnly(false);
3980 } 3981 }
3981 3982
3982 updateView(); 3983 updateView();
3983} 3984}
3984 3985
3985void CalendarView::showIntro() 3986void CalendarView::showIntro()
3986{ 3987{
3987 kdDebug() << "To be implemented." << endl; 3988 kdDebug() << "To be implemented." << endl;
3988} 3989}
3989 3990
3990QWidgetStack *CalendarView::viewStack() 3991QWidgetStack *CalendarView::viewStack()
3991{ 3992{
3992 return mRightFrame; 3993 return mRightFrame;
3993} 3994}
3994 3995
3995QWidget *CalendarView::leftFrame() 3996QWidget *CalendarView::leftFrame()
3996{ 3997{
3997 return ( QWidget *)mLeftFrame; 3998 return ( QWidget *)mLeftFrame;
3998} 3999}
3999 4000
4000DateNavigator *CalendarView::dateNavigator() 4001DateNavigator *CalendarView::dateNavigator()
4001{ 4002{
4002 return mNavigator; 4003 return mNavigator;
4003} 4004}
4004 4005
4005KDateNavigator* CalendarView::dateNavigatorWidget() 4006KDateNavigator* CalendarView::dateNavigatorWidget()
4006{ 4007{
4007 return mDateNavigator->navigatorView(); 4008 return mDateNavigator->navigatorView();
4008} 4009}
4009void CalendarView::toggleDateNavigatorWidget() 4010void CalendarView::toggleDateNavigatorWidget()
4010{ 4011{
4011 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ; 4012 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ;
4012 4013
4013 if (!KOPrefs::instance()->mShowDateNavigator ) 4014 if (!KOPrefs::instance()->mShowDateNavigator )
4014 mDateNavigator->hide(); 4015 mDateNavigator->hide();
4015 else 4016 else
4016 mDateNavigator->show(); 4017 mDateNavigator->show();
4017} 4018}
4018void CalendarView::addView(KOrg::BaseView *view) 4019void CalendarView::addView(KOrg::BaseView *view)
4019{ 4020{
4020 mViewManager->addView(view); 4021 mViewManager->addView(view);
4021} 4022}
4022 4023
4023void CalendarView::showView(KOrg::BaseView *view) 4024void CalendarView::showView(KOrg::BaseView *view)
4024{ 4025{
4025 mViewManager->showView(view, mLeftFrame->isVisible()); 4026 mViewManager->showView(view, mLeftFrame->isVisible());
4026} 4027}
4027 4028
4028Incidence *CalendarView::currentSelection() 4029Incidence *CalendarView::currentSelection()
4029{ 4030{
4030 return mViewManager->currentSelection(); 4031 return mViewManager->currentSelection();
4031} 4032}
4032void CalendarView::toggleAllDaySize() 4033void CalendarView::toggleAllDaySize()
4033{ 4034{
4034 /* 4035 /*
4035 if ( KOPrefs::instance()->mAllDaySize > 47 ) 4036 if ( KOPrefs::instance()->mAllDaySize > 47 )
4036 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 4037 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
4037 else 4038 else
4038 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 4039 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
4039 */ 4040 */
4040 viewManager()->agendaView()->toggleAllDay(); 4041 viewManager()->agendaView()->toggleAllDay();
4041} 4042}
4042void CalendarView::toggleExpand() 4043void CalendarView::toggleExpand()
4043{ 4044{
4044 // if ( mLeftFrame->isHidden() ) { 4045 // if ( mLeftFrame->isHidden() ) {
4045 // mLeftFrame->show(); 4046 // mLeftFrame->show();
4046 // emit calendarViewExpanded( false ); 4047 // emit calendarViewExpanded( false );
4047 // } else { 4048 // } else {
4048 // mLeftFrame->hide(); 4049 // mLeftFrame->hide();
4049 // emit calendarViewExpanded( true ); 4050 // emit calendarViewExpanded( true );
4050 // } 4051 // }
4051 //qDebug(" CalendarView::toggleExpand()"); 4052 //qDebug(" CalendarView::toggleExpand()");
4052 globalFlagBlockAgenda = 1; 4053 globalFlagBlockAgenda = 1;
4053 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 4054 emit calendarViewExpanded( !mLeftFrame->isHidden() );
4054 globalFlagBlockAgenda = 5; 4055 globalFlagBlockAgenda = 5;
4055 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 4056 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
4056 //mViewManager->showView( 0, true ); 4057 //mViewManager->showView( 0, true );
4057} 4058}
4058 4059
4059void CalendarView::calendarModified( bool modified, Calendar * ) 4060void CalendarView::calendarModified( bool modified, Calendar * )
4060{ 4061{
4061 setModified( modified ); 4062 setModified( modified );
4062} 4063}
4063 4064
4064Todo *CalendarView::selectedTodo() 4065Todo *CalendarView::selectedTodo()
4065{ 4066{
4066 Incidence *incidence = currentSelection(); 4067 Incidence *incidence = currentSelection();
4067 if ( incidence && incidence->type() == "Todo" ) { 4068 if ( incidence && incidence->type() == "Todo" ) {
4068 return static_cast<Todo *>( incidence ); 4069 return static_cast<Todo *>( incidence );
4069 } 4070 }
4070 4071
4071 incidence = mTodoList->selectedIncidences().first(); 4072 incidence = mTodoList->selectedIncidences().first();
4072 if ( incidence && incidence->type() == "Todo" ) { 4073 if ( incidence && incidence->type() == "Todo" ) {
4073 return static_cast<Todo *>( incidence ); 4074 return static_cast<Todo *>( incidence );
4074 } 4075 }
4075 4076
4076 return 0; 4077 return 0;
4077} 4078}
4078 4079
4079void CalendarView::dialogClosing(Incidence *in) 4080void CalendarView::dialogClosing(Incidence *in)
4080{ 4081{
4081 // mDialogList.remove(in); 4082 // mDialogList.remove(in);
4082} 4083}
4083 4084
4084void CalendarView::showIncidence() 4085void CalendarView::showIncidence()
4085{ 4086{
4086 mViewerCallerIsSearchDialog = false; 4087 mViewerCallerIsSearchDialog = false;
4087 Incidence *incidence = currentSelection(); 4088 Incidence *incidence = currentSelection();
4088 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4089 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4089 if ( incidence ) { 4090 if ( incidence ) {
4090 ShowIncidenceVisitor v; 4091 ShowIncidenceVisitor v;
4091 v.act( incidence, this ); 4092 v.act( incidence, this );
4092 } 4093 }
4093} 4094}
4094void CalendarView::editIncidenceDescription() 4095void CalendarView::editIncidenceDescription()
4095{ 4096{
4096 mFlagEditDescription = true; 4097 mFlagEditDescription = true;
4097 editIncidence(); 4098 editIncidence();
4098 mFlagEditDescription = false; 4099 mFlagEditDescription = false;
4099} 4100}
4100void CalendarView::editIncidence() 4101void CalendarView::editIncidence()
4101{ 4102{
4102 // qDebug("editIncidence() "); 4103 // qDebug("editIncidence() ");
4103 Incidence *incidence = currentSelection(); 4104 Incidence *incidence = currentSelection();
4104 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4105 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4105 if ( incidence ) { 4106 if ( incidence ) {
4106 EditIncidenceVisitor v; 4107 EditIncidenceVisitor v;
4107 v.act( incidence, this ); 4108 v.act( incidence, this );
4108 } 4109 }
4109} 4110}
4110 4111
4111void CalendarView::deleteIncidence() 4112void CalendarView::deleteIncidence()
4112{ 4113{
4113 Incidence *incidence = currentSelection(); 4114 Incidence *incidence = currentSelection();
4114 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4115 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4115 if ( incidence ) { 4116 if ( incidence ) {
4116 deleteIncidence(incidence); 4117 deleteIncidence(incidence);
4117 } 4118 }
4118} 4119}
4119void CalendarView::showIncidence(QString uid) 4120void CalendarView::showIncidence(QString uid)
4120{ 4121{
4121 Incidence *inc = mCalendar->incidence( uid ); 4122 Incidence *inc = mCalendar->incidence( uid );
4122 if ( inc ) 4123 if ( inc )
4123 showIncidence( inc ); 4124 showIncidence( inc );
4124} 4125}
4125void CalendarView::showIncidence(Incidence *incidence) 4126void CalendarView::showIncidence(Incidence *incidence)
4126{ 4127{
4127 mViewerCallerIsSearchDialog = false; 4128 mViewerCallerIsSearchDialog = false;
4128 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() ); 4129 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() );
4129 if ( sender() && mDialogManager->getSearchDialog() ) { 4130 if ( sender() && mDialogManager->getSearchDialog() ) {
4130 if ( sender () == mDialogManager->getSearchDialog()->listview() ) { 4131 if ( sender () == mDialogManager->getSearchDialog()->listview() ) {
4131 mViewerCallerIsSearchDialog = true; 4132 mViewerCallerIsSearchDialog = true;
4132 } 4133 }
4133 } 4134 }
4134 if ( incidence ) { 4135 if ( incidence ) {
4135 ShowIncidenceVisitor v; 4136 ShowIncidenceVisitor v;
4136 v.act( incidence, this ); 4137 v.act( incidence, this );
4137 } 4138 }
4138} 4139}
4139 4140
4140void CalendarView::editIncidence(Incidence *incidence) 4141void CalendarView::editIncidence(Incidence *incidence)
4141{ 4142{
4142 if ( incidence ) { 4143 if ( incidence ) {
4143 4144
4144 EditIncidenceVisitor v; 4145 EditIncidenceVisitor v;
4145 v.act( incidence, this ); 4146 v.act( incidence, this );
4146 4147
4147 } 4148 }
4148} 4149}
4149 4150
4150void CalendarView::deleteIncidence(Incidence *incidence) 4151void CalendarView::deleteIncidence(Incidence *incidence)
4151{ 4152{
4152 //qDebug(" CalendarView::deleteIncidence "); 4153 //qDebug(" CalendarView::deleteIncidence ");
4153 if ( incidence ) { 4154 if ( incidence ) {
4154 DeleteIncidenceVisitor v; 4155 DeleteIncidenceVisitor v;
4155 v.act( incidence, this ); 4156 v.act( incidence, this );
4156 } 4157 }
4157} 4158}
4158 4159
4159 4160
4160void CalendarView::lookForOutgoingMessages() 4161void CalendarView::lookForOutgoingMessages()
4161{ 4162{
4162 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 4163 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
4163 ogd->loadMessages(); 4164 ogd->loadMessages();
4164} 4165}
4165 4166
4166void CalendarView::lookForIncomingMessages() 4167void CalendarView::lookForIncomingMessages()
4167{ 4168{
4168 IncomingDialog *icd = mDialogManager->incomingDialog(); 4169 IncomingDialog *icd = mDialogManager->incomingDialog();
4169 icd->retrieve(); 4170 icd->retrieve();
4170} 4171}
4171 4172
4172bool CalendarView::removeCompletedSubTodos( Todo* t ) 4173bool CalendarView::removeCompletedSubTodos( Todo* t )
4173{ 4174{
4174 bool deleteTodo = true; 4175 bool deleteTodo = true;
4175 QPtrList<Incidence> subTodos; 4176 QPtrList<Incidence> subTodos;
4176 Incidence *aTodo; 4177 Incidence *aTodo;
4177 subTodos = t->relations(); 4178 subTodos = t->relations();
4178 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 4179 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
4179 if (! removeCompletedSubTodos( (Todo*) aTodo )) 4180 if (! removeCompletedSubTodos( (Todo*) aTodo ))
4180 deleteTodo = false; 4181 deleteTodo = false;
4181 } 4182 }
4182 if ( deleteTodo ) { 4183 if ( deleteTodo ) {
4183 if ( t->isCompleted() && !t->doesRecur()) { 4184 if ( t->isCompleted() && !t->doesRecur()) {
4184 checkExternalId( t ); 4185 checkExternalId( t );
4185 mCalendar->deleteTodo( t ); 4186 mCalendar->deleteTodo( t );
4186 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 4187 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
4187 } 4188 }
4188 else 4189 else
4189 deleteTodo = false; 4190 deleteTodo = false;
4190 } 4191 }
4191 return deleteTodo; 4192 return deleteTodo;
4192 4193
4193} 4194}
4194void CalendarView::purgeCompleted() 4195void CalendarView::purgeCompleted()
4195{ 4196{
4196 int result = KMessageBox::warningContinueCancel(this, 4197 int result = KMessageBox::warningContinueCancel(this,
4197 i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge")); 4198 i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge"));
4198 4199
4199 if (result == KMessageBox::Continue) { 4200 if (result == KMessageBox::Continue) {
4200 4201
4201 QPtrList<Todo> todoCal; 4202 QPtrList<Todo> todoCal;
4202 QPtrList<Todo> rootTodos; 4203 QPtrList<Todo> rootTodos;
4203 //QPtrList<Incidence> rel; 4204 //QPtrList<Incidence> rel;
4204 Todo *aTodo;//, *rTodo; 4205 Todo *aTodo;//, *rTodo;
4205 Incidence *rIncidence; 4206 Incidence *rIncidence;
4206 bool childDelete = false; 4207 bool childDelete = false;
4207 bool deletedOne = true; 4208 bool deletedOne = true;
4208 todoCal = calendar()->todos(); 4209 todoCal = calendar()->todos();
4209 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 4210 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
4210 if ( !aTodo->relatedTo() ) 4211 if ( !aTodo->relatedTo() )
4211 rootTodos.append( aTodo ); 4212 rootTodos.append( aTodo );
4212 } 4213 }
4213 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 4214 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
4214 removeCompletedSubTodos( aTodo ); 4215 removeCompletedSubTodos( aTodo );
4215 } 4216 }
4216 4217
4217 updateView(); 4218 updateView();
4218 } 4219 }
4219} 4220}
4220 4221
4221void CalendarView::slotCalendarChanged() 4222void CalendarView::slotCalendarChanged()
4222{ 4223{
4223 ; 4224 ;
4224} 4225}
4225 4226
4226void CalendarView::keyPressEvent ( QKeyEvent *e) 4227void CalendarView::keyPressEvent ( QKeyEvent *e)
4227{ 4228{
4228 //qDebug(" alendarView::keyPressEvent "); 4229 //qDebug(" alendarView::keyPressEvent ");
4229 e->ignore(); 4230 e->ignore();
4230} 4231}
4231 4232
4232 4233
4233bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) 4234bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
4234{ 4235{
4235 // mSyncManager = manager; 4236 // mSyncManager = manager;
4236 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { 4237 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) {
4237 qDebug("KO: SyncKDE request detected!"); 4238 qDebug("KO: SyncKDE request detected!");
4238 } 4239 }
4239 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 4240 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
4240 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 4241 mCurrentSyncName = mSyncManager->getCurrentSyncName();
4241 return syncCalendar( filename, mode ); 4242 return syncCalendar( filename, mode );
4242} 4243}
4243bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 4244bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
4244{ 4245{
4245 //mSyncManager = manager; 4246 //mSyncManager = manager;
4246 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 4247 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
4247 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 4248 mCurrentSyncName = mSyncManager->getCurrentSyncName();
4248 if ( resource == "sharp" ) 4249 if ( resource == "sharp" )
4249 syncExternal( 0 ); 4250 syncExternal( 0 );
4250 if ( resource == "phone" ) 4251 if ( resource == "phone" )
4251 syncExternal( 1 ); 4252 syncExternal( 1 );
4252 // pending setmodified 4253 // pending setmodified
4253 return true; 4254 return true;
4254} 4255}
4255void CalendarView::setSyncManager(KSyncManager* manager) 4256void CalendarView::setSyncManager(KSyncManager* manager)
4256{ 4257{
4257 mSyncManager = manager; 4258 mSyncManager = manager;
4258} 4259}
4259 4260
4260void CalendarView::removeSyncInfo( QString syncProfile) 4261void CalendarView::removeSyncInfo( QString syncProfile)
4261{ 4262{
4262 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1()); 4263 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1());
4263 mCalendar->removeSyncInfo( syncProfile ); 4264 mCalendar->removeSyncInfo( syncProfile );
4264 4265
4265} 4266}
4266 4267
4267void CalendarView::undo_delete() 4268void CalendarView::undo_delete()
4268{ 4269{
4269 //qDebug("undo_delete() "); 4270 //qDebug("undo_delete() ");
4270 Incidence* undo = mCalendar->undoIncidence(); 4271 Incidence* undo = mCalendar->undoIncidence();
4271 if ( !undo ) { 4272 if ( !undo ) {
4272 KMessageBox::sorry(this,i18n("There is nothing to undo!"), 4273 KMessageBox::sorry(this,i18n("There is nothing to undo!"),
4273 i18n("KO/Pi")); 4274 i18n("KO/Pi"));
4274 return; 4275 return;
4275 } 4276 }
4276 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,undo->summary().left(25) + 4277 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,undo->summary().left(25) +
4277 i18n("\nAre you sure you want\nto restore this?"), 4278 i18n("\nAre you sure you want\nto restore this?"),
4278 i18n("KO/Pi Confirmation"),i18n("Restore"))) { 4279 i18n("KO/Pi Confirmation"),i18n("Restore"))) {
4279 mCalendar->undoDeleteIncidence(); 4280 mCalendar->undoDeleteIncidence();
4280 updateView(); 4281 updateView();
4281 } 4282 }
4282} 4283}
4283 4284
4284void CalendarView::slotViewerClosed() 4285void CalendarView::slotViewerClosed()
4285{ 4286{
4286 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) ); 4287 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) );
4287} 4288}
4288 4289
4289void CalendarView::resetFocus() 4290void CalendarView::resetFocus()
4290{ 4291{
4291 if ( mViewerCallerIsSearchDialog ) { 4292 if ( mViewerCallerIsSearchDialog ) {
4292 if ( mDialogManager->getSearchDialog()->isVisible() ){ 4293 if ( mDialogManager->getSearchDialog()->isVisible() ){
4293 mDialogManager->getSearchDialog()->raise(); 4294 mDialogManager->getSearchDialog()->raise();
4294 mDialogManager->getSearchDialog()->setActiveWindow(); 4295 mDialogManager->getSearchDialog()->setActiveWindow();
4295 mDialogManager->getSearchDialog()->listview()->resetFocus(); 4296 mDialogManager->getSearchDialog()->listview()->resetFocus();
4296 } else 4297 } else
4297 mViewerCallerIsSearchDialog = false; 4298 mViewerCallerIsSearchDialog = false;
4298 } 4299 }
4299 if ( !mViewerCallerIsSearchDialog ) { 4300 if ( !mViewerCallerIsSearchDialog ) {
4300 //mViewManager->currentView()->setFocus(); 4301 //mViewManager->currentView()->setFocus();
4301 //qDebug("sssssssssssssssset focus "); 4302 //qDebug("sssssssssssssssset focus ");
4302 topLevelWidget()->raise(); 4303 topLevelWidget()->raise();
4303 setActiveWindow(); 4304 setActiveWindow();
4304 //setFocus(); 4305 //setFocus();
4305 } 4306 }
4306 mViewerCallerIsSearchDialog = false; 4307 mViewerCallerIsSearchDialog = false;
4307} 4308}
4308 4309
4309void CalendarView::showNextAlarms() 4310void CalendarView::showNextAlarms()
4310{ 4311{
4311 QString message; 4312 QString message;
4312 QDateTime nextAl = mCalendar->nextAlarmEventDateTime(); 4313 QDateTime nextAl = mCalendar->nextAlarmEventDateTime();
4313 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) { 4314 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) {
4314 QString sum = mCalendar->nextSummary(); 4315 QString sum = mCalendar->nextSummary();
4315 QDateTime nextA = mNextAlarmDateTime; 4316 QDateTime nextA = mNextAlarmDateTime;
4316 QDateTime cur = QDateTime::currentDateTime(); 4317 QDateTime cur = QDateTime::currentDateTime();
4317 int secs = cur.secsTo( nextA ); 4318 int secs = cur.secsTo( nextA );
4318 int min = secs /60; 4319 int min = secs /60;
4319 int hours = min /60; 4320 int hours = min /60;
4320 min = min % 60; 4321 min = min % 60;
4321 int days = hours /24; 4322 int days = hours /24;
4322 hours = hours % 24; 4323 hours = hours % 24;
4323 4324
4324 //message = i18n("The next alarm is in:\n"); 4325 //message = i18n("The next alarm is in:\n");
4325 if ( days > 1 ) 4326 if ( days > 1 )
4326 message += i18n("%1 days\n").arg( days ); 4327 message += i18n("%1 days\n").arg( days );
4327 else if ( days == 1 ) 4328 else if ( days == 1 )
4328 message += i18n("1 day\n"); 4329 message += i18n("1 day\n");
4329 if ( hours > 1 ) 4330 if ( hours > 1 )
4330 message += i18n("%1 hours\n").arg( hours ); 4331 message += i18n("%1 hours\n").arg( hours );
4331 else if ( hours == 1 ) 4332 else if ( hours == 1 )
4332 message += i18n("1 hour\n"); 4333 message += i18n("1 hour\n");
4333 if ( min > 1 ) 4334 if ( min > 1 )
4334 message += i18n("%1 minutes\n").arg( min ); 4335 message += i18n("%1 minutes\n").arg( min );
4335 else if ( min == 1 ) 4336 else if ( min == 1 )
4336 message += i18n("1 minute\n"); 4337 message += i18n("1 minute\n");
4337 if ( message.isEmpty() ) 4338 if ( message.isEmpty() )
4338 message = i18n("The next alarm is in\nless than one minute!"); 4339 message = i18n("The next alarm is in\nless than one minute!");
4339 else 4340 else
4340 message = i18n("The next alarm is in:\n") + message; 4341 message = i18n("The next alarm is in:\n") + message;
4341 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ; 4342 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ;
4342 } else { 4343 } else {
4343 message = i18n("There is no next alarm."); 4344 message = i18n("There is no next alarm.");
4344 4345
4345 } 4346 }
4346#ifdef DESKTOP_VERSION 4347#ifdef DESKTOP_VERSION
4347 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 4348 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
4348 message += i18n("\nThe internal alarm notification is disabled!\n"); 4349 message += i18n("\nThe internal alarm notification is disabled!\n");
4349 message += i18n("Enable it in the settings menu, TAB alarm."); 4350 message += i18n("Enable it in the settings menu, TAB alarm.");
4350 } 4351 }
4351 4352
4352#endif 4353#endif
4353 KMessageBox::information( this, message); 4354 KMessageBox::information( this, message);
4354} 4355}