summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/confedit/listviewitemconf.h1
-rw-r--r--noncore/apps/confedit/listviewitemconffile.cpp30
-rw-r--r--noncore/apps/confedit/listviewitemconffile.h2
-rw-r--r--noncore/apps/confedit/mainwindow.cpp47
-rw-r--r--noncore/apps/confedit/mainwindow.h10
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
@@ -4,32 +4,33 @@
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef LISTVIEWITEMCONF_H
#define LISTVIEWITEMCONF_H
#include <qlistview.h>
class ListViewItemConf : public QListViewItem
{
public:
enum {File, Group, Key};
ListViewItemConf(ListViewItemConf *parent);
ListViewItemConf(QListView *parent);
~ListViewItemConf();
int getType();
virtual void displayText() = 0;
virtual void changed();
+ bool isChanged() {return _changed;};
virtual void unchanged();
protected:
int _type;
bool _changed;
};
#endif
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
@@ -52,55 +52,83 @@ void ListViewItemConfFile::parseFile()
while ( !t.atEnd() )
{
s = t.readLine().stripWhiteSpace();
// qDebug( "line: >%s<\n", s.latin1() );
if (s.contains("<?xml"))
{
_valid = false;
break;
}else
if ( s[0] == '[' && s[s.length()-1] == ']' )
{
// qDebug("got group"+s);
group = s.mid(1,s.length()-2);
groupItem = new ListViewItemConfigEntry(this, group );
insertItem( groupItem );
} else
if ( int pos = s.find('=') )
{
// qDebug("got key"+s);
item = new ListViewItemConfigEntry(this, group, s );
groupItem->insertItem( item );
}
}
confFile.close();
+ unchanged();
setExpandable( _valid );
}
+
+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()
{
if (!_changed) return;
QString backup = confFileInfo->absFilePath()+"~";
qDebug("make backup to "+backup);
QFile conf(confFileInfo->absFilePath());
QFile back(backup);
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();
if (!conf.open(IO_WriteOnly)) return;
QTextStream *t = new QTextStream( &conf );
for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling())
{
((ListViewItemConfigEntry*)it)->save(t);
}
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
@@ -4,32 +4,34 @@
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
// (c) 2002 Patrick S. Vogt <tille@handhelds.org>
#ifndef LISTVIEWITEMCONFFILE_H
#define LISTVIEWITEMCONFFILE_H
#include <qwidget.h>
#include <qlistview.h>
#include <qfile.h>
#include <qfileinfo.h>
#include "listviewitemconf.h"
class ListViewItemConfFile : public ListViewItemConf {
public:
ListViewItemConfFile(QFileInfo *file, QListView *parent=0);
~ListViewItemConfFile();
void parseFile();
QString fileName();
virtual void displayText();
+ bool revertable();
void save();
+ void revert();
protected:
private:
bool _valid;
QFileInfo *confFileInfo;
};
#endif
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
@@ -17,86 +17,95 @@
#include <qpe/resource.h>
#include <qpe/config.h>
#include <qpe/qpetoolbar.h>
#include <qaction.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qtoolbutton.h>
#include <qstring.h>
#include <qlabel.h>
#include <qfile.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qlineedit.h>
#include "listviewconfdir.h"
#include "listviewitemconf.h"
#include "listviewitemconfigentry.h"
MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) :
QMainWindow( parent, name, f ), _currentItem(0), _fileItem(0)
{
setCaption( tr("Conf File Editor") );
- popupTimer = new QTimer(this);
- popupMenu = new QPopupMenu(this);
-
QWidget *mainWidget = new QWidget(this);
setCentralWidget( mainWidget);
QGridLayout *mainLayout = new QGridLayout( mainWidget );
mainLayout->setSpacing( 3 );
mainLayout->setMargin( 3 );
settingList = new ListViewConfDir( "/root/Settings/", this, "settingslist");
mainLayout->addWidget( settingList, 0, 0 );
editor = new EditWidget(this);
mainLayout->addWidget( editor, 1, 0 );
connect(settingList, SIGNAL( pressed(QListViewItem*) ),
this, SLOT(setCurrent(QListViewItem*)));
- connect( popupTimer, SIGNAL(timeout()),
- this, SLOT(showPopup()) );
- connect( settingList, SIGNAL( clicked( QListViewItem* ) ),
- this, SLOT( stopTimer( QListViewItem* ) ) );
connect( editor->LineEditGroup, SIGNAL( textChanged(const QString&) ),
SLOT( groupChanged(const QString&) ) );
connect( editor->LineEditKey, SIGNAL( textChanged(const QString&) ),
SLOT( keyChanged(const QString&) ) );
connect( editor->LineEditValue, SIGNAL( textChanged(const QString&) ),
SLOT( valueChanged(const QString&) ) );
makeMenu();
}
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* ) ) );
}
MainWindow::~MainWindow()
{
}
void MainWindow::setCurrent(QListViewItem *item)
{
if (!item) return;
ListViewItemConf *i = (ListViewItemConf*) item;
if (!i) return;
if (i->getType() == ListViewItemConf::File)
{
qDebug("start timer");
popupTimer->start( 750, true );
editor->hide();
updateGeometry();
_currentItem=0;
_fileItem = (ListViewItemConfFile*)item;
return;
}else editor->show();
_fileItem = 0;
@@ -130,39 +139,43 @@ void MainWindow::keyChanged(const QString &k)
{
if (!_currentItem) return;
_currentItem->keyChanged(k);
}
void MainWindow::valueChanged(const QString &v)
{
if (!_currentItem) return;
_currentItem->valueChanged(v);
}
void MainWindow::stopTimer( QListViewItem* )
{
qDebug("stopTimer");
popupTimer->stop();
}
void MainWindow::saveConfFile()
{
if (!_fileItem) return;
_fileItem->save();
}
+void MainWindow::revertConfFile()
+{
+ if (!_fileItem) return;
+ _fileItem->revert();
+}
+
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
@@ -20,37 +20,45 @@
class QPEToolBar;
class ListViewItemConfFile;
class ListViewConfDir;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
~MainWindow();
public slots:
void setCurrent(QListViewItem*);
void groupChanged(const QString&);
void keyChanged(const QString&);
void valueChanged(const QString&);
void showPopup();
void stopTimer( QListViewItem* );
void saveConfFile();
+ void revertConfFile();
private:
ListViewConfDir *settingList;
EditWidget *editor;
ListViewItemConfigEntry *_currentItem;
ListViewItemConfFile *_fileItem;
QTimer *popupTimer;
- QPopupMenu *popupMenu;
+ QPopupMenu *popupMenuFile;
+ QPopupMenu *popupMenuEntry;
+ QAction *popupActionSave;
+ QAction *popupActionRevert;
+ QAction *popupActionDelete;
+ QAction *popupActionNew;
+// QAction *popupAction;
+// QAction *popupAction;
void makeMenu();
};
#endif