cleanup of connection management, new major version number 3, use static connection methods; refs #26, refs #28, refs #29
parent
08784114fb
commit
e2dc8a3595
20 changed files with 1236 additions and 552 deletions
@ -0,0 +1,88 @@ |
||||
/****************************************************************************
|
||||
** Meta object code from reading C++ file 'cardgui-model.hxx' |
||||
** |
||||
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.0.2) |
||||
** |
||||
** WARNING! All changes made in this file will be lost! |
||||
*****************************************************************************/ |
||||
|
||||
#include "cardgui-model.hxx" |
||||
#include <QtCore/qbytearray.h> |
||||
#include <QtCore/qmetatype.h> |
||||
#if !defined(Q_MOC_OUTPUT_REVISION) |
||||
#error "The header file 'cardgui-model.hxx' doesn't include <QObject>." |
||||
#elif Q_MOC_OUTPUT_REVISION != 67 |
||||
#error "This file was generated using the moc from 5.0.2. It" |
||||
#error "cannot be used with the include files from this version of Qt." |
||||
#error "(The moc has changed too much.)" |
||||
#endif |
||||
|
||||
QT_BEGIN_MOC_NAMESPACE |
||||
struct qt_meta_stringdata_CardGuiModel_t { |
||||
QByteArrayData data[1]; |
||||
char stringdata[14]; |
||||
}; |
||||
#define QT_MOC_LITERAL(idx, ofs, len) \ |
||||
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
|
||||
offsetof(qt_meta_stringdata_CardGuiModel_t, stringdata) + ofs \
|
||||
- idx * sizeof(QByteArrayData) \
|
||||
) |
||||
static const qt_meta_stringdata_CardGuiModel_t qt_meta_stringdata_CardGuiModel = { |
||||
{ |
||||
QT_MOC_LITERAL(0, 0, 12) |
||||
}, |
||||
"CardGuiModel\0" |
||||
}; |
||||
#undef QT_MOC_LITERAL |
||||
|
||||
static const uint qt_meta_data_CardGuiModel[] = { |
||||
|
||||
// content:
|
||||
7, // revision
|
||||
0, // classname
|
||||
0, 0, // classinfo
|
||||
0, 0, // methods
|
||||
0, 0, // properties
|
||||
0, 0, // enums/sets
|
||||
0, 0, // constructors
|
||||
0, // flags
|
||||
0, // signalCount
|
||||
|
||||
0 // eod
|
||||
}; |
||||
|
||||
void CardGuiModel::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) |
||||
{ |
||||
Q_UNUSED(_o); |
||||
Q_UNUSED(_id); |
||||
Q_UNUSED(_c); |
||||
Q_UNUSED(_a); |
||||
} |
||||
|
||||
const QMetaObject CardGuiModel::staticMetaObject = { |
||||
{ &QAbstractItemModel::staticMetaObject, qt_meta_stringdata_CardGuiModel.data, |
||||
qt_meta_data_CardGuiModel, qt_static_metacall, 0, 0} |
||||
}; |
||||
|
||||
|
||||
const QMetaObject *CardGuiModel::metaObject() const |
||||
{ |
||||
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; |
||||
} |
||||
|
||||
void *CardGuiModel::qt_metacast(const char *_clname) |
||||
{ |
||||
if (!_clname) return 0; |
||||
if (!strcmp(_clname, qt_meta_stringdata_CardGuiModel.stringdata)) |
||||
return static_cast<void*>(const_cast< CardGuiModel*>(this)); |
||||
return QAbstractItemModel::qt_metacast(_clname); |
||||
} |
||||
|
||||
int CardGuiModel::qt_metacall(QMetaObject::Call _c, int _id, void **_a) |
||||
{ |
||||
_id = QAbstractItemModel::qt_metacall(_c, _id, _a); |
||||
if (_id < 0) |
||||
return _id; |
||||
return _id; |
||||
} |
||||
QT_END_MOC_NAMESPACE |
@ -0,0 +1,122 @@ |
||||
/*! @file
|
||||
|
||||
@id $Id$ |
||||
*/ |
||||
// 1 2 3 4 5 6 7 8
|
||||
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
|
||||
#ifndef CARDGUI_MODEL_HXX |
||||
#define CARDGUI_MODEL_HXX |
||||
|
||||
#include <cardos.hxx> |
||||
|
||||
#include <QtCore/QAbstractItemModel> |
||||
#include <QtGui/QFont> |
||||
|
||||
class CardGuiModel: public QAbstractItemModel { |
||||
|
||||
Q_OBJECT; |
||||
|
||||
public: |
||||
|
||||
CardGuiModel(cardos::Commands& cmd, const std::string& path): |
||||
_rootItem(cmd, path) { |
||||
} |
||||
|
||||
QVariant data(const QModelIndex &index, int role) const { |
||||
if (!index.isValid()) return QVariant(); |
||||
cardos::Object* o(static_cast<cardos::Object*>(index.internalPointer())); |
||||
switch (role) { |
||||
case Qt::TextAlignmentRole: |
||||
return Qt::AlignTop; |
||||
case Qt::FontRole: |
||||
if (index.column() == 2) { |
||||
QFont f("Monospaced"); |
||||
f.setStyleHint(QFont::TypeWriter); |
||||
return f; |
||||
} else return QVariant(); |
||||
case Qt::DisplayRole: |
||||
switch (index.column()) { |
||||
case 0: return QString::fromStdString(o->logicalName()); |
||||
case 1: return QString::fromStdString(o->name()); |
||||
case 3: return QString::fromStdString(o->contentInfo()); |
||||
case 2: if (o->content().size()) |
||||
return QString::fromStdString(crypto::readable(o->content())); |
||||
default: return QVariant(); |
||||
} |
||||
default: return QVariant(); |
||||
} |
||||
} |
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const { |
||||
if (!index.isValid()) return 0; |
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable; |
||||
} |
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, |
||||
int role = Qt::DisplayRole) const { |
||||
if (orientation!=Qt::Horizontal || role!=Qt::DisplayRole) |
||||
return QVariant(); |
||||
switch (section) { |
||||
case 0: return "Object"; |
||||
case 1: return "ID"; |
||||
case 3: return "Logical Content"; |
||||
case 2: return "Binary Content"; |
||||
default: return QVariant(); |
||||
} |
||||
} |
||||
|
||||
QModelIndex index(int row, int column, |
||||
const QModelIndex &parent = QModelIndex()) const { |
||||
if (!hasIndex(row, column, parent)) return QModelIndex(); |
||||
const cardos::Object* parentItem(0); |
||||
if (!parent.isValid()) |
||||
parentItem = &_rootItem; |
||||
else |
||||
parentItem = static_cast<cardos::Object*>(parent.internalPointer()); |
||||
if (row<parentItem->size()) |
||||
return |
||||
createIndex(row, column, &(*parentItem->children().at(row))); |
||||
return QModelIndex(); |
||||
} |
||||
|
||||
std::pair<const cardos::Object*, int> scan(const cardos::Object& o, |
||||
const cardos::Object* c) const { |
||||
int i(0); |
||||
for (cardos::Object::Children::const_iterator it(o.children().begin()); |
||||
it!=o.children().end(); ++it, ++i) { |
||||
if (it->get()==c) return std::make_pair(&o, i); |
||||
std::pair<const cardos::Object*, int> res(scan(**it, c)); |
||||
if (res.first) return res; |
||||
} |
||||
return std::make_pair((const cardos::Object*)0, 0); |
||||
} |
||||
|
||||
QModelIndex parent(const QModelIndex &index) const { |
||||
if (!index.isValid()) return QModelIndex(); |
||||
cardos::Object* childItem |
||||
(static_cast<cardos::Object*>(index.internalPointer())); |
||||
if (childItem==&_rootItem) return QModelIndex(); |
||||
std::pair<const cardos::Object*, int> |
||||
parentItem(scan(_rootItem, childItem)); |
||||
if (!parentItem.first) return QModelIndex(); |
||||
return createIndex(parentItem.second, 0, |
||||
const_cast<cardos::Object*>(parentItem.first)); |
||||
} |
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const { |
||||
if (parent.isValid() && parent.internalPointer()) |
||||
return static_cast<cardos::Object*>(parent.internalPointer())->size(); |
||||
else |
||||
return _rootItem.size(); |
||||
} |
||||
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const { |
||||
return 4; |
||||
} |
||||
|
||||
protected: |
||||
cardos::Dir _rootItem; |
||||
}; |
||||
|
||||
#endif |
@ -0,0 +1,20 @@ |
||||
/*! @file
|
||||
|
||||
@id $Id$ |
||||
*/ |
||||
// 1 2 3 4 5 6 7 8
|
||||
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
|
||||
#include <cardgui.hxx> |
||||
|
||||
#include <mrw/vector.hxx> |
||||
#include <mrw/args.hxx> |
||||
|
||||
#include <QApplication> |
||||
|
||||
int main(int argc, char** argv) { |
||||
QApplication app(argc, argv); |
||||
CardGui win; |
||||
win.show(); |
||||
return app.exec(); |
||||
} |
@ -0,0 +1,108 @@ |
||||
/*! @file
|
||||
|
||||
@id $Id$ |
||||
*/ |
||||
// 1 2 3 4 5 6 7 8
|
||||
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
|
||||
#ifndef CARDGUI_HXX |
||||
#define CARDGUI_HXX |
||||
|
||||
#include <cardgui-model.hxx> |
||||
#include <cardgui_ui.hxx> |
||||
#include <password.hxx> |
||||
|
||||
#include <QtCore/QProcess> |
||||
#include <QtWidgets/QMessageBox> |
||||
|
||||
class CardGui: public QMainWindow, protected Ui_CardGui { |
||||
|
||||
Q_OBJECT; |
||||
|
||||
public: |
||||
|
||||
CardGui(QWidget* p=0): |
||||
QMainWindow(p), _pwd(this) { |
||||
setupUi(this); |
||||
on__rescan_clicked(); |
||||
} |
||||
|
||||
void resizeEvent(QResizeEvent* event) { |
||||
QMainWindow::resizeEvent(event); |
||||
if (_tree->model()) |
||||
for (int i = 0; i < _tree->model()->columnCount(); ++i) |
||||
_tree->resizeColumnToContents(i); |
||||
} |
||||
|
||||
public Q_SLOTS: |
||||
|
||||
void on__rescan_clicked(bool=true) { |
||||
static bool inRescan(false); |
||||
if (inRescan) return; |
||||
inRescan = true; |
||||
try { |
||||
delete _tree->model(); |
||||
_tree->setModel(0); |
||||
_card->clear(); |
||||
pcsc::Connection::Strings readers(pcsc::Connection::scan()); |
||||
for (pcsc::Connection::Strings::iterator r(readers.begin()); |
||||
r!=readers.end(); ++r) |
||||
_card->addItem(QString::fromStdString(*r)); |
||||
} catch (...) { |
||||
} |
||||
inRescan = false; |
||||
} |
||||
|
||||
void on__card_currentIndexChanged(int) { |
||||
on__reload_clicked(); |
||||
} |
||||
|
||||
void on__reload_clicked(bool=true) { |
||||
try { |
||||
delete _tree->model(); |
||||
_tree->setModel(0); |
||||
cardos::Commands cmd(pcsc::Connection::reader |
||||
(_card->currentText().toStdString())); |
||||
_tree->setModel(new CardGuiModel(cmd, "3f00")); |
||||
} catch (...) { |
||||
on__rescan_clicked(); |
||||
} |
||||
} |
||||
|
||||
void on__actionRestartPCSCD_triggered() { |
||||
delete _tree->model(); |
||||
_tree->setModel(0); |
||||
if (_pwd.exec()) { |
||||
_p.start("sudo -S service pcscd restart"); |
||||
_p.write((_pwd.password()+"\n").toUtf8()); |
||||
_p.closeWriteChannel(); |
||||
if (!_p.waitForFinished()) |
||||
QMessageBox::warning(this, tr("Restarting PCSC Daemon failed"), |
||||
tr("<html><p>Restarting PCSC daemon" |
||||
" failed with message:</p>" |
||||
"\n<pre>%1</pre></html>") |
||||
.arg(QString::fromUtf8 |
||||
(_p.readAll()+"\n"+ |
||||
_p.readAllStandardOutput()+"\n"+ |
||||
_p.readAllStandardError()))); |
||||
else |
||||
QMessageBox::information(this, tr("Restarted PCSC Daemon"), |
||||
tr("<html><p>Restarted PCSC daemon" |
||||
" with message:</p>" |
||||
"\n<pre>%1</pre></html>") |
||||
.arg(QString::fromUtf8 |
||||
(_p.readAll()+"\n"+ |
||||
_p.readAllStandardOutput()+"\n"+ |
||||
_p.readAllStandardError()))); |
||||
} |
||||
on__reload_clicked(); |
||||
} |
||||
|
||||
protected: |
||||
|
||||
Password _pwd; |
||||
QProcess _p; |
||||
|
||||
}; |
||||
|
||||
#endif |
@ -0,0 +1,103 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>CardGui</class> |
||||
<widget class="QMainWindow" name="CardGui"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>1349</width> |
||||
<height>878</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>MainWindow</string> |
||||
</property> |
||||
<widget class="QWidget" name="centralwidget"> |
||||
<layout class="QVBoxLayout" name="verticalLayout"> |
||||
<item> |
||||
<widget class="QTabWidget" name="tabWidget"> |
||||
<property name="currentIndex"> |
||||
<number>0</number> |
||||
</property> |
||||
<widget class="QWidget" name="tab"> |
||||
<attribute name="title"> |
||||
<string>CardOS V4.4</string> |
||||
</attribute> |
||||
<layout class="QGridLayout" name="gridLayout"> |
||||
<item row="0" column="0"> |
||||
<widget class="QTreeView" name="_tree"> |
||||
<property name="alternatingRowColors"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="verticalScrollMode"> |
||||
<enum>QAbstractItemView::ScrollPerPixel</enum> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||
<item> |
||||
<widget class="QPushButton" name="_rescan"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="text"> |
||||
<string>rescan for cards</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QComboBox" name="_card"/> |
||||
</item> |
||||
<item> |
||||
<widget class="QPushButton" name="_reload"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="text"> |
||||
<string>reload card info</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<widget class="QMenuBar" name="menubar"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>1349</width> |
||||
<height>23</height> |
||||
</rect> |
||||
</property> |
||||
<widget class="QMenu" name="menuFile"> |
||||
<property name="title"> |
||||
<string>File</string> |
||||
</property> |
||||
<addaction name="_actionRestartPCSCD"/> |
||||
</widget> |
||||
<addaction name="menuFile"/> |
||||
</widget> |
||||
<widget class="QStatusBar" name="statusbar"/> |
||||
<action name="_actionRestartPCSCD"> |
||||
<property name="text"> |
||||
<string>Restart PCSCD</string> |
||||
</property> |
||||
</action> |
||||
</widget> |
||||
<resources/> |
||||
<connections/> |
||||
</ui> |
@ -0,0 +1,30 @@ |
||||
/*! @file
|
||||
|
||||
@id $Id$ |
||||
*/ |
||||
// 1 2 3 4 5 6 7 8
|
||||
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
|
||||
#ifndef PASSWORD_HXX |
||||
#define PASSWORD_HXX |
||||
|
||||
#include <password_ui.hxx> |
||||
|
||||
class Password: public QDialog, protected Ui_Password { |
||||
|
||||
Q_OBJECT; |
||||
|
||||
public: |
||||
|
||||
Password(QWidget* p=0): |
||||
QDialog(p) { |
||||
setupUi(this); |
||||
} |
||||
|
||||
QString password() { |
||||
return _pwd->text(); |
||||
} |
||||
|
||||
}; |
||||
|
||||
#endif |
@ -0,0 +1,101 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>Password</class> |
||||
<widget class="QDialog" name="Password"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>360</width> |
||||
<height>152</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Dialog</string> |
||||
</property> |
||||
<layout class="QVBoxLayout" name="verticalLayout"> |
||||
<item> |
||||
<widget class="QLabel" name="label_2"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="text"> |
||||
<string>Your password is required to restart PCSC daemon. Please anter your user password and make sure, you are allowed to sudo on this host.</string> |
||||
</property> |
||||
<property name="alignment"> |
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> |
||||
</property> |
||||
<property name="wordWrap"> |
||||
<bool>true</bool> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||
<item> |
||||
<widget class="QLabel" name="label"> |
||||
<property name="text"> |
||||
<string>Password:</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLineEdit" name="_pwd"> |
||||
<property name="echoMode"> |
||||
<enum>QLineEdit::Password</enum> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<widget class="QDialogButtonBox" name="buttonBox"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="standardButtons"> |
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<resources/> |
||||
<connections> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>accepted()</signal> |
||||
<receiver>Password</receiver> |
||||
<slot>accept()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>248</x> |
||||
<y>254</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>157</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>rejected()</signal> |
||||
<receiver>Password</receiver> |
||||
<slot>reject()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>316</x> |
||||
<y>260</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>286</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
</connections> |
||||
</ui> |
Loading…
Reference in new issue