23 #include "kdepim-version.h" 
   29 #include <QStringList> 
   30 #include <QTextStream> 
   33 #include <kapplication.h> 
   36 #include <kstandarddirs.h> 
   38 #include <kio/netaccess.h> 
   39 #include <kcal/calendarlocal.h> 
   40 #include <kcal/journal.h> 
   51     const QString configfile = KGlobal::dirs()->saveLocation( 
"config" ) + QLatin1String(
"knotesrc");
 
   52     if ( QFile::exists( configfile ) ) {
 
   54                     KSharedConfig::openConfig( configfile, KConfig::SimpleConfig ),
 
   56         double version = test.readEntry( 
"version", 9999999.99 );
 
   58         if ( version == 1.0 ) {
 
   59             if ( !( KStandardDirs::checkAccess( configfile, W_OK ) &&
 
   60                     QFile::remove( configfile ) ) ) {
 
   61                 kError( 5500 ) << 
"Could not delete old config file" << configfile;
 
   69     bool converted = 
false;
 
   71     QDir noteDir( KGlobal::dirs()->saveLocation( 
"appdata", QLatin1String(
"notes/") ) );
 
   72     const QStringList notes = noteDir.entryList( QDir::Files, QDir::Name );
 
   73     for ( QStringList::ConstIterator note = notes.constBegin(); note != notes.constEnd();
 
   75         QString file = noteDir.absoluteFilePath( *note );
 
   76         KConfig *test = 
new KConfig( file, KConfig::SimpleConfig );
 
   77         KConfigGroup grp( test, 
"General" );
 
   78         double version = grp.readEntry( 
"version", 1.0 );
 
   80         if ( version < 3.0 ) {
 
   83             Journal *journal = 
new Journal();
 
   86             if ( version < 2.0 ) {
 
   87                 success = convertKNotes1Config( journal, noteDir, *note );
 
   89                 success = convertKNotes2Config( journal, noteDir, *note );
 
   96                 calendar->addJournal( journal );
 
   99         } 
else if ( version < 3.2 ) { 
 
  101             uint state = grp.readEntry( 
"state", uint( NET::SkipTaskbar ) );
 
  103             grp.writeEntry( 
"ShowInTaskbar",
 
  104                             ( state & NET::SkipTaskbar ) ? 
false : 
true );
 
  105             grp.writeEntry( 
"KeepAbove",
 
  106                             ( state & NET::KeepAbove ) ? 
true : 
false );
 
  108             grp.deleteEntry( 
"state" );
 
  116 bool KNotesLegacy::convertKNotes1Config( Journal *journal, QDir ¬eDir,
 
  117                                          const QString &file )
 
  119     QFile infile( noteDir.absoluteFilePath( file ) );
 
  120     if ( !infile.open( QIODevice::ReadOnly ) ) {
 
  121         kError( 5500 ) << 
"Could not open input file: \"" 
  122                        << infile.fileName() << 
"\"";
 
  126     QTextStream input( &infile );
 
  129     journal->setSummary( input.readLine() );
 
  131     const QStringList props = input.readLine().split( QLatin1Char(
'+'), QString::SkipEmptyParts );
 
  134     if ( props.count() != 13 ) {
 
  135         kWarning( 5500 ) <<
"The file \"" << infile.fileName()
 
  136                         << 
"\" lacks version information but is not a valid" 
  137                         << 
"KNotes 1 config file either!";
 
  142     const QString configFile = noteDir.absoluteFilePath( journal->uid() );
 
  145     KIO::NetAccess::file_copy(
 
  146                 KUrl( KGlobal::dirs()->saveLocation( 
"config" ) + QLatin1String(
"knotesrc") ),
 
  151     KNoteConfig config( KSharedConfig::openConfig( configFile,
 
  152                                                    KConfig::NoGlobals ) );
 
  154     config.setVersion( QLatin1String(KDEPIM_VERSION) );
 
  157     config.setWidth( props[3].toUInt() );
 
  158     config.setHeight( props[4].toUInt() );
 
  161     uint red = input.readLine().toUInt();
 
  162     uint green = input.readLine().toUInt();
 
  163     uint blue = input.readLine().toUInt();
 
  164     config.setBgColor( QColor( red, green, blue ) );
 
  167     red = input.readLine().toUInt();
 
  168     green = input.readLine().toUInt();
 
  169     blue = input.readLine().toUInt();
 
  170     config.setFgColor( QColor( red, green, blue ) );
 
  173     QString fontfamily = input.readLine();
 
  174     if ( fontfamily.isEmpty() )
 
  175         fontfamily = QLatin1String( 
"Sans Serif" );
 
  176     uint size = input.readLine().toUInt();
 
  177     size = qMax( size, ( uint ) 4 );
 
  178     uint weight = input.readLine().toUInt();
 
  179     bool italic = ( input.readLine().toUInt() == 1 );
 
  180     QFont font( fontfamily, size, weight, italic );
 
  182     config.setTitleFont( font );
 
  183     config.setFont( font );
 
  189     config.setAutoIndent( input.readLine().toUInt() == 1 );
 
  192     config.setRichText( 
false );
 
  194     int note_desktop = props[0].toUInt();
 
  197     if ( input.readLine().toUInt() == 1 )
 
  200     else if ( props[11].toUInt() == 1 )
 
  201         note_desktop = NETWinInfo::OnAllDesktops;
 
  204     config.setDesktop( note_desktop );
 
  205     config.setPosition( QPoint( props[1].toUInt(), props[2].toUInt() ) );
 
  206     config.setKeepAbove( props[12].toUInt() & 2048 );
 
  208     config.writeConfig();
 
  212     while ( !input.atEnd() ) {
 
  213         text.append( input.readLine() );
 
  214         if ( !input.atEnd() ) {
 
  215             text.append( QLatin1Char(
'\n') );
 
  219     journal->setDescription( text );
 
  221     if ( !infile.remove() )
 
  223         kWarning( 5500 ) << 
"Could not delete input file: \"" << infile.fileName()
 
  230 bool KNotesLegacy::convertKNotes2Config( Journal *journal, QDir ¬eDir,
 
  231                                          const QString &file )
 
  233     const QString configFile = noteDir.absoluteFilePath( journal->uid() );
 
  236     if ( !noteDir.rename( file, journal->uid() ) ) {
 
  237         kError( 5500 ) << 
"Could not rename input file: \"" 
  238                        << noteDir.absoluteFilePath( file ) << 
"\" to \"" 
  239                        << configFile << 
"\"!";
 
  244     KConfig config( configFile );
 
  245     KConfigGroup grp( &config, 
"Data" );
 
  246     journal->setSummary( grp.readEntry( 
"name" ) );
 
  247     config.deleteGroup( 
"Data", KConfig::Localized );
 
  248     KConfigGroup _grp2(&config, 
"General" ); 
 
  249     _grp2.writeEntry( 
"version", KDEPIM_VERSION );
 
  250     KConfigGroup _grp3(&config, 
"WindowDisplay" ); 
 
  252     uint state = _grp3.readEntry( 
"state", uint( NET::SkipTaskbar ) );
 
  253     _grp3.writeEntry( 
"ShowInTaskbar",
 
  254                       ( state & NET::SkipTaskbar ) ? 
false : 
true );
 
  255     _grp3.writeEntry( 
"KeepAbove",
 
  256                       ( state & NET::KeepAbove ) ? 
true : 
false );
 
  258     _grp3.deleteEntry( 
"state" );
 
  261     QFile infile( noteDir.absoluteFilePath( QLatin1Char(
'.') + file + QLatin1String(
"_data") ) );
 
  262     if ( infile.open( QIODevice::ReadOnly ) ) {
 
  263         QTextStream input( &infile );
 
  264         input.setCodec( 
"UTF-8" );
 
  265         journal->setDescription( input.readAll() );
 
  266         if ( !infile.remove() ) {
 
  267             kWarning( 5500 ) << 
"Could not delete data file: \"" << infile.fileName()
 
  272         kWarning( 5500 ) << 
"Could not open data file: \"" << infile.fileName()
 
static bool convert(KCal::CalendarLocal *calendar)