Skip to content
Browse files

show errors with pretty MessageBar

  • Loading branch information...
1 parent 358d35b commit 1da78d4d0e08972a3c50d87ec62990221c68ad39 @dougma committed Sep 3, 2009
View
41 app/radio/Application.cpp
@@ -30,59 +30,20 @@ Application::Application( int& argc, char** argv )
{
}
+// lastfmlib invokes this directly, for some errors:
void
Application::onWsError( lastfm::ws::Error e )
{
switch (e)
{
- case lastfm::ws::OperationFailed:
- //TODOCOPY
- //TODO use the non intrusive status messages
- QMessageBoxBuilder( 0 ) //TODO window pointer
- .setTitle( "Oops" )
- .setText( "Last.fm is b0rked" )
- .exec();
- break;
-
case lastfm::ws::InvalidSessionKey:
logout();
break;
-
default:
break;
}
}
-void
-Application::onRadioError( int code, const QVariant& data )
-{
- switch (code)
- {
- case lastfm::ws::NotEnoughContent:
- emit error( tr("Sorry, there is no more content available for this radio station.") );
- break;
-
- case lastfm::ws::MalformedResponse:
- case lastfm::ws::TryAgainLater:
- emit error( tr("Sorry, there was a radio error at Last.fm. Please try again later.") );
- break;
-
- case lastfm::ws::SubscribersOnly:
- emit error( tr("Sorry, this station is only available to Last.fm subscribers. "
- "<A href='http://www.last.fm/subscribe'>Sign up</a>.") );
- break;
-
- case lastfm::ws::UnknownError:
- // string contains Phonon generated user readable error message
- emit error( data.toString() );
- break;
-
- default:
- emit error( tr("Sorry, an unexpected error occurred.") );
- break;
- }
-}
-
enum Argument
{
LastFmUrl,
View
1 app/radio/Application.h
@@ -41,6 +41,5 @@ namespace moralistfad
/** all webservices connect to this and emit in the case of bad errors that
* need to be handled at a higher level */
void onWsError( lastfm::ws::Error );
- void onRadioError( int, const class QVariant& );
};
}
View
60 app/radio/MainWindow.cpp
@@ -1,5 +1,25 @@
+/*
+ Copyright 2005-2009 Last.fm Ltd.
+
+ This file is part of the Last.fm Desktop Application Suite.
+
+ lastfm-desktop is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ lastfm-desktop is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with lastfm-desktop. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#include "MainWindow.h"
#include "MainWidget.h"
+#include "widgets/MessageBar.h"
#include "widgets/MultiStarterWidget.h"
#include "widgets/PlaybackControlsWidget.h"
#include <lastfm/RadioStation>
@@ -33,7 +53,12 @@ MainWindow::MainWindow()
setStatusBar( status );
- MainWidget* mw = new MainWidget( this );
+ MainWidget* mw;
+
+ QWidget* w = new QWidget();
+ QVBoxLayout* v = new QVBoxLayout(w);
+ v->addWidget(m_messageBar = new MessageBar());
+ v->addWidget(mw = new MainWidget());
connect(mw, SIGNAL(startRadio(RadioStation)), SIGNAL(startRadio(RadioStation)));
AuthenticatedUser user;
@@ -42,7 +67,38 @@ MainWindow::MainWindow()
connect(user.getPlaylists(), SIGNAL(finished()), mw, SLOT(onUserGotPlaylists()));
connect(user.getRecentStations(), SIGNAL(finished()), mw, SLOT(onUserGotRecentStations()));
- setCentralWidget( mw );
+ setCentralWidget( w );
finishUi();
}
+
+void
+MainWindow::onRadioError(int code, const QVariant& data)
+{
+ switch (code)
+ {
+ case lastfm::ws::NotEnoughContent:
+ m_messageBar->show(tr("Sorry, there is no more content available for this radio station."));
+ break;
+
+ case lastfm::ws::MalformedResponse:
+ case lastfm::ws::TryAgainLater:
+ m_messageBar->show(tr("Sorry, there was a radio error at Last.fm. Please try again later."));
+ break;
+
+ case lastfm::ws::SubscribersOnly:
+ m_messageBar->show(tr("Sorry, this station is only available to Last.fm subscribers. "
+ "<A href='http://www.last.fm/subscribe'>Sign up</a>."));
+ break;
+
+ case lastfm::ws::UnknownError:
+ // string contains Phonon generated user readable error message
+ m_messageBar->show(data.toString());
+ break;
+
+ default:
+ m_messageBar->show("Sorry, an unexpected error occurred.");
+ break;
+ }
+}
+
View
30 app/radio/MainWindow.h
@@ -1,17 +1,45 @@
+/*
+ Copyright 2005-2009 Last.fm Ltd.
+
+ This file is part of the Last.fm Desktop Application Suite.
+
+ lastfm-desktop is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ lastfm-desktop is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with lastfm-desktop. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "lib/unicorn/UnicornMainWindow.h"
#include <lastfm/RadioStation>
+class MessageBar;
+
class MainWindow : public unicorn::MainWindow
{
Q_OBJECT
+
public:
MainWindow();
signals:
- void startRadio( const RadioStation& );
+ void startRadio(const RadioStation&);
+
+public slots:
+ void onRadioError(int code, const QVariant& data);
+
+private:
+ MessageBar* m_messageBar;
};
#endif // MAINWINDOW_H
View
3 app/radio/main.cpp
@@ -32,6 +32,7 @@
#include "lib/unicorn/UniqueApplication.h"
#include "lib/unicorn/UnicornApplication.h"
#include "MainWindow.h"
+#include "widgets/MessageBar.h"
#include "Radio.h"
#include "app/moose.h"
@@ -88,7 +89,6 @@ int main( int argc, char** argv )
radio = new Radio();
qAddPostRoutine(cleanup);
- app.connect( radio, SIGNAL(error(int, QVariant)), SLOT(onRadioError(int, QVariant)) );
ScrobSocket* scrobsock = new ScrobSocket("ass");
scrobsock->connect(radio, SIGNAL(trackSpooled(Track)), SLOT(start(Track)));
@@ -102,6 +102,7 @@ int main( int argc, char** argv )
MainWindow window;
q->connect(&window, SIGNAL(startRadio(RadioStation)), SLOT(onStartRadio(RadioStation)));
+ window.connect(radio, SIGNAL(error(int, QVariant)), SLOT(onRadioError(int, QVariant)) );
window.setWindowTitle( app.applicationName() );
View
145 app/radio/widgets/MessageBar.cpp
@@ -0,0 +1,145 @@
+/*
+ Copyright 2005-2009 Last.fm Ltd.
+ - Primarily authored by Max Howell, Jono Cole and Doug Mansell
+
+ This file is part of the Last.fm Desktop Application Suite.
+
+ lastfm-desktop is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ lastfm-desktop is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with lastfm-desktop. If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "MessageBar.h"
+#include "common/qt/reverse.cpp"
+#include <QtGui>
+
+
+MessageBar::MessageBar()
+{
+ setFixedHeight( 0 );
+
+ ui.papyrus = new QWidget( this );
+
+ QPalette p = palette();
+ p.setColor( QPalette::Text, Qt::black );
+ p.setColor( QPalette::Window, QColor( 0xfa, 0xfa, 0xc7 ) );
+ setPalette( p );
+ setAutoFillBackground( true );
+
+ m_timeline = new QTimeLine( 500, this );
+ m_timeline->setUpdateInterval( 10 );
+ connect( m_timeline, SIGNAL(frameChanged( int )), SLOT(animate( int )) );
+}
+
+
+void
+MessageBar::show( const QString& message, const QString& id )
+{
+ QLabel* label = findChild<QLabel*>( id );
+
+ if (label && id.size()) {
+ if (message.isEmpty())
+ {
+ QProgressBar* p = label->findChild<QProgressBar*>();
+ if (p)
+ p->setRange( 0, 1 ),
+ p->setValue( 1 );
+ QTimer::singleShot( 3000, label, SLOT(deleteLater()) );
+ }
+ else
+ label->setText( message );
+ return;
+ }
+
+ label = new QLabel( message, ui.papyrus );
+ label->setBackgroundRole( QPalette::Base );
+ label->setMargin( 8 );
+ label->setIndent( 4 );
+ label->setTextFormat( Qt::RichText );
+ label->setOpenExternalLinks( true );
+ label->setTextInteractionFlags( Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse );
+
+ QPushButton* close = new QPushButton( "x" );
+ QHBoxLayout* h = new QHBoxLayout( label );
+ h->addStretch();
+
+ if (id.size())
+ {
+ label->setObjectName( id );
+
+ QProgressBar* p;
+ h->addWidget( p = new QProgressBar );
+ p->setRange( 0, 0 );
+ p->setFixedWidth( 90 );
+ }
+
+ h->addWidget( close );
+ h->setMargin( 4 );
+
+ label->setFixedWidth( width() );
+ label->adjustSize();
+ label->show();
+
+ ui.papyrus->move( 0, -label->height() );
+
+ doLayout();
+
+ connect( close, SIGNAL(clicked()), label, SLOT(deleteLater()) );
+ connect( label, SIGNAL(destroyed()), SLOT(onLabelDestroyed()), Qt::QueuedConnection );
+
+ m_timeline->setFrameRange( height(), ui.papyrus->height() );
+ m_timeline->start();
+}
+
+
+void
+MessageBar::animate( int i )
+{
+ setFixedHeight( i );
+ ui.papyrus->move( 0, i - ui.papyrus->height() );
+}
+
+
+void
+MessageBar::doLayout()
+{
+ int y = 0;
+ foreach (QLabel* l, Qt::reverse<QLabel*>( findChildren<QLabel*>() ))
+ {
+ l->move( 0, y );
+ y += l->height();
+ }
+ ui.papyrus->setFixedSize( width(), y );
+}
+
+
+void
+MessageBar::onLabelDestroyed()
+{
+ doLayout();
+ setFixedHeight( ui.papyrus->height() );
+}
+
+
+void
+MessageBar::resizeEvent( QResizeEvent* )
+{
+ ui.papyrus->setFixedWidth( width() );
+ foreach (QLabel* l, findChildren<QLabel*>())
+ l->setFixedWidth( width() );
+}
+
+
+void
+MessageBar::remove( const QString& id )
+{
+ delete findChild<QLabel*>( id );
+}
View
53 app/radio/widgets/MessageBar.h
@@ -0,0 +1,53 @@
+/*
+ Copyright 2005-2009 Last.fm Ltd.
+ - Primarily authored by Max Howell, Jono Cole and Doug Mansell
+
+ This file is part of the Last.fm Desktop Application Suite.
+
+ lastfm-desktop is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ lastfm-desktop is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with lastfm-desktop. If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef MESSAGE_BAR_H
+#define MESSAGE_BAR_H
+
+#include <QWidget>
+
+
+/** @author <max@last.fm> */
+
+class MessageBar : public QWidget
+{
+ Q_OBJECT
+
+ class QTimeLine* m_timeline;
+
+ struct Ui {
+ QWidget* papyrus;
+ } ui;
+
+ virtual void resizeEvent( QResizeEvent* );
+ void doLayout();
+
+public:
+ MessageBar();
+
+public slots:
+ void show( const QString&, const QString& id = QString() );
+ void remove( const QString& id );
+
+private slots:
+ void animate( int );
+ void onLabelDestroyed();
+};
+
+#endif

0 comments on commit 1da78d4

Please sign in to comment.
Something went wrong with that request. Please try again.