From 699e4ac319d6fc11837545d0cba943e46514aad5 Mon Sep 17 00:00:00 2001 From: Frederick Thomssen Date: Sat, 7 May 2016 08:24:57 +0200 Subject: [PATCH] Add network error messages to retrieve methods --- IssueCreator.cpp | 49 ++++++++++++++++++++++++++++++++++------- IssueCreator.h | 2 +- IssueSelector.cpp | 24 +++++++++++++++++++-- IssueSelector.h | 7 ------ RedTimer.cpp | 55 +++++++++++++++++++++++++++++++++++++++++------ RedTimer.pro | 2 +- Settings.cpp | 53 +++++++++++++++++++-------------------------- Settings.h | 31 +++----------------------- qtredmine | 2 +- 9 files changed, 140 insertions(+), 85 deletions(-) diff --git a/IssueCreator.cpp b/IssueCreator.cpp index 0972903..33dee9f 100644 --- a/IssueCreator.cpp +++ b/IssueCreator.cpp @@ -51,10 +51,10 @@ IssueCreator::IssueCreator( SimpleRedmineClient* redmine, QQuickView* parent ) connect( qml("create"), SIGNAL(clicked()), this, SLOT(save()) ); // Connect the cancel button clicked signal to the close slot - connect( qml("cancel"), SIGNAL(clicked()), this, SLOT(closeWin()) ); + connect( qml("cancel"), SIGNAL(clicked()), this, SLOT(close()) ); // Connect the closed signal to the close slot - connect( this, &Window::closed, [=](){ closeWin(); } ); + connect( this, &Window::closed, [=](){ close(); } ); RETURN(); } @@ -66,16 +66,18 @@ IssueCreator::~IssueCreator() } void -IssueCreator::closeWin() +IssueCreator::close() { ENTER(); if( isVisible() ) { DEBUG() << "Closing issue creator window"; + if( cancelOnClose_ ) cancelled(); - close(); + + Window::close(); } RETURN(); @@ -100,9 +102,20 @@ IssueCreator::loadCurrentUser() { ENTER(); - redmine_->retrieveCurrentUser( [&]( User user ) + redmine_->retrieveCurrentUser( [&]( User user, RedmineError redmineError, QStringList errors ) { ENTER(); + + if( redmineError != NO_ERROR ) + { + QString errorMsg = tr("Could not load issue statuses."); + for( const auto& error : errors ) + errorMsg.append("\n").append(error); + + message( errorMsg, QtCriticalMsg ); + RETURN(); + } + currentUserId_ = user.id; RETURN(); } ); @@ -115,10 +128,20 @@ IssueCreator::loadProjects() { ENTER(); - redmine_->retrieveProjects( [&]( Projects projects ) + redmine_->retrieveProjects( [&]( Projects projects, RedmineError redmineError, QStringList errors ) { ENTER(); + if( redmineError != NO_ERROR ) + { + QString errorMsg = tr("Could not load projects."); + for( const auto& error : errors ) + errorMsg.append("\n").append(error); + + message( errorMsg, QtCriticalMsg ); + RETURN(); + } + projectModel_.clear(); projectModel_.push_back( SimpleItem(NULL_ID, "Choose project") ); for( const auto& project : projects ) @@ -139,10 +162,20 @@ IssueCreator::loadTrackers() { ENTER(); - redmine_->retrieveTrackers( [&]( Trackers trackers ) + redmine_->retrieveTrackers( [&]( Trackers trackers, RedmineError redmineError, QStringList errors ) { ENTER(); + if( redmineError != NO_ERROR ) + { + QString errorMsg = tr("Could not load trackers."); + for( const auto& error : errors ) + errorMsg.append("\n").append(error); + + message( errorMsg, QtCriticalMsg ); + RETURN(); + } + trackerModel_.clear(); trackerModel_.push_back( SimpleItem(NULL_ID, "Choose tracker") ); for( const auto& tracker : trackers ) @@ -226,7 +259,7 @@ IssueCreator::save() message( tr("New issue created with ID %1").arg(id) ); created( id ); - closeWin(); + close(); RETURN(); } ); diff --git a/IssueCreator.h b/IssueCreator.h index 49ac942..f8b7434 100644 --- a/IssueCreator.h +++ b/IssueCreator.h @@ -82,7 +82,7 @@ public slots: /** * @brief Close the issue selector dialog */ - void closeWin(); + void close(); /** * @brief Display the issue selector dialog diff --git a/IssueSelector.cpp b/IssueSelector.cpp index 35a780a..e1ddac8 100644 --- a/IssueSelector.cpp +++ b/IssueSelector.cpp @@ -104,10 +104,20 @@ IssueSelector::loadIssues() { ENTER()(projectId_); - redmine_->retrieveIssues( [&]( Issues issues ) + redmine_->retrieveIssues( [&]( Issues issues, RedmineError redmineError, QStringList errors ) { ENTER(); + if( redmineError != NO_ERROR ) + { + QString errorMsg = tr("Could not load issues."); + for( const auto& error : errors ) + errorMsg.append("\n").append(error); + + message( errorMsg, QtCriticalMsg ); + RETURN(); + } + issuesModel_.clear(); for( const auto& issue : issues ) @@ -129,10 +139,20 @@ IssueSelector::loadProjects() projectModel_.clear(); projectModel_.push_back( SimpleItem(NULL_ID, "Choose project") ); - redmine_->retrieveProjects( [=]( Projects projects ) + redmine_->retrieveProjects( [=]( Projects projects, RedmineError redmineError, QStringList errors ) { ENTER(); + if( redmineError != NO_ERROR ) + { + QString errorMsg = tr("Could not load projects."); + for( const auto& error : errors ) + errorMsg.append("\n").append(error); + + message( errorMsg, QtCriticalMsg ); + RETURN(); + } + int currentIndex = 0; // Reset in case this has changed since calling loadProjects() diff --git a/IssueSelector.h b/IssueSelector.h index 6287243..0b282f3 100644 --- a/IssueSelector.h +++ b/IssueSelector.h @@ -49,13 +49,6 @@ class IssueSelector : public Window */ int getProjectId() const; - /** - * @brief Get the issue selector window - * - * @return Issue selector window - */ - QQuickView* window() const; - /// @} /// @name Setters diff --git a/RedTimer.cpp b/RedTimer.cpp index d992794..0a1e693 100644 --- a/RedTimer.cpp +++ b/RedTimer.cpp @@ -23,7 +23,7 @@ RedTimer::RedTimer( QApplication* parent, bool trayIcon ) redmine_ = new SimpleRedmineClient( this ); // Settings initialisation - settings_ = new Settings( redmine_, this ); + settings_ = new Settings( redmine_ ); settings_->load(); // Main window initialisation @@ -78,7 +78,7 @@ RedTimer::RedTimer( QApplication* parent, bool trayIcon ) ctx_->setContextProperty( "issueStatusModel", &issueStatusModel_ ); // Set transient window parent - settings_->window()->setTransientParent( this ); + settings_->setTransientParent( this ); // Connect the create issue button connect( qml("createIssue"), SIGNAL(clicked()), this, SLOT(createIssue()) ); @@ -381,10 +381,21 @@ RedTimer::loadActivities() { ENTER(); - redmine_->retrieveTimeEntryActivities( [&]( Enumerations activities ) + redmine_->retrieveTimeEntryActivities( [&]( Enumerations activities, RedmineError redmineError, + QStringList errors ) { ENTER(); + if( redmineError != NO_ERROR ) + { + QString errorMsg = tr("Could not load activities."); + for( const auto& error : errors ) + errorMsg.append("\n").append(error); + + message( errorMsg, QtCriticalMsg ); + RETURN(); + } + int currentIndex = 0; activityModel_.clear(); @@ -448,10 +459,20 @@ RedTimer::loadIssue( int issueId, bool startTimer, bool saveNewIssue ) if( timer_->isActive() ) stop( true, false ); - redmine_->retrieveIssue( [=]( Issue issue ) + redmine_->retrieveIssue( [=]( Issue issue, RedmineError redmineError, QStringList errors ) { ENTER()(issue); + if( redmineError != NO_ERROR ) + { + QString errorMsg = tr("Could not load issue."); + for( const auto& error : errors ) + errorMsg.append("\n").append(error); + + message( errorMsg, QtCriticalMsg ); + RETURN(); + } + issue_ = issue; addRecentIssue( issue ); @@ -480,10 +501,21 @@ RedTimer::loadIssueStatuses() { ENTER(); - redmine_->retrieveIssueStatuses( [&]( IssueStatuses issueStatuses ) + redmine_->retrieveIssueStatuses( [&]( IssueStatuses issueStatuses, RedmineError redmineError, + QStringList errors ) { ENTER(); + if( redmineError != NO_ERROR ) + { + QString errorMsg = tr("Could not load issue statuses."); + for( const auto& error : errors ) + errorMsg.append("\n").append(error); + + message( errorMsg, QtCriticalMsg ); + RETURN(); + } + int currentIndex = 0; issueStatusModel_.clear(); @@ -518,10 +550,21 @@ RedTimer::loadLatestActivity() RETURN(); } - redmine_->retrieveTimeEntries( [&]( TimeEntries timeEntries ) + redmine_->retrieveTimeEntries( [&]( TimeEntries timeEntries, RedmineError redmineError, + QStringList errors ) { ENTER(); + if( redmineError != NO_ERROR ) + { + QString errorMsg = tr("Could not load time entries."); + for( const auto& error : errors ) + errorMsg.append("\n").append(error); + + message( errorMsg, QtCriticalMsg ); + RETURN(); + } + if( timeEntries.size() == 1 ) activityId_ = timeEntries[0].activity.id; diff --git a/RedTimer.pro b/RedTimer.pro index 9660e0d..c1ef6ae 100644 --- a/RedTimer.pro +++ b/RedTimer.pro @@ -6,7 +6,7 @@ QMAKE_CXXFLAGS += -std=c++11 RC_ICONS = icons/clock_red.ico ICON = icons/clock_red.icns -VERSION = 0.1.0 +VERSION = 0.1.1 QMAKE_TARGET_COMPANY = "Thomssen IT" QMAKE_TARGET_PRODUCT = "RedTimer" QMAKE_TARGET_DESCRIPTION = "Redmine Time Tracker" diff --git a/Settings.cpp b/Settings.cpp index 5d6663b..9a88f94 100644 --- a/Settings.cpp +++ b/Settings.cpp @@ -8,24 +8,18 @@ using namespace qtredmine; using namespace redtimer; using namespace std; -Settings::Settings( SimpleRedmineClient* redmine, QObject* parent ) - : QObject( parent ), +Settings::Settings( SimpleRedmineClient* redmine, QQuickView* parent ) + : Window( "qrc:/Settings.qml", parent ), redmine_( redmine ), settings_( "RedTimer.ini", QSettings::IniFormat, this ) { ENTER(); // Settings window initialisation - win_ = new QQuickView(); - win_->setResizeMode( QQuickView::SizeRootObjectToView ); - win_->setSource( QUrl(QStringLiteral("qrc:/Settings.qml")) ); - win_->setModality( Qt::ApplicationModal ); - win_->setFlags( Qt::Dialog ); - win_->setTitle( "Settings" ); - - // Settings window access members - ctx_ = win_->rootContext(); - item_ = qobject_cast( win_->rootObject() ); + setResizeMode( QQuickView::SizeRootObjectToView ); + setModality( Qt::ApplicationModal ); + setFlags( Qt::Dialog ); + setTitle( "Settings" ); // Connect the cancel button connect( qml("cancel"), SIGNAL(clicked()), this, SLOT(close()) ); @@ -83,10 +77,10 @@ Settings::close() { ENTER(); - if( win_->isVisible() ) + if( isVisible() ) { DEBUG() << "Closing settings window"; - win_->close(); + Window::close(); } RETURN(); @@ -106,10 +100,10 @@ Settings::display() updateIssueStatuses(); - if( !win_->isVisible() ) + if( !isVisible() ) { DEBUG() << "Displaying settings window"; - win_->show(); + show(); } RETURN(); @@ -168,13 +162,6 @@ Settings::load() RETURN(); } -QQuickItem* -Settings::qml( QString qmlItem ) -{ - ENTER()(qmlItem); - RETURN( item_->findChild(qmlItem) ); -} - void Settings::save() { @@ -221,10 +208,21 @@ Settings::updateIssueStatuses() RETURN(); } - redmine_->retrieveIssueStatuses( [&]( IssueStatuses issueStatuses ) + redmine_->retrieveIssueStatuses( [&]( IssueStatuses issueStatuses, RedmineError redmineError, + QStringList errors ) { ENTER(); + if( redmineError != NO_ERROR ) + { + QString errorMsg = tr("Could not load issue statuses."); + for( const auto& error : errors ) + errorMsg.append("\n").append(error); + + message( errorMsg, QtCriticalMsg ); + RETURN(); + } + int currentIndex = 0; // Sort issues ascending by ID @@ -253,10 +251,3 @@ Settings::updateIssueStatuses() RETURN(); } - -QQuickView* -Settings::window() const -{ - ENTER(); - RETURN( win_ ); -} diff --git a/Settings.h b/Settings.h index 96720de..657295d 100644 --- a/Settings.h +++ b/Settings.h @@ -2,6 +2,7 @@ #define SETTINGS_H #include "Models.h" +#include "Window.h" #include "qtredmine/SimpleRedmineClient.h" @@ -16,7 +17,7 @@ namespace redtimer { /** * @brief A settings window and IO access for RedTimer */ -class Settings : public QObject +class Settings : public Window { Q_OBJECT @@ -78,30 +79,12 @@ class Settings : public QObject /// Redmine connection object qtredmine::SimpleRedmineClient* redmine_; - /// Settings window object - QQuickView* win_; - - /// Issue selector window context - QQmlContext* ctx_; - - /// Settings item object - QQuickItem* item_; - /// Application settings QSettings settings_; /// Cached issue statuses SimpleModel issueStatusModel_; - /** - * @brief Get a QML GUI item - * - * @param qmlItem Name of the QML GUI item - * - * @return QML GUI item - */ - QQuickItem* qml( QString qmlItem ); - public: /** * @brief Constructor for a Settings object @@ -109,8 +92,7 @@ class Settings : public QObject * @param redmine Redmine connection object * @param parent Parent QObject */ - explicit Settings( qtredmine::SimpleRedmineClient* redmine, - QObject* parent = nullptr ); + explicit Settings( qtredmine::SimpleRedmineClient* redmine, QQuickView* parent = nullptr ); /** * @brief Load settings from settings file @@ -122,13 +104,6 @@ class Settings : public QObject */ void save(); - /** - * @brief Get the settings window - * - * @return Settings window - */ - QQuickView* window() const; - public slots: /** * @brief Store the settings from the settings dialog in this class diff --git a/qtredmine b/qtredmine index adc055b..154863d 160000 --- a/qtredmine +++ b/qtredmine @@ -1 +1 @@ -Subproject commit adc055b1482103e1690c49ff37659cb56c21dd37 +Subproject commit 154863da2d4683d73829ae63ad2e62f56769cd06