author | mickeyl <mickeyl> | 2004-04-04 13:54:40 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-04-04 13:54:40 (UTC) |
commit | 16cf79e90b5217f8d4bfce2a0fa817ae4b73db36 (patch) (unidiff) | |
tree | 0701eae15aa606a0211a2fccfde0eafdac69357c /noncore/apps/confedit/listviewitemconffile.cpp | |
parent | 8d2d2664e5f544b8292806e617deb7a0e4170dc0 (diff) | |
download | opie-16cf79e90b5217f8d4bfce2a0fa817ae4b73db36.zip opie-16cf79e90b5217f8d4bfce2a0fa817ae4b73db36.tar.gz opie-16cf79e90b5217f8d4bfce2a0fa817ae4b73db36.tar.bz2 |
convert to Opie Debugging Framework
Diffstat (limited to 'noncore/apps/confedit/listviewitemconffile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp index 1ff2c44..2958cf5 100644 --- a/noncore/apps/confedit/listviewitemconffile.cpp +++ b/noncore/apps/confedit/listviewitemconffile.cpp | |||
@@ -1,103 +1,109 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> | 9 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> |
10 | 10 | ||
11 | #include "listviewitemconffile.h" | 11 | #include "listviewitemconffile.h" |
12 | #include "listviewitemconfigentry.h" | ||
13 | |||
14 | /* OPIE */ | ||
15 | #include <opie2/odebug.h> | ||
16 | using namespace Opie::Core; | ||
17 | |||
18 | /* QT */ | ||
12 | #include <qmessagebox.h> | 19 | #include <qmessagebox.h> |
13 | #include <qtextstream.h> | 20 | #include <qtextstream.h> |
14 | #include "listviewitemconfigentry.h" | ||
15 | 21 | ||
16 | #define tr QObject::tr | 22 | #define tr QObject::tr |
17 | 23 | ||
18 | ListViewItemConfFile::ListViewItemConfFile(QFileInfo *file, QListView *parent) | 24 | ListViewItemConfFile::ListViewItemConfFile(QFileInfo *file, QListView *parent) |
19 | : ListViewItemConf(parent), _valid(false) | 25 | : ListViewItemConf(parent), _valid(false) |
20 | { | 26 | { |
21 | confFileInfo = file; | 27 | confFileInfo = file; |
22 | // parseFile(); | 28 | // parseFile(); |
23 | displayText(); | 29 | displayText(); |
24 | } | 30 | } |
25 | 31 | ||
26 | ListViewItemConfFile::~ListViewItemConfFile() | 32 | ListViewItemConfFile::~ListViewItemConfFile() |
27 | { | 33 | { |
28 | } | 34 | } |
29 | 35 | ||
30 | 36 | ||
31 | void ListViewItemConfFile::displayText() | 37 | void ListViewItemConfFile::displayText() |
32 | { | 38 | { |
33 | setText(0,(_changed?"*":"")+confFileInfo->fileName()); | 39 | setText(0,(_changed?"*":"")+confFileInfo->fileName()); |
34 | } | 40 | } |
35 | 41 | ||
36 | QString ListViewItemConfFile::fileName() | 42 | QString ListViewItemConfFile::fileName() |
37 | { | 43 | { |
38 | return confFileInfo->fileName(); | 44 | return confFileInfo->fileName(); |
39 | } | 45 | } |
40 | 46 | ||
41 | void ListViewItemConfFile::parseFile() | 47 | void ListViewItemConfFile::parseFile() |
42 | { | 48 | { |
43 | //qDebug("ListViewItemConfFile::parseFile BEGIN"); | 49 | //odebug << "ListViewItemConfFile::parseFile BEGIN" << oendl; |
44 | QFile confFile(confFileInfo->absFilePath()); | 50 | QFile confFile(confFileInfo->absFilePath()); |
45 | if(! confFile.open(IO_ReadOnly)) | 51 | if(! confFile.open(IO_ReadOnly)) |
46 | QMessageBox::critical(0,tr("Could not open"),tr("The file ")+confFileInfo->fileName()+tr(" could not be opened."),1,0); | 52 | QMessageBox::critical(0,tr("Could not open"),tr("The file ")+confFileInfo->fileName()+tr(" could not be opened."),1,0); |
47 | QTextStream t( &confFile ); | 53 | QTextStream t( &confFile ); |
48 | QString s; | 54 | QString s; |
49 | QString group; | 55 | QString group; |
50 | ListViewItemConfigEntry *groupItem; | 56 | ListViewItemConfigEntry *groupItem; |
51 | ListViewItemConfigEntry *item; | 57 | ListViewItemConfigEntry *item; |
52 | while ( !t.atEnd() ) | 58 | while ( !t.atEnd() ) |
53 | { | 59 | { |
54 | s = t.readLine().stripWhiteSpace(); | 60 | s = t.readLine().stripWhiteSpace(); |
55 | //qDebug( "line: >%s<\n", s.latin1() ); | 61 | //odebug << "line: >" << s.latin1() << "<\n" << oendl; |
56 | if (s.contains("<?xml")) | 62 | if (s.contains("<?xml")) |
57 | { | 63 | { |
58 | _valid = false; | 64 | _valid = false; |
59 | break; | 65 | break; |
60 | }else | 66 | }else |
61 | if ( s[0] == '[' && s[s.length()-1] == ']' ) | 67 | if ( s[0] == '[' && s[s.length()-1] == ']' ) |
62 | { | 68 | { |
63 | // qDebug("got group"+s); | 69 | // odebug << "got group"+s << oendl; |
64 | group = s.mid(1,s.length()-2); | 70 | group = s.mid(1,s.length()-2); |
65 | if (!groupItem) groupItem = new ListViewItemConfigEntry(this, tr("no group") ); | 71 | if (!groupItem) groupItem = new ListViewItemConfigEntry(this, tr("no group") ); |
66 | groupItem = new ListViewItemConfigEntry(this, group ); | 72 | groupItem = new ListViewItemConfigEntry(this, group ); |
67 | insertItem( groupItem ); | 73 | insertItem( groupItem ); |
68 | } else | 74 | } else |
69 | if ( int pos = s.find('=') ) | 75 | if ( int pos = s.find('=') ) |
70 | { | 76 | { |
71 | // qDebug("got key"+s); | 77 | // odebug << "got key"+s << oendl; |
72 | if (!groupItem) qDebug("PANIK NO GROUP! >%s<",group.latin1()); | 78 | if (!groupItem) odebug << "PANIK NO GROUP! >" << group.latin1() << "<" << oendl; |
73 | item = new ListViewItemConfigEntry(this, group, s ); | 79 | item = new ListViewItemConfigEntry(this, group, s ); |
74 | groupItem->insertItem( item ); | 80 | groupItem->insertItem( item ); |
75 | } | 81 | } |
76 | } | 82 | } |
77 | confFile.close(); | 83 | confFile.close(); |
78 | setExpandable( _valid ); | 84 | setExpandable( _valid ); |
79 | //qDebug("ListViewItemConfFile::parseFile END"); | 85 | //odebug << "ListViewItemConfFile::parseFile END" << oendl; |
80 | } | 86 | } |
81 | 87 | ||
82 | 88 | ||
83 | void ListViewItemConfFile::remove() | 89 | void ListViewItemConfFile::remove() |
84 | { | 90 | { |
85 | QFile::remove(confFileInfo->absFilePath()); | 91 | QFile::remove(confFileInfo->absFilePath()); |
86 | QFile::remove(backupFileName()); | 92 | QFile::remove(backupFileName()); |
87 | delete this; | 93 | delete this; |
88 | } | 94 | } |
89 | 95 | ||
90 | void ListViewItemConfFile::revert() | 96 | void ListViewItemConfFile::revert() |
91 | { | 97 | { |
92 | if (!_changed) | 98 | if (!_changed) |
93 | { | 99 | { |
94 | // read the backup file | 100 | // read the backup file |
95 | QFile conf(confFileInfo->absFilePath()); | 101 | QFile conf(confFileInfo->absFilePath()); |
96 | QFile back(backupFileName()); | 102 | QFile back(backupFileName()); |
97 | 103 | ||
98 | if (!back.open(IO_ReadOnly)) return; | 104 | if (!back.open(IO_ReadOnly)) return; |
99 | if (!conf.open(IO_WriteOnly)) return; | 105 | if (!conf.open(IO_WriteOnly)) return; |
100 | 106 | ||
101 | #define SIZE 124 | 107 | #define SIZE 124 |
102 | char buf[SIZE]; | 108 | char buf[SIZE]; |
103 | while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c); | 109 | while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c); |