Commit 69459e74 authored by Luigi Toscano's avatar Luigi Toscano

Redirect error and warning signals to a KMessageWidget

Those two categories are usually longer messages and more
important, so more fit for a (new) KMessageWidget; simple
notice signals still go to PageViewMessage into PageView.

A more general review of all the messages should be probably
performed in order to assign proper categories to them.

Reviewed by: Albert Astal Cid
parent 4c553ac8
......@@ -43,7 +43,6 @@
#include <kfiledialog.h>
#include <kinputdialog.h>
#include <kmessagebox.h>
#include <kmessagewidget.h>
#include <knuminput.h>
#include <kio/netaccess.h>
#include <kmenu.h>
......@@ -440,13 +439,21 @@ m_cliPresentation(false), m_cliPrint(false), m_embedMode(detectEmbedMode(parentW
m_formsMessage->setWordWrap( true );
m_formsMessage->setMessageType( KMessageWidget::Information );
rightLayout->addWidget( m_formsMessage );
m_infoMessage = new KMessageWidget( rightContainer );
m_infoMessage->setVisible( false );
m_infoMessage->setWordWrap( true );
m_infoMessage->setMessageType( KMessageWidget::Information );
rightLayout->addWidget( m_infoMessage );
m_infoTimer = new QTimer();
m_infoTimer->setSingleShot( true );
connect( m_infoTimer, SIGNAL(timeout()), m_infoMessage, SLOT(animatedHide()) );
m_pageView = new PageView( rightContainer, m_document );
QMetaObject::invokeMethod( m_pageView, "setFocus", Qt::QueuedConnection ); //usability setting
// m_splitter->setFocusProxy(m_pageView);
connect( m_pageView, SIGNAL(rightClick(const Okular::Page*,QPoint)), this, SLOT(slotShowMenu(const Okular::Page*,QPoint)) );
connect( m_document, SIGNAL(error(QString,int)), m_pageView, SLOT(errorMessage(QString,int)) );
connect( m_document, SIGNAL(warning(QString,int)), m_pageView, SLOT(warningMessage(QString,int)) );
connect( m_document, SIGNAL(notice(QString,int)), m_pageView, SLOT(noticeMessage(QString,int)) );
connect( m_document, SIGNAL(error(QString,int)), this, SLOT(errorMessage(QString,int)) );
connect( m_document, SIGNAL(warning(QString,int)), this, SLOT(warningMessage(QString,int)) );
connect( m_document, SIGNAL(notice(QString,int)), this, SLOT(noticeMessage(QString,int)) );
connect( m_document, SIGNAL(sourceReferenceActivated(const QString&,int,int,bool*)), this, SLOT(slotHandleActivatedSourceReference(const QString&,int,int,bool*)) );
rightLayout->addWidget( m_pageView );
m_findBar = new FindBar( m_document, rightContainer );
......@@ -857,6 +864,7 @@ Part::~Part()
delete m_pageSizeLabel;
delete m_reviewsWidget;
delete m_bookmarkList;
delete m_infoTimer;
delete m_document;
......@@ -1025,7 +1033,7 @@ void Part::slotJobFinished(KJob *job)
{
if ( job->error() == KIO::ERR_USER_CANCELED )
{
m_pageView->noticeMessage( i18n( "The loading of %1 has been canceled.", realUrl().pathOrUrl() ) );
m_pageView->displayMessage( i18n( "The loading of %1 has been canceled.", realUrl().pathOrUrl() ) );
}
}
......@@ -2741,6 +2749,50 @@ void Part::psTransformEnded(int exit, QProcess::ExitStatus status)
}
void Part::displayInfoMessage( const QString &message, KMessageWidget::MessageType messageType, int duration )
{
if ( !Okular::Settings::showOSD() )
{
if (messageType == KMessageWidget::Error)
{
KMessageBox::error( widget(), message );
}
return;
}
// hide messageWindow if string is empty
if ( message.isEmpty() )
m_infoMessage->animatedHide();
// display message (duration is length dependant)
if ( duration < 0 )
{
duration = 500 + 100 * message.length();
}
m_infoTimer->start( duration );
m_infoMessage->setText( message );
m_infoMessage->setMessageType( messageType );
m_infoMessage->animatedShow();
}
void Part::errorMessage( const QString &message, int duration )
{
displayInfoMessage( message, KMessageWidget::Error, duration );
}
void Part::warningMessage( const QString &message, int duration )
{
displayInfoMessage( message, KMessageWidget::Warning, duration );
}
void Part::noticeMessage( const QString &message, int duration )
{
// less important message -> simpleer display widget in the PageView
m_pageView->displayMessage( message, QString(), PageViewMessage::Info, duration );
}
void Part::unsetDummyMode()
{
if ( m_embedMode == PrintPreviewMode )
......
......@@ -18,6 +18,7 @@
#include <kparts/part.h>
#include <kpluginfactory.h>
#include <kmessagewidget.h>
#include <qicon.h>
#include <qlist.h>
#include <qpointer.h>
......@@ -47,7 +48,6 @@ class KAboutData;
class KTemporaryFile;
class KAction;
class KMenu;
class KMessageWidget;
namespace KParts { class GUIActivateEvent; }
class FindBar;
......@@ -165,6 +165,7 @@ class OKULAR_PART_EXPORT Part : public KParts::ReadWritePart, public Okular::Doc
bool openFile();
bool openUrl(const KUrl &url);
void guiActivateEvent(KParts::GUIActivateEvent *event);
void displayInfoMessage( const QString &message, KMessageWidget::MessageType messageType = KMessageWidget::Information, int duration = -1 );;
public:
bool saveFile();
bool queryClose();
......@@ -228,6 +229,10 @@ class OKULAR_PART_EXPORT Part : public KParts::ReadWritePart, public Okular::Doc
void psTransformEnded(int, QProcess::ExitStatus);
KConfigDialog * slotGeneratorPreferences();
void errorMessage( const QString &message, int duration = 0 );
void warningMessage( const QString &message, int duration = -1 );
void noticeMessage( const QString &message, int duration = -1 );
private:
void setupViewerActions();
void setViewerShortcuts();
......@@ -257,6 +262,7 @@ class OKULAR_PART_EXPORT Part : public KParts::ReadWritePart, public Okular::Doc
FindBar * m_findBar;
KMessageWidget * m_topMessage;
KMessageWidget * m_formsMessage;
KMessageWidget * m_infoMessage;
QPointer<ThumbnailList> m_thumbnailList;
QPointer<PageView> m_pageView;
QPointer<TOC> m_toc;
......@@ -337,6 +343,9 @@ class OKULAR_PART_EXPORT Part : public KParts::ReadWritePart, public Okular::Doc
KXMLGUIClient *m_generatorGuiClient;
FileKeeper *m_keeper;
// Timer for m_infoMessage
QTimer *m_infoTimer;
private slots:
void slotAnnotationPreferences();
void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled);
......
......@@ -114,21 +114,6 @@ Q_OBJECT
void updateCursor();
public slots:
void errorMessage( const QString & message, int duration = -1 )
{
displayMessage( message, QString(), PageViewMessage::Error, duration );
}
void noticeMessage( const QString & message, int duration = -1 )
{
displayMessage( message, QString(), PageViewMessage::Info, duration );
}
void warningMessage( const QString & message, int duration = -1 )
{
displayMessage( message, QString(), PageViewMessage::Warning, duration );
}
void copyTextSelection() const;
void selectAll();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment