summaryrefslogtreecommitdiff
path: root/noncore/apps/confedit/listviewitemconffile.cpp
Unidiff
Diffstat (limited to 'noncore/apps/confedit/listviewitemconffile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/confedit/listviewitemconffile.cpp59
1 files changed, 32 insertions, 27 deletions
diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp
index 2958cf5..a7d6b00 100644
--- a/noncore/apps/confedit/listviewitemconffile.cpp
+++ b/noncore/apps/confedit/listviewitemconffile.cpp
@@ -20,90 +20,95 @@ using namespace Opie::Core;
20#include <qtextstream.h> 20#include <qtextstream.h>
21 21
22#define tr QObject::tr 22#define tr QObject::tr
23 23
24ListViewItemConfFile::ListViewItemConfFile(QFileInfo *file, QListView *parent) 24ListViewItemConfFile::ListViewItemConfFile(QFileInfo *file, QListView *parent)
25 : ListViewItemConf(parent), _valid(false) 25 : ListViewItemConf(parent), _valid(false)
26{ 26{
27 confFileInfo = file; 27 confFileInfo = file;
28 // parseFile(); 28 // parseFile();
29 displayText(); 29 displayText();
30} 30}
31 31
32ListViewItemConfFile::~ListViewItemConfFile() 32ListViewItemConfFile::~ListViewItemConfFile()
33{ 33{
34} 34}
35 35
36 36
37void ListViewItemConfFile::displayText() 37void ListViewItemConfFile::displayText()
38{ 38{
39 setText(0,(_changed?"*":"")+confFileInfo->fileName()); 39 setText(0,(_changed?"*":"")+confFileInfo->fileName());
40} 40}
41 41
42QString ListViewItemConfFile::fileName() 42QString ListViewItemConfFile::fileName()
43{ 43{
44 return confFileInfo->fileName(); 44 return confFileInfo->fileName();
45} 45}
46 46
47void ListViewItemConfFile::parseFile() 47void ListViewItemConfFile::parseFile()
48{ 48{
49 //odebug << "ListViewItemConfFile::parseFile BEGIN" << oendl; 49 //odebug << "ListViewItemConfFile::parseFile BEGIN" << oendl;
50 QFile confFile(confFileInfo->absFilePath()); 50 QFile confFile(confFileInfo->absFilePath());
51 if(! confFile.open(IO_ReadOnly)) 51 if(! confFile.open(IO_ReadOnly))
52 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);
53 QTextStream t( &confFile ); 53
54 QString s; 54 QTextStream t( &confFile );
55 QString s;
55 QString group; 56 QString group;
56 ListViewItemConfigEntry *groupItem; 57 ListViewItemConfigEntry *groupItem = 0;
57 ListViewItemConfigEntry *item; 58 ListViewItemConfigEntry *item;
58 while ( !t.atEnd() ) 59 while ( !t.atEnd() )
59 { 60 {
60 s = t.readLine().stripWhiteSpace(); 61 s = t.readLine().stripWhiteSpace();
61 //odebug << "line: >" << s.latin1() << "<\n" << oendl; 62 //odebug << "line: >" << s.latin1() << "<\n" << oendl;
62 if (s.contains("<?xml")) 63 if (s.contains("<?xml"))
63 { 64 {
64 _valid = false; 65 _valid = false;
65 break; 66 break;
66 }else 67 }
67 if ( s[0] == '[' && s[s.length()-1] == ']' ) 68 else if ( s[0] == '[' && s[s.length()-1] == ']' )
68 { 69 {
69 // odebug << "got group"+s << oendl; 70 //odebug << "got group"+s << oendl;
70 group = s.mid(1,s.length()-2); 71 group = s.mid(1,s.length()-2);
71 if (!groupItem) groupItem = new ListViewItemConfigEntry(this, tr("no group") ); 72 if (!groupItem)
73 groupItem = new ListViewItemConfigEntry(this, tr("no group") );
74
72 groupItem = new ListViewItemConfigEntry(this, group ); 75 groupItem = new ListViewItemConfigEntry(this, group );
73 insertItem( groupItem ); 76 insertItem( groupItem );
74 } else 77 }
75 if ( int pos = s.find('=') ) 78 else if ( int pos = s.find('=') )
76 { 79 {
77// odebug << "got key"+s << oendl; 80 //odebug << "got key"+s << oendl;
78 if (!groupItem) odebug << "PANIK NO GROUP! >" << group.latin1() << "<" << oendl; 81 if (!groupItem)
79 item = new ListViewItemConfigEntry(this, group, s ); 82 odebug << "PANIC! no group >" << group.latin1() << "<" << oendl;
83
84 item = new ListViewItemConfigEntry(this, group, s );
80 groupItem->insertItem( item ); 85 groupItem->insertItem( item );
81 } 86 }
82 } 87 }
83 confFile.close(); 88 confFile.close();
84 setExpandable( _valid ); 89 setExpandable( _valid );
85 //odebug << "ListViewItemConfFile::parseFile END" << oendl; 90 //odebug << "ListViewItemConfFile::parseFile END" << oendl;
86} 91}
87 92
88 93
89void ListViewItemConfFile::remove() 94void ListViewItemConfFile::remove()
90{ 95{
91 QFile::remove(confFileInfo->absFilePath()); 96 QFile::remove(confFileInfo->absFilePath());
92 QFile::remove(backupFileName()); 97 QFile::remove(backupFileName());
93 delete this; 98 delete this;
94} 99}
95 100
96void ListViewItemConfFile::revert() 101void ListViewItemConfFile::revert()
97{ 102{
98 if (!_changed) 103 if (!_changed)
99 { 104 {
100 // read the backup file 105 // read the backup file
101 QFile conf(confFileInfo->absFilePath()); 106 QFile conf(confFileInfo->absFilePath());
102 QFile back(backupFileName()); 107 QFile back(backupFileName());
103 108
104 if (!back.open(IO_ReadOnly)) return; 109 if (!back.open(IO_ReadOnly)) return;
105 if (!conf.open(IO_WriteOnly)) return; 110 if (!conf.open(IO_WriteOnly)) return;
106 111
107 #define SIZE 124 112 #define SIZE 124
108 char buf[SIZE]; 113 char buf[SIZE];
109 while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c); 114 while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c);