Ananas Library 0.9.5
dselectdb.ui.h
1/****************************************************************************
2** $Id: dselectdb.ui.h,v 1.40 2007/10/16 07:36:45 app Exp $
3**
4** Code file of the Ananas select database window
5** of Ananas Designer and Engine applications
6**
7** Created : 20031201
8**
9** Copyright (C) 2003-2004 Leader InfoTech. All rights reserved.
10** Copyright (C) 2003-2006 Grigory Panov <gr1313 at mail.ru>, Yoshkar-Ola.
11**
12** This file is part of the Library of the Ananas
13** automation accounting system.
14**
15** This file may be distributed and/or modified under the terms of the
16** GNU General Public License version 2 as published by the Free Software
17** Foundation and appearing in the file LICENSE.GPL included in the
18** packaging of this file.
19**
20** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
21** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22**
23** See http://www.leaderit.ru/page=ananas or email sales@leaderit.ru
24** See http://www.leaderit.ru/gpl/ for GPL licensing information.
25**
26** Contact org@leaderit.ru if any conditions of this licensing are
27** not clear to you.
28**
29**********************************************************************/
30
31/****************************************************************************
32** ui.h extension file, included from the uic-generated form implementation.
33**
34** If you wish to add, delete or rename functions or slots use
35** Qt Designer which will update this file, preserving your code. Create an
36** init() function in place of a constructor, and a destroy() function in
37** place of a destructor.
38*****************************************************************************/
39//#include "acfgobj.h"
40#include <qdir.h>
41#include <qstring.h>
42#include <qfiledialog.h>
43#include <qlineedit.h>
44#include <qstring.h>
45#include <qdom.h>
46
47#include "deditrc.h"
48#include "dimportdb.h"
49#include "acfgrc.h"
50#include "atests.h"
51#include "adataexchange.h"
52#include "alog.h"
53#include "binreloc.h"
54
55void dSelectDB::init()
56{
57 aLog::init();
58 createMenu();
59 progressBar1->hide();
60 dbPath->setText("");
61 QString fname;
62 withgroups = 1;
63 settings.insertSearchPath( QSettings::Unix, QString(QDir::homeDirPath())+QString("/.ananas"));
64 settings.insertSearchPath( QSettings::Windows, "/ananasgroup/ananas" );
65
66 local = settings.entryList("/groups").count();
67 changes = false;
68 if(!local)
69 {
70
71 aLog::print(aLog::MT_DEBUG, tr("dSelectDB local settings not found"));
72// settings.insertSearchPath( QSettings::Windows, "/ananasgroup/ananas/globalsettings");
73#ifdef Q_OS_WIN32
74 QStringList subkeys = settings.subkeyList("/ananasgroup/ananas/globalsettings");
75 settings.insertSearchPath(QSettings::Windows,"/ananasgroup/ananas/globalsettings");
76 QStringList entryGroup;
77 for(uint i=0; i<subkeys.count();i++)
78 {
79 QString str =subkeys[i];
80 //str = str.left(str.length()-2); // length("rc")=2
81 entryGroup =settings.entryList("/"+str);
82 settings.beginGroup("/"+str);
83 readSettings(entryGroup);
84 settings.endGroup();
85 }
86
87#else
88 QString suff = "*_grouprc";
89 BrInitError error;
90 if (br_init_lib(&error) == 0 && error != BR_INIT_ERROR_DISABLED) {
91 aLog::print(aLog::MT_INFO, tr("Warning: BinReloc failed to initialize (error code %1)\n").arg(error));
92 aLog::print(aLog::MT_INFO, tr("Will fallback to hardcoded default path.\n"));
93 }
94 QString etcDir;
95 if ( QString(br_find_prefix("/usr")) == "/usr" ) {
96 etcDir= "/etc";
97 } else {
98 etcDir= br_find_etc_dir("/etc");
99 }
100 aLog::print(aLog::MT_DEBUG, tr("dSelectDB::init BinReloc path to etc dir is '%1'\n").arg( etcDir ));
101
102 QDir dir( etcDir + QString("/ananas"),suff,QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::Readable);
103 QStringList subkeys = dir.entryList(suff);
104 settings.insertSearchPath(QSettings::Unix,etcDir + QString("/ananas/"));
105 QStringList entryGroup;
106 for(uint i=0; i<subkeys.count();i++)
107 {
108 QString str =subkeys[i];
109 str = str.left(str.length()-2); // length("rc")=2
110 entryGroup =settings.entryList("/"+str);
111 settings.beginGroup("/"+str);
112 readSettings(entryGroup);
113 settings.endGroup();
114 }
115#endif
116 }
117 else
118 {
119 QStringList lst = settings.entryList("/groups");
120 settings.beginGroup("/groups");
121 readSettings(lst);
122 settings.endGroup();
123 }
124 setIcon( rcIcon("ananas-32x32.png"));
125 listDBRC->hideColumn( 1 );
126 listDBRC->setSorting( -1 );
127 listDBRC->header()->hide();
128 listDBRC->setRootIsDecorated(1);
129 buttonOk->setEnabled( FALSE );
130 return;
131}
132
133void dSelectDB::readSettings(QStringList entryGroup)
134{
135 rcfile="";
136 ro_mode=0;
137 QFile f, fc;
138 QString s, sp, sn, rc;
139 rcListViewItem *item, *gitem=NULL; //, *subitem;
140 for(uint j=0; j<entryGroup.count();j++)
141 {
142 QStringList eitems;
143 eitems = settings.entryList(entryGroup[j]);
144 QString groupName = "unknown group";
145 groupName = settings.readEntry(entryGroup[j]);
146 aLog::print(aLog::MT_DEBUG, tr("dSelectDB read settings for group with name %1").arg(groupName));
147 rcListViewItem * lastIt = (rcListViewItem *) listDBRC->lastItem();
148 if(lastIt!=NULL)
149 {
150 while(lastIt->depth()>0)
151 {
152 lastIt =(rcListViewItem *) lastIt->parent();
153 }
154 gitem= new rcListViewItem(listDBRC, lastIt, groupName, "", true );
155 gitem->setOpen(true);
156 }
157 else
158 {
159 gitem= new rcListViewItem(listDBRC, groupName, "", true );
160 gitem->setOpen(true);
161 }
162// withgroups=1;
163 QMap<QString,QString> cfg;
164 for(int k = eitems.count()-1; k>=0; k--)
165 {
166 if(k<0) break;
167 rc = settings.readEntry(entryGroup[j]+"/"+eitems[k]);
168 cfg = aTests::readConfig(QDir::convertSeparators(rc));
169 sn=cfg["dbtitle"];
170 if (gitem) item= new rcListViewItem( gitem, sn, rc );
171 else item= new rcListViewItem( listDBRC, sn, rc );
172 }
173 }
174}
175
176
177void dSelectDB::itemSelect( QListViewItem *item )
178{
179 if (! item ) return;
180 rcListViewItem *i = ( rcListViewItem *) item ;
181 buttonOk->setEnabled( !i->group );
182 dbPath->setText(QDir::convertSeparators(i->rcfile));
183 //dbPath->show();
184
185}
186
187
188void dSelectDB::newGroup()
189{
190 QListViewItem *gitem;
191 gitem = new rcListViewItem(listDBRC, tr("New group"), "", true );
192 listDBRC->setRootIsDecorated(1);
193 gitem->setOpen(true);
194 listDBRC->setSelected(gitem, true);
195 editItem();
196 withgroups=1;
197 changes = true;
198 //saveRC();
199}
200
201
202void dSelectDB::newItem()
203{
204 rcListViewItem *item, *gitem;
205 QString rc;
206 item= ( rcListViewItem *) listDBRC->selectedItem();
207 if (!item) return;
208 if (withgroups) {
209 if (item->parent()) gitem = ( rcListViewItem *) item->parent();
210 else gitem=item;
211 item = new rcListViewItem(gitem, tr("New shema"), "myrc");
212 gitem->setOpen(true);
213
214 } else {
215 item = new rcListViewItem(listDBRC, tr("New shema"), "myrc");
216 }
217 listDBRC->setSelected(item, true);
218 editItem();
219 changes = true;
220}
221
222
223void dSelectDB::editItem()
224{
225 rcListViewItem *item;
226 dEditRC *d = new dEditRC(this);
227
228 item = ( rcListViewItem *) listDBRC->selectedItem();
229 if (!item) return;
230 if ( item->group )
231 {
232 // Group
233 item->setRenameEnabled(0, true);
234 item->startRename(0);
235 changes = true;
236 }
237 else
238 {
239 // Resource
240 d->setdata( QDir::convertSeparators(item->rcfile), item );
241 if ( d->exec() == QDialog::Accepted )
242 {
243 changes = true;
244 }
245 }
246}
247
248
249
250void dSelectDB::deleteItem()
251{
252 QListViewItem *item;
253 item=listDBRC->selectedItem();
254 if (item)
255 {
256 QString msg = tr("Delete item?");
257 if(QMessageBox::question(this,tr("confirm delete"),msg,QMessageBox::Ok,QMessageBox::Cancel)!=QMessageBox::Ok)
258 {
259 return;
260 }
261
262 delete item;
263 if (listDBRC->childCount()==0) withgroups=0;
264 changes = true;
265 }
266}
267
268
269void dSelectDB::saveRC()
270{
271 rcListViewItem *item, *gitem;
272 QFile f( rcfile );
273 aLog::print(aLog::MT_INFO, tr("dSelectDB save settings"));
274 if (!local)
275 {
276 if(!changes) return;
277 QString home = QDir::homeDirPath();
278#ifndef Q_OS_WIN32
279 QString msg = QString("Все внесенные изменения будут сохранены локально в вашем домашнем каталоге.\nПри очередном запуске программы будут использованы локальные настройки из каталога\n%1/.ananas.\nЕсли Вы хотите использовать глобальные настройки, вам следует удалить каталог\n%2/.ananas").arg(home).arg(home);
280#else
281 QString msg = tr("save settings local?");
282#endif
283 if(QMessageBox::question(this,tr("save"),QString::fromUtf8(msg),QMessageBox::Ok,QMessageBox::Cancel)!=QMessageBox::Ok)
284 {
285 return;
286 }
287 }
288 BrInitError error;
289 if (br_init_lib(&error) == 0 && error != BR_INIT_ERROR_DISABLED) {
290 aLog::print(aLog::MT_INFO, tr("Warning: BinReloc failed to initialize (error code %1)\n").arg(error));
291 aLog::print(aLog::MT_INFO, tr("Will fallback to hardcoded default path.\n"));
292 }
293
294 QString etcDir;
295 if ( QString(br_find_prefix("/usr")) == "/usr" ) {
296 etcDir= "/etc";
297 } else {
298 etcDir= br_find_etc_dir("/etc");
299 }
300 aLog::print(aLog::MT_DEBUG, tr("dSelectDB::saveRC BinReloc path to etc dir is '%1'\n").arg(etcDir) );
301
302 settings.removeSearchPath( QSettings::Unix, etcDir + QString("/ananas") );
303 settings.removeSearchPath( QSettings::Windows, "/ananasgroup/ananas/globalsettings");
304
305
306 gitem= ( rcListViewItem *) listDBRC->firstChild();
307 uint gcount=0;
308 uint ecount=0;
309 clearSettings();
310
311 settings.beginGroup("/groups");
312
313 while (gitem)
314 {
315 if (withgroups)
316 {
317 settings.writeEntry(QString::number(gcount),gitem->text(0));
318 if(gitem->childCount())
319 {
320 item = ( rcListViewItem *) gitem->firstChild();
321 while (item)
322 {
323 settings.writeEntry(QString::number(gcount)+"/"+QString::number(ecount),item->rcfile);
324 item = ( rcListViewItem *) item->nextSibling();
325 ++ecount;
326 }
327 }
328 }
329 ++gcount;
330 gitem = ( rcListViewItem *) gitem->nextSibling();
331 }
332 settings.endGroup();
333}
334
335
336void dSelectDB::onOK()
337{
338 rcListViewItem *item;
339
340 saveRC();
341 item = ( rcListViewItem *) listDBRC->selectedItem();
342 if (item) {
343 if ( !item->rcfile.isEmpty() ) {
344 rcfile = item->rcfile;
345 accept();
346 }
347 }
348}
349
350
351void dSelectDB::onCancel()
352{
353 //saveRC();
354 reject();
355}
356
357
358void dSelectDB::ItemRenamed(QListViewItem *item, int col)
359{
360 if (!item) return;
361 if (col>1) return;
362}
363
364
365void dSelectDB::clearSettings()
366{
367 QStringList eitems;
368 QStringList entryGroup =settings.entryList("/groups");
369 settings.beginGroup("/groups");
370 for(uint j=0; j<entryGroup.count();j++)
371 {
372 eitems = settings.entryList(entryGroup[j]);
373 settings.removeEntry(entryGroup[j]);
374 for(int k = eitems.count()-1; k>=0; k--)
375 {
376 if(k<0) break;
377 settings.removeEntry(entryGroup[j]+"/"+eitems[k]);
378 }
379 }
380 settings.endGroup();
381}
382
383
384void dSelectDB::onHelp()
385{
386 HelpCfgForm f;
387 f.exec();
388}
389
390void dSelectDB::createMenu()
391{
392
393 menuBar = new QMenuBar(this);
394 QPopupMenu *menuFile = new QPopupMenu(this);
395 menuFile->insertItem(tr("E&xit"), this, SLOT(onCancel()));
396
397 QPopupMenu *menuEdit = new QPopupMenu(this);
398 menuEdit->insertItem(tr("New &group"), this, SLOT(newGroup()));
399 menuEdit->insertItem(tr("&New shema"), this, SLOT(newItem()));
400 menuEdit->insertSeparator();
401 menuEdit->insertItem(tr("Edi&t"), this, SLOT(editItem()));
402 menuEdit->insertSeparator();
403 menuEdit->insertItem(tr("&Delete"), this, SLOT(deleteItem()));
404
405 QPopupMenu *menuAction = new QPopupMenu(this);
406 menuAction->insertItem(tr("&Import"), this, SLOT(importItem()));
407 menuAction->insertItem(tr("&Export"), this, SLOT(exportItem()));
408
409 menuBar->insertItem(tr("Program"), menuFile);
410 menuBar->insertItem(tr("Actions"), menuEdit);
411 menuBar->insertItem(tr("Service"), menuAction);
412 layout()->setMenuBar(menuBar);
413 menuBar->show();
414}
415
416
417void dSelectDB::importItem()
418{
419 rcListViewItem *item,*gitem;
420 dImportDB *d = new dImportDB(this);
421 item = (rcListViewItem *)listDBRC->selectedItem();
422 if (!item) return;
423 if (withgroups)
424 {
425 if (item->parent()) gitem = ( rcListViewItem *) item->parent();
426 else gitem=item;
427 item = new rcListViewItem(gitem, tr("New shema"), "myrc");
428 gitem->setOpen(true);
429
430 }
431 else
432 {
433 item = new rcListViewItem(listDBRC, tr("New shema"), "myrc");
434 }
435 listDBRC->setSelected(item, true);
436 d->setdata("", item );
437 if ( d->exec() == QDialog::Accepted )
438 {
439 bool res;
440 QString rcfile = item->rcfile;
441 QString filename = d->eCfgName->text();
442 dbPath->hide();
443 progressBar1->show();
444 progressBar1->reset();
445 aBackup newBase;
446 connect (&newBase, SIGNAL(progress(int,int)), progressBar1, SLOT( setProgress(int,int)));
447 if(newBase.importData(rcfile, filename, true)==false)
448 {
449 QMessageBox::information(this,tr("Backup"),newBase.lastError(),QMessageBox::NoButton);
450 progressBar1->hide();
451 dbPath->show();
452 aLog::print(aLog::MT_INFO, tr("dSelectDB business schema import"));
453 }
454 else
455 {
456 aLog::print(aLog::MT_ERROR, tr("dSelectDB restore: %1").arg(newBase.lastError()));
457 QMessageBox::critical(this,tr("Backup"),newBase.lastError(),0, QMessageBox::NoButton);
458 progressBar1->hide();
459 delete item;
460 item =0;
461 return;
462 }
463
464
465
466 changes = true;
467 }
468 else
469 {
470 delete item;
471 item = 0;
472 return;
473 }
474}
475
476
477void dSelectDB::exportItem()
478{
479// progressBar1->setTotalSteps(10);
480 QString dir,rcfile,filename;
481#ifndef Q_OS_WIN32
482 dir = "/home";
483#endif
484
485 rcListViewItem *item = ( rcListViewItem *) listDBRC->selectedItem();
486 if (item)
487 {
488 if ( !item->rcfile.isEmpty() && !item->group )
489 {
490 rcfile = item->rcfile;
491 }
492 else
493 {
494 QMessageBox::information(this,tr("Select item"),tr("Please, select item for export"),QMessageBox::NoButton);
495 return;
496 }
497
498 QFileDialog *fdlg = new QFileDialog(this, "fileDialog",true); // create modal dialog
499 fdlg->setMode ( QFileDialog::AnyFile );
500 if(fdlg->exec()==QDialog::Accepted)
501 {
502 filename = fdlg->selectedFile();
503 }
504 else
505 {
506 return;
507 }
508 delete fdlg;
509 fdlg = 0;
510
511 aBackup backupBase;
512 dbPath->hide();
513 progressBar1->show();
514 progressBar1->reset();
515 connect (&backupBase, SIGNAL(progress(int,int)), progressBar1, SLOT( setProgress(int,int)));
516 if(backupBase.exportData(rcfile, filename, true )==0)
517 {
518 aLog::print(aLog::MT_INFO, tr("dSelectDB backup ok"));
519 QMessageBox::information(this,tr("Backup"),backupBase.lastError(),QMessageBox::NoButton);
520 progressBar1->hide();
521 dbPath->show();
522 }
523 else
524 {
525 aLog::print(aLog::MT_DEBUG, tr("dSelectDB backup: %1").arg(backupBase.lastError()));
526 QMessageBox::critical(this,tr("Backup"),backupBase.lastError(),0, QMessageBox::NoButton);
527 progressBar1->hide();
528 return;
529 }
530 }
531 else
532 {
533 QMessageBox::information(this,tr("Select item"),tr("Please, select item for export"),QMessageBox::NoButton);
534 return;
535 }
536
537}
538
539
540void dSelectDB::onDblClick( QListViewItem *item)
541{
542
543 if (! (( rcListViewItem *)item)->group )
544 {
545 onOK();
546
547 }
548}
549
550
551void dSelectDB::comboBox1_activated( int )
552{
553 int id = comboBox1->currentItem();
554 switch ( id )
555 {
556 case 1:
557 newGroup();
558 break;
559 case 2:
560 newItem();
561 break;
562 }
563 comboBox1->setCurrentItem(0);
564}
Класс aBackup определяет программный интерфейс для бэкапа и востановления базы данных....
Definition adataexchange.h:53
static void print(int status, const QString &text)
Definition alog.cpp:58
static void init(const QString &logname="", int loglevel=0)
Definition alog.cpp:129
static QMap< QString, QString > readConfig(const QString &cfg_name, const QString &log_name=QString::null)
Definition atests.cpp:89
Definition dimportdb.h:17
Definition rclistviewitem.h:46