00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qfile.h>
00022 #include <qfont.h>
00023 #include <qpoint.h>
00024 #include <qcolor.h>
00025 #include <qstringlist.h>
00026 #include <qtextstream.h>
00027
00028 #include <kdebug.h>
00029 #include <kapplication.h>
00030 #include <kglobal.h>
00031 #include <kstandarddirs.h>
00032 #include <kurl.h>
00033 #include <ksimpleconfig.h>
00034 #include <kio/netaccess.h>
00035
00036 #include <unistd.h>
00037
00038 #include "version.h"
00039 #include "knoteslegacy.h"
00040
00041 #include "libkcal/calendarlocal.h"
00042 #include "libkcal/journal.h"
00043
00044 #include <netwm.h>
00045
00046 using namespace KCal;
00047
00048
00049 void KNotesLegacy::cleanUp()
00050 {
00051
00052 QString configfile = KGlobal::dirs()->findResource( "config", "knotesrc" );
00053 KSimpleConfig *test = new KSimpleConfig( configfile );
00054 test->setGroup( "General" );
00055 double version = test->readDoubleNumEntry( "version", 1 );
00056 if ( version == 1 )
00057 {
00058 delete test;
00059 if ( !( checkAccess( configfile, W_OK ) &&
00060 KIO::NetAccess::del( KURL(configfile), 0 ) ) )
00061 {
00062 kdError(5500) << k_funcinfo << "Could not delete old config file!!" << endl;
00063
00064 }
00065 }
00066 else if ( version < 3 )
00067 {
00068 test->writeEntry( "version", KNOTES_VERSION );
00069 delete test;
00070 }
00071 else
00072 delete test;
00073 }
00074
00075 bool KNotesLegacy::convert( CalendarLocal *calendar )
00076 {
00077 bool converted = false;
00078
00079 QDir noteDir( KGlobal::dirs()->saveLocation( "appdata", "notes/" ) );
00080 QStringList notes = noteDir.entryList( QDir::Files, QDir::Name );
00081 for ( QStringList::Iterator note = notes.begin(); note != notes.end(); note++ )
00082 {
00083 QString file = noteDir.absFilePath( *note );
00084 KSimpleConfig* test = new KSimpleConfig( file, true );
00085 test->setGroup( "General" );
00086 double version = test->readDoubleNumEntry( "version", 1 );
00087 delete test;
00088
00089 if ( version < 3.0 )
00090 {
00091
00092 Journal *journal = new Journal();
00093
00094 if ( version < 2.0 )
00095 convertKNotes1Config( journal, noteDir, *note );
00096 else
00097 convertKNotes2Config( journal, noteDir, *note );
00098
00099 calendar->addJournal( journal );
00100 converted = true;
00101 }
00102 }
00103
00104 return converted;
00105 }
00106
00107 void KNotesLegacy::convertKNotes1Config( Journal *journal, QDir& noteDir,
00108 const QString& file )
00109 {
00110 QFile infile( noteDir.absFilePath( file ) );
00111
00112 if ( !infile.open( IO_ReadOnly ) )
00113 {
00114 kdError(5500) << k_funcinfo << "Could not open input file: " << infile.name() << endl;
00115
00116
00117 return;
00118 }
00119
00120 QTextStream input( &infile );
00121
00122
00123 QString configFile = noteDir.absFilePath( journal->uid() );
00124
00125
00126 KIO::NetAccess::copy(
00127 KURL( KGlobal::dirs()->findResource( "config", "knotesrc" ) ), KURL( configFile ), 0
00128 );
00129
00130
00131 journal->setSummary( input.readLine() );
00132
00133
00134
00135 KSimpleConfig config( configFile );
00136
00137 config.setGroup( "General" );
00138 config.writeEntry( "version", KNOTES_VERSION );
00139
00140
00141 config.setGroup( "Actions" );
00142 config.writeEntry( "mail", "kmail --msg %f" );
00143
00144 config.setGroup( "Display" );
00145
00146
00147 QString geo = input.readLine();
00148
00149 int pos, data[13];
00150 int n = 0;
00151
00152 while ( (pos = geo.find('+')) != -1 )
00153 {
00154 if( n < 13 )
00155 data[n++] = geo.left(pos).toInt();
00156 geo.remove( 0, pos + 1 );
00157 }
00158 if ( n < 13 )
00159 data[n++] = geo.toInt();
00160
00161 config.writeEntry( "width", data[3] );
00162 config.writeEntry( "height", data[4] );
00163
00164
00165 uint red = input.readLine().toUInt();
00166 uint green = input.readLine().toUInt();
00167 uint blue = input.readLine().toUInt();
00168 config.writeEntry( "bgcolor", QColor( red, green, blue ) );
00169
00170
00171 red = input.readLine().toUInt();
00172 green = input.readLine().toUInt();
00173 blue = input.readLine().toUInt();
00174 config.writeEntry( "fgcolor", QColor( red, green, blue ) );
00175
00176 config.setGroup( "Editor" );
00177
00178
00179 QString fontfamily = input.readLine();
00180 if ( fontfamily.isEmpty() )
00181 fontfamily = QString( "helvetica" );
00182 uint size = input.readLine().toUInt();
00183 size = QMAX( size, 4 );
00184 uint weight = input.readLine().toUInt();
00185 bool italic = ( input.readLine().toUInt() == 1 );
00186 QFont font( fontfamily, size, weight, italic );
00187
00188 config.writeEntry( "titlefont", font );
00189 config.writeEntry( "font", font );
00190
00191
00192 input.readLine();
00193
00194
00195 bool indent = ( input.readLine().toUInt() == 1 );
00196 config.writeEntry( "autoindent", indent );
00197
00198
00199 config.writeEntry( "richtext", false );
00200 config.writeEntry( "tabsize", 4 );
00201
00202 config.setGroup( "WindowDisplay" );
00203
00204
00205 bool hidden = ( input.readLine().toUInt() == 1 );
00206
00207 int note_desktop = data[0];
00208 if ( hidden )
00209 note_desktop = 0;
00210 else if ( data[11] == 1 )
00211 note_desktop = NETWinInfo::OnAllDesktops;
00212
00213 config.writeEntry( "desktop", note_desktop );
00214
00215 if ( data[1] >= 0 && data[2] >= 0 )
00216 config.writeEntry( "position", QPoint( data[1], data[2] ) );
00217 else
00218 config.writeEntry( "position", QPoint( 10, 10 ) );
00219
00220 if ( data[12] & 2048 )
00221 config.writeEntry( "state", NET::SkipTaskbar | NET::StaysOnTop );
00222 else
00223 config.writeEntry( "state", NET::SkipTaskbar );
00224
00225 config.sync();
00226
00227
00228 QString text;
00229 while ( !input.atEnd() )
00230 {
00231 text.append( input.readLine() );
00232 if ( !input.atEnd() )
00233 text.append( '\n' );
00234 }
00235
00236 journal->setDescription( text );
00237 journal->addAttachment( new Attachment( configFile, CONFIG_MIME ) );
00238
00239 infile.close();
00240 infile.remove();
00241 }
00242
00243 void KNotesLegacy::convertKNotes2Config( Journal *journal, QDir& noteDir,
00244 const QString& file )
00245 {
00246
00247 noteDir.rename( file, journal->uid() );
00248 QString configFile = noteDir.absFilePath( journal->uid() );
00249
00250
00251 KConfig config( configFile );
00252 config.setGroup( "Data" );
00253 journal->setSummary( config.readEntry( "name" ) );
00254 config.deleteEntry( "name" );
00255 config.deleteGroup( "Data", false );
00256 config.setGroup( "General" );
00257 config.writeEntry( "version", KNOTES_VERSION );
00258
00259
00260 QFile infile( noteDir.absFilePath( "." + file + "_data" ) );
00261 if ( infile.open( IO_ReadOnly ) )
00262 {
00263 QTextStream input( &infile );
00264 input.setEncoding( QTextStream::UnicodeUTF8 );
00265 journal->setDescription( input.read() );
00266 infile.close();
00267 infile.remove();
00268 }
00269 else
00270 kdError(5500) << k_funcinfo << "Could not open input file: " << infile.name() << endl;
00271
00272 journal->addAttachment( new Attachment( configFile, CONFIG_MIME ) );
00273 }