kitchensync

desktop.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2002,2003 Holger Freyther <freyther@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 
00023 #include "desktop.h"
00024 
00025 #include <qregexp.h>
00026 
00027 
00028 using namespace OpieHelper;
00029 
00030 Desktop::Desktop( CategoryEdit* edit )
00031     : Base( edit )
00032 {}
00033 
00034 Desktop::~Desktop()
00035 {}
00036 
00037 
00038 KSync::OpieDesktopSyncee* Desktop::toSyncee( const QString& str)
00039 {
00040     KSync::OpieDesktopSyncee* syncee;
00041     syncee = new KSync::OpieDesktopSyncee();
00042 
00043     // convert the string
00044     QString string ( str );
00045     string.remove(0, 35 );
00046     string.replace(QRegExp("&amp;"), "&" );
00047     string.replace(QRegExp("&0x20;"), " ");
00048     string.replace(QRegExp("&0x0d;"), "\n");
00049     string.replace(QRegExp("&0x0a;"), "\r");
00050     string.replace(QRegExp("\r\n"), "\n" ); // hell we're on unix
00051 
00052     if ( !str.contains("[Desktop Entry]") ) {
00053         delete syncee;
00054         return 0l;
00055     }
00056     QStringList list = QStringList::split('\n', string );
00057     QStringList::Iterator it;
00058     it = list.begin();
00059     list.remove( it ); // remove the [Desktop Entry]
00060 
00061     KSync::OpieDesktopSyncEntry *entry;
00062     QString name,  type,  fileName,  size;
00063     QStringList category;
00064 
00065     for ( it = list.begin(); it != list.end(); ++it ) { // QAsciiDict?
00066         QString con( (*it).stripWhiteSpace() );
00067 
00068         if (con.startsWith("Categories = ") ) {
00069             con = con.remove(0, 13 );
00070             //con = con.remove( con.length() -1, 1 ); // remove the last char ;
00071             QStringList catList = QStringList::split(';',con ); // no empty cats
00072             category = edit()->categoriesByIds( catList, QString::null );
00073 
00074         }else if ( con.startsWith("Name = ") ) {
00075             con = con.remove(0, 7 );
00076             name = con.stripWhiteSpace();
00077         }else if ( con.startsWith("Type = ") ) {
00078             con = con.remove( 0, 7 );
00079             type = con.stripWhiteSpace() ;
00080         }else if ( con.startsWith("File = ") ) {
00081             con = con.remove( 0, 7 );
00082             fileName = con.stripWhiteSpace();
00083         }else if ( con.startsWith("Size = ") ) {
00084             con = con.remove(0, 7 );
00085             size = con.stripWhiteSpace();
00086         }else if ( (*it).stripWhiteSpace() == "[Desktop Entry]" ) {
00087             entry= new KSync::OpieDesktopSyncEntry( category,
00088                                                     fileName,
00089                                                     name,
00090                                                     type,
00091                                                     size, syncee );
00092             syncee->addEntry( entry );
00093         }
00094 
00095     }
00096     // one is missing
00097     entry = new KSync::OpieDesktopSyncEntry( category,
00098                                              fileName,
00099                                              name,
00100                                              type,
00101                                              size, syncee );
00102     syncee->addEntry( entry );
00103     return syncee;
00104 }
00105 
KDE Home | KDE Accessibility Home | Description of Access Keys