Skip to content

Commit

Permalink
Add network error messages to retrieve methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederick Thomssen committed May 7, 2016
1 parent f14f091 commit 699e4ac
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 85 deletions.
49 changes: 41 additions & 8 deletions IssueCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
Expand All @@ -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();
} );
Expand All @@ -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 )
Expand All @@ -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 )
Expand Down Expand Up @@ -226,7 +259,7 @@ IssueCreator::save()
message( tr("New issue created with ID %1").arg(id) );

created( id );
closeWin();
close();

RETURN();
} );
Expand Down
2 changes: 1 addition & 1 deletion IssueCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public slots:
/**
* @brief Close the issue selector dialog
*/
void closeWin();
void close();

/**
* @brief Display the issue selector dialog
Expand Down
24 changes: 22 additions & 2 deletions IssueSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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()
Expand Down
7 changes: 0 additions & 7 deletions IssueSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 49 additions & 6 deletions RedTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()) );
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion RedTimer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
53 changes: 22 additions & 31 deletions Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QQuickItem*>( 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()) );
Expand Down Expand Up @@ -83,10 +77,10 @@ Settings::close()
{
ENTER();

if( win_->isVisible() )
if( isVisible() )
{
DEBUG() << "Closing settings window";
win_->close();
Window::close();
}

RETURN();
Expand All @@ -106,10 +100,10 @@ Settings::display()

updateIssueStatuses();

if( !win_->isVisible() )
if( !isVisible() )
{
DEBUG() << "Displaying settings window";
win_->show();
show();
}

RETURN();
Expand Down Expand Up @@ -168,13 +162,6 @@ Settings::load()
RETURN();
}

QQuickItem*
Settings::qml( QString qmlItem )
{
ENTER()(qmlItem);
RETURN( item_->findChild<QQuickItem*>(qmlItem) );
}

void
Settings::save()
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -253,10 +251,3 @@ Settings::updateIssueStatuses()

RETURN();
}

QQuickView*
Settings::window() const
{
ENTER();
RETURN( win_ );
}
Loading

0 comments on commit 699e4ac

Please sign in to comment.