25 #include <tqstringlist.h>
26 #include <tqtextstream.h>
29 #include <tdeapplication.h>
30 #include <tdeglobal.h>
32 #include <kstandarddirs.h>
33 #include <ksimpleconfig.h>
34 #include <tdeio/netaccess.h>
38 #include "knoteslegacy.h"
39 #include "knoteconfig.h"
42 #include "libkcal/calendarlocal.h"
43 #include "libkcal/journal.h"
50 void KNotesLegacy::cleanUp()
53 TQString configfile = TDEGlobal::dirs()->saveLocation(
"config" ) +
"knotesrc";
54 if ( TQFile::exists( configfile ) ) {
55 KSimpleConfig *test =
new KSimpleConfig( configfile );
56 test->setGroup(
"General" );
57 double version = test->readDoubleNumEntry(
"version", 1.0 );
60 if ( version == 1.0 ) {
61 if ( !( checkAccess( configfile, W_OK ) &&
62 TQFile::remove( configfile ) ) )
64 kdError(5500) << k_funcinfo <<
"Could not delete old config file " << configfile << endl;
70 bool KNotesLegacy::convert( CalendarLocal *calendar )
72 bool converted =
false;
74 TQDir noteDir( TDEGlobal::dirs()->saveLocation(
"appdata",
"notes/" ) );
75 const TQStringList notes = noteDir.entryList( TQDir::Files, TQDir::Name );
76 for ( TQStringList::ConstIterator note = notes.constBegin(); note != notes.constEnd(); ++note )
78 TQString file = noteDir.absFilePath( *note );
79 KSimpleConfig* test =
new KSimpleConfig( file );
80 test->setGroup(
"General" );
81 double version = test->readDoubleNumEntry(
"version", 1.0 );
87 Journal *journal =
new Journal();
91 success = convertKNotes1Config( journal, noteDir, *note );
93 success = convertKNotes2Config( journal, noteDir, *note );
100 calendar->addJournal( journal );
105 else if ( version < 3.2 )
107 uint state = test->readUnsignedLongNumEntry(
"state", NET::SkipTaskbar );
108 test->writeEntry(
"ShowInTaskbar", (state & NET::SkipTaskbar) ?
false :
true );
109 test->writeEntry(
"KeepAbove", (state & NET::KeepAbove) ?
true :
false );
110 test->deleteEntry(
"state" );
118 bool KNotesLegacy::convertKNotes1Config( Journal *journal, TQDir& noteDir,
119 const TQString& file )
121 TQFile infile( noteDir.absFilePath( file ) );
122 if ( !infile.open( IO_ReadOnly ) )
124 kdError(5500) << k_funcinfo <<
"Could not open input file: \""
125 << infile.name() <<
"\"" << endl;
129 TQTextStream input( &infile );
132 journal->setSummary( input.readLine() );
134 TQStringList props = TQStringList::split(
'+', input.readLine() );
137 if ( props.count() != 13 )
139 kdWarning(5500) << k_funcinfo <<
"The file \"" << infile.name()
140 <<
"\" lacks version information but is not a valid "
141 <<
"KNotes 1 config file either!" << endl;
146 TQString configFile = noteDir.absFilePath( journal->uid() );
149 TDEIO::NetAccess::copy(
150 KURL( TDEGlobal::dirs()->saveLocation(
"config" ) +
"knotesrc" ),
155 KNoteConfig config( TDESharedConfig::openConfig( configFile,
false,
false ) );
157 config.setVersion( KNOTES_VERSION );
160 config.setWidth( props[3].toUInt() );
161 config.setHeight( props[4].toUInt() );
164 uint red = input.readLine().toUInt();
165 uint green = input.readLine().toUInt();
166 uint blue = input.readLine().toUInt();
167 config.setBgColor( TQColor( red, green, blue ) );
170 red = input.readLine().toUInt();
171 green = input.readLine().toUInt();
172 blue = input.readLine().toUInt();
173 config.setFgColor( TQColor( red, green, blue ) );
176 TQString fontfamily = input.readLine();
177 if ( fontfamily.isEmpty() )
178 fontfamily = TQString(
"Sans Serif" );
179 uint size = input.readLine().toUInt();
180 size = TQMAX( size, 4 );
181 uint weight = input.readLine().toUInt();
182 bool italic = ( input.readLine().toUInt() == 1 );
183 TQFont font( fontfamily, size, weight, italic );
185 config.setTitleFont( font );
186 config.setFont( font );
192 config.setAutoIndent( input.readLine().toUInt() == 1 );
195 config.setRichText(
false );
197 int note_desktop = props[0].toUInt();
200 if ( input.readLine().toUInt() == 1 )
202 else if ( props[11].toUInt() == 1 )
203 note_desktop = NETWinInfo::OnAllDesktops;
205 config.setDesktop( note_desktop );
206 config.setPosition( TQPoint( props[1].toUInt(), props[2].toUInt() ) );
207 config.setKeepAbove( props[12].toUInt() & 2048 );
209 config.writeConfig();
213 while ( !input.atEnd() )
215 text.append( input.readLine() );
216 if ( !input.atEnd() )
220 journal->setDescription( text );
222 if ( !infile.remove() )
223 kdWarning(5500) << k_funcinfo <<
"Could not delete input file: \"" << infile.name() <<
"\"" << endl;
228 bool KNotesLegacy::convertKNotes2Config( Journal *journal, TQDir& noteDir,
229 const TQString& file )
231 TQString configFile = noteDir.absFilePath( journal->uid() );
234 if ( !noteDir.rename( file, journal->uid() ) )
236 kdError(5500) << k_funcinfo <<
"Could not rename input file: \""
237 << noteDir.absFilePath( file ) <<
"\" to \""
238 << configFile <<
"\"!" << endl;
243 TDEConfig config( configFile );
244 config.setGroup(
"Data" );
245 journal->setSummary( config.readEntry(
"name" ) );
246 config.deleteGroup(
"Data",
true );
247 config.setGroup(
"General" );
248 config.writeEntry(
"version", KNOTES_VERSION );
249 config.setGroup(
"WindowDisplay" );
250 uint state = config.readUnsignedLongNumEntry(
"state", NET::SkipTaskbar );
251 config.writeEntry(
"ShowInTaskbar", (state & NET::SkipTaskbar) ?
false :
true );
252 config.writeEntry(
"KeepAbove", (state & NET::KeepAbove) ?
true :
false );
253 config.deleteEntry(
"state" );
256 TQFile infile( noteDir.absFilePath(
"." + file +
"_data" ) );
257 if ( infile.open( IO_ReadOnly ) )
259 TQTextStream input( &infile );
260 input.setEncoding( TQTextStream::UnicodeUTF8 );
261 journal->setDescription( input.read() );
262 if ( !infile.remove() )
263 kdWarning(5500) << k_funcinfo <<
"Could not delete data file: \"" << infile.name() <<
"\"" << endl;
266 kdWarning(5500) << k_funcinfo <<
"Could not open data file: \"" << infile.name() <<
"\"" << endl;