[<prev] [next>] [day] [month] [year] [list]
Message-ID: <e5bfff550610210259m3b6ad77cg3607f779f33c31f2@mail.gmail.com>
Date: Sat, 21 Oct 2006 11:59:26 +0200
From: "Marco Costalba" <mcostalba@...il.com>
To: sam@...nborg.org
Cc: linux-kernel@...r.kernel.org
Subject: [PATCH] kconfig: ask for saving configuration before quitting when something changed
This clears a TODO
Signed-off-by: Marco Costalba <mcostalba@...il.com>
---
scripts/kconfig/qconf.cc | 59 +++++++++++++++++++++++++++++++++++++++++++--
scripts/kconfig/qconf.h | 13 ++++++++++
2 files changed, 69 insertions(+), 3 deletions(-)
diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc
index eec81b0..6f4c360 100644
--- a/scripts/kconfig/qconf.cc
+++ b/scripts/kconfig/qconf.cc
@@ -37,6 +37,26 @@ #endif
static QApplication *configApp;
static ConfigSettings *configSettings;
+static QMap<struct symbol*, SymValue> touchedSyms;
+
+static void aboutToChange(struct symbol* sym)
+{
+ if (sym && !touchedSyms.contains(sym)) {
+ SymValue originalValue(sym);
+ touchedSyms.insert(sym, originalValue);
+ }
+}
+
+static bool isSomethingChanged()
+{
+ QMap<struct symbol*, SymValue>::Iterator it;
+ for (it = touchedSyms.begin(); it != touchedSyms.end(); ++it) {
+ SymValue curVal(it.key());
+ if (curVal != it.data())
+ return true;
+ }
+ return false;
+}
static inline QString qgettext(const char* str)
{
@@ -48,6 +68,33 @@ static inline QString qgettext(const QSt
return QString::fromLocal8Bit(gettext(str.latin1()));
}
+bool SymValue::operator!=(const SymValue& v)
+{
+ if (v.type != type)
+ return true;
+
+ if (type == S_BOOLEAN || type == S_TRISTATE)
+ return v.expr != expr;
+
+ return v.data != data;
+}
+
+void SymValue::readValue(struct symbol* sym)
+{
+ type = sym_get_type(sym);
+ switch (type) {
+ case S_BOOLEAN:
+ case S_TRISTATE:
+ expr = sym_get_tristate_value(sym);
+ break;
+ case S_INT:
+ case S_HEX:
+ case S_STRING:
+ data = sym_get_string_value(sym);
+ break;
+ }
+}
+
/**
* Reads a list of integer values from the application settings.
*/
@@ -86,6 +133,7 @@ #if QT_VERSION >= 300
void ConfigItem::okRename(int col)
{
Parent::okRename(col);
+ aboutToChange(menu->sym);
sym_set_string_value(menu->sym, text(dataColIdx).latin1());
}
#endif
@@ -298,6 +346,7 @@ void ConfigLineEdit::keyPressEvent(QKeyE
break;
case Key_Return:
case Key_Enter:
+ aboutToChange(item->menu->sym);
sym_set_string_value(item->menu->sym, text().latin1());
parent()->updateList(item);
break;
@@ -469,7 +518,7 @@ void ConfigList::setValue(ConfigItem* it
case S_BOOLEAN:
case S_TRISTATE:
oldval = sym_get_tristate_value(sym);
-
+ aboutToChange(sym);
if (!sym_set_tristate_value(sym, val))
return;
if (oldval == no && item->menu->list)
@@ -500,6 +549,7 @@ void ConfigList::changeValue(ConfigItem*
case S_BOOLEAN:
case S_TRISTATE:
oldexpr = sym_get_tristate_value(sym);
+ aboutToChange(sym);
newexpr = sym_toggle_tristate_value(sym);
if (item->menu->list) {
if (oldexpr == newexpr)
@@ -1442,6 +1492,8 @@ void ConfigMainWindow::saveConfig(void)
{
if (conf_write(NULL))
QMessageBox::information(this, "qconf", "Unable to save configuration!");
+ else
+ touchedSyms.clear();
}
void ConfigMainWindow::saveConfigAs(void)
@@ -1451,6 +1503,8 @@ void ConfigMainWindow::saveConfigAs(void
return;
if (conf_write(QFile::encodeName(s)))
QMessageBox::information(this, "qconf", "Unable to save configuration!");
+ else
+ touchedSyms.clear();
}
void ConfigMainWindow::searchConfig(void)
@@ -1583,11 +1637,10 @@ void ConfigMainWindow::showFullView(void
/*
* ask for saving configuration before quitting
- * TODO ask only when something changed
*/
void ConfigMainWindow::closeEvent(QCloseEvent* e)
{
- if (!sym_change_count) {
+ if (!isSomethingChanged()) {
e->accept();
return;
}
diff --git a/scripts/kconfig/qconf.h b/scripts/kconfig/qconf.h
index 8d11f3c..8617698 100644
--- a/scripts/kconfig/qconf.h
+++ b/scripts/kconfig/qconf.h
@@ -45,6 +45,19 @@ enum listMode {
singleMode, menuMode, symbolMode, fullMode, listMode
};
+class SymValue {
+public:
+ SymValue() {}; // QMap needs this to store us
+ SymValue(struct symbol* sym) { readValue(sym); }
+ bool operator!=(const SymValue&);
+private:
+ void readValue(struct symbol* sym);
+
+ int type;
+ tristate expr;
+ QString data;
+};
+
class ConfigList : public QListView {
Q_OBJECT
typedef class QListView Parent;
--
1.4.3.ge193
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists