2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
7 #include "uniconfroot.h"
8 #include "uniconfgen.h"
9 #include "wvistreamlist.h"
12 #include <kaboutdialog.h>
13 #include <kaboutdata.h>
14 #include <kcmdlineargs.h>
15 #include <khelpmenu.h>
17 #include <kpopupmenu.h>
18 #include <kstatusbar.h>
20 #include <qfiledialog.h>
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
);
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,
91 i18n("Undo last change."));
92 toolbar
->insertButton(redoIcon
, 4, SIGNAL(clicked()), this,
94 i18n("Redo last change."));
97 status
->message(i18n("Ready"), 0);
99 mw
= new UkMainWin(this, cfg
, "UkMainWin");
100 setCentralWidget(mw
);
108 // delete this first, because it has references to some of our other
109 // members (particularly UniConf).
115 void UniKonf::startConn()
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"));
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())
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
);
158 // FIXME: We should remove <temp> from the list here.
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()
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));
210 if (dlg
.result() == QDialog::Accepted
)
218 void UniKonf::notdone()
220 KMessageBox::sorry(this, i18n("Not implemented yet!"));
224 void UniKonf::saveConfig()
230 void UniKonf::showToolB()
232 if (settings_menu
->isItemChecked(1))
234 settings_menu
->setItemChecked(1, false);
239 settings_menu
->setItemChecked(1, true);
245 void UniKonf::showStatB()
247 if (settings_menu
->isItemChecked(2))
249 settings_menu
->setItemChecked(2, false);
254 settings_menu
->setItemChecked(2, true);
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());