WvDBusMsg::is_reply() had an unnecessary hack for message #1.
[wvapps.git] / unikonf / unikonf.cc
blob2b4446f3ca49d2c609d6fa1279186d150f7b105a
1 /*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 */
5 #include "unikonf.h"
6 #include "unikonf.moc"
7 #include "uniconfroot.h"
8 #include "uniconfgen.h"
9 #include "wvistreamlist.h"
11 #include <klocale.h>
12 #include <kaboutdialog.h>
13 #include <kaboutdata.h>
14 #include <kcmdlineargs.h>
15 #include <khelpmenu.h>
16 #include <kmenubar.h>
17 #include <kpopupmenu.h>
18 #include <kstatusbar.h>
19 #include <ktoolbar.h>
20 #include <qfiledialog.h>
23 /**
24 * This is the application's main window.
26 UniKonf::UniKonf(QWidget *parent, const char *name)
27 : KMainWindow(parent, name), cfg(root), log("UniKonf", WvLog::Debug1)
29 config = new KSimpleConfig("unikonfrc");
31 QPixmap configureIcon(locate("icon",
32 "hicolor/16x16/actions/configure.png"));
33 QPixmap searchIcon(locate("icon", "hicolor/16x16/actions/find.png"));
34 QPixmap exitIcon(locate("icon", "hicolor/16x16/actions/exit.png"));
35 QPixmap saveIcon(locate("icon", "hicolor/16x16/actions/filesave.png"));
36 QPixmap undoIcon(locate("icon", "hicolor/16x16/actions/undo.png"));
37 QPixmap redoIcon(locate("icon", "hicolor/16x16/actions/redo.png"));
38 QPixmap exportIcon(locate("icon", "hicolor/16x16/actions/fileexport.png"));
40 file_menu = new KPopupMenu(this);
42 file_menu->insertItem(saveIcon, i18n("&Save"), this,
43 SLOT(saveConfig()), CTRL+Key_S, 0, 2);
44 file_menu->setItemEnabled(2, false);
45 file_menu->insertItem(exportIcon, i18n("&Export"), this,
46 SLOT(exportslot()), CTRL+Key_X);
47 file_menu->insertSeparator();
48 file_menu->insertItem(exitIcon, i18n("&Quit"), qApp,
49 SLOT(quit()), CTRL+Key_Q);
51 edit_menu = new KPopupMenu(this);
53 edit_menu->insertItem(undoIcon, i18n("Undo"), this,
54 SLOT(undo()), CTRL+Key_Z);
55 edit_menu->setItemEnabled(2, true);
56 edit_menu->insertItem(redoIcon, i18n("Redo"), this,
57 SLOT(redo()), CTRL+Key_R);
58 edit_menu->setItemEnabled(3, true);
60 settings_menu = new KPopupMenu(this);
61 settings_menu->setCheckable(true);
62 settings_menu->insertItem(i18n("Show Toolbar"), this,
63 SLOT(showToolB()), 0, 1);
64 settings_menu->insertItem(i18n("Show StatusBar"), this,
65 SLOT(showStatB()), 0, 2);
66 settings_menu->insertSeparator();
67 settings_menu->insertItem(configureIcon, i18n("Configure UniKonf..."),
68 this, SLOT(settings()));
69 settings_menu->setItemChecked(1, true);
70 settings_menu->setItemChecked(2, true);
72 KPopupMenu *help_menu = helpMenu();
74 KMenuBar *_menuBar = menuBar();
75 _menuBar->insertItem(i18n("&File"), file_menu);
76 _menuBar->insertItem(i18n("&Edit"), edit_menu);
77 _menuBar->insertItem(i18n("&Settings"), settings_menu);
78 _menuBar->insertItem(i18n("&Help"), help_menu);
80 toolbar = toolBar();
81 toolbar->insertButton("exit", 0, SIGNAL(clicked()), qApp, SLOT(quit()),
82 true, i18n("Exit Application"));
83 toolbar->insertButton("configure", 1, SIGNAL(clicked()), this,
84 SLOT(settings()), true,
85 i18n("Manage Connections to UniConf Servers"));
86 toolbar->insertButton(saveIcon, 2, SIGNAL(clicked()), this,
87 SLOT(saveConfig()), true,
88 i18n("Save all changes."));
89 toolbar->insertButton(undoIcon, 3, SIGNAL(clicked()), this,
90 SLOT(undo()), true,
91 i18n("Undo last change."));
92 toolbar->insertButton(redoIcon, 4, SIGNAL(clicked()), this,
93 SLOT(redo()), true,
94 i18n("Redo last change."));
96 status = statusBar();
97 status->message(i18n("Ready"), 0);
99 mw = new UkMainWin(this, cfg, "UkMainWin");
100 setCentralWidget(mw);
102 startConn();
106 UniKonf::~UniKonf()
108 // delete this first, because it has references to some of our other
109 // members (particularly UniConf).
110 delete mw;
111 mw = NULL;
115 void UniKonf::startConn()
117 stopConn();
119 int mountedsubtrees = 0;
120 QStringList mountlist(config->groupList());
121 if (mountlist.isEmpty())
123 KMessageBox::detailedSorry(this, i18n("No Mountpoints Specified"),
124 i18n("UniKonf currently has no subtrees mounted.\n"
125 "Please select Settings -> Configure to add a mountpoint.\n"));
127 else
129 QStringList mounts(config->groupList());
130 WvString failedlist("Failed to connect to data source(s): ");
132 // Connect to every server in our server list.
133 bool failure = false; // we failed to connect to at least one server
134 setCursor(waitCursor);
136 for (QStringList::Iterator i = mounts.begin(); i != mounts.end(); i++)
138 if (((*i).contains("KFile") == 0) &&
139 ((*i).contains("Global") == 0) &&
140 ((*i).contains("Cert") == 0) &&
141 ((*i).contains("<default>") == 0) )
143 QString mountpoint = *i;
144 config->setGroup(mountpoint);
145 QString moniker = config->readEntry("moniker");
147 if (moniker.isNull())
148 continue;
149 UniConf temp = cfg[WvString(mountpoint)];
150 IUniConfGen *gen = temp.mount(WvString(moniker));
152 if (!gen || !gen->isok())
154 temp.unmount(gen, false);
155 failedlist.append("%s, ", moniker);
156 failure = true;
158 // FIXME: We should remove <temp> from the list here.
159 continue;
161 else
162 mountedsubtrees++;
165 if (failure)
167 KMessageBox::detailedSorry(this, i18n("Failed to Connect"),
168 i18n(failedlist.cstr()));
169 status->message(i18n("Ready"), 0);
171 setCursor(arrowCursor);
174 file_menu->setItemEnabled(2, true);
176 WvString str("Mounted %s %s.", mountedsubtrees,
177 (mountedsubtrees==1 ? "subtree" : "subtrees"));
178 status->message(i18n(str), 0);
182 void UniKonf::stopConn()
184 // disable the watch
185 cfg.del_callback(this);
187 // Disable the Import/Export Menu Items
188 file_menu->setItemEnabled(2, false);
189 file_menu->setItemEnabled(3, false);
191 // Disable the Search/Find Menu Items
192 edit_menu->setItemEnabled(2, false);
193 edit_menu->setItemEnabled(3, false);
195 // Clear out the current configuration
196 // FIXME: unmount everything, not just the top!
197 if (root.whichmount())
198 root.unmount(root.whichmount(), true);
200 // Reset the Status Bar to the default state.
201 status->message(i18n("Ready"), 0);
205 void UniKonf::settings()
207 UniKonfCfg dlg(this, "unikonf", config);
208 dlg.setInitialSize(QSize(556, 345));
209 dlg.exec();
210 if (dlg.result() == QDialog::Accepted)
212 stopConn();
213 startConn();
218 void UniKonf::notdone()
220 KMessageBox::sorry(this, i18n("Not implemented yet!"));
224 void UniKonf::saveConfig()
226 cfg.commit();
230 void UniKonf::showToolB()
232 if (settings_menu->isItemChecked(1))
234 settings_menu->setItemChecked(1, false);
235 toolbar->hide();
237 else
239 settings_menu->setItemChecked(1, true);
240 toolbar->show();
245 void UniKonf::showStatB()
247 if (settings_menu->isItemChecked(2))
249 settings_menu->setItemChecked(2, false);
250 status->hide();
252 else
254 settings_menu->setItemChecked(2, true);
255 status->show();
260 void UniKonf::undo()
262 mw->do_undo();
266 void UniKonf::redo()
268 mw->do_redo();
272 void UniKonf::exportslot()
274 QString filename = QFileDialog::getSaveFileName(QString::null,
275 "INI Files (*.ini)", this, "Export dialog",
276 "Choose file to export to");
277 UniConfRoot newroot(WvString("ini:%s", filename));
278 UniConf::RecursiveIter i(newroot);
279 for (i.rewind(); i.next(); )
280 newroot.xset(i->fullkey(), i->getme());
281 newroot.commit();