From: <em...@us...> - 2006-08-14 15:54:16
|
Author: emostar Date: Mon Aug 14 17:53:55 2006 New Revision: 4558 URL: http://svn.licq.org/viewvc/licq?rev=3D4558&view=3Drev Log: * Make the manager class be a singleton * Change the caption to match the type of message it is * Fix a possible crash. Still to do: * Fix some sizing issues. * Fix the way the message box is displayed. (Always behind the parent, even= though we can't set the parent) Modified: trunk/qt-gui/src/ewidgets.cpp trunk/qt-gui/src/ewidgets.h Modified: trunk/qt-gui/src/ewidgets.cpp URL: http://svn.licq.org/viewvc/licq/trunk/qt-gui/src/ewidgets.cpp?rev=3D45= 58&r1=3D4557&r2=3D4558&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- trunk/qt-gui/src/ewidgets.cpp (original) +++ trunk/qt-gui/src/ewidgets.cpp Mon Aug 14 17:53:55 2006 @@ -39,8 +39,6 @@ =20 using namespace std; =20 -CLicqMessageManager *pMessageMgr =3D new CLicqMessageManager(); - /*! \brief Dialog with configurable yes/no buttons * * In it's easiest form, this dialog displays szQuery and the buttons szBt= n1 and szBtn2.=20 @@ -94,37 +92,17 @@ =20 void InformUser(QWidget *q, QString sz) { - pMessageMgr->addMessage(QMessageBox::Information, sz, q); - return; - //(void) new CLicqMessageBox(szInfo, QMessageBox::Information, q); -#ifdef USE_KDE - KMessageBox::information(q, sz, QMessageBox::tr("Licq Information"), QSt= ring::null, false); -#else - QMessageBox::information(q, QMessageBox::tr("Licq Information"), sz, QMe= ssageBox::Ok | QMessageBox::Default); -#endif + CLicqMessageManager::Instance()->addMessage(QMessageBox::Information, sz= , q); } =20 void WarnUser(QWidget *q, QString sz) { - pMessageMgr->addMessage(QMessageBox::Warning, sz, q); - return; -#ifdef USE_KDE - KMessageBox::sorry(q, sz, QMessageBox::tr("Licq Warning"), false); -#else - QMessageBox::warning(q, QMessageBox::tr("Licq Warning"), sz, QMessageBox= ::Ok | QMessageBox::Default, 0); -#endif + CLicqMessageManager::Instance()->addMessage(QMessageBox::Warning, sz, q); } =20 void CriticalUser(QWidget *q, QString sz) { - pMessageMgr->addMessage(QMessageBox::Critical, sz, q); - return; - //(void) new CLicqMessageBox(szInfo, QMessageBox::Critical, q); -#ifdef USE_KDE - KMessageBox::error(q, sz, QMessageBox::tr("Licq Error"), false); -#else - QMessageBox::warning(q, QMessageBox::tr("Licq Error"), sz, QMessageBox::= Ok | QMessageBox::Default, 0); -#endif + CLicqMessageManager::Instance()->addMessage(QMessageBox::Critical, sz, q= ); } =20 //-----CELabel------------------------------------------------------------= ------ @@ -1126,7 +1104,7 @@ } =20 CLicqMessageBox::CLicqMessageBox(QWidget *parent) - : QDialog(parent, "LicqInfo", false, WDestructiveClose), m_nUnreadNum(0) + : QDialog(0, "LicqInfo", false, WDestructiveClose), m_nUnreadNum(0) { setCaption("Licq"); =20 @@ -1168,12 +1146,12 @@ //m_btnMore->setDisabled(true); m_btnNext =3D new QPushButton("&Next", frmButtons); m_btnNext->setDisabled(true); - m_btnOk =3D new QPushButton("&OK", frmButtons); - m_btnOk->setDefault(true); + m_btnClear =3D new QPushButton("&Ok", frmButtons); + m_btnClear->setDefault(true); =20 lay2->addWidget(m_btnMore); lay2->addWidget(m_btnNext); - lay2->addWidget(m_btnOk); + lay2->addWidget(m_btnClear); =20 topLay->addWidget(frmMessage, 0, Qt::AlignCenter); topLay->addWidget(frmButtons, 0, Qt::AlignCenter); @@ -1184,7 +1162,7 @@ // Connect all the signals here connect(m_btnMore, SIGNAL(clicked()), this, SLOT(slot_toggleMore())); connect(m_btnNext, SIGNAL(clicked()), this, SLOT(slot_clickNext())); - connect(m_btnOk, SIGNAL(clicked()), this, SLOT(slot_clickOk())); + connect(m_btnClear, SIGNAL(clicked()), this, SLOT(slot_clickClear())); connect(m_lstMsg, SIGNAL(selectionChanged(QListViewItem *)), this, SLOT(slot_listChanged(QListViewItem *))); =20 @@ -1201,7 +1179,6 @@ // The icons we will show QPixmap pix =3D getMessageIcon(type); QImage img; - =20 // If we have only one message in queue, show that one, otherwise update // the number of pending messages. @@ -1212,12 +1189,14 @@ m_btnNext->setText("&Next"); m_btnNext->setEnabled(false); m_btnMore->setEnabled(false); + m_btnClear->setText("&Ok"); showExtension(false); // We are opening the window, so default to not = showing this } else { m_nUnreadNum++; unread =3D true; // It is unread + m_btnClear->setText("&Clear All"); QString nextStr =3D QString("&Next (%1)").arg(m_nUnreadNum); m_btnNext->setText(nextStr); if (!m_btnNext->isEnabled()) @@ -1239,6 +1218,11 @@ pEntry->setMessage(msg); pEntry->setFullIcon(pix); pEntry->setUnread(unread); + pEntry->setType(type); + + // Set the caption if we set the text and icon here + if (m_nUnreadNum =3D=3D 0) + updateCaption(pEntry); } =20 /// //////////////////////////////////////////////////////// @@ -1298,27 +1282,20 @@ } =20 /// //////////////////////////////////////////////////////// -/// @brief Close the message box +/// @brief Clear all pending messages and close the message box /// -/// When the ok button is clicked, we will close the dialog and -/// remove the oldest message (the one that was just shown) from the -/// pending message queue. +/// When the clear all button is clicked, we will close the dialog and +/// remove all messages from the queue. /// //////////////////////////////////////////////////////// -void CLicqMessageBox::slot_clickOk() +void CLicqMessageBox::slot_clickClear() { // Hide the window first hide(); =20 - // Remove any items that have been read + // Remove all items that have been read QListViewItemIterator it(m_lstMsg); while (it.current()) - { - CLicqMessageBoxItem *item =3D dynamic_cast<CLicqMessageBoxItem *>(it.c= urrent()); - if (!item->isUnread()) - delete it.current(); - else - ++it; - } + delete it.current(); } =20 /// //////////////////////////////////////////////////////// @@ -1331,9 +1308,11 @@ /// //////////////////////////////////////////////////////// void CLicqMessageBox::slot_listChanged(QListViewItem *i) { + // Change the icon, message and caption CLicqMessageBoxItem *item =3D dynamic_cast<CLicqMessageBoxItem *>(i); m_lblIcon->setPixmap(item->getFullIcon()); m_lblMessage->setText(item->getMessage()); + updateCaption(item); =20 // Mark it as read if (item->isUnread()) @@ -1353,6 +1332,34 @@ m_btnNext->setEnabled(false); } m_btnNext->setText(nextStr); +} + +/// //////////////////////////////////////////////////////// +/// @brief Change the caption of the message box +///=20 +/// @param item The CLicqMessageBoxItem that will be shown +/// //////////////////////////////////////////////////////// +void CLicqMessageBox::updateCaption(CLicqMessageBoxItem *item) +{ + if (!item) + return; + + QString strCaption; + switch (item->getType()) + { + case QMessageBox::Information: + strCaption =3D "Licq Information"; + break; + + case QMessageBox::Warning: + strCaption =3D "Licq Warning"; + break; + + case QMessageBox::Critical: + strCaption =3D "Licq Critical"; + break; + } + setCaption(strCaption); } =20 QPixmap CLicqMessageBox::getMessageIcon(QMessageBox::Icon type) @@ -1387,6 +1394,8 @@ return icon; } =20 +CLicqMessageManager *CLicqMessageManager::m_pInstance =3D 0; + CLicqMessageManager::CLicqMessageManager() : m_pMsgDlg(0) { @@ -1398,6 +1407,14 @@ delete m_pMsgDlg; } =20 +CLicqMessageManager *CLicqMessageManager::Instance() +{ + if (m_pInstance =3D=3D 0) + m_pInstance =3D new CLicqMessageManager; + + return m_pInstance; +} + void CLicqMessageManager::addMessage(QMessageBox::Icon type, const QString= &msg, QWidget *parent) { Modified: trunk/qt-gui/src/ewidgets.h URL: http://svn.licq.org/viewvc/licq/trunk/qt-gui/src/ewidgets.h?rev=3D4558= &r1=3D4557&r2=3D4558&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- trunk/qt-gui/src/ewidgets.h (original) +++ trunk/qt-gui/src/ewidgets.h Mon Aug 14 17:53:55 2006 @@ -210,6 +210,29 @@ =20 /* -----------------------------------------------------------------------= ------ */ =20 +class CLicqMessageBoxItem : public QListViewItem +{ +public: + CLicqMessageBoxItem(QListView *, QListViewItem *); + void paintCell(QPainter *, const QColorGroup &, int, int, int); + + void setMessage(const QString &s) { m_msg =3D s; } + void setFullIcon(const QPixmap &p) { m_fullIcon =3D p; } + void setUnread(bool b) { m_unread =3D b; } + void setType(QMessageBox::Icon t) { m_type =3D t; } + + QString getMessage() const { return m_msg; } + QPixmap getFullIcon() const { return m_fullIcon; } + bool isUnread() const { return m_unread; } + QMessageBox::Icon getType() const { return m_type; } + +private: + QString m_msg; + QPixmap m_fullIcon; + bool m_unread; + QMessageBox::Icon m_type; +}; + class CLicqMessageBox : public QDialog { Q_OBJECT @@ -220,18 +243,19 @@ public slots: void slot_toggleMore(); void slot_clickNext(); - void slot_clickOk(); + void slot_clickClear(); void slot_listChanged(QListViewItem *); =20 private: QPixmap getMessageIcon(QMessageBox::Icon); + void updateCaption(CLicqMessageBoxItem *); =20 int m_nUnreadNum; QLabel *m_lblIcon, *m_lblMessage; QPushButton *m_btnNext, *m_btnMore, - *m_btnOk; + *m_btnClear; QListView *m_lstMsg; QFrame *m_frmList; QSize m_Size; @@ -240,33 +264,19 @@ class CLicqMessageManager { public: + ~CLicqMessageManager(); + + static CLicqMessageManager *Instance(); + + void addMessage(QMessageBox::Icon type, const QString &msg, QWidget *p); + +private: CLicqMessageManager(); - ~CLicqMessageManager(); - - void addMessage(QMessageBox::Icon type, const QString &msg, QWidget *p); - -private: + CLicqMessageManager(const CLicqMessageManager &); + CLicqMessageManager &operator=3D(const CLicqMessageManager &); + + static CLicqMessageManager *m_pInstance; CLicqMessageBox *m_pMsgDlg; }; =20 -class CLicqMessageBoxItem : public QListViewItem -{ -public: - CLicqMessageBoxItem(QListView *, QListViewItem *); - void paintCell(QPainter *, const QColorGroup &, int, int, int); - - void setMessage(const QString &s) { m_msg =3D s; } - void setFullIcon(const QPixmap &p) { m_fullIcon =3D p; } - void setUnread(bool b) { m_unread =3D b; } - - QString getMessage() const { return m_msg; } - QPixmap getFullIcon() const { return m_fullIcon; } - bool isUnread() const { return m_unread; } - -private: - QString m_msg; - QPixmap m_fullIcon; - bool m_unread; -}; - #endif |