diff --git a/lib/db_base.cpp b/lib/db_base.cpp index 7fd5576c..c27dabcf 100644 --- a/lib/db_base.cpp +++ b/lib/db_base.cpp @@ -19,10 +19,6 @@ #include #include -#warning drop UI dependencies -#include "widgets/ImportMulti.h" -#include "ui_ImportMulti.h" - void db_base::restart_timer() { if (!IS_GUI_APP) @@ -275,16 +271,6 @@ QString db_base::pem2QString(QModelIndexList indexes) const return bba.qstring(); } -void db_base::pem2clipboard(QModelIndexList indexes) const -{ - QString msg = pem2QString(indexes); - QClipboard *cb = QApplication::clipboard(); - - if (cb->supportsSelection()) - cb->setText(msg, QClipboard::Selection); - cb->setText(msg); -} - void db_base::deletePKI(QModelIndex idx) { pki_base *pki = fromIndex(idx); @@ -625,33 +611,6 @@ void db_base::timerEvent(QTimerEvent *event) } } -void db_base::load_default(load_base &load) -{ - QString s; - QStringList slist = QFileDialog::getOpenFileNames(NULL, load.caption, - Settings["workingdir"], load.filter); - - if (!slist.count()) - return; - - update_workingdir(slist[0]); - - ImportMulti *dlgi = new ImportMulti(NULL); - foreach(s, slist) { - pki_base *item = NULL; - try { - item = load.loadItem(s); - dlgi->addItem(item); - } - catch (errorEx &err) { - XCA_ERROR(err); - delete item; - } - } - dlgi->execute(); - delete dlgi; -} - bool db_base::columnHidden(int col) const { if (!isValidCol(col)) diff --git a/lib/db_base.h b/lib/db_base.h index ad78af67..a4e72c7f 100644 --- a/lib/db_base.h +++ b/lib/db_base.h @@ -92,7 +92,6 @@ class db_base: public QAbstractItemModel { return dynamic_cast(fromIndex(index)); } - void load_default(load_base &load); void insertChild(pki_base *child, pki_base *parent = NULL); int rownumber(const pki_base *child) const; void createSuccess(const pki_base *pki) const; @@ -117,7 +116,6 @@ class db_base: public QAbstractItemModel dbheaderList getAllHeaders() { return allHeaders; } - void pem2clipboard(QModelIndexList indexes) const; QString pem2QString(QModelIndexList indexes) const; void deletePKI(QModelIndex idx); @@ -128,7 +126,6 @@ class db_base: public QAbstractItemModel public slots: virtual void newItem() { } - virtual void load() { } void columnResetDefaults(); void sectionResized(int i, int, int newSize); void sortIndicatorChanged(int, Qt::SortOrder); diff --git a/lib/db_crl.cpp b/lib/db_crl.cpp index 8c8da367..12f7face 100644 --- a/lib/db_crl.cpp +++ b/lib/db_crl.cpp @@ -44,12 +44,6 @@ pki_base *db_crl::newPKI(enum pki_type type) return new pki_crl(); } -void db_crl::load() -{ - load_crl l; - load_default(l); -} - void db_crl::revokeCerts(pki_crl *crl) { db_x509 *certs = Database.model(); diff --git a/lib/db_crl.h b/lib/db_crl.h index 19ddf334..4ef2fd3b 100644 --- a/lib/db_crl.h +++ b/lib/db_crl.h @@ -24,7 +24,6 @@ class db_crl: public db_x509name pki_base *insert(pki_base *item); void removeSigner(pki_base *signer); void store(QModelIndex index); - void load(); void updateCertView(); pki_crl *newCrl(const crljob &crljob); }; diff --git a/lib/db_key.cpp b/lib/db_key.cpp index 0379f4f3..088f8b2d 100644 --- a/lib/db_key.cpp +++ b/lib/db_key.cpp @@ -188,13 +188,6 @@ pki_key *db_key::newKey(const keyjob &task, const QString &name) return key; } -void db_key::load(void) -{ - load_key l; - load_default(l); -} - - void db_key::store(QModelIndex index) { QString title = tr("Export public key [%1]"); diff --git a/lib/db_key.h b/lib/db_key.h index f788fbdf..8a2a1c48 100644 --- a/lib/db_key.h +++ b/lib/db_key.h @@ -34,7 +34,6 @@ class db_key: public db_base pki_key *newKey(const keyjob &task, const QString &name); public slots: - void load(); void store(QModelIndex index); signals: diff --git a/lib/db_temp.cpp b/lib/db_temp.cpp index aa702560..9dafc84d 100644 --- a/lib/db_temp.cpp +++ b/lib/db_temp.cpp @@ -107,12 +107,6 @@ bool db_temp::alterTemp(pki_temp *temp) return true; } -void db_temp::load() -{ - load_temp l; - load_default(l); -} - void db_temp::store(QModelIndex index) { pki_temp *temp = fromIndex(index); diff --git a/lib/db_temp.h b/lib/db_temp.h index 10d34cfb..ee5cef5c 100644 --- a/lib/db_temp.h +++ b/lib/db_temp.h @@ -25,7 +25,6 @@ class db_temp: public db_x509name pki_base *newPKI(enum pki_type type = none); void fillContextMenu(QMenu *menu, const QModelIndex &index); QList getPredefs() const; - void load(); void store(QModelIndex index); bool alterTemp(pki_temp *temp); }; diff --git a/lib/db_x509.cpp b/lib/db_x509.cpp index 726856bd..3b7b2b25 100644 --- a/lib/db_x509.cpp +++ b/lib/db_x509.cpp @@ -333,12 +333,6 @@ pki_base *db_x509::insert(pki_base *item) return insertPKI(cert); } -void db_x509::load(void) -{ - load_cert c; - load_default(c); -} - pki_x509 *db_x509::get1SelectedCert() { QModelIndexList indexes = mainwin->certView->getSelectedIndexes(); diff --git a/lib/db_x509.h b/lib/db_x509.h index dc0a8fbc..668e9110 100644 --- a/lib/db_x509.h +++ b/lib/db_x509.h @@ -56,7 +56,6 @@ class db_x509: public db_x509super void toRequest(QModelIndex idx); void store(QModelIndex idx); void store(QModelIndexList list); - void load(); void updateCaProperties(pki_x509 *cert); void toCertificate(QModelIndex index); void certRenewal(QModelIndexList indexes); diff --git a/lib/db_x509req.cpp b/lib/db_x509req.cpp index aa8cc94f..5296fec1 100644 --- a/lib/db_x509req.cpp +++ b/lib/db_x509req.cpp @@ -100,12 +100,6 @@ void db_x509req::newItem(pki_temp *temp, pki_x509req *orig) } } -void db_x509req::load(void) -{ - load_req l; - load_default(l); -} - void db_x509req::store(QModelIndex index) { pki_x509req *req = fromIndex(index); diff --git a/lib/db_x509req.h b/lib/db_x509req.h index ac50ee4b..32038949 100644 --- a/lib/db_x509req.h +++ b/lib/db_x509req.h @@ -26,7 +26,6 @@ class db_x509req: public db_x509super pki_base *newPKI(enum pki_type type = none); void fillContextMenu(QMenu *menu, const QModelIndex &index); void store(QModelIndex index); - void load(); QList getAllRequests(); void resetX509count(); void setSigned(QModelIndex index, bool signe); diff --git a/lib/func.cpp b/lib/func.cpp index 5ddd231c..e975bb36 100644 --- a/lib/func.cpp +++ b/lib/func.cpp @@ -45,6 +45,8 @@ #define getch() getchar() #endif +bool is_gui_app = false; + int console_write(FILE *fp, const QByteArray &ba) { if (ba.size() == 0) diff --git a/lib/func.h b/lib/func.h index 256a9536..80459c4d 100644 --- a/lib/func.h +++ b/lib/func.h @@ -29,12 +29,13 @@ #define COL_DIM "\x1b[2m" #define COL_UNDER "\x1b[4m" -#define IS_GUI_APP (qobject_cast(QCoreApplication::instance())) +#define IS_GUI_APP (is_gui_app) class Validity; class MainWindow; class QPixmap; extern MainWindow *mainwin; +extern bool is_gui_app; typedef struct asn1_object_st ASN1_OBJECT; typedef struct asn1_string_st ASN1_STRING; diff --git a/lib/main.cpp b/lib/main.cpp index 558fcd88..f03767e2 100644 --- a/lib/main.cpp +++ b/lib/main.cpp @@ -378,6 +378,7 @@ int main(int argc, char *argv[]) { /* On windows, always instantiate a GUI app */ coreApp = gui = new XcaApplication(argc, argv); + is_gui_app = true; } coreApp->setApplicationName(PACKAGE_TARNAME); diff --git a/widgets/CertTreeView.cpp b/widgets/CertTreeView.cpp index 447cdc81..7a889809 100644 --- a/widgets/CertTreeView.cpp +++ b/widgets/CertTreeView.cpp @@ -113,18 +113,14 @@ void CertTreeView::toOtherToken() void CertTreeView::loadPKCS12() { - if (basemodel) { - load_pkcs12 l; - certs()->load_default(l); - } + load_pkcs12 l; + load_default(&l); } void CertTreeView::loadPKCS7() { - if (basemodel) { - load_pkcs7 l; - certs()->load_default(l); - } + load_pkcs7 l; + load_default(&l); } void CertTreeView::genCrl() @@ -230,3 +226,9 @@ void CertTreeView::unRevoke() if (basemodel) certs()->unRevoke(getSelectedIndexes()); } + +void CertTreeView::load() +{ + load_cert c; + load_default(&c); +} diff --git a/widgets/CertTreeView.h b/widgets/CertTreeView.h index 14fa824c..33c91145 100644 --- a/widgets/CertTreeView.h +++ b/widgets/CertTreeView.h @@ -40,5 +40,6 @@ class CertTreeView: public X509SuperTreeView void caProperties(); void revoke(); void unRevoke(); + void load(); }; #endif diff --git a/widgets/CrlTreeView.cpp b/widgets/CrlTreeView.cpp index 8f03698a..439ebe23 100644 --- a/widgets/CrlTreeView.cpp +++ b/widgets/CrlTreeView.cpp @@ -55,3 +55,8 @@ void CrlTreeView::newItem() newItem(ca); } +void CrlTreeView::load() +{ + load_crl l; + load_default(&l); +} diff --git a/widgets/CrlTreeView.h b/widgets/CrlTreeView.h index b36ee818..699dd232 100644 --- a/widgets/CrlTreeView.h +++ b/widgets/CrlTreeView.h @@ -29,5 +29,6 @@ class CrlTreeView: public XcaTreeView public slots: void newItem(pki_x509 *cert); void newItem(); + void load(); }; #endif diff --git a/widgets/KeyTreeView.cpp b/widgets/KeyTreeView.cpp index cd19d57d..e09a5743 100644 --- a/widgets/KeyTreeView.cpp +++ b/widgets/KeyTreeView.cpp @@ -214,3 +214,9 @@ void KeyTreeView::clipboardFormat(QAction *a) Settings["KeyFormat"] = a->data().toInt(); } + +void KeyTreeView::load(void) +{ + load_key l; + load_default(&l); +} diff --git a/widgets/KeyTreeView.h b/widgets/KeyTreeView.h index fe55048d..ca6afe47 100644 --- a/widgets/KeyTreeView.h +++ b/widgets/KeyTreeView.h @@ -35,6 +35,7 @@ class KeyTreeView: public XcaTreeView void changeSoPin(); void toToken(); void newItem(); + void load(); void newItem(const QString &name); void clipboardFormat(QAction*); }; diff --git a/widgets/MainWindow.cpp b/widgets/MainWindow.cpp index eb7c927d..f0c4b239 100644 --- a/widgets/MainWindow.cpp +++ b/widgets/MainWindow.cpp @@ -219,9 +219,7 @@ void MainWindow::init_images() void MainWindow::loadPem() { load_pem l; - db_key *keys = Database.model(); - if (keys) - keys->load_default(l); + keyView->load_default(&l); } bool MainWindow::pastePem(QString text, bool silent) diff --git a/widgets/ReqTreeView.cpp b/widgets/ReqTreeView.cpp index a9228597..6135fcc0 100644 --- a/widgets/ReqTreeView.cpp +++ b/widgets/ReqTreeView.cpp @@ -60,3 +60,9 @@ void ReqTreeView::unmarkSigned() if (basemodel) reqs()->setSigned(currentIndex(), false); } + +void ReqTreeView::load(void) +{ + load_req l; + load_default(&l); +} diff --git a/widgets/ReqTreeView.h b/widgets/ReqTreeView.h index e2f4cf15..242d6eb1 100644 --- a/widgets/ReqTreeView.h +++ b/widgets/ReqTreeView.h @@ -30,5 +30,6 @@ class ReqTreeView: public X509SuperTreeView void signReq(); void markSigned(); void unmarkSigned(); + void load(); }; #endif diff --git a/widgets/TempTreeView.cpp b/widgets/TempTreeView.cpp index 25996448..8d55dda3 100644 --- a/widgets/TempTreeView.cpp +++ b/widgets/TempTreeView.cpp @@ -107,3 +107,9 @@ bool TempTreeView::alterTemp(pki_temp *temp) temps()->alterTemp(temp); return true; } + +void TempTreeView::load() +{ + load_temp l; + load_default(&l); +} diff --git a/widgets/TempTreeView.h b/widgets/TempTreeView.h index dd3f8733..0147ed7e 100644 --- a/widgets/TempTreeView.h +++ b/widgets/TempTreeView.h @@ -34,6 +34,7 @@ class TempTreeView: public XcaTreeView void reqFromTemp(); void duplicateTemp(); void newItem(); + void load(); signals: void newReq(pki_temp *); diff --git a/widgets/XcaTreeView.cpp b/widgets/XcaTreeView.cpp index 73ca72e4..ced2d421 100644 --- a/widgets/XcaTreeView.cpp +++ b/widgets/XcaTreeView.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "OidResolver.h" #include "XcaHeaderView.h" @@ -21,6 +22,7 @@ #include "XcaWarning.h" #include "XcaDialog.h" #include "XcaApplication.h" +#include "ImportMulti.h" #include "ui_ItemProperties.h" @@ -303,10 +305,31 @@ void XcaTreeView::newItem() basemodel->newItem(); } -void XcaTreeView::load() +void XcaTreeView::load_default(load_base *load) { - if (basemodel) - basemodel->load(); + QString s; + QStringList slist = QFileDialog::getOpenFileNames(NULL, load->caption, + Settings["workingdir"], load->filter); + + if (!slist.count()) + return; + + update_workingdir(slist[0]); + + ImportMulti *dlgi = new ImportMulti(NULL); + foreach(s, slist) { + pki_base *item = NULL; + try { + item = load->loadItem(s); + dlgi->addItem(item); + } + catch (errorEx &err) { + XCA_ERROR(err); + delete item; + } + } + dlgi->execute(); + delete dlgi; } void XcaTreeView::doubleClick(const QModelIndex &m) @@ -337,8 +360,15 @@ void XcaTreeView::editComment() void XcaTreeView::pem2clipboard() { - if (basemodel) - basemodel->pem2clipboard(getSelectedIndexes()); + if (!basemodel) + return; + + QString msg = basemodel->pem2QString(getSelectedIndexes()); + QClipboard *cb = QApplication::clipboard(); + + if (cb->supportsSelection()) + cb->setText(msg, QClipboard::Selection); + cb->setText(msg); } void XcaTreeView::headerDetails() diff --git a/widgets/XcaTreeView.h b/widgets/XcaTreeView.h index 080da589..b21ffbbd 100644 --- a/widgets/XcaTreeView.h +++ b/widgets/XcaTreeView.h @@ -22,6 +22,7 @@ class pki_base; class QKeyEvent; class QContextMenuEvent; class QMenu; +class load_base; class XcaTreeView: public QTreeView { @@ -58,6 +59,7 @@ class XcaTreeView: public QTreeView void keyPressEvent(QKeyEvent *event); virtual void showPki(pki_base *) {}; virtual void storeItems(QModelIndexList indexes); + virtual void load_default(load_base *load); public slots: void changeView(); @@ -71,7 +73,6 @@ class XcaTreeView: public QTreeView void showItems(); void newItem(); void doubleClick(const QModelIndex &m); - void load(); void pem2clipboard(); void headerDetails(); void columnRemove();