-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.cpp | 15 | ||||
-rw-r--r-- | noncore/apps/confedit/mainwindow.cpp | 1 |
2 files changed, 13 insertions, 3 deletions
diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp index 1f85095..ce6504c 100644 --- a/noncore/apps/confedit/listviewitemconffile.cpp +++ b/noncore/apps/confedit/listviewitemconffile.cpp | |||
@@ -45,107 +45,116 @@ void ListViewItemConfFile::parseFile() | |||
45 | QFile confFile(confFileInfo->absFilePath()); | 45 | QFile confFile(confFileInfo->absFilePath()); |
46 | if(! confFile.open(IO_ReadOnly)) | 46 | if(! confFile.open(IO_ReadOnly)) |
47 | QMessageBox::critical(0,tr("Could not open"),tr("The file ")+confFileInfo->fileName()+tr(" could not be opened."),1,0); | 47 | QMessageBox::critical(0,tr("Could not open"),tr("The file ")+confFileInfo->fileName()+tr(" could not be opened."),1,0); |
48 | QTextStream t( &confFile ); | 48 | QTextStream t( &confFile ); |
49 | QString s; | 49 | QString s; |
50 | QString group; | 50 | QString group; |
51 | ListViewItemConfigEntry *groupItem; | 51 | ListViewItemConfigEntry *groupItem; |
52 | ListViewItemConfigEntry *item; | 52 | ListViewItemConfigEntry *item; |
53 | while ( !t.atEnd() ) | 53 | while ( !t.atEnd() ) |
54 | { | 54 | { |
55 | s = t.readLine().stripWhiteSpace(); | 55 | s = t.readLine().stripWhiteSpace(); |
56 | //qDebug( "line: >%s<\n", s.latin1() ); | 56 | //qDebug( "line: >%s<\n", s.latin1() ); |
57 | if (s.contains("<?xml")) | 57 | if (s.contains("<?xml")) |
58 | { | 58 | { |
59 | _valid = false; | 59 | _valid = false; |
60 | break; | 60 | break; |
61 | }else | 61 | }else |
62 | if ( s[0] == '[' && s[s.length()-1] == ']' ) | 62 | if ( s[0] == '[' && s[s.length()-1] == ']' ) |
63 | { | 63 | { |
64 | // qDebug("got group"+s); | 64 | // qDebug("got group"+s); |
65 | group = s.mid(1,s.length()-2); | 65 | group = s.mid(1,s.length()-2); |
66 | if (!groupItem) groupItem = new ListViewItemConfigEntry(this, tr("no group") ); | 66 | if (!groupItem) groupItem = new ListViewItemConfigEntry(this, tr("no group") ); |
67 | groupItem = new ListViewItemConfigEntry(this, group ); | 67 | groupItem = new ListViewItemConfigEntry(this, group ); |
68 | insertItem( groupItem ); | 68 | insertItem( groupItem ); |
69 | } else | 69 | } else |
70 | if ( int pos = s.find('=') ) | 70 | if ( int pos = s.find('=') ) |
71 | { | 71 | { |
72 | // qDebug("got key"+s); | 72 | // qDebug("got key"+s); |
73 | if (!groupItem) qDebug("PANIK NO GROUP! >%s<",group.latin1()); | 73 | if (!groupItem) qDebug("PANIK NO GROUP! >%s<",group.latin1()); |
74 | item = new ListViewItemConfigEntry(this, group, s ); | 74 | item = new ListViewItemConfigEntry(this, group, s ); |
75 | groupItem->insertItem( item ); | 75 | groupItem->insertItem( item ); |
76 | } | 76 | } |
77 | } | 77 | } |
78 | confFile.close(); | 78 | confFile.close(); |
79 | setExpandable( _valid ); | 79 | setExpandable( _valid ); |
80 | //qDebug("ListViewItemConfFile::parseFile END"); | 80 | //qDebug("ListViewItemConfFile::parseFile END"); |
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | ||
84 | void ListViewItemConfFile::remove() | 84 | void ListViewItemConfFile::remove() |
85 | { | 85 | { |
86 | QFile::remove(confFileInfo->absFilePath()); | 86 | QFile::remove(confFileInfo->absFilePath()); |
87 | QFile::remove(backupFileName()); | 87 | QFile::remove(backupFileName()); |
88 | delete this; | 88 | delete this; |
89 | } | 89 | } |
90 | 90 | ||
91 | void ListViewItemConfFile::revert() | 91 | void ListViewItemConfFile::revert() |
92 | { | 92 | { |
93 | if (_changed) | 93 | if (!_changed) |
94 | { | 94 | { |
95 | parseFile(); | 95 | // read the backup file |
96 | }else{ | ||
97 | QFile conf(confFileInfo->absFilePath()); | 96 | QFile conf(confFileInfo->absFilePath()); |
98 | QFile back(backupFileName()); | 97 | QFile back(backupFileName()); |
99 | 98 | ||
100 | if (!back.open(IO_ReadOnly)) return; | 99 | if (!back.open(IO_ReadOnly)) return; |
101 | if (!conf.open(IO_WriteOnly)) return; | 100 | if (!conf.open(IO_WriteOnly)) return; |
102 | 101 | ||
103 | #define SIZE 124 | 102 | #define SIZE 124 |
104 | char buf[SIZE]; | 103 | char buf[SIZE]; |
105 | while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c); | 104 | while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c); |
106 | conf.close(); | 105 | conf.close(); |
107 | back.close(); | 106 | back.close(); |
108 | } | 107 | } |
108 | parseFile(); | ||
109 | expand(); | ||
109 | } | 110 | } |
110 | 111 | ||
111 | void ListViewItemConfFile::save() | 112 | void ListViewItemConfFile::save() |
112 | { | 113 | { |
113 | if (!_changed) return; | 114 | if (!_changed) return; |
114 | QFile conf(confFileInfo->absFilePath()); | 115 | QFile conf(confFileInfo->absFilePath()); |
115 | QFile back(backupFileName()); | 116 | QFile back(backupFileName()); |
116 | 117 | ||
117 | if (!conf.open(IO_ReadOnly)) return; | 118 | if (!conf.open(IO_ReadOnly)) return; |
118 | if (!back.open(IO_WriteOnly)) return; | 119 | if (!back.open(IO_WriteOnly)) return; |
119 | 120 | ||
120 | char buf[SIZE]; | 121 | char buf[SIZE]; |
121 | while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c); | 122 | while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c); |
122 | conf.close(); | 123 | conf.close(); |
123 | back.close(); | 124 | back.close(); |
124 | 125 | ||
125 | 126 | ||
126 | if (!conf.open(IO_WriteOnly)) return; | 127 | if (!conf.open(IO_WriteOnly)) return; |
127 | QTextStream *t = new QTextStream( &conf ); | 128 | QTextStream *t = new QTextStream( &conf ); |
128 | for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling()) | 129 | for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling()) |
129 | { | 130 | { |
130 | ((ListViewItemConfigEntry*)it)->save(t); | 131 | ((ListViewItemConfigEntry*)it)->save(t); |
131 | } | 132 | } |
132 | conf.close(); | 133 | conf.close(); |
133 | unchanged(); | 134 | unchanged(); |
134 | } | 135 | } |
135 | 136 | ||
136 | 137 | ||
137 | bool ListViewItemConfFile::revertable() | 138 | bool ListViewItemConfFile::revertable() |
138 | { | 139 | { |
139 | return _changed || QFile(backupFileName()).exists(); | 140 | return _changed || QFile(backupFileName()).exists(); |
140 | } | 141 | } |
141 | 142 | ||
142 | QString ListViewItemConfFile::backupFileName() | 143 | QString ListViewItemConfFile::backupFileName() |
143 | { | 144 | { |
144 | return confFileInfo->absFilePath()+"~"; | 145 | return confFileInfo->absFilePath()+"~"; |
145 | } | 146 | } |
146 | 147 | ||
147 | 148 | ||
148 | void ListViewItemConfFile::expand() | 149 | void ListViewItemConfFile::expand() |
149 | { | 150 | { |
151 | QListViewItem *subItem = firstChild(); | ||
152 | QListViewItem *toDel; | ||
153 | while(subItem) | ||
154 | { | ||
155 | toDel = subItem; | ||
156 | subItem = subItem->nextSibling(); | ||
157 | delete toDel; | ||
158 | } | ||
150 | parseFile(); | 159 | parseFile(); |
151 | } | 160 | } |
diff --git a/noncore/apps/confedit/mainwindow.cpp b/noncore/apps/confedit/mainwindow.cpp index 6de8741..c91c846 100644 --- a/noncore/apps/confedit/mainwindow.cpp +++ b/noncore/apps/confedit/mainwindow.cpp | |||
@@ -28,96 +28,97 @@ | |||
28 | #include <qpushbutton.h> | 28 | #include <qpushbutton.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | #include <qlineedit.h> | 30 | #include <qlineedit.h> |
31 | 31 | ||
32 | #include "listviewconfdir.h" | 32 | #include "listviewconfdir.h" |
33 | #include "listviewitemconf.h" | 33 | #include "listviewitemconf.h" |
34 | #include "listviewitemconfigentry.h" | 34 | #include "listviewitemconfigentry.h" |
35 | 35 | ||
36 | 36 | ||
37 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : | 37 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : |
38 | QDialog( parent, name, f ), _currentItem(0), _fileItem(0) | 38 | QDialog( parent, name, f ), _currentItem(0), _fileItem(0) |
39 | { | 39 | { |
40 | setCaption( tr("Conf File Editor") ); | 40 | setCaption( tr("Conf File Editor") ); |
41 | 41 | ||
42 | //setBaseSize( qApp->globalStrut() ); | 42 | //setBaseSize( qApp->globalStrut() ); |
43 | setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));//, sizePolicy().hasHeightForWidth() ) ); | 43 | setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));//, sizePolicy().hasHeightForWidth() ) ); |
44 | 44 | ||
45 | mainLayout = new QVBoxLayout( this ); | 45 | mainLayout = new QVBoxLayout( this ); |
46 | mainLayout->setSpacing( 0 ); | 46 | mainLayout->setSpacing( 0 ); |
47 | mainLayout->setMargin( 0 ); | 47 | mainLayout->setMargin( 0 ); |
48 | 48 | ||
49 | 49 | ||
50 | qDebug("creating settingList"); | 50 | qDebug("creating settingList"); |
51 | settingList = new ListViewConfDir( "/root/Settings/", this, "settingslist"); | 51 | settingList = new ListViewConfDir( "/root/Settings/", this, "settingslist"); |
52 | settingList->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));//, sizePolicy().hasHeightForWidth() ) ); | 52 | settingList->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));//, sizePolicy().hasHeightForWidth() ) ); |
53 | mainLayout->addWidget( settingList, 0); | 53 | mainLayout->addWidget( settingList, 0); |
54 | 54 | ||
55 | qDebug("creating editor"); | 55 | qDebug("creating editor"); |
56 | editor = new EditWidget(this); | 56 | editor = new EditWidget(this); |
57 | editor->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Maximum));//, sizePolicy().hasHeightForWidth() ) ); | 57 | editor->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Maximum));//, sizePolicy().hasHeightForWidth() ) ); |
58 | mainLayout->addWidget( editor, 1 ); | 58 | mainLayout->addWidget( editor, 1 ); |
59 | editor->layoutType( ListViewItemConf::File ); | 59 | editor->layoutType( ListViewItemConf::File ); |
60 | 60 | ||
61 | makeMenu(); | 61 | makeMenu(); |
62 | 62 | ||
63 | connect(settingList, SIGNAL( pressed(QListViewItem*) ), | 63 | connect(settingList, SIGNAL( pressed(QListViewItem*) ), |
64 | this, SLOT(setCurrent(QListViewItem*))); | 64 | this, SLOT(setCurrent(QListViewItem*))); |
65 | connect( settingList, SIGNAL( clicked( QListViewItem* ) ), | 65 | connect( settingList, SIGNAL( clicked( QListViewItem* ) ), |
66 | this, SLOT( stopTimer( QListViewItem* ) ) ); | 66 | this, SLOT( stopTimer( QListViewItem* ) ) ); |
67 | 67 | ||
68 | connect( editor->LineEditGroup, SIGNAL( textChanged(const QString&) ), | 68 | connect( editor->LineEditGroup, SIGNAL( textChanged(const QString&) ), |
69 | SLOT( groupChanged(const QString&) ) ); | 69 | SLOT( groupChanged(const QString&) ) ); |
70 | connect( editor->LineEditKey, SIGNAL( textChanged(const QString&) ), | 70 | connect( editor->LineEditKey, SIGNAL( textChanged(const QString&) ), |
71 | SLOT( keyChanged(const QString&) ) ); | 71 | SLOT( keyChanged(const QString&) ) ); |
72 | connect( editor->LineEditValue, SIGNAL( textChanged(const QString&) ), | 72 | connect( editor->LineEditValue, SIGNAL( textChanged(const QString&) ), |
73 | SLOT( valueChanged(const QString&) ) ); | 73 | SLOT( valueChanged(const QString&) ) ); |
74 | 74 | ||
75 | setCurrent(0); | 75 | setCurrent(0); |
76 | editor->layoutType(EditWidget::File); | ||
76 | } | 77 | } |
77 | 78 | ||
78 | void MainWindow::makeMenu() | 79 | void MainWindow::makeMenu() |
79 | { | 80 | { |
80 | popupTimer = new QTimer(this); | 81 | popupTimer = new QTimer(this); |
81 | popupMenuFile = new QPopupMenu(this); | 82 | popupMenuFile = new QPopupMenu(this); |
82 | popupMenuEntry = new QPopupMenu(this); | 83 | popupMenuEntry = new QPopupMenu(this); |
83 | 84 | ||
84 | popupActionSave = new QAction( tr("Save"),QString::null, 0, this, 0 ); | 85 | popupActionSave = new QAction( tr("Save"),QString::null, 0, this, 0 ); |
85 | popupActionSave->addTo( popupMenuFile ); | 86 | popupActionSave->addTo( popupMenuFile ); |
86 | // popupActionSave->addTo( popupMenuEntry ); | 87 | // popupActionSave->addTo( popupMenuEntry ); |
87 | connect( popupActionSave, SIGNAL( activated() ), | 88 | connect( popupActionSave, SIGNAL( activated() ), |
88 | this , SLOT( saveConfFile() ) ); | 89 | this , SLOT( saveConfFile() ) ); |
89 | 90 | ||
90 | popupActionRevert = new QAction( tr("Revert"),QString::null, 0, this, 0 ); | 91 | popupActionRevert = new QAction( tr("Revert"),QString::null, 0, this, 0 ); |
91 | popupActionRevert->addTo( popupMenuFile ); | 92 | popupActionRevert->addTo( popupMenuFile ); |
92 | popupActionRevert->addTo( popupMenuEntry ); | 93 | popupActionRevert->addTo( popupMenuEntry ); |
93 | connect( popupActionRevert, SIGNAL( activated() ), | 94 | connect( popupActionRevert, SIGNAL( activated() ), |
94 | this , SLOT( revertConfFile() ) ); | 95 | this , SLOT( revertConfFile() ) ); |
95 | 96 | ||
96 | popupActionDelete = new QAction( tr("Delete"),QString::null, 0, this, 0 ); | 97 | popupActionDelete = new QAction( tr("Delete"),QString::null, 0, this, 0 ); |
97 | popupActionDelete->addTo( popupMenuFile ); | 98 | popupActionDelete->addTo( popupMenuFile ); |
98 | popupActionDelete->addTo( popupMenuEntry ); | 99 | popupActionDelete->addTo( popupMenuEntry ); |
99 | connect( popupActionDelete, SIGNAL( activated() ), | 100 | connect( popupActionDelete, SIGNAL( activated() ), |
100 | this , SLOT( removeConfFile() ) ); | 101 | this , SLOT( removeConfFile() ) ); |
101 | 102 | ||
102 | connect( popupTimer, SIGNAL(timeout()), | 103 | connect( popupTimer, SIGNAL(timeout()), |
103 | this, SLOT(showPopup()) ); | 104 | this, SLOT(showPopup()) ); |
104 | } | 105 | } |
105 | 106 | ||
106 | MainWindow::~MainWindow() | 107 | MainWindow::~MainWindow() |
107 | { | 108 | { |
108 | } | 109 | } |
109 | 110 | ||
110 | 111 | ||
111 | 112 | ||
112 | void MainWindow::setCurrent(QListViewItem *item) | 113 | void MainWindow::setCurrent(QListViewItem *item) |
113 | { | 114 | { |
114 | //qDebug("MainWindow::setCurrent"); | 115 | //qDebug("MainWindow::setCurrent"); |
115 | if (!item) return; | 116 | if (!item) return; |
116 | _item = (ListViewItemConf*) item; | 117 | _item = (ListViewItemConf*) item; |
117 | if (!_item) return; | 118 | if (!_item) return; |
118 | popupTimer->start( 750, true ); | 119 | popupTimer->start( 750, true ); |
119 | if (_item->getType() == ListViewItemConf::File) | 120 | if (_item->getType() == ListViewItemConf::File) |
120 | { | 121 | { |
121 | editor->layoutType(EditWidget::File); | 122 | editor->layoutType(EditWidget::File); |
122 | _currentItem=0; | 123 | _currentItem=0; |
123 | _fileItem = (ListViewItemConfFile*)item; | 124 | _fileItem = (ListViewItemConfFile*)item; |