author | zautrix <zautrix> | 2005-01-14 11:37:40 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-01-14 11:37:40 (UTC) |
commit | 61c95ce0295f1397db6499c5b468a9fb3d32a0f4 (patch) (unidiff) | |
tree | 2bceecc46d42a572adfad7d8e5000d1534642cbd /kde2file | |
parent | a46ecf5ed81460ec9a4e457798e1bf0fb74c5624 (diff) | |
download | kdepimpi-61c95ce0295f1397db6499c5b468a9fb3d32a0f4.zip kdepimpi-61c95ce0295f1397db6499c5b468a9fb3d32a0f4.tar.gz kdepimpi-61c95ce0295f1397db6499c5b468a9fb3d32a0f4.tar.bz2 |
made kapi saving faster
-rw-r--r-- | kde2file/abdump/main.cpp | 2 | ||||
-rw-r--r-- | kde2file/caldump/main.cpp | 2 |
2 files changed, 1 insertions, 3 deletions
diff --git a/kde2file/abdump/main.cpp b/kde2file/abdump/main.cpp index 1ee64f5..9ad78e5 100644 --- a/kde2file/abdump/main.cpp +++ b/kde2file/abdump/main.cpp | |||
@@ -1,195 +1,193 @@ | |||
1 | /******************************************************************************* | 1 | /******************************************************************************* |
2 | * main.cpp * | 2 | * main.cpp * |
3 | * * | 3 | * * |
4 | * | 4 | * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * | 7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License, or * | 8 | * the Free Software Foundation; either version 2 of the License, or * |
9 | * (at your option) any later version. * | 9 | * (at your option) any later version. * |
10 | * * | 10 | * * |
11 | * This program is distributed in the hope that it will be useful, * | 11 | * This program is distributed in the hope that it will be useful, * |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
14 | * GNU General Public License for more details. * | 14 | * GNU General Public License for more details. * |
15 | * * | 15 | * * |
16 | * You should have received a copy of the GNU General Public License * | 16 | * You should have received a copy of the GNU General Public License * |
17 | * along with this program; if not, write to the Free Software * | 17 | * along with this program; if not, write to the Free Software * |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | * * | 19 | * * |
20 | * As a special exception, permission is given to link this program * | 20 | * As a special exception, permission is given to link this program * |
21 | * with any edition of Qt, and distribute the resulting executable, * | 21 | * with any edition of Qt, and distribute the resulting executable, * |
22 | * without including the source code for Qt in the source distribution. * | 22 | * without including the source code for Qt in the source distribution. * |
23 | * * | 23 | * * |
24 | ******************************************************************************/ | 24 | ******************************************************************************/ |
25 | 25 | ||
26 | #include <kcmdlineargs.h> | 26 | #include <kcmdlineargs.h> |
27 | #include <kaboutdata.h> | 27 | #include <kaboutdata.h> |
28 | #include <klocale.h> | 28 | #include <klocale.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <kconfig.h> | 30 | #include <kconfig.h> |
31 | #include <kstandarddirs.h> | 31 | #include <kstandarddirs.h> |
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | 33 | ||
34 | #include <kabc/addressbook.h> | 34 | #include <kabc/addressbook.h> |
35 | #include <kabc/stdaddressbook.h> | 35 | #include <kabc/stdaddressbook.h> |
36 | #include <kabc/resource.h> | 36 | #include <kabc/resource.h> |
37 | #include <kabc/vcardconverter.h> | 37 | #include <kabc/vcardconverter.h> |
38 | 38 | ||
39 | #include <qdatetime.h> | 39 | #include <qdatetime.h> |
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qdir.h> | 41 | #include <qdir.h> |
42 | #include <qapplication.h> | 42 | #include <qapplication.h> |
43 | 43 | ||
44 | #include <stdlib.h> | 44 | #include <stdlib.h> |
45 | #include <iostream> | 45 | #include <iostream> |
46 | 46 | ||
47 | using namespace std; | 47 | using namespace std; |
48 | 48 | ||
49 | static const char progName[] = "kdecalendar"; | 49 | static const char progName[] = "kdecalendar"; |
50 | static const char progDisplay[] = "KDE_Addressbook"; | 50 | static const char progDisplay[] = "KDE_Addressbook"; |
51 | static const char progVersion[] = "33.1/3"; | 51 | static const char progVersion[] = "33.1/3"; |
52 | static const char progDesc[] = "A command line interface to KDE addressbooks"; | 52 | static const char progDesc[] = "A command line interface to KDE addressbooks"; |
53 | 53 | ||
54 | 54 | ||
55 | static KCmdLineOptions options[] = | 55 | static KCmdLineOptions options[] = |
56 | { | 56 | { |
57 | { "dump", | 57 | { "dump", |
58 | I18N_NOOP( "Dumps addressbook" ), 0 }, | 58 | I18N_NOOP( "Dumps addressbook" ), 0 }, |
59 | { "read", | 59 | { "read", |
60 | I18N_NOOP( "Reads addressbook" ), 0 }, | 60 | I18N_NOOP( "Reads addressbook" ), 0 }, |
61 | KCmdLineLastOption | 61 | KCmdLineLastOption |
62 | }; | 62 | }; |
63 | 63 | ||
64 | int main( int argc, char *argv[] ) | 64 | int main( int argc, char *argv[] ) |
65 | { | 65 | { |
66 | KAboutData aboutData( | 66 | KAboutData aboutData( |
67 | progName, // internal program name | 67 | progName, // internal program name |
68 | I18N_NOOP( progDisplay ), // displayable program name. | 68 | I18N_NOOP( progDisplay ), // displayable program name. |
69 | progVersion, // version string | 69 | progVersion, // version string |
70 | I18N_NOOP( progDesc ), // short porgram description | 70 | I18N_NOOP( progDesc ), // short porgram description |
71 | KAboutData::License_GPL, // license type | 71 | KAboutData::License_GPL, // license type |
72 | "(c) 2004, Lutz Rogowski", // copyright statement | 72 | "(c) 2004, Lutz Rogowski", // copyright statement |
73 | 0, // any free form text | 73 | 0, // any free form text |
74 | "", // program home page address | 74 | "", // program home page address |
75 | "bugs.kde.org" // bug report email address | 75 | "bugs.kde.org" // bug report email address |
76 | ); | 76 | ); |
77 | 77 | ||
78 | 78 | ||
79 | // KCmdLineArgs::init() final 'true' argument indicates no commandline options | 79 | // KCmdLineArgs::init() final 'true' argument indicates no commandline options |
80 | // for QApplication/KApplication (no KDE or Qt options) | 80 | // for QApplication/KApplication (no KDE or Qt options) |
81 | KCmdLineArgs::init( argc, argv, &aboutData, true ); | 81 | KCmdLineArgs::init( argc, argv, &aboutData, true ); |
82 | KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. | 82 | KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. |
83 | 83 | ||
84 | KInstance ins ( progName ); | 84 | KInstance ins ( progName ); |
85 | 85 | ||
86 | KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); | 86 | KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); |
87 | 87 | ||
88 | bool read = false; | 88 | bool read = false; |
89 | if ( args->isSet( "read" ) ) { | 89 | if ( args->isSet( "read" ) ) { |
90 | read = true; | 90 | read = true; |
91 | qDebug("read "); | 91 | qDebug("read "); |
92 | } | 92 | } |
93 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; | 93 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; |
94 | 94 | ||
95 | KABC::StdAddressBook* standardAddressBook = KABC::StdAddressBook::self(); | 95 | KABC::StdAddressBook* standardAddressBook = KABC::StdAddressBook::self(); |
96 | standardAddressBook->setAutomaticSave( false ); | 96 | standardAddressBook->setAutomaticSave( false ); |
97 | qDebug("************************************* "); | 97 | qDebug("************************************* "); |
98 | qDebug("***************kdeABdump************* "); | 98 | qDebug("***************kdeABdump************* "); |
99 | qDebug("************************************* "); | 99 | qDebug("************************************* "); |
100 | if ( !read ) { | 100 | if ( !read ) { |
101 | KABC::AddressBook::Iterator it; | 101 | KABC::AddressBook::Iterator it; |
102 | KABC::VCardConverter converter; | 102 | KABC::VCardConverter converter; |
103 | QString datastream; | 103 | QString datastream; |
104 | for( it = standardAddressBook->begin(); it != standardAddressBook->end(); ++it ) { | 104 | for( it = standardAddressBook->begin(); it != standardAddressBook->end(); ++it ) { |
105 | if ( (*it).isEmpty() || ! (*it).resource() ) | 105 | if ( (*it).isEmpty() || ! (*it).resource() ) |
106 | continue; | 106 | continue; |
107 | if ( (*it).resource()->readOnly() ) | ||
108 | continue; | ||
109 | KABC::Addressee a = ( *it ); | 107 | KABC::Addressee a = ( *it ); |
110 | QString vcard = converter.createVCard( a ); | 108 | QString vcard = converter.createVCard( a ); |
111 | vcard += QString("\r\n"); | 109 | vcard += QString("\r\n"); |
112 | datastream += vcard; | 110 | datastream += vcard; |
113 | } | 111 | } |
114 | QFile outFile(fileName); | 112 | QFile outFile(fileName); |
115 | if ( outFile.open(IO_WriteOnly) ) { | 113 | if ( outFile.open(IO_WriteOnly) ) { |
116 | QTextStream t( &outFile ); // use a text stream | 114 | QTextStream t( &outFile ); // use a text stream |
117 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 115 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
118 | t <<datastream; | 116 | t <<datastream; |
119 | t << "\r\n\r\n"; | 117 | t << "\r\n\r\n"; |
120 | outFile.close(); | 118 | outFile.close(); |
121 | } | 119 | } |
122 | } else { | 120 | } else { |
123 | //Addressee::List aList;//parseVCards( const QString& vcard ); | 121 | //Addressee::List aList;//parseVCards( const QString& vcard ); |
124 | KABC::Addressee::List list; | 122 | KABC::Addressee::List list; |
125 | int added = 0, changedC = 0, deleted = 0; | 123 | int added = 0, changedC = 0, deleted = 0; |
126 | QFile file( fileName ); | 124 | QFile file( fileName ); |
127 | if ( file.open( IO_ReadOnly ) ) { | 125 | if ( file.open( IO_ReadOnly ) ) { |
128 | QTextStream t( &file ); // use a text stream | 126 | QTextStream t( &file ); // use a text stream |
129 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 127 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
130 | QString data; | 128 | QString data; |
131 | data = t.read(); | 129 | data = t.read(); |
132 | file.close(); | 130 | file.close(); |
133 | KABC::VCardConverter converter; | 131 | KABC::VCardConverter converter; |
134 | list = converter.parseVCards( data ); | 132 | list = converter.parseVCards( data ); |
135 | qDebug("kdeABdump::file has %d entries", list.count()); | 133 | qDebug("kdeABdump::file has %d entries", list.count()); |
136 | 134 | ||
137 | KABC::Addressee::List::Iterator it; | 135 | KABC::Addressee::List::Iterator it; |
138 | for ( it = list.begin();it != list.end();++it) { | 136 | for ( it = list.begin();it != list.end();++it) { |
139 | (*it).setChanged( true ); | 137 | (*it).setChanged( true ); |
140 | bool changed = ((*it).custom( "KADDRESSBOOK", "X-ExternalID" ) == "changed"); | 138 | bool changed = ((*it).custom( "KADDRESSBOOK", "X-ExternalID" ) == "changed"); |
141 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 139 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
142 | //qDebug("ext %s ", (*it).custom( "KADDRESSBOOK", "X-ExternalID" ).latin1()); | 140 | //qDebug("ext %s ", (*it).custom( "KADDRESSBOOK", "X-ExternalID" ).latin1()); |
143 | if ( changed ) { | 141 | if ( changed ) { |
144 | //qDebug("changed Addressee found! "); | 142 | //qDebug("changed Addressee found! "); |
145 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); | 143 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); |
146 | if ( ! std.isEmpty() ) | 144 | if ( ! std.isEmpty() ) |
147 | (*it).setResource(std.resource()); | 145 | (*it).setResource(std.resource()); |
148 | standardAddressBook->insertAddressee( (*it) ); | 146 | standardAddressBook->insertAddressee( (*it) ); |
149 | ++changedC; | 147 | ++changedC; |
150 | } else { | 148 | } else { |
151 | //maybe added? | 149 | //maybe added? |
152 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); | 150 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); |
153 | if ( std.isEmpty() ) { | 151 | if ( std.isEmpty() ) { |
154 | standardAddressBook->insertAddressee( (*it) ); | 152 | standardAddressBook->insertAddressee( (*it) ); |
155 | ++added; | 153 | ++added; |
156 | } | 154 | } |
157 | } | 155 | } |
158 | } | 156 | } |
159 | KABC::AddressBook::Iterator itA = standardAddressBook->begin(); | 157 | KABC::AddressBook::Iterator itA = standardAddressBook->begin(); |
160 | KABC::AddressBook::Iterator it2 ; | 158 | KABC::AddressBook::Iterator it2 ; |
161 | while ( itA != standardAddressBook->end() ) { | 159 | while ( itA != standardAddressBook->end() ) { |
162 | bool found = false; | 160 | bool found = false; |
163 | KABC::Addressee::List::Iterator itL; | 161 | KABC::Addressee::List::Iterator itL; |
164 | for ( itL = list.begin();itL != list.end();++itL) { | 162 | for ( itL = list.begin();itL != list.end();++itL) { |
165 | if ( (*itL).uid() == (*itA).uid() ) { | 163 | if ( (*itL).uid() == (*itA).uid() ) { |
166 | found = true; | 164 | found = true; |
167 | break; | 165 | break; |
168 | } | 166 | } |
169 | } | 167 | } |
170 | if ( !found ) { | 168 | if ( !found ) { |
171 | it2 = itA; | 169 | it2 = itA; |
172 | ++itA; | 170 | ++itA; |
173 | standardAddressBook->removeAddressee( it2 ); | 171 | standardAddressBook->removeAddressee( it2 ); |
174 | ++deleted; | 172 | ++deleted; |
175 | } else { | 173 | } else { |
176 | ++itA; | 174 | ++itA; |
177 | } | 175 | } |
178 | } | 176 | } |
179 | 177 | ||
180 | //standardAddressBook->saveAll(); | 178 | //standardAddressBook->saveAll(); |
181 | standardAddressBook->setAutomaticSave( true ); | 179 | standardAddressBook->setAutomaticSave( true ); |
182 | qDebug("************************************* "); | 180 | qDebug("************************************* "); |
183 | qDebug("*************kdeABdump*************** "); | 181 | qDebug("*************kdeABdump*************** "); |
184 | qDebug("************************************* "); | 182 | qDebug("************************************* "); |
185 | qDebug("Addressbook entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", changedC,deleted, added, fileName.latin1()); | 183 | qDebug("Addressbook entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", changedC,deleted, added, fileName.latin1()); |
186 | } else | 184 | } else |
187 | qDebug("error open file "); | 185 | qDebug("error open file "); |
188 | } | 186 | } |
189 | 187 | ||
190 | delete standardAddressBook; | 188 | delete standardAddressBook; |
191 | //KABC::StdAddressBook::close(); | 189 | //KABC::StdAddressBook::close(); |
192 | //StdAddressBook::mSelf = 0; | 190 | //StdAddressBook::mSelf = 0; |
193 | qDebug("ente "); | 191 | qDebug("ente "); |
194 | return 0; | 192 | return 0; |
195 | } | 193 | } |
diff --git a/kde2file/caldump/main.cpp b/kde2file/caldump/main.cpp index be1735b..08ccafb 100644 --- a/kde2file/caldump/main.cpp +++ b/kde2file/caldump/main.cpp | |||
@@ -4,250 +4,250 @@ | |||
4 | * | 4 | * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * | 7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License, or * | 8 | * the Free Software Foundation; either version 2 of the License, or * |
9 | * (at your option) any later version. * | 9 | * (at your option) any later version. * |
10 | * * | 10 | * * |
11 | * This program is distributed in the hope that it will be useful, * | 11 | * This program is distributed in the hope that it will be useful, * |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
14 | * GNU General Public License for more details. * | 14 | * GNU General Public License for more details. * |
15 | * * | 15 | * * |
16 | * You should have received a copy of the GNU General Public License * | 16 | * You should have received a copy of the GNU General Public License * |
17 | * along with this program; if not, write to the Free Software * | 17 | * along with this program; if not, write to the Free Software * |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | * * | 19 | * * |
20 | * As a special exception, permission is given to link this program * | 20 | * As a special exception, permission is given to link this program * |
21 | * with any edition of Qt, and distribute the resulting executable, * | 21 | * with any edition of Qt, and distribute the resulting executable, * |
22 | * without including the source code for Qt in the source distribution. * | 22 | * without including the source code for Qt in the source distribution. * |
23 | * * | 23 | * * |
24 | ******************************************************************************/ | 24 | ******************************************************************************/ |
25 | 25 | ||
26 | #ifdef HAVE_CONFIG_H | 26 | #ifdef HAVE_CONFIG_H |
27 | #include "config.h" | 27 | #include "config.h" |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | #if TIME_WITH_SYS_TIME | 30 | #if TIME_WITH_SYS_TIME |
31 | # include <sys/time.h> | 31 | # include <sys/time.h> |
32 | # include <time.h> | 32 | # include <time.h> |
33 | #else | 33 | #else |
34 | # if HAVE_SYS_TIME_H | 34 | # if HAVE_SYS_TIME_H |
35 | # include <sys/time.h> | 35 | # include <sys/time.h> |
36 | # else | 36 | # else |
37 | # include <time.h> | 37 | # include <time.h> |
38 | # endif | 38 | # endif |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | #include <kcmdlineargs.h> | 41 | #include <kcmdlineargs.h> |
42 | #include <kaboutdata.h> | 42 | #include <kaboutdata.h> |
43 | #include <klocale.h> | 43 | #include <klocale.h> |
44 | #include <kglobal.h> | 44 | #include <kglobal.h> |
45 | #include <kconfig.h> | 45 | #include <kconfig.h> |
46 | #include <kstandarddirs.h> | 46 | #include <kstandarddirs.h> |
47 | #include <kdebug.h> | 47 | #include <kdebug.h> |
48 | 48 | ||
49 | #include <libkcal/calformat.h> | 49 | #include <libkcal/calformat.h> |
50 | #include <libkcal/calendarresources.h> | 50 | #include <libkcal/calendarresources.h> |
51 | #include <libkcal/resourcelocal.h> | 51 | #include <libkcal/resourcelocal.h> |
52 | #include <libkcal/filestorage.h> | 52 | #include <libkcal/filestorage.h> |
53 | #include <libkcal/icalformat.h> | 53 | #include <libkcal/icalformat.h> |
54 | 54 | ||
55 | #include <qdatetime.h> | 55 | #include <qdatetime.h> |
56 | #include <qfile.h> | 56 | #include <qfile.h> |
57 | #include <qdir.h> | 57 | #include <qdir.h> |
58 | #include <qapplication.h> | 58 | #include <qapplication.h> |
59 | 59 | ||
60 | #include <stdlib.h> | 60 | #include <stdlib.h> |
61 | #include <iostream> | 61 | #include <iostream> |
62 | 62 | ||
63 | using namespace KCal; | 63 | using namespace KCal; |
64 | using namespace std; | 64 | using namespace std; |
65 | 65 | ||
66 | static const char progName[] = "kdecalendar"; | 66 | static const char progName[] = "kdecalendar"; |
67 | static const char progDisplay[] = "KDE_Calendar"; | 67 | static const char progDisplay[] = "KDE_Calendar"; |
68 | static const char progVersion[] = "33.1/3"; | 68 | static const char progVersion[] = "33.1/3"; |
69 | static const char progDesc[] = "A command line interface to KDE calendars"; | 69 | static const char progDesc[] = "A command line interface to KDE calendars"; |
70 | 70 | ||
71 | 71 | ||
72 | static KCmdLineOptions options[] = | 72 | static KCmdLineOptions options[] = |
73 | { | 73 | { |
74 | { "dump", | 74 | { "dump", |
75 | I18N_NOOP( "Dumps calendar" ), 0 }, | 75 | I18N_NOOP( "Dumps calendar" ), 0 }, |
76 | { "read", | 76 | { "read", |
77 | I18N_NOOP( "Reads calendar" ), 0 }, | 77 | I18N_NOOP( "Reads calendar" ), 0 }, |
78 | KCmdLineLastOption | 78 | KCmdLineLastOption |
79 | }; | 79 | }; |
80 | 80 | ||
81 | int main( int argc, char *argv[] ) | 81 | int main( int argc, char *argv[] ) |
82 | { | 82 | { |
83 | KAboutData aboutData( | 83 | KAboutData aboutData( |
84 | progName, // internal program name | 84 | progName, // internal program name |
85 | I18N_NOOP( progDisplay ), // displayable program name. | 85 | I18N_NOOP( progDisplay ), // displayable program name. |
86 | progVersion, // version string | 86 | progVersion, // version string |
87 | I18N_NOOP( progDesc ), // short porgram description | 87 | I18N_NOOP( progDesc ), // short porgram description |
88 | KAboutData::License_GPL, // license type | 88 | KAboutData::License_GPL, // license type |
89 | "(c) 2004, Lutz Rogowski", // copyright statement | 89 | "(c) 2004, Lutz Rogowski", // copyright statement |
90 | 0, // any free form text | 90 | 0, // any free form text |
91 | "", // program home page address | 91 | "", // program home page address |
92 | "bugs.kde.org" // bug report email address | 92 | "bugs.kde.org" // bug report email address |
93 | ); | 93 | ); |
94 | 94 | ||
95 | 95 | ||
96 | // KCmdLineArgs::init() final 'true' argument indicates no commandline options | 96 | // KCmdLineArgs::init() final 'true' argument indicates no commandline options |
97 | // for QApplication/KApplication (no KDE or Qt options) | 97 | // for QApplication/KApplication (no KDE or Qt options) |
98 | KCmdLineArgs::init( argc, argv, &aboutData, true ); | 98 | KCmdLineArgs::init( argc, argv, &aboutData, true ); |
99 | KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. | 99 | KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. |
100 | 100 | ||
101 | KInstance ins ( progName ); | 101 | KInstance ins ( progName ); |
102 | 102 | ||
103 | KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); | 103 | KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); |
104 | 104 | ||
105 | bool read = false; | 105 | bool read = false; |
106 | if ( args->isSet( "read" ) ) { | 106 | if ( args->isSet( "read" ) ) { |
107 | read = true; | 107 | read = true; |
108 | qDebug("read "); | 108 | qDebug("read "); |
109 | } | 109 | } |
110 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; | 110 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; |
111 | CalendarResources *calendarResource = 0; | 111 | CalendarResources *calendarResource = 0; |
112 | CalendarLocal *localCalendar = 0; | 112 | CalendarLocal *localCalendar = 0; |
113 | KConfig c( locate( "config", "korganizerrc" ) ); | 113 | KConfig c( locate( "config", "korganizerrc" ) ); |
114 | c.setGroup( "Time & Date" ); | 114 | c.setGroup( "Time & Date" ); |
115 | QString tz = c.readEntry( "TimeZoneId" ); | 115 | QString tz = c.readEntry( "TimeZoneId" ); |
116 | calendarResource = new CalendarResources( tz ); | 116 | calendarResource = new CalendarResources( tz ); |
117 | calendarResource->readConfig(); | 117 | calendarResource->readConfig(); |
118 | calendarResource->load(); | 118 | calendarResource->load(); |
119 | qDebug("************************************* "); | 119 | qDebug("************************************* "); |
120 | qDebug("**************kdecaldump************* "); | 120 | qDebug("**************kdecaldump************* "); |
121 | qDebug("************************************* "); | 121 | qDebug("************************************* "); |
122 | qDebug("Using timezone ID: %s", calendarResource->timeZoneId().latin1()); | 122 | qDebug("Using timezone ID: %s", calendarResource->timeZoneId().latin1()); |
123 | 123 | ||
124 | if ( !read ) { | 124 | if ( !read ) { |
125 | localCalendar = new CalendarLocal(); | 125 | localCalendar = new CalendarLocal(); |
126 | localCalendar->setTimeZoneId( calendarResource->timeZoneId()); | 126 | localCalendar->setTimeZoneId( calendarResource->timeZoneId()); |
127 | KCal::Incidence::List allInc = calendarResource->rawIncidences(); | 127 | KCal::Incidence::List allInc = calendarResource->rawIncidences(); |
128 | Incidence::List::ConstIterator it; | 128 | Incidence::List::ConstIterator it; |
129 | int num = 0; | 129 | int num = 0; |
130 | for( it = allInc.begin(); it != allInc.end(); ++it ) { | 130 | for( it = allInc.begin(); it != allInc.end(); ++it ) { |
131 | ResourceCalendar * re = calendarResource->resource( (*it) ); | 131 | ResourceCalendar * re = calendarResource->resource( (*it) ); |
132 | if ( re && !re->readOnly() ) { | 132 | if ( re && /*!re->readOnly() now readonly syncing possible */) { |
133 | ++num; | 133 | ++num; |
134 | Incidence* cl = (*it)->clone(); | 134 | Incidence* cl = (*it)->clone(); |
135 | cl->setLastModified( (*it)->lastModified() ); | 135 | cl->setLastModified( (*it)->lastModified() ); |
136 | if ( cl->type() == "Journal" ) | 136 | if ( cl->type() == "Journal" ) |
137 | localCalendar->addJournal( (Journal *) cl ); | 137 | localCalendar->addJournal( (Journal *) cl ); |
138 | else if ( cl->type() == "Todo" ) | 138 | else if ( cl->type() == "Todo" ) |
139 | localCalendar->addTodo( (Todo *) cl ); | 139 | localCalendar->addTodo( (Todo *) cl ); |
140 | else if ( cl->type() == "Event" ) | 140 | else if ( cl->type() == "Event" ) |
141 | localCalendar->addEvent( (Event *) cl ); | 141 | localCalendar->addEvent( (Event *) cl ); |
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | ||
145 | FileStorage* storage = new FileStorage( calendarResource ); | 145 | FileStorage* storage = new FileStorage( calendarResource ); |
146 | storage->setFileName( fileName ); | 146 | storage->setFileName( fileName ); |
147 | storage->setSaveFormat( new ICalFormat() ); | 147 | storage->setSaveFormat( new ICalFormat() ); |
148 | storage->save(); | 148 | storage->save(); |
149 | delete storage; | 149 | delete storage; |
150 | qDebug("************************************* "); | 150 | qDebug("************************************* "); |
151 | qDebug("************kdecaldump*************** "); | 151 | qDebug("************kdecaldump*************** "); |
152 | qDebug("************************************* "); | 152 | qDebug("************************************* "); |
153 | qDebug("%d calendar entries dumped to file %s", num, fileName.latin1()); | 153 | qDebug("%d calendar entries dumped to file %s", num, fileName.latin1()); |
154 | 154 | ||
155 | } else { | 155 | } else { |
156 | qDebug("************load"); | 156 | qDebug("************load"); |
157 | localCalendar = new CalendarLocal(); | 157 | localCalendar = new CalendarLocal(); |
158 | localCalendar->setTimeZoneId( calendarResource->timeZoneId()); | 158 | localCalendar->setTimeZoneId( calendarResource->timeZoneId()); |
159 | FileStorage* storage = new FileStorage( localCalendar ); | 159 | FileStorage* storage = new FileStorage( localCalendar ); |
160 | storage->setFileName( fileName ); | 160 | storage->setFileName( fileName ); |
161 | int num = 0; | 161 | int num = 0; |
162 | int del = 0; | 162 | int del = 0; |
163 | int add = 0; | 163 | int add = 0; |
164 | if ( storage->load() ) { | 164 | if ( storage->load() ) { |
165 | qDebug("***********loaded!"); | 165 | qDebug("***********loaded!"); |
166 | KCal::Incidence::List newInc = localCalendar->rawIncidences(); | 166 | KCal::Incidence::List newInc = localCalendar->rawIncidences(); |
167 | Incidence::List::ConstIterator it; | 167 | Incidence::List::ConstIterator it; |
168 | for( it = newInc.begin(); it != newInc.end(); ++it ) { | 168 | for( it = newInc.begin(); it != newInc.end(); ++it ) { |
169 | if ( (*it)->pilotId() > 1 ) { //changed | 169 | if ( (*it)->pilotId() > 1 ) { //changed |
170 | qDebug("*********pilot id %d %s ",(*it)->pilotId() ,(*it)->summary().latin1()); | 170 | qDebug("*********pilot id %d %s ",(*it)->pilotId() ,(*it)->summary().latin1()); |
171 | Incidence *incOld = calendarResource->incidence( (*it)->uid() ); | 171 | Incidence *incOld = calendarResource->incidence( (*it)->uid() ); |
172 | ResourceCalendar * res = 0; | 172 | ResourceCalendar * res = 0; |
173 | if ( incOld ) | 173 | if ( incOld ) |
174 | res = calendarResource->resource( incOld ); | 174 | res = calendarResource->resource( incOld ); |
175 | if ( res ) { | 175 | if ( res ) { |
176 | Incidence* cl = (*it)->clone(); | 176 | Incidence* cl = (*it)->clone(); |
177 | cl->setPilotId( incOld->pilotId() ); | 177 | cl->setPilotId( incOld->pilotId() ); |
178 | ++num; | 178 | ++num; |
179 | if ( incOld->type() == "Journal" ) | 179 | if ( incOld->type() == "Journal" ) |
180 | calendarResource->deleteJournal( (Journal *) incOld ); | 180 | calendarResource->deleteJournal( (Journal *) incOld ); |
181 | else if ( incOld->type() == "Todo" ) | 181 | else if ( incOld->type() == "Todo" ) |
182 | calendarResource->deleteTodo( (Todo *) incOld ); | 182 | calendarResource->deleteTodo( (Todo *) incOld ); |
183 | else if ( incOld->type() == "Event" ) | 183 | else if ( incOld->type() == "Event" ) |
184 | calendarResource->deleteEvent( (Event *) incOld ); | 184 | calendarResource->deleteEvent( (Event *) incOld ); |
185 | qDebug("*********change incidence %s ",cl->summary().latin1()); | 185 | qDebug("*********change incidence %s ",cl->summary().latin1()); |
186 | if ( cl->type() == "Journal" ) | 186 | if ( cl->type() == "Journal" ) |
187 | calendarResource->addJournal( (Journal *) cl, res ); | 187 | calendarResource->addJournal( (Journal *) cl, res ); |
188 | else if ( cl->type() == "Todo" ) | 188 | else if ( cl->type() == "Todo" ) |
189 | calendarResource->addTodo( (Todo *) cl, res ); | 189 | calendarResource->addTodo( (Todo *) cl, res ); |
190 | else if ( cl->type() == "Event" ) | 190 | else if ( cl->type() == "Event" ) |
191 | calendarResource->addEvent( (Event *) cl, res ); | 191 | calendarResource->addEvent( (Event *) cl, res ); |
192 | 192 | ||
193 | } else { | 193 | } else { |
194 | Incidence* cl = (*it)->clone(); | 194 | Incidence* cl = (*it)->clone(); |
195 | qDebug("*********add incidence %s ",cl->summary().latin1()); | 195 | qDebug("*********add incidence %s ",cl->summary().latin1()); |
196 | calendarResource->addIncidence( cl ); | 196 | calendarResource->addIncidence( cl ); |
197 | ++add; | 197 | ++add; |
198 | } | 198 | } |
199 | } else { // maybe added | 199 | } else { // maybe added |
200 | Incidence *incOld = calendarResource->incidence( (*it)->uid() ); | 200 | Incidence *incOld = calendarResource->incidence( (*it)->uid() ); |
201 | if ( !incOld ) { //added | 201 | if ( !incOld ) { //added |
202 | Incidence* cl = (*it)->clone(); | 202 | Incidence* cl = (*it)->clone(); |
203 | qDebug("*********add incidence %s ",cl->summary().latin1()); | 203 | qDebug("*********add incidence %s ",cl->summary().latin1()); |
204 | calendarResource->addIncidence( cl ); | 204 | calendarResource->addIncidence( cl ); |
205 | ++add; | 205 | ++add; |
206 | } | 206 | } |
207 | } | 207 | } |
208 | } | 208 | } |
209 | KCal::Incidence::List allInc = calendarResource->rawIncidences(); | 209 | KCal::Incidence::List allInc = calendarResource->rawIncidences(); |
210 | 210 | ||
211 | for( it = allInc.begin(); it != allInc.end(); ++it ) { | 211 | for( it = allInc.begin(); it != allInc.end(); ++it ) { |
212 | ResourceCalendar * re = calendarResource->resource( (*it) ); | 212 | ResourceCalendar * re = calendarResource->resource( (*it) ); |
213 | if ( re && !re->readOnly() ) { | 213 | if ( re && !re->readOnly() ) { |
214 | Incidence* cl = localCalendar->incidence( (*it)->uid() ); | 214 | Incidence* cl = localCalendar->incidence( (*it)->uid() ); |
215 | if ( !cl ) { | 215 | if ( !cl ) { |
216 | ++del; | 216 | ++del; |
217 | cl = (*it); | 217 | cl = (*it); |
218 | if ( cl->type() == "Journal" ) | 218 | if ( cl->type() == "Journal" ) |
219 | calendarResource->deleteJournal( (Journal *) cl ); | 219 | calendarResource->deleteJournal( (Journal *) cl ); |
220 | else if ( cl->type() == "Todo" ) | 220 | else if ( cl->type() == "Todo" ) |
221 | calendarResource->deleteTodo( (Todo *) cl ); | 221 | calendarResource->deleteTodo( (Todo *) cl ); |
222 | else if ( cl->type() == "Event" ) | 222 | else if ( cl->type() == "Event" ) |
223 | calendarResource->deleteEvent( (Event *) cl ); | 223 | calendarResource->deleteEvent( (Event *) cl ); |
224 | //QDateTime lm = cl->lastModified(); | 224 | //QDateTime lm = cl->lastModified(); |
225 | //cl->setResources( (*it)->resources() ); | 225 | //cl->setResources( (*it)->resources() ); |
226 | //cl->setLastModified(lm); | 226 | //cl->setLastModified(lm); |
227 | } | 227 | } |
228 | } | 228 | } |
229 | } | 229 | } |
230 | 230 | ||
231 | calendarResource->save(); | 231 | calendarResource->save(); |
232 | qDebug("************************************* "); | 232 | qDebug("************************************* "); |
233 | qDebug("************kdecaldump*************** "); | 233 | qDebug("************kdecaldump*************** "); |
234 | qDebug("************************************* "); | 234 | qDebug("************************************* "); |
235 | qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1()); | 235 | qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1()); |
236 | 236 | ||
237 | } else | 237 | } else |
238 | qDebug("ERROR loading file %s",fileName.latin1() ); | 238 | qDebug("ERROR loading file %s",fileName.latin1() ); |
239 | 239 | ||
240 | } | 240 | } |
241 | 241 | ||
242 | if ( localCalendar ) { | 242 | if ( localCalendar ) { |
243 | localCalendar->close(); | 243 | localCalendar->close(); |
244 | delete localCalendar; | 244 | delete localCalendar; |
245 | } | 245 | } |
246 | if ( calendarResource ) { | 246 | if ( calendarResource ) { |
247 | calendarResource->close(); | 247 | calendarResource->close(); |
248 | delete calendarResource; | 248 | delete calendarResource; |
249 | } | 249 | } |
250 | 250 | ||
251 | qDebug("ente "); | 251 | qDebug("ente "); |
252 | return 0; | 252 | return 0; |
253 | } | 253 | } |