-rw-r--r-- | noncore/apps/confedit/listviewitemconf.cpp | 5 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconf.h | 4 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.cpp | 24 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.h | 8 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconfigentry.cpp | 18 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconfigentry.h | 5 | ||||
-rw-r--r-- | noncore/apps/confedit/mainwindow.cpp | 65 | ||||
-rw-r--r-- | noncore/apps/confedit/mainwindow.h | 4 |
8 files changed, 104 insertions, 29 deletions
diff --git a/noncore/apps/confedit/listviewitemconf.cpp b/noncore/apps/confedit/listviewitemconf.cpp index 55f8422..91edca2 100644 --- a/noncore/apps/confedit/listviewitemconf.cpp +++ b/noncore/apps/confedit/listviewitemconf.cpp @@ -42,5 +42,10 @@ void ListViewItemConf::unchanged() { ((ListViewItemConf*)it)->unchanged(); } displayText(); +} + +bool ListViewItemConf::revertable() +{ + return _changed; }
\ No newline at end of file diff --git a/noncore/apps/confedit/listviewitemconf.h b/noncore/apps/confedit/listviewitemconf.h index c6e60ba..3c504ed 100644 --- a/noncore/apps/confedit/listviewitemconf.h +++ b/noncore/apps/confedit/listviewitemconf.h @@ -22,12 +22,16 @@ public: ListViewItemConf(QListView *parent); ~ListViewItemConf(); int getType(); + void save(); + virtual void revert() = 0; + virtual void remove() = 0; virtual void displayText() = 0; virtual void changed(); bool isChanged() {return _changed;}; virtual void unchanged(); + virtual bool revertable(); protected: int _type; bool _changed; diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp index b075063..228421b 100644 --- a/noncore/apps/confedit/listviewitemconffile.cpp +++ b/noncore/apps/confedit/listviewitemconffile.cpp @@ -77,17 +77,23 @@ void ListViewItemConfFile::parseFile() setExpandable( _valid ); } +void ListViewItemConfFile::remove() +{ + QFile::remove(confFileInfo->absFilePath()); + QFile::remove(backupFileName()); + delete this; +} + void ListViewItemConfFile::revert() { if (_changed) { parseFile(); }else{ - QString backup = confFileInfo->absFilePath()+"~"; QFile conf(confFileInfo->absFilePath()); - QFile back(backup); + QFile back(backupFileName()); if (!back.open(IO_ReadOnly)) return; if (!conf.open(IO_WriteOnly)) return; @@ -101,17 +107,14 @@ void ListViewItemConfFile::revert() void ListViewItemConfFile::save() { if (!_changed) return; - QString backup = confFileInfo->absFilePath()+"~"; - qDebug("make backup to "+backup); QFile conf(confFileInfo->absFilePath()); - QFile back(backup); + QFile back(backupFileName()); if (!conf.open(IO_ReadOnly)) return; if (!back.open(IO_WriteOnly)) return; - #define SIZE 124 char buf[SIZE]; while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c); conf.close(); back.close(); @@ -129,6 +132,11 @@ void ListViewItemConfFile::save() bool ListViewItemConfFile::revertable() { - return _changed || QFile(confFileInfo->absFilePath()+"~").exists(); -}
\ No newline at end of file + return _changed || QFile(backupFileName()).exists(); +} + +QString ListViewItemConfFile::backupFileName() +{ + return confFileInfo->absFilePath()+"~"; +} diff --git a/noncore/apps/confedit/listviewitemconffile.h b/noncore/apps/confedit/listviewitemconffile.h index ae23eab..679a2ed 100644 --- a/noncore/apps/confedit/listviewitemconffile.h +++ b/noncore/apps/confedit/listviewitemconffile.h @@ -23,12 +23,14 @@ public: ListViewItemConfFile(QFileInfo *file, QListView *parent=0); ~ListViewItemConfFile(); void parseFile(); QString fileName(); - virtual void displayText(); - bool revertable(); void save(); - void revert(); + virtual void displayText(); + virtual bool revertable(); + virtual void revert(); + virtual void remove(); + QString backupFileName(); protected: private: bool _valid; QFileInfo *confFileInfo; diff --git a/noncore/apps/confedit/listviewitemconfigentry.cpp b/noncore/apps/confedit/listviewitemconfigentry.cpp index 77ce17d..b947514 100644 --- a/noncore/apps/confedit/listviewitemconfigentry.cpp +++ b/noncore/apps/confedit/listviewitemconfigentry.cpp @@ -18,8 +18,11 @@ ListViewItemConfigEntry::ListViewItemConfigEntry(ListViewItemConfFile *parent, Q _fileItem = parent; _file = parent->fileName(); _group = group; setKey(key); + _groupOrig = group; + _keyOrig = _key; + _valueOrig = _value; _fileItem->unchanged(); } ListViewItemConfigEntry::~ListViewItemConfigEntry() @@ -106,8 +109,14 @@ void ListViewItemConfigEntry::changed() displayText(); _fileItem->changed(); } + +void ListViewItemConfigEntry::remove() +{ + delete this; +} + void ListViewItemConfigEntry::save(QTextStream *t) { QString s; if (isGroup()) @@ -124,5 +133,14 @@ void ListViewItemConfigEntry::save(QTextStream *t) for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling()) { ((ListViewItemConfigEntry*)it)->save(t); } +} + +void ListViewItemConfigEntry::revert() +{ + _group = _groupOrig; + _key = _keyOrig; + _value = _valueOrig; + _changed=false; + displayText(); }
\ No newline at end of file diff --git a/noncore/apps/confedit/listviewitemconfigentry.h b/noncore/apps/confedit/listviewitemconfigentry.h index 1ff0491..6b651a6 100644 --- a/noncore/apps/confedit/listviewitemconfigentry.h +++ b/noncore/apps/confedit/listviewitemconfigentry.h @@ -33,14 +33,19 @@ public: void keyChanged(QString); void valueChanged(QString); virtual void displayText(); virtual void changed(); + virtual void remove(); void save(QTextStream*); + virtual void revert(); private: QString _file; QString _group; QString _key; QString _value; + QString _groupOrig; + QString _keyOrig; + QString _valueOrig; ListViewItemConfFile *_fileItem; }; #endif diff --git a/noncore/apps/confedit/mainwindow.cpp b/noncore/apps/confedit/mainwindow.cpp index 77b91f6..17a5058 100644 --- a/noncore/apps/confedit/mainwindow.cpp +++ b/noncore/apps/confedit/mainwindow.cpp @@ -39,20 +39,27 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : setCaption( tr("Conf File Editor") ); QWidget *mainWidget = new QWidget(this); setCentralWidget( mainWidget); - QGridLayout *mainLayout = new QGridLayout( mainWidget ); mainLayout->setSpacing( 3 ); mainLayout->setMargin( 3 ); + qDebug("settingList"); settingList = new ListViewConfDir( "/root/Settings/", this, "settingslist"); + settingList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding));//, sizePolicy().hasHeightForWidth() ) ); mainLayout->addWidget( settingList, 0, 0 ); + qDebug("editor"); editor = new EditWidget(this); + editor->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum));//, sizePolicy().hasHeightForWidth() ) ); +// editor->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)3));//, sizePolicy().hasHeightForWidth() ) ); mainLayout->addWidget( editor, 1, 0 ); + makeMenu(); + + qDebug("connect"); connect(settingList, SIGNAL( pressed(QListViewItem*) ), this, SLOT(setCurrent(QListViewItem*))); @@ -61,31 +68,48 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : connect( editor->LineEditKey, SIGNAL( textChanged(const QString&) ), SLOT( keyChanged(const QString&) ) ); connect( editor->LineEditValue, SIGNAL( textChanged(const QString&) ), SLOT( valueChanged(const QString&) ) ); - makeMenu(); +// qDebug("editor->hide()"); +// editor->hide(); + qDebug("connect"); + connect( settingList, SIGNAL( clicked( QListViewItem* ) ), + this, SLOT( stopTimer( QListViewItem* ) ) ); } void MainWindow::makeMenu() { - + qDebug("MainWindow::makeMenu()"); popupTimer = new QTimer(this); popupMenuFile = new QPopupMenu(this); + popupMenuEntry = new QPopupMenu(this); + qDebug("Save"); popupActionSave = new QAction( tr("Save"),QString::null, 0, this, 0 ); popupActionSave->addTo( popupMenuFile ); + // popupActionSave->addTo( popupMenuEntry ); connect( popupActionSave, SIGNAL( activated() ), this , SLOT( saveConfFile() ) ); + + qDebug("Revert"); popupActionRevert = new QAction( tr("Revert"),QString::null, 0, this, 0 ); popupActionRevert->addTo( popupMenuFile ); + popupActionRevert->addTo( popupMenuEntry ); connect( popupActionRevert, SIGNAL( activated() ), this , SLOT( revertConfFile() ) ); + qDebug("Delete"); + popupActionDelete = new QAction( tr("Delete"),QString::null, 0, this, 0 ); + popupActionDelete->addTo( popupMenuFile ); + popupActionDelete->addTo( popupMenuEntry ); + connect( popupActionDelete, SIGNAL( activated() ), + this , SLOT( removeConfFile() ) ); + + qDebug("connect"); connect( popupTimer, SIGNAL(timeout()), this, SLOT(showPopup()) ); - connect( settingList, SIGNAL( clicked( QListViewItem* ) ), - this, SLOT( stopTimer( QListViewItem* ) ) ); + qDebug("connect"); } MainWindow::~MainWindow() { @@ -95,14 +119,13 @@ MainWindow::~MainWindow() void MainWindow::setCurrent(QListViewItem *item) { if (!item) return; - ListViewItemConf *i = (ListViewItemConf*) item; - if (!i) return; - if (i->getType() == ListViewItemConf::File) + _item = (ListViewItemConf*) item; + if (!_item) return; + popupTimer->start( 750, true ); + if (_item->getType() == ListViewItemConf::File) { - qDebug("start timer"); - popupTimer->start( 750, true ); editor->hide(); updateGeometry(); _currentItem=0; _fileItem = (ListViewItemConfFile*)item; @@ -125,8 +148,10 @@ void MainWindow::setCurrent(QListViewItem *item) }else{ editor->isKey(false); } updateGeometry(); + editor->updateGeometry(); + settingList->updateGeometry(); } void MainWindow::groupChanged(const QString &g) @@ -149,9 +174,8 @@ void MainWindow::valueChanged(const QString &v) void MainWindow::stopTimer( QListViewItem* ) { - qDebug("stopTimer"); popupTimer->stop(); } void MainWindow::saveConfFile() @@ -161,21 +185,28 @@ void MainWindow::saveConfFile() } void MainWindow::revertConfFile() { - if (!_fileItem) return; - _fileItem->revert(); + if (!_item) return; + _item->revert(); } +void MainWindow::removeConfFile() +{ + if (!_item) return; + _item->remove(); +} void MainWindow::showPopup() { - qDebug("showPopup"); +qDebug("showPopup"); + if (!_item) return; + popupActionRevert->setEnabled(_item->revertable()); + popupActionSave->setEnabled(_item->isChanged()); if (_fileItem) { popupActionSave->setEnabled(_fileItem->isChanged()); - popupActionRevert->setEnabled(_fileItem->revertable()); popupMenuFile->popup( QCursor::pos() ); - }else if(_currentItem->isChanged()) + }else if(_currentItem) { - + popupMenuEntry->popup( QCursor::pos() ); } } diff --git a/noncore/apps/confedit/mainwindow.h b/noncore/apps/confedit/mainwindow.h index e0dc0b0..886b829 100644 --- a/noncore/apps/confedit/mainwindow.h +++ b/noncore/apps/confedit/mainwindow.h @@ -20,9 +20,9 @@ class QPEToolBar; class ListViewItemConfFile; class ListViewConfDir; - +class ListViewItemConf; class MainWindow : public QMainWindow { Q_OBJECT @@ -41,12 +41,14 @@ public slots: void showPopup(); void stopTimer( QListViewItem* ); void saveConfFile(); void revertConfFile(); + void removeConfFile(); private: ListViewConfDir *settingList; EditWidget *editor; + ListViewItemConf *_item; ListViewItemConfigEntry *_currentItem; ListViewItemConfFile *_fileItem; QTimer *popupTimer; QPopupMenu *popupMenuFile; |