diff options
author | Jan Darmochwal | 2010-10-07 16:56:12 +0200 |
---|---|---|
committer | Jan Darmochwal | 2010-10-07 16:56:12 +0200 |
commit | e7e9cf2849d0000acf47ecde86e4853687a03409 (patch) | |
tree | aa811c315fa49eccf3691f932ebbc8b28d67fa14 | |
parent | Added files to parse command line options (diff) | |
download | vmchooser-e7e9cf2849d0000acf47ecde86e4853687a03409.tar.gz vmchooser-e7e9cf2849d0000acf47ecde86e4853687a03409.tar.xz vmchooser-e7e9cf2849d0000acf47ecde86e4853687a03409.zip |
Tidy up the code
* fixed compiler warnings, added -Werror to CMakeLists.txt
* removed LibXml2 and boost stuff from CMakeLists.txt
* fixed some things cpplint.py complains about:
* make single-argument constructors explicit
* add space before if/for/while/...
* don't put { on a line of its own
* remove space after ! operator
* add space between // and comment
* remove extra space before ( in function call
* remove extra space before )
* shorten lines to <= 80 characters
* remove blank lines at the start of a code block
* maybe others
-rw-r--r-- | CMakeLists.txt | 31 | ||||
-rw-r--r-- | src/dialog.cpp | 46 | ||||
-rw-r--r-- | src/dialog.h | 10 | ||||
-rw-r--r-- | src/globals.h | 8 | ||||
-rw-r--r-- | src/main.cpp | 265 | ||||
-rw-r--r-- | src/save_restore_session.cpp | 4 | ||||
-rw-r--r-- | src/session.h | 2 | ||||
-rw-r--r-- | src/sessiontreeitem.cpp | 38 | ||||
-rw-r--r-- | src/sessiontreeitem.h | 7 | ||||
-rw-r--r-- | src/sessiontreemodel.cpp | 51 | ||||
-rw-r--r-- | src/sessiontreemodel.h | 9 | ||||
-rw-r--r-- | src/ui/dialog.ui | 2 | ||||
-rw-r--r-- | src/vsession.cpp | 20 | ||||
-rw-r--r-- | src/vsession.h | 6 | ||||
-rw-r--r-- | src/xsession.cpp | 4 | ||||
-rw-r--r-- | src/xsession.h | 5 |
16 files changed, 221 insertions, 287 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9601a66..0f26a29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 2.6) project(vmchooser) set(CMAKE_BUILD_TYPE Debug) -set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Wall -Wextra") +set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Wall -Wextra -Werror") set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -Wall -Wextra -Werror") set(CMAKE_VERBOSE_MAKEFILE TRUE) @@ -20,33 +20,6 @@ file(GLOB_RECURSE VMCHOOSER_TSS src/i18n/*.ts) include_directories(${CMAKE_CURRENT_BINARY_DIR}) # -# Boost libraries -# -set(Boost_USE_STATIC_LIBS ON) -find_package(Boost COMPONENTS "filesystem" "regex" "system" REQUIRED) -if(Boost_FOUND) - message(STATUS "Boost libraries found") - #message(STATUS "Boost_LIBRARIES=${Boost_LIBRARIES}") - link_directories(${Boost_LIBRARY_DIRS}) - include_directories(${Boost_INCLUDE_DIRS}) -else(Boost_FOUND) - message(FATAL_ERROR "Boost libraries not found") -endif(Boost_FOUND) - -# -# LibXml2 library -# -find_package(LibXml2 REQUIRED) -if(LIBXML2_FOUND) - # TODO: this sucks, but we will get rid of libxml2 anyway - message(STATUS "LibXml2 found") - set(LIBXML2_INCLUDE_DIRS "/usr/include/libxml2") - include_directories(${LIBXML2_INCLUDE_DIRS}) -else(LIBXML2_FOUND) - message(FATAL_ERROR "LibXml2 not found") -endif(LIBXML2_FOUND) - -# # Qt4 # find_package(Qt4 4.5.0 REQUIRED) @@ -105,8 +78,6 @@ add_executable(vmchooser target_link_libraries(vmchooser ${QT_LIBRARIES} - ${Boost_LIBRARIES} - ${LIBXML2_LIBRARIES} ) #install(TARGETS vmchooser RUNTIME DESTINATION diff --git a/src/dialog.cpp b/src/dialog.cpp index 48e2be7..d359c75 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -3,10 +3,8 @@ #include "save_restore_session.h" #include "sessiontreeitem.h" -Dialog::Dialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::Dialog) -{ +Dialog::Dialog(QWidget *parent) + : QDialog(parent), ui(new Ui::Dialog) { model_ = new SessionTreeModel(parent); ui->setupUi(this); @@ -27,15 +25,13 @@ Dialog::Dialog(QWidget *parent) : } } -Dialog::~Dialog() -{ +Dialog::~Dialog() { delete ui; delete model_; delete ifaceDBus_; } -void Dialog::changeEvent(QEvent *e) -{ +void Dialog::changeEvent(QEvent *e) { QDialog::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: @@ -46,10 +42,9 @@ void Dialog::changeEvent(QEvent *e) } } -void Dialog::on_treeView_activated(QModelIndex index) -{ - //TODO handle failures - //TODO get rid of this->entries, storing them in the model should be enough +void Dialog::on_treeView_activated(QModelIndex index) { + // TODO handle failures + // TODO get rid of this->entries, storing them in the model should be enough // alternatively use references instead of copies? SessionTreeItem* item = @@ -79,25 +74,21 @@ void Dialog::addItems(const QList<Session*>& entries, const QString& section) { ui->treeView->expandAll(); } -void Dialog::on_pushButtonAbort_clicked() -{ +void Dialog::on_pushButtonAbort_clicked() { close(); } -void Dialog::on_pushButtonStart_clicked() -{ +void Dialog::on_pushButtonStart_clicked() { // TODO: check if a model is selected this->on_treeView_activated(ui->treeView->selectionModel()->currentIndex()); } -void Dialog::readPVSSettings() -{ +void Dialog::readPVSSettings() { QDBusPendingReply<QString> reply; reply = ifaceDBus_->getConfigValue("Permissions/vnc_lecturer"); reply.waitForFinished(); - if (reply.isValid()) - { + if (reply.isValid()) { if (reply.value() == "rw") { ui->comboBoxLecturer->setCurrentIndex(2); } else if (reply.value() == "ro") { @@ -109,8 +100,7 @@ void Dialog::readPVSSettings() reply = ifaceDBus_->getConfigValue("Permissions/vnc_other"); reply.waitForFinished(); - if (reply.isValid()) - { + if (reply.isValid()) { if (reply.value() == "rw") { ui->comboBoxOthers->setCurrentIndex(2); } else if (reply.value() == "ro") { @@ -131,8 +121,7 @@ void Dialog::readPVSSettings() ui->checkBoxFileTransfer->setChecked(reply.value() == "T"); } -void Dialog::writePVSSettings() -{ +void Dialog::writePVSSettings() { int accessLecturer = ui->comboBoxLecturer->currentIndex(); if (accessLecturer == 2) { ifaceDBus_->setConfigValue("Permissions/vnc_lecturer", "rw"); @@ -157,16 +146,14 @@ void Dialog::writePVSSettings() QString(ui->checkBoxFileTransfer->isChecked() ? "T" : "F")); } -void Dialog::on_comboBoxLecturer_currentIndexChanged(int index) -{ +void Dialog::on_comboBoxLecturer_currentIndexChanged(int index) { // TODO: may others have more access than lecturer? if (index < ui->comboBoxOthers->currentIndex()) { ui->comboBoxOthers->setCurrentIndex(index); } } -void Dialog::on_comboBoxOthers_currentIndexChanged(int index) -{ +void Dialog::on_comboBoxOthers_currentIndexChanged(int index) { // TODO: may others have more access than lecturer? if (index > ui->comboBoxLecturer->currentIndex()) { ui->comboBoxLecturer->setCurrentIndex(index); @@ -188,7 +175,8 @@ void Dialog::selectSession(const QString& name) { const Session* s(item->session()); if (!s) continue; if (s->shortDescription() == name) { - ui->treeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select); + ui->treeView->selectionModel() + ->setCurrentIndex(index, QItemSelectionModel::Select); return; } } diff --git a/src/dialog.h b/src/dialog.h index f8794d9..1b2e7c9 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -14,24 +14,24 @@ namespace Ui { class Dialog : public QDialog { Q_OBJECT -public: - Dialog(QWidget *parent = 0); + public: + explicit Dialog(QWidget *parent = 0); ~Dialog(); void addItems(const QList<Session*>&, const QString& section); void selectSession(const QString& name); void selectPreviousSession(); -protected: + protected: void changeEvent(QEvent *e); -private: + private: Ui::Dialog *ui; SessionTreeModel *model_; OrgOpenslxPvsInterface *ifaceDBus_; void readPVSSettings(); void writePVSSettings(); -private slots: + private slots: void on_comboBoxOthers_currentIndexChanged(int index); void on_comboBoxLecturer_currentIndexChanged(int index); void on_pushButtonStart_clicked(); diff --git a/src/globals.h b/src/globals.h index b616741..5aa78ba 100644 --- a/src/globals.h +++ b/src/globals.h @@ -1,10 +1,10 @@ #ifndef VMCHOOSER_GLOBALS_H #define VMCHOOSER_GLOBALS_H -//#define VMCHOOSER_PLUGIN_PATH "/opt/openslx/plugin-repo/vmchooser/" -//#define VMCHOOSER_BIN_PATH "/var/opt/openslx/bin/" -//#define VMCHOOSER_ETC_BASE_PATH "/etc/opt/openslx/plugins/vmchooser/" -//#define VMCHOOSER_VMPATH "/var/lib/virt" +// #define VMCHOOSER_PLUGIN_PATH "/opt/openslx/plugin-repo/vmchooser/" +// #define VMCHOOSER_BIN_PATH "/var/opt/openslx/bin/" +// #define VMCHOOSER_ETC_BASE_PATH "/etc/opt/openslx/plugins/vmchooser/" +// #define VMCHOOSER_VMPATH "/var/lib/virt" #define VMCHOOSER_PLUGIN_PATH "/home/zwerg/vmchooser/plugin/" #define VMCHOOSER_BIN_PATH "/home/zwerg/vmchooser/bin/" diff --git a/src/main.cpp b/src/main.cpp index 90a9fbc..91b39e7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,10 +13,6 @@ #include "globals.h" #include "command_line_options.h" -#include <boost/filesystem.hpp> - -namespace bfs=boost::filesystem; - int main(int argc, char *argv[]) { QApplication a(argc, argv); @@ -26,134 +22,137 @@ int main(int argc, char *argv[]) { std::string version = "0.0.13"; - CommandLineOptions cmdOptions(argc, argv); - - std::string usage(a.translate( - "Console", - "Usage: vmchooser [ OPTIONS | FILE ]\n\n" - " -d, --default name of default session\n" - " -p, --path path to vmware .xml files\n" - " -x, --xpath path of X Session .desktop files\n" - " -s, --size window size <width>x<height>\n" - " -v, --version print version and exit\n" - " -h, --help print usage information and exit\n" - "\nFILE can be a vmware .xml or an X .desktop file\n" - ).toUtf8().data()); - - if (cmdOptions.contains("error")) { - std::cerr << usage; - return 1; - } - - if (cmdOptions.contains("usage")) { - std::cout << usage; - return 0; - } - - if (cmdOptions.contains("version")) { - std::cout << version; - return 0; - } - - if (cmdOptions.contains("file")) { - QString file(cmdOptions.value("file")); - - if (file.endsWith(".desktop")) { - XSession s; - return s.init(file) && s.run(); - } else if (file.endsWith(".xml")) { - // our XML-files can contain multiple sessions - // let's just take the first one - Session* s(VSession::readXmlFile(file).value(0)); - return s && s->run(); - } else { - std::cerr << "not a valid session file" << std::endl; - return 1; - } - } - - // read configuration file: - // file supplied as command line option or - // user vmchooser.conf or - // globel vmchooser.conf - QString confFile; - QString userConfFile(QDir::homePath() + "/" + - VMCHOOSER_USER_PATH + "/" + - VMCHOOSER_CONF_FILE); - QString globalConfFile(QString(VMCHOOSER_ETC_BASE_PATH) + "/" + - VMCHOOSER_CONF_FILE); - if (cmdOptions.contains("config")) { - confFile = cmdOptions.value("config"); - } else if (QFileInfo(userConfFile).exists()) { - confFile = userConfFile; - } else { - confFile = globalConfFile; - } - QSettings settings(confFile, QSettings::IniFormat); - settings.setIniCodec("UTF-8"); - - QString defaultSession; - if (cmdOptions.contains("default")) { - defaultSession = cmdOptions.value("default"); - } else if (settings.contains("default")) { - defaultSession = settings.value("default").toString(); - } else { - defaultSession = readSessionName(); - } - - QString vSessionXmlPath; - if (cmdOptions.contains("path")) { - vSessionXmlPath = cmdOptions.value("path"); - } else if (settings.contains("path")) { - vSessionXmlPath = settings.value("path").toString(); - } else { - vSessionXmlPath = VMCHOOSER_VMPATH; - } - - QString xSessionPath; - if (cmdOptions.contains("xpath")) { - xSessionPath = cmdOptions.value("xpath"); - } else if (settings.contains("xpath")) { - xSessionPath = settings.value("xpath").toString(); - } else { - xSessionPath = VMCHOOSER_X_SESSIONS_PATH; - } - - QString size; - if (cmdOptions.contains("size")) { - size = cmdOptions.value("size"); - } else if (settings.contains("size")) { - size = settings.value("size").toString(); - } - - int width, height; - QRegExp rx("^(\\d+)x(\\d+)$"); - if (rx.indexIn(size) != -1) { - QStringList list = rx.capturedTexts(); - width = list.value(1).toInt(); - height = list.value(2).toInt(); - } else if (!size.isEmpty()) { - std::cerr << a.translate("Console", "invlid size argument").toUtf8().data() << std::endl; - exit(1); - } else { - width = VMCHOOSER_DEFAULT_WIDTH; - height = VMCHOOSER_DEFAULT_HEIGHT; - } - - /* read session files */ - QList<Session*> xsessions(XSession::readSessions(xSessionPath)); - QList<Session*> vsessions(VSession::readXmlDir(vSessionXmlPath)); - - Dialog w; - w.resize(width, height); - if (xsessions.size()) { - w.addItems(xsessions, a.translate("Dialog", "X Sessions")); - } - if (vsessions.size()) { - w.addItems(vsessions, a.translate("Dialog", "Virtual Sessions")); - } - w.selectSession(defaultSession); - w.show(); - return a.exec(); + CommandLineOptions cmdOptions(argc, argv); + + std::string usage(a.translate( + "Console", + "Usage: vmchooser [ OPTIONS | FILE ]\n\n" + " -d, --default name of default session\n" + " -p, --path path to vmware .xml files\n" + " -x, --xpath path of X Session .desktop files\n" + " -s, --size window size <width>x<height>\n" + " -v, --version print version and exit\n" + " -h, --help print usage information and exit\n" + "\nFILE can be a vmware .xml or an X .desktop file\n") + .toUtf8().data()); + + if (cmdOptions.contains("error")) { + std::cerr << usage; + return 1; + } + + if (cmdOptions.contains("usage")) { + std::cout << usage; + return 0; + } + + if (cmdOptions.contains("version")) { + std::cout << version; + return 0; + } + + if (cmdOptions.contains("file")) { + QString file(cmdOptions.value("file")); + + if (file.endsWith(".desktop")) { + XSession s; + return s.init(file) && s.run(); + } else if (file.endsWith(".xml")) { + // our XML-files can contain multiple sessions + // let's just take the first one + Session* s(VSession::readXmlFile(file).value(0)); + return s && s->run(); + } else { + std::cerr << "not a valid session file" << std::endl; + return 1; + } + } + + // read configuration file: + // file supplied as command line option or + // user vmchooser.conf or + // globel vmchooser.conf + QString confFile; + QString userConfFile(QDir::homePath() + "/" + + VMCHOOSER_USER_PATH + "/" + + VMCHOOSER_CONF_FILE); + QString globalConfFile(QString(VMCHOOSER_ETC_BASE_PATH) + "/" + + VMCHOOSER_CONF_FILE); + if (cmdOptions.contains("config")) { + confFile = cmdOptions.value("config"); + } else if (QFileInfo(userConfFile).exists()) { + confFile = userConfFile; + } else { + confFile = globalConfFile; + } + QSettings settings(confFile, QSettings::IniFormat); + settings.setIniCodec("UTF-8"); + + QString defaultSession; + if (cmdOptions.contains("default")) { + defaultSession = cmdOptions.value("default"); + } else if (settings.contains("default")) { + defaultSession = settings.value("default").toString(); + } else { + defaultSession = readSessionName(); + } + + QString vSessionXmlPath; + if (cmdOptions.contains("path")) { + vSessionXmlPath = cmdOptions.value("path"); + } else if (settings.contains("path")) { + vSessionXmlPath = settings.value("path").toString(); + } else { + vSessionXmlPath = VMCHOOSER_VMPATH; + } + + QString xSessionPath; + if (cmdOptions.contains("xpath")) { + xSessionPath = cmdOptions.value("xpath"); + } else if (settings.contains("xpath")) { + xSessionPath = settings.value("xpath").toString(); + } else { + xSessionPath = VMCHOOSER_X_SESSIONS_PATH; + } + + QString size; + if (cmdOptions.contains("size")) { + size = cmdOptions.value("size"); + } else if (settings.contains("size")) { + size = settings.value("size").toString(); + } + + int width, height; + QRegExp rx("^(\\d+)x(\\d+)$"); + if (rx.indexIn(size) != -1) { + QStringList list = rx.capturedTexts(); + width = list.value(1).toInt(); + height = list.value(2).toInt(); + } else if (!size.isEmpty()) { + std::cerr + << a.translate("Console", + "invlid size argument").toUtf8().data() + << std::endl; + exit(1); + } else { + width = VMCHOOSER_DEFAULT_WIDTH; + height = VMCHOOSER_DEFAULT_HEIGHT; + } + + /* read session files */ + QList<Session*> xsessions(XSession::readSessions(xSessionPath)); + QList<Session*> vsessions(VSession::readXmlDir(vSessionXmlPath)); + + Dialog w; + w.resize(width, height); + if (xsessions.size()) { + w.addItems(xsessions, a.translate("Dialog", "X Sessions")); + } + if (vsessions.size()) { + w.addItems(vsessions, a.translate("Dialog", "Virtual Sessions")); + } + w.selectSession(defaultSession); + w.show(); + return a.exec(); } diff --git a/src/save_restore_session.cpp b/src/save_restore_session.cpp index 3b0e8ab..a9f31f1 100644 --- a/src/save_restore_session.cpp +++ b/src/save_restore_session.cpp @@ -8,8 +8,8 @@ void writeSessionName(QString name) { QDir saveFileDir(QDir::homePath() + "/" + VMCHOOSER_USER_PATH); QString saveFileName(VMCHOOSER_PREVIOUS_SESSION_FILE); - if (! saveFileDir.exists()) { - if (! saveFileDir.mkpath(saveFileDir.path())) { + if (!saveFileDir.exists()) { + if (!saveFileDir.mkpath(saveFileDir.path())) { // TODO: error return; } diff --git a/src/session.h b/src/session.h index a61f286..2033ba7 100644 --- a/src/session.h +++ b/src/session.h @@ -4,7 +4,7 @@ class QString; class Session { -public: + public: virtual ~Session() {} virtual bool isActive() const = 0; diff --git a/src/sessiontreeitem.cpp b/src/sessiontreeitem.cpp index 5e07ad4..45a4774 100644 --- a/src/sessiontreeitem.cpp +++ b/src/sessiontreeitem.cpp @@ -1,47 +1,39 @@ #include "sessiontreeitem.h" -SessionTreeItem::SessionTreeItem(const Session* session, SessionTreeItem *parent) : - parent_(parent), session_(session) -{ +SessionTreeItem::SessionTreeItem(const Session* session, + SessionTreeItem *parent) + : parent_(parent), session_(session) { } -SessionTreeItem::SessionTreeItem(const QString& text, SessionTreeItem *parent) : - parent_(parent), session_(NULL), text_(text) -{ +SessionTreeItem::SessionTreeItem(const QString& text, SessionTreeItem *parent) + : parent_(parent), session_(NULL), text_(text) { } -SessionTreeItem::~SessionTreeItem() -{ +SessionTreeItem::~SessionTreeItem() { qDeleteAll(children_); } -void SessionTreeItem::appendChild(SessionTreeItem *item) -{ +void SessionTreeItem::appendChild(SessionTreeItem *item) { children_.append(item); } -SessionTreeItem *SessionTreeItem::child(int row) -{ +SessionTreeItem *SessionTreeItem::child(int row) { return children_.value(row); } -int SessionTreeItem::childCount() const -{ +int SessionTreeItem::childCount() const { return children_.count(); } -int SessionTreeItem::columnCount() const -{ +int SessionTreeItem::columnCount() const { return 1; } -SessionTreeItem *SessionTreeItem::parent() -{ +SessionTreeItem *SessionTreeItem::parent() { return parent_; } -int SessionTreeItem::row() const -{ +int SessionTreeItem::row() const { if (parent_) { return parent_->children_.indexOf(const_cast<SessionTreeItem*>(this)); } @@ -49,12 +41,10 @@ int SessionTreeItem::row() const return 0; } -const Session* SessionTreeItem::session() const -{ +const Session* SessionTreeItem::session() const { return session_; } -const QString SessionTreeItem::text() const -{ +const QString SessionTreeItem::text() const { return text_; } diff --git a/src/sessiontreeitem.h b/src/sessiontreeitem.h index ee587ae..77a1078 100644 --- a/src/sessiontreeitem.h +++ b/src/sessiontreeitem.h @@ -8,9 +8,8 @@ #include "session.h" #include <QString> -class SessionTreeItem -{ -public: +class SessionTreeItem { + public: SessionTreeItem(const Session* session, SessionTreeItem *parent = 0); SessionTreeItem(const QString& text, SessionTreeItem *parent = 0); ~SessionTreeItem(); @@ -25,7 +24,7 @@ public: const Session* session() const; const QString text() const; -private: + private: QList<SessionTreeItem*> children_; SessionTreeItem *parent_; const Session *session_; diff --git a/src/sessiontreemodel.cpp b/src/sessiontreemodel.cpp index a5088d2..6ebe11c 100644 --- a/src/sessiontreemodel.cpp +++ b/src/sessiontreemodel.cpp @@ -5,44 +5,34 @@ #include "sessiontreeitem.h" SessionTreeModel::SessionTreeModel(QObject *parent) - : QAbstractItemModel(parent) -{ + : QAbstractItemModel(parent) { root_ = new SessionTreeItem("dummy"); } -SessionTreeModel::~SessionTreeModel() -{ +SessionTreeModel::~SessionTreeModel() { delete root_; } -int SessionTreeModel::columnCount(const QModelIndex &parent) const - { - //TODO: check if this is right for invalid parent of root_ +int SessionTreeModel::columnCount(const QModelIndex& /*parent*/) const { return 1; - } +} -int SessionTreeModel::rowCount(const QModelIndex &parent) const -{ +int SessionTreeModel::rowCount(const QModelIndex &parent) const { SessionTreeItem* parentItem; - if (parent.column() > 0) - { + if (parent.column() > 0) { return 0; } - if (!parent.isValid()) - { + if (!parent.isValid()) { parentItem = root_; - } - else - { + } else { parentItem = static_cast<SessionTreeItem*>(parent.internalPointer()); } return parentItem->childCount(); } -QVariant SessionTreeModel::data(const QModelIndex &index, int role) const -{ +QVariant SessionTreeModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } @@ -78,8 +68,7 @@ QVariant SessionTreeModel::data(const QModelIndex &index, int role) const return QVariant(); } -Qt::ItemFlags SessionTreeModel::flags(const QModelIndex &index) const -{ +Qt::ItemFlags SessionTreeModel::flags(const QModelIndex &index) const { if (!index.isValid()) { return 0; } @@ -94,16 +83,14 @@ Qt::ItemFlags SessionTreeModel::flags(const QModelIndex &index) const } } -QVariant SessionTreeModel::headerData(int section, Qt::Orientation orientation, - int role) const -{ +QVariant SessionTreeModel::headerData(int /*section*/, + Qt::Orientation /*orientation*/, + int /*role*/) const { return QVariant(); } QModelIndex SessionTreeModel::index(int row, int column, - const QModelIndex &parent) -const -{ + const QModelIndex &parent) const { if (!hasIndex(row, column, parent)) { return QModelIndex(); } @@ -124,13 +111,13 @@ const } } -QModelIndex SessionTreeModel::parent(const QModelIndex &index) const -{ +QModelIndex SessionTreeModel::parent(const QModelIndex &index) const { if (!index.isValid()) { return QModelIndex(); } - SessionTreeItem *childItem = static_cast<SessionTreeItem*>(index.internalPointer()); + SessionTreeItem *childItem = + static_cast<SessionTreeItem*>(index.internalPointer()); SessionTreeItem *parentItem = childItem->parent(); if (parentItem == root_) { @@ -140,8 +127,8 @@ QModelIndex SessionTreeModel::parent(const QModelIndex &index) const return createIndex(parentItem->row(), 0, parentItem); } -void SessionTreeModel::addItems(const QList<Session*>& sessions, const QString& section) -{ +void SessionTreeModel::addItems(const QList<Session*>& sessions, + const QString& section) { SessionTreeItem* parentItem; bool sectionExists = false; diff --git a/src/sessiontreemodel.h b/src/sessiontreemodel.h index 31611cb..b5d8ff8 100644 --- a/src/sessiontreemodel.h +++ b/src/sessiontreemodel.h @@ -8,12 +8,11 @@ class SessionTreeItem; class Session; -class SessionTreeModel : public QAbstractItemModel -{ +class SessionTreeModel : public QAbstractItemModel { Q_OBJECT -public: - SessionTreeModel(QObject *parent = 0); + public: + explicit SessionTreeModel(QObject *parent = 0); ~SessionTreeModel(); QVariant data(const QModelIndex &index, int role) const; @@ -29,7 +28,7 @@ public: void addItems(const QList<Session*>& sessions, const QString& section); -private: + private: SessionTreeItem* root_; }; diff --git a/src/ui/dialog.ui b/src/ui/dialog.ui index 6594b63..9ff6728 100644 --- a/src/ui/dialog.ui +++ b/src/ui/dialog.ui @@ -129,7 +129,7 @@ </widget> </item> <item> - <layout class="QHBoxLayout" name="horizontalLayout"> + <layout class="QHBoxLayout" name="horizontalLayout2"> <item> <spacer name="horizontalSpacer"> <property name="orientation"> diff --git a/src/vsession.cpp b/src/vsession.cpp index f3d2604..bcd13b0 100644 --- a/src/vsession.cpp +++ b/src/vsession.cpp @@ -47,7 +47,8 @@ QString VSession::getAttribute(const QString &nodeName, // TODO } - return this->doc_.namedItem("eintrag").namedItem(nodeName).toElement().attribute(attribute); + return this->doc_.namedItem("eintrag").namedItem(nodeName).toElement() + .attribute(attribute); } QString VSession::getNodeText(const QString& nodeName) const { @@ -124,21 +125,22 @@ void VSession::addPrinters(const QString& script, const QString& type) { QProcess addPrintersScript; addPrintersScript.start(script, QIODevice::ReadOnly); - while (! addPrintersScript.atEnd()) { + while (!addPrintersScript.atEnd()) { QString line(addPrintersScript.readLine()); QStringList tokens(line.split("\t")); if (tokens.size() < 2 or tokens.size() > 3) { // TODO error message // invalid output of printerScript - //printserver\tprinter\tprinter description + // printserver\tprinter\tprinter description continue; } // TODO: check return values, exceptions, ... QDomElement printerNode(doc_.createElement(type)); printerNode.setAttribute("name", tokens.at(1)); - printerNode.setAttribute("path", "\\\\" + tokens.at(0) + "\\" + tokens.at(1)); + printerNode.setAttribute("path", + "\\\\" + tokens.at(0) + "\\" + tokens.at(1)); if (tokens.size() == 3) { QDomText printerDescriptionNode(doc_.createTextNode(tokens.at(3))); printerNode.appendChild(printerDescriptionNode); @@ -160,7 +162,7 @@ void VSession::addUserAndHostname() { this->addNodeWithAttribute("username", username); // Qt >= 4.7 has <QHostInfo> - //QString hostname(QHostInfo::localHostName()); + // QString hostname(QHostInfo::localHostName()); char hname[HOST_NAME_MAX + 1]; gethostname(hname, HOST_NAME_MAX); QString hostname(hname); @@ -181,7 +183,7 @@ void VSession::addUserAndHostname() { bool VSession::run() const { QString command = getAttribute("command"); - if (! command.isEmpty()) { + if (!command.isEmpty()) { if (QProcess::startDetached(command)) { // TODO: save session return true; @@ -199,7 +201,7 @@ bool VSession::run() const { session.addUserAndHostname(); // TODO: read the group configuration XML - //session.readGroupXml(&dat, env); + // session.readGroupXml(&dat, env); // write xml to temporary file QTemporaryFile tmpfile(QDir::tempPath() + "/vmchooser-XXXXXX.xml"); @@ -267,7 +269,7 @@ QList<Session*> VSession::readXmlDir(const QString& path) { QProcess myFilterScript; myFilterScript.start(appDir.filePath(filterscript), QStringList(path), QIODevice::ReadOnly); - while (! myFilterScript.atEnd()) { + while (!myFilterScript.atEnd()) { QString filename(myFilterScript.readLine()); if (QDir::isRelativePath(filename)) { filename.prepend(path + "/"); @@ -282,7 +284,7 @@ QList<Session*> VSession::readXmlDir(const QString& path) { QDirIterator di(path, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); - while(di.hasNext()) { + while (di.hasNext()) { if (!di.next().endsWith(".xml")) continue; retval.append(readXmlFile(di.fileInfo().absoluteFilePath())); } diff --git a/src/vsession.h b/src/vsession.h index da3a5a4..0a1bf71 100644 --- a/src/vsession.h +++ b/src/vsession.h @@ -16,7 +16,7 @@ enum ImgType { }; class VSession : public Session { -public: + public: bool init(const QString& xml, const QString& baseDirPath); ImgType imgtype() const; @@ -56,7 +56,7 @@ public: bool replace = true); // TODO: remove next line void addTODO(const QString& value, const QString& nodeName, - const QString& attribute = "param"); // TODO: this adds node and attribute + const QString& attribute = "param"); // TODO: remove next line void addNodeText(const QString& text, const QString& nodeName); @@ -73,7 +73,7 @@ public: static QList<Session*> readXmlDir(const QString& path); static QList<Session*> readXmlFile(const QString& filepath); -private: + private: QDomDocument doc_; QString baseDirPath_; }; diff --git a/src/xsession.cpp b/src/xsession.cpp index 1f02b6b..a888e91 100644 --- a/src/xsession.cpp +++ b/src/xsession.cpp @@ -83,7 +83,7 @@ int XSession::priority() const { QString XSession::icon() const { QString icon(this->icon_); - if(icon.isEmpty()) { + if (icon.isEmpty()) { if (this->name_.contains("kde", Qt::CaseInsensitive)) { icon = "kde"; } else if (this->name_.contains("gnome", Qt::CaseInsensitive)) { @@ -110,7 +110,7 @@ QList<Session*> XSession::readSessions(const QString& path) { } XSession* session = new XSession; - if(session->init(fi.absoluteFilePath())) { + if (session->init(fi.absoluteFilePath())) { retval.append(session); } } diff --git a/src/xsession.h b/src/xsession.h index 50563c2..184b85a 100644 --- a/src/xsession.h +++ b/src/xsession.h @@ -11,12 +11,11 @@ // TODO: sort (operator<) class XSession : public Session { -public: + public: void init(const QString& name, const QString& exec, const QString& comment, const QString& icon); bool init(const QString& filename); - bool isActive() const; bool isLocked() const; int priority() const; @@ -37,7 +36,7 @@ public: static QList<Session*> readSessions(const QString& path); -private: + private: QString name_; QString exec_; QString comment_; |