00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#include <qregexp.h>
00023
00024
#include "desktop.h"
00025
00026
using namespace OpieHelper;
00027
00028 Desktop::Desktop( CategoryEdit* edit )
00029 : Base( edit ) {
00030
00031
00032 }
00033 Desktop::~Desktop() {
00034
00035 }
00036 KSync::OpieDesktopSyncee* Desktop::toSyncee(
const QString& str) {
00037 KSync::OpieDesktopSyncee* syncee;
00038 syncee =
new KSync::OpieDesktopSyncee();
00039
00040
00041
QString string ( str );
00042 string.remove(0, 35 );
00043 string.replace(
QRegExp(
"&"),
"&" );
00044 string.replace(
QRegExp(
"&0x20;"),
" ");
00045 string.replace(
QRegExp(
"&0x0d;"),
"\n");
00046 string.replace(
QRegExp(
"&0x0a;"),
"\r");
00047 string.replace(
QRegExp(
"\r\n"),
"\n" );
00048
00049
if ( !str.contains(
"[Desktop Entry]") ) {
00050 kdDebug(5224) <<
"Desktop Entry: " << str << endl;
00051
delete syncee;
00052
return 0l;
00053 }
00054
QStringList list = QStringList::split(
'\n', string );
00055 QStringList::Iterator it;
00056 it = list.begin();
00057 list.remove( it );
00058
00059
KSync::OpieDesktopSyncEntry *entry;
00060
QString name, type, fileName, size;
00061
QStringList category;
00062
00063
for ( it = list.begin(); it != list.end(); ++it ) {
00064
QString con( (*it).stripWhiteSpace() );
00065
00066
if (con.startsWith(
"Categories = ") ) {
00067 con = con.remove(0, 13 );
00068
00069
QStringList catList = QStringList::split(
';',con );
00070 category = edit()->categoriesByIds( catList, QString::null );
00071
00072 }
else if ( con.startsWith(
"Name = ") ) {
00073 con = con.remove(0, 7 );
00074 name = con.stripWhiteSpace();
00075 }
else if ( con.startsWith(
"Type = ") ) {
00076 con = con.remove( 0, 7 );
00077 type = con.stripWhiteSpace() ;
00078 }
else if ( con.startsWith(
"File = ") ) {
00079 con = con.remove( 0, 7 );
00080 fileName = con.stripWhiteSpace();
00081 }
else if ( con.startsWith(
"Size = ") ) {
00082 con = con.remove(0, 7 );
00083 size = con.stripWhiteSpace();
00084 }
else if ( (*it).stripWhiteSpace() ==
"[Desktop Entry]" ) {
00085 entry=
new KSync::OpieDesktopSyncEntry( category,
00086 fileName,
00087 name,
00088 type,
00089 size, syncee );
00090 syncee->addEntry( entry );
00091 }
00092
00093 }
00094
00095 entry =
new KSync::OpieDesktopSyncEntry( category,
00096 fileName,
00097 name,
00098 type,
00099 size, syncee );
00100 syncee->addEntry( entry );
00101
return syncee;
00102 }
00103