Diffstat (limited to 'noncore/apps/confedit/listviewitemconffile.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp new file mode 100644 index 0000000..5457384 --- a/dev/null +++ b/noncore/apps/confedit/listviewitemconffile.cpp | |||
@@ -0,0 +1,88 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> | ||
10 | |||
11 | #include "listviewitemconffile.h" | ||
12 | #include <qmessagebox.h> | ||
13 | #include <qtextstream.h> | ||
14 | #include <qstring.h> | ||
15 | #include "listviewitemconfigentry.h" | ||
16 | |||
17 | #define tr QObject::tr | ||
18 | |||
19 | ListViewItemConfFile::ListViewItemConfFile(QFileInfo *file, QListView *parent) | ||
20 | : ListViewItemConf(parent), _valid(false) | ||
21 | { | ||
22 | confFileInfo = file; | ||
23 | parseFile(); | ||
24 | _changed = false; | ||
25 | displayText(); | ||
26 | } | ||
27 | |||
28 | ListViewItemConfFile::~ListViewItemConfFile() | ||
29 | { | ||
30 | } | ||
31 | |||
32 | |||
33 | void ListViewItemConfFile::displayText() | ||
34 | { | ||
35 | setText(0,(_changed?"*":"*")+confFileInfo->fileName()); | ||
36 | } | ||
37 | |||
38 | QString ListViewItemConfFile::fileName() | ||
39 | { | ||
40 | return confFileInfo->fileName(); | ||
41 | } | ||
42 | |||
43 | void ListViewItemConfFile::parseFile() | ||
44 | { | ||
45 | qDebug( confFileInfo->absFilePath() ); | ||
46 | QFile confFile(confFileInfo->absFilePath()); | ||
47 | qDebug( confFileInfo->absFilePath() ); | ||
48 | // QString fileName = confFileInfo->fileName(); | ||
49 | if(! confFile.open(IO_ReadOnly)) | ||
50 | QMessageBox::critical(0,tr("Could not open"),tr("The file ")+confFileInfo->fileName()+tr(" could not be opened."),1,0); | ||
51 | QTextStream t( &confFile ); | ||
52 | QString s; | ||
53 | QString group; | ||
54 | ListViewItemConfigEntry *groupItem; | ||
55 | ListViewItemConfigEntry *item; | ||
56 | while ( !t.atEnd() ) | ||
57 | { | ||
58 | s = t.readLine().stripWhiteSpace(); | ||
59 | //qDebug( "line: >%s<\n", s.latin1() ); | ||
60 | if (s.contains("<?xml")) | ||
61 | { | ||
62 | _valid = false; | ||
63 | break; | ||
64 | }else | ||
65 | if ( s[0] == '[' && s[s.length()-1] == ']' ) | ||
66 | { | ||
67 | qDebug("got group"+s); | ||
68 | group = s.mid(1,s.length()-2); | ||
69 | groupItem = new ListViewItemConfigEntry(this, group ); | ||
70 | insertItem( groupItem ); | ||
71 | } else | ||
72 | if ( int pos = s.find('=') ) | ||
73 | { | ||
74 | // qDebug("got key"+s); | ||
75 | item = new ListViewItemConfigEntry(this, group, s ); | ||
76 | groupItem->insertItem( item ); | ||
77 | } | ||
78 | } | ||
79 | confFile.close(); | ||
80 | setExpandable( _valid ); | ||
81 | } | ||
82 | |||
83 | void ListViewItemConfFile::save() | ||
84 | { | ||
85 | qDebug("ListViewItemConfFile::save()"); | ||
86 | qDebug("no saveing yet..."); | ||
87 | unchanged(); | ||
88 | } | ||