-rw-r--r-- | noncore/apps/confedit/listviewitemconf.h | 1 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.cpp | 30 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.h | 2 | ||||
-rw-r--r-- | noncore/apps/confedit/mainwindow.cpp | 47 | ||||
-rw-r--r-- | noncore/apps/confedit/mainwindow.h | 10 |
5 files changed, 71 insertions, 19 deletions
diff --git a/noncore/apps/confedit/listviewitemconf.h b/noncore/apps/confedit/listviewitemconf.h index 5837625..c6e60ba 100644 --- a/noncore/apps/confedit/listviewitemconf.h +++ b/noncore/apps/confedit/listviewitemconf.h @@ -27,2 +27,3 @@ public: virtual void changed(); + bool isChanged() {return _changed;}; virtual void unchanged(); diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp index 858726d..b075063 100644 --- a/noncore/apps/confedit/listviewitemconffile.cpp +++ b/noncore/apps/confedit/listviewitemconffile.cpp @@ -75,2 +75,3 @@ void ListViewItemConfFile::parseFile() confFile.close(); + unchanged(); setExpandable( _valid ); @@ -78,2 +79,24 @@ void ListViewItemConfFile::parseFile() + +void ListViewItemConfFile::revert() +{ + if (_changed) + { + parseFile(); + }else{ + QString backup = confFileInfo->absFilePath()+"~"; + QFile conf(confFileInfo->absFilePath()); + QFile back(backup); + + if (!back.open(IO_ReadOnly)) return; + if (!conf.open(IO_WriteOnly)) return; + + #define SIZE 124 + char buf[SIZE]; + while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c); + conf.close(); + back.close(); + } +} + void ListViewItemConfFile::save() @@ -103,4 +126,9 @@ void ListViewItemConfFile::save() conf.close(); - qDebug("no saveing yet..."); unchanged(); } + + +bool ListViewItemConfFile::revertable() +{ + return _changed || QFile(confFileInfo->absFilePath()+"~").exists(); +}
\ No newline at end of file diff --git a/noncore/apps/confedit/listviewitemconffile.h b/noncore/apps/confedit/listviewitemconffile.h index d89b19c..ae23eab 100644 --- a/noncore/apps/confedit/listviewitemconffile.h +++ b/noncore/apps/confedit/listviewitemconffile.h @@ -27,3 +27,5 @@ public: virtual void displayText(); + bool revertable(); void save(); + void revert(); protected: diff --git a/noncore/apps/confedit/mainwindow.cpp b/noncore/apps/confedit/mainwindow.cpp index 47d9518..77b91f6 100644 --- a/noncore/apps/confedit/mainwindow.cpp +++ b/noncore/apps/confedit/mainwindow.cpp @@ -40,5 +40,2 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : - popupTimer = new QTimer(this); - popupMenu = new QPopupMenu(this); - QWidget *mainWidget = new QWidget(this); @@ -60,6 +57,2 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : - connect( popupTimer, SIGNAL(timeout()), - this, SLOT(showPopup()) ); - connect( settingList, SIGNAL( clicked( QListViewItem* ) ), - this, SLOT( stopTimer( QListViewItem* ) ) ); @@ -78,2 +71,18 @@ void MainWindow::makeMenu() + popupTimer = new QTimer(this); + popupMenuFile = new QPopupMenu(this); + + popupActionSave = new QAction( tr("Save"),QString::null, 0, this, 0 ); + popupActionSave->addTo( popupMenuFile ); + connect( popupActionSave, SIGNAL( activated() ), + this , SLOT( saveConfFile() ) ); + popupActionRevert = new QAction( tr("Revert"),QString::null, 0, this, 0 ); + popupActionRevert->addTo( popupMenuFile ); + connect( popupActionRevert, SIGNAL( activated() ), + this , SLOT( revertConfFile() ) ); + + connect( popupTimer, SIGNAL(timeout()), + this, SLOT(showPopup()) ); + connect( settingList, SIGNAL( clicked( QListViewItem* ) ), + this, SLOT( stopTimer( QListViewItem* ) ) ); } @@ -153,2 +162,8 @@ void MainWindow::saveConfFile() +void MainWindow::revertConfFile() +{ + if (!_fileItem) return; + _fileItem->revert(); +} + void MainWindow::showPopup() @@ -156,13 +171,11 @@ void MainWindow::showPopup() qDebug("showPopup"); - if (!_fileItem) return; - popupMenu->clear(); - - QAction *popupAction; - popupAction = new QAction( tr("Save"),QString::null, 0, this, 0 ); - popupAction->addTo( popupMenu ); - connect( popupAction, SIGNAL( activated() ), - this , SLOT( saveConfFile() ) ); - + if (_fileItem) + { + popupActionSave->setEnabled(_fileItem->isChanged()); + popupActionRevert->setEnabled(_fileItem->revertable()); + popupMenuFile->popup( QCursor::pos() ); + }else if(_currentItem->isChanged()) + { - popupMenu->popup( QCursor::pos() ); + } } diff --git a/noncore/apps/confedit/mainwindow.h b/noncore/apps/confedit/mainwindow.h index b015dac..e0dc0b0 100644 --- a/noncore/apps/confedit/mainwindow.h +++ b/noncore/apps/confedit/mainwindow.h @@ -43,2 +43,3 @@ public slots: void saveConfFile(); + void revertConfFile(); @@ -50,3 +51,10 @@ private: QTimer *popupTimer; - QPopupMenu *popupMenu; + QPopupMenu *popupMenuFile; + QPopupMenu *popupMenuEntry; + QAction *popupActionSave; + QAction *popupActionRevert; + QAction *popupActionDelete; + QAction *popupActionNew; +// QAction *popupAction; +// QAction *popupAction; |