Browse files

KDE4 integration, go!

  • Loading branch information...
1 parent 9029f5b commit 43abe3d121d2871ec3cb481e25e6e158b82f6ef1 @wengxt wengxt committed Oct 8, 2011
View
18 CMakeLists.txt
@@ -3,6 +3,24 @@ cmake_minimum_required(VERSION 2.6)
project(hotot-qt)
find_package(Qt4 4.7 REQUIRED COMPONENTS QtCore QtGui QtWebkit QtSql)
+find_package(Gettext REQUIRED)
+
+option(WITH_KDE "Enable KDE4 integration" ON)
+
+# Setup KDE4 support
+if(WITH_KDE)
+ find_package(KDE4)
+ if(KDE4_FOUND)
+ message(STATUS "Enabling KDE4 integration")
+ include_directories(${KDE4_INCLUDES})
+ add_definitions(${KDE4_DEFINITIONS})
+ set(HAVE_KDE 1)
+ else(KDE4_FOUND)
+ message(STATUS "KDE4 not found, disabling KDE integration")
+ endif(KDE4_FOUND)
+ else(WITH_KDE)
+ message(STATUS "Not enabling KDE4 integration")
+endif(WITH_KDE)
configure_file(config.h.in config.h)
View
3 config.h.in
@@ -1 +1,2 @@
-#define PREFIX "@CMAKE_INSTALL_PREFIX@"
+#define PREFIX "@CMAKE_INSTALL_PREFIX@"
+#cmakedefine HAVE_KDE
View
3 qt/CMakeLists.txt
@@ -1,2 +1,3 @@
add_subdirectory(src)
-add_subdirectory(data)
+add_subdirectory(data)
+add_subdirectory(po)
View
1 qt/data/hotot-qt.desktop
@@ -6,3 +6,4 @@ Comment=Lightweight Twitter Client base on QtWebkit
Exec=hotot-qt
Icon=hotot-qt
Categories=Qt;Network;
+X-DBUS-StartupType=Unique
View
10 qt/po/CMakeLists.txt
@@ -0,0 +1,10 @@
+set(POT_FILE
+ hotot-qt.pot
+)
+
+file(GLOB PO_FILES
+ *.po
+)
+
+# Update .po files and compile them to binary .gmo files
+gettext_create_translations(${POT_FILE} ALL ${PO_FILES})
View
46 qt/po/Messages.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+BASEDIR="../src" # root of translatable sources
+PROJECT="hotot-qt" # project name
+BUGADDR="https://github.com/shellex/Hotot/issues" # MSGID-Bugs
+WDIR="`pwd`" # working dir
+
+echo "Preparing rc files"
+
+# we use simple sorting to make sure the lines do not jump around too much from system to system
+find "${BASEDIR}" -name '*.rc' -o -name '*.ui' -o -name '*.kcfg' | sort > "${WDIR}/rcfiles.list"
+xargs --arg-file="${WDIR}/rcfiles.list" extractrc > "${WDIR}/rc.cpp"
+
+# additional string for KAboutData
+echo 'i18nc("NAME OF TRANSLATORS","Your names");' >> "${WDIR}/rc.cpp"
+echo 'i18nc("EMAIL OF TRANSLATORS","Your emails");' >> "${WDIR}/rc.cpp"
+
+echo "Done preparing rc files"
+echo "Extracting messages"
+
+# see above on sorting
+
+find "${BASEDIR}" -name '*.cpp' -o -name '*.h' -o -name '*.c' | sort > "${WDIR}/infiles.list"
+echo "rc.cpp" >> "${WDIR}/infiles.list"
+
+xgettext --from-code=UTF-8 -C -kde -ci18n -ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3 \
+ -ktr2i18n:1 -kI18N_NOOP:1 -kI18N_NOOP2:1c,2 -kaliasLocale -kki18n:1 -kki18nc:1c,2 \
+ -kki18np:1,2 -kki18ncp:1c,2,3 --msgid-bugs-address="${BUGADDR}" --files-from=infiles.list \
+ -D "${BASEDIR}" -D "${WDIR}" -o "${PROJECT}.pot" || \
+ { echo "error while calling xgettext. aborting."; exit 1; }
+echo "Done extracting messages"
+
+echo "Merging translations"
+catalogs=`find . -name '*.po'`
+for cat in $catalogs; do
+ echo "$cat"
+ msgmerge -o "$cat.new" "$cat" "${WDIR}/${PROJECT}.pot"
+ mv "$cat.new" "$cat"
+done
+
+echo "Done merging translations"
+echo "Cleaning up"
+rm "${WDIR}/rcfiles.list"
+rm "${WDIR}/infiles.list"
+rm "${WDIR}/rc.cpp"
+echo "Done"
View
96 qt/po/hotot-qt.pot
@@ -0,0 +1,96 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: https://github.com/shellex/Hotot/issues\n"
+"POT-Creation-Date: 2011-10-09 05:39+0800\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. i18n: file: ../src/mainwindow.ui:14
+#. i18n: ectx: property (windowTitle), widget (QMainWindow, MainWindow)
+#: ../src/kdetraybackend.cpp:23 ../src/main.cpp:47 rc.cpp:3
+msgid "Hotot"
+msgstr ""
+
+#: ../src/kdetraybackend.cpp:52 ../src/qttraybackend.cpp:52
+msgid "%1 unread Messages"
+msgstr ""
+
+#: ../src/main.cpp:49
+msgid "Lightweight, Flexible Microblogging"
+msgstr ""
+
+#: ../src/main.cpp:51
+msgid "(c) 2009-2011 Shellex Wai\n"
+msgstr ""
+
+#: ../src/main.cpp:57
+msgid "Shellex Wai"
+msgstr ""
+
+#: ../src/main.cpp:57
+msgid "Developer and Artwork"
+msgstr ""
+
+#: ../src/main.cpp:58
+msgid "Jiahua Huang"
+msgstr ""
+
+#: ../src/main.cpp:58 ../src/main.cpp:59 ../src/main.cpp:60 ../src/main.cpp:61
+msgid "Developer"
+msgstr ""
+
+#: ../src/main.cpp:59
+msgid "Jimmy Xu"
+msgstr ""
+
+#: ../src/main.cpp:60
+msgid "Tualatrix Chou"
+msgstr ""
+
+#: ../src/main.cpp:61
+msgid "Xu Zhen"
+msgstr ""
+
+#: ../src/main.cpp:62
+msgid "Evan"
+msgstr ""
+
+#: ../src/main.cpp:62
+msgid "Artwork"
+msgstr ""
+
+#: ../src/main.cpp:63
+msgid "Marguerite Su"
+msgstr ""
+
+#: ../src/main.cpp:63
+msgid "Document"
+msgstr ""
+
+#. i18n: file: ../src/mainwindow.ui:22
+#. i18n: ectx: property (url), widget (QWebView, webView)
+#: rc.cpp:6
+msgid "about:blank"
+msgstr ""
+
+#: rc.cpp:7
+msgctxt "NAME OF TRANSLATORS"
+msgid "Your names"
+msgstr ""
+
+#: rc.cpp:8
+msgctxt "EMAIL OF TRANSLATORS"
+msgid "Your emails"
+msgstr ""
View
96 qt/po/zh_CN.po
@@ -0,0 +1,96 @@
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+#
+# Weng Xuetian <wengxt@gmail.com>, 2011.
+msgid ""
+msgstr ""
+"Project-Id-Version: \n"
+"Report-Msgid-Bugs-To: https://github.com/shellex/Hotot/issues\n"
+"POT-Creation-Date: 2011-10-09 05:39+0800\n"
+"PO-Revision-Date: 2011-10-09 05:40+0800\n"
+"Last-Translator: Weng Xuetian <wengxt@gmail.com>\n"
+"Language-Team: Chinese Simplified <kde-china@kde.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Lokalize 1.2\n"
+"Plural-Forms: nplurals=2; plural=n != 1;\n"
+
+#: ../src/kdetraybackend.cpp:52 ../src/qttraybackend.cpp:52
+msgid "%1 unread Messages"
+msgstr "%1 条未读信息"
+
+#: ../src/main.cpp:51
+msgid "(c) 2009-2011 Shellex Wai\n"
+msgstr "(c) 2009-2011 Shellex Wai\n"
+
+#: ../src/main.cpp:62
+msgid "Artwork"
+msgstr "美工"
+
+#: ../src/main.cpp:58 ../src/main.cpp:59 ../src/main.cpp:60 ../src/main.cpp:61
+msgid "Developer"
+msgstr "开发"
+
+#: ../src/main.cpp:57
+msgid "Developer and Artwork"
+msgstr "开发和美工"
+
+#: ../src/main.cpp:63
+msgid "Document"
+msgstr "文档"
+
+#: ../src/main.cpp:62
+msgid "Evan"
+msgstr "Evan"
+
+#. i18n: file: ../src/mainwindow.ui:14
+#. i18n: ectx: property (windowTitle), widget (QMainWindow, MainWindow)
+#: ../src/kdetraybackend.cpp:23 ../src/main.cpp:47 rc.cpp:3
+msgid "Hotot"
+msgstr "Hotot"
+
+#: ../src/main.cpp:58
+msgid "Jiahua Huang"
+msgstr "Jiahua Huang"
+
+#: ../src/main.cpp:59
+msgid "Jimmy Xu"
+msgstr "Jimmy Xu"
+
+#: ../src/main.cpp:49
+msgid "Lightweight, Flexible Microblogging"
+msgstr "轻量,灵活的微博客客户端"
+
+#: ../src/main.cpp:63
+msgid "Marguerite Su"
+msgstr "Marguerite Su"
+
+#: ../src/main.cpp:57
+msgid "Shellex Wai"
+msgstr "Shellex Wai"
+
+#: ../src/main.cpp:60
+msgid "Tualatrix Chou"
+msgstr "Tualatrix Chou"
+
+#: ../src/main.cpp:61
+msgid "Xu Zhen"
+msgstr "Xu Zhen"
+
+#: rc.cpp:8
+msgctxt "EMAIL OF TRANSLATORS"
+msgid "Your emails"
+msgstr "wengxt@gmail.com"
+
+#: rc.cpp:7
+msgctxt "NAME OF TRANSLATORS"
+msgid "Your names"
+msgstr "CSSlayer Weng"
+
+#. i18n: file: ../src/mainwindow.ui:22
+#. i18n: ectx: property (url), widget (QWebView, webView)
+#: rc.cpp:6
+msgid "about:blank"
+msgstr "about:blank"
View
13 qt/src/CMakeLists.txt
@@ -14,8 +14,17 @@ set(Hotot_QT_SRCS
main.cpp
mainwindow.cpp
hototwebpage.cpp
+ trayiconbackend.cpp
+ qttraybackend.cpp
)
+if (HAVE_KDE)
+ set(Hotot_QT_SRCS
+ ${Hotot_QT_SRCS}
+ kdetraybackend.cpp
+ )
+endif (HAVE_KDE)
+
qt4_automoc(${Hotot_QT_SRCS})
qt4_wrap_ui(Hotot_QT_SRCS mainwindow.ui)
add_executable(hotot-qt ${Hotot_QT_SRCS})
@@ -27,4 +36,8 @@ target_link_libraries(hotot-qt
${QT_QTNETWORK_LIBRARY}
)
+if(HAVE_KDE)
+ target_link_libraries(hotot-qt ${KDE4_KDEUI_LIBRARY})
+endif(HAVE_KDE)
+
install(TARGETS hotot-qt DESTINATION bin)
View
8 qt/src/common.h
@@ -0,0 +1,8 @@
+#include "config.h"
+
+#ifdef HAVE_KDE
+#include <KLocalizedString>
+#else
+#include <libintl.h>
+#define i18n(x) QString::fromUtf8(gettext(x))
+#endif
View
1 qt/src/formpost.h
@@ -2,7 +2,6 @@
#ifndef __FORMPOST_H__
#define __FORMPOST_H__
-#include <QtPlugin>
#include <QString>
#include <QByteArray>
#include <QFile>
View
6 qt/src/hototwebpage.cpp
@@ -61,7 +61,11 @@ bool HototWebPage::handleUri(const QString& originmsg)
m_mainWindow->notification(notify_type, title, summary, image);
}
-
+ else if (method == "unread_alert")
+ {
+ QString number = QUrl::fromPercentEncoding(msg.section("/", 2, 2).toUtf8());
+ m_mainWindow->unreadAlert(number);
+ }
}
else if (type == "action")
{
View
55 qt/src/kdetraybackend.cpp
@@ -0,0 +1,55 @@
+#include "common.h"
+
+// KDE
+#include <KStatusNotifierItem>
+#include <KMenu>
+#include <KIcon>
+
+// Hotot
+#include "mainwindow.h"
+#include "kdetraybackend.h"
+
+KDETrayBackend::KDETrayBackend(MainWindow* parent):
+ TrayIconBackend(parent),
+ m_mainWindow(parent),
+ m_statusNotifierItem(new KStatusNotifierItem("hotot", this))
+{
+ m_statusNotifierItem->setIconByName("hotot-qt");
+ m_statusNotifierItem->setTitle("Hotot");
+ m_statusNotifierItem->setToolTipIconByName("hotot-qt");
+ m_statusNotifierItem->setStatus( KStatusNotifierItem::Active );
+ m_statusNotifierItem->setCategory( KStatusNotifierItem::Communications );
+ m_statusNotifierItem->setStandardActionsEnabled(false);
+ m_statusNotifierItem->setToolTipTitle(i18n("Hotot"));
+
+ connect(m_statusNotifierItem, SIGNAL(activateRequested(bool,QPoint)), this, SLOT(activate()));
+}
+
+void KDETrayBackend::showMessage(QString type, QString title, QString message, QString image)
+{
+ Q_UNUSED(type)
+ Q_UNUSED(image)
+ m_statusNotifierItem->setStatus( KStatusNotifierItem::NeedsAttention );
+ m_statusNotifierItem->showMessage(title, message, "hotot-qt", 4000);
+}
+
+void KDETrayBackend::setContextMenu(QMenu* menu)
+{
+ KMenu* kmenu = m_statusNotifierItem->contextMenu();
+ Q_FOREACH(QAction* action, menu->actions())
+ {
+ kmenu->addAction(action);
+ }
+}
+
+void KDETrayBackend::activate()
+{
+ m_mainWindow->triggerVisible();
+}
+
+void KDETrayBackend::unreadAlert(QString number)
+{
+ m_statusNotifierItem->setToolTipSubTitle(i18n("%1 unread Messages").arg(number));
+}
+
+#include "kdetraybackend.moc"
View
21 qt/src/kdetraybackend.h
@@ -0,0 +1,21 @@
+#ifndef KDETRAY_BACKEND_H
+#define KDETRAY_BACKEND_H
+#include "trayiconbackend.h"
+
+class KStatusNotifierItem;
+class KDETrayBackend : public TrayIconBackend
+{
+ Q_OBJECT
+public:
+ KDETrayBackend(MainWindow* parent = 0);
+ virtual void setContextMenu(QMenu* menu);
+ virtual void showMessage(QString type, QString title, QString message, QString image);
+ virtual void unreadAlert(QString number);
+protected Q_SLOTS:
+ void activate();
+private:
+ MainWindow* m_mainWindow;
+ KStatusNotifierItem* m_statusNotifierItem;
+};
+
+#endif
View
55 qt/src/main.cpp
@@ -17,14 +17,67 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
-#include <QtGui/QApplication>
+#include "common.h"
+
+// Qt
+#include <QApplication>
+#include <libintl.h>
+
+// KDE
+#ifdef HAVE_KDE
+#include <KAboutData>
+#include <KApplication>
+#include <KCmdLineOptions>
+#include <KUniqueApplication>
+#include <KDebug>
+#endif
+
+// System
+#include <stdio.h>
+
+// Hotot
#include "mainwindow.h"
int main(int argc, char *argv[])
{
+#ifdef HAVE_KDE
+
+ KAboutData aboutData( "hotot-qt", // internal name
+ 0, // catalog name
+ ki18n("Hotot"), // program name
+ "0.9.9", // app version from config-kmess.h
+ ki18n("Lightweight, Flexible Microblogging"), // short description
+ KAboutData::License_LGPL, // license
+ ki18n("(c) 2009-2011 Shellex Wai\n"), // copyright
+ KLocalizedString(),
+ "http://www.hotot.org/", // home page
+ "https://github.com/shellex/Hotot/issues" // address for bugs
+ );
+
+ aboutData.addAuthor( ki18n("Shellex Wai"), ki18n("Developer and Artwork"), "5h3ll3x@gmail.com" );
+ aboutData.addAuthor( ki18n("Jiahua Huang"), ki18n("Developer"), "jhuangjiahua" "@" "gmail" "." "com" );
+ aboutData.addAuthor( ki18n("Jimmy Xu"), ki18n("Developer"), "xu.jimmy.wrk" "@" "gmail" "." "com" );
+ aboutData.addAuthor( ki18n("Tualatrix Chou"), ki18n("Developer"), "tualatrix" "@" "gmail" "." "com" );
+ aboutData.addAuthor( ki18n("Xu Zhen"), ki18n("Developer"), "xnreformer" "@" "gmail" "." "com" );
+ aboutData.addAuthor( ki18n("Evan"), ki18n("Artwork"), "www.freemagi.com" );
+ aboutData.addAuthor( ki18n("Marguerite Su"), ki18n("Document"), "admin" "@" "doublechou.pp.ru" );
+
+ KCmdLineOptions options;
+ KCmdLineArgs::init( argc, argv, &aboutData );
+
+ KCmdLineArgs::addCmdLineOptions( options );
+ KCmdLineArgs::parsedArgs();
+
+ KApplication a;
+ MainWindow w;
+ w.show();
+ return a.exec();
+#else
+ bind_textdomain_codeset("hotot-qt", "UTF-8");
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
+#endif
}
View
124 qt/src/mainwindow.cpp
@@ -17,8 +17,12 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
-#include "mainwindow.h"
-#include "ui_mainwindow.h"
+#include "common.h"
+
+// system
+#include <unistd.h>
+
+// Qt
#include <QWebView>
#include <QWebDatabase>
#include <QWebSettings>
@@ -33,13 +37,20 @@
#include <QLocale>
#include <QSystemTrayIcon>
#include <QMenu>
+
+// Hotot
+#include "ui_mainwindow.h"
+#include "mainwindow.h"
#include "hototwebpage.h"
-#include "config.h"
+#include "trayiconbackend.h"
+#include "qttraybackend.h"
+#ifdef HAVE_KDE
+#include "kdetraybackend.h"
+#endif
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
- m_trayicon(0),
m_page(0),
m_webView(0)
{
@@ -50,30 +61,24 @@ MainWindow::MainWindow(QWidget *parent) :
restoreGeometry(settings.value("geometry").toByteArray());
restoreState(settings.value("windowState").toByteArray());
- this->setWindowTitle(tr("Hotot"));
+ this->setWindowTitle(i18n("Hotot"));
this->setWindowIcon(QIcon::fromTheme("hotot-qt", QIcon("share/hotot-qt/html/image/ic64_hotot_classics.png" )));
ui->setupUi(this);
- m_trayicon = new QSystemTrayIcon(this);
- m_trayicon->setIcon(QIcon::fromTheme("hotot-qt", QIcon("share/hotot-qt/html/image/ic64_hotot_classics.png" )));
- m_trayicon->show();
- connect(m_trayicon,
- SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
- this,
- SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason)));
- connect(m_trayicon,
- SIGNAL(messageClicked()),
- this,
- SLOT(messageClicked()));
-
m_menu = new QMenu(this);
QAction* action;
- action = new QAction(QIcon::fromTheme("application-exit"), tr("&Exit"), this);
+ action = new QAction(QIcon::fromTheme("application-exit"), i18n("&Exit"), this);
action->setShortcut(QKeySequence::Quit);
connect(action, SIGNAL(triggered()), this, SLOT(close()));
m_menu->addAction(action);
- m_trayicon->setContextMenu(m_menu);
+#ifdef HAVE_KDE
+ m_tray = new KDETrayBackend(this);
+#else
+ m_tray = new QtTrayBackend(this);
+#endif
+
+ m_tray->setContextMenu(m_menu);
this->addAction(action);
this->m_page = new HototWebPage(this);
@@ -127,63 +132,63 @@ void MainWindow::initDatabases()
const QList<QWebDatabase>& databases = origin.databases();
Q_FOREACH(QWebDatabase webDatabase, databases)
{
- QSqlDatabase sqldb = QSqlDatabase::addDatabase("QSQLITE", "myconnection");
- sqldb.setDatabaseName(webDatabase.fileName());
- if (sqldb.open()) {
- sqldb.exec("vacuum");
-
- if (webDatabase.name() == "hotot.cache")
- {
+ {
+ QSqlDatabase sqldb = QSqlDatabase::addDatabase("QSQLITE", "myconnection");
+ sqldb.setDatabaseName(webDatabase.fileName());
+ if (sqldb.open()) {
sqldb.exec("vacuum");
- QSqlQuery result = sqldb.exec("select value from Info where key=\"settings\"");
- while (result.next())
- {
- QString settings = result.value(0).toString();
- m_webView->page()->currentFrame()->evaluateJavaScript("hotot_qt = " + settings + ";");
- bool useHttpProxy = m_webView->page()->currentFrame()->evaluateJavaScript("hotot_qt.use_http_proxy").toBool();
- int httpProxyPort = m_webView->page()->currentFrame()->evaluateJavaScript("hotot_qt.http_proxy_port").toInt();
- QString httpProxyHost = m_webView->page()->currentFrame()->evaluateJavaScript("hotot_qt.http_proxy_host").toString();
- if (useHttpProxy)
+ if (webDatabase.name() == "hotot.cache")
+ {
+ sqldb.exec("vacuum");
+ QSqlQuery result = sqldb.exec("select value from Info where key=\"settings\"");
+ while (result.next())
{
- QNetworkProxy proxy(QNetworkProxy::HttpProxy,
- httpProxyHost,
- httpProxyPort);
-
- m_webView->page()->networkAccessManager()->setProxy(proxy);
+ QString settings = result.value(0).toString();
+ m_webView->page()->currentFrame()->evaluateJavaScript("hotot_qt = " + settings + ";");
+ bool useHttpProxy = m_webView->page()->currentFrame()->evaluateJavaScript("hotot_qt.use_http_proxy").toBool();
+ int httpProxyPort = m_webView->page()->currentFrame()->evaluateJavaScript("hotot_qt.http_proxy_port").toInt();
+ QString httpProxyHost = m_webView->page()->currentFrame()->evaluateJavaScript("hotot_qt.http_proxy_host").toString();
+
+ if (useHttpProxy)
+ {
+ QNetworkProxy proxy(QNetworkProxy::HttpProxy,
+ httpProxyHost,
+ httpProxyPort);
+
+ m_webView->page()->networkAccessManager()->setProxy(proxy);
+ }
}
}
+ sqldb.close();
}
- sqldb.close();
}
+ QSqlDatabase::removeDatabase("myconnection");
}
}
-void MainWindow::trayIconClicked(QSystemTrayIcon::ActivationReason reason)
+void MainWindow::triggerVisible()
{
- if (reason == QSystemTrayIcon::Trigger)
+ if (this->isActiveWindow())
{
- if (this->isActiveWindow())
- {
- if (this->isVisible())
- this->hide();
- }
- else
- {
- if (!this->isVisible())
- this->show();
- this->activateWindow();
- this->raise();
- }
+ if (this->isVisible())
+ this->hide();
+ }
+ else
+ {
+ if (!this->isVisible())
+ this->show();
+ this->activateWindow();
+ this->raise();
}
}
void MainWindow::notification(QString type, QString title, QString message, QString image)
{
- m_trayicon->showMessage(title, message);
+ m_tray->showMessage(type, title, message, image);
}
-void MainWindow::messageClicked()
+void MainWindow::activate()
{
if (!this->isActiveWindow())
{
@@ -194,4 +199,9 @@ void MainWindow::messageClicked()
}
}
+void MainWindow::unreadAlert(QString number)
+{
+ m_tray->unreadAlert(number);
+}
+
#include "mainwindow.moc"
View
13 qt/src/mainwindow.h
@@ -20,10 +20,12 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
+// Qt
#include <QMainWindow>
#include <QSystemTrayIcon>
-class QSystemTrayIcon;
+class TrayIconBackend;
+class KStatusNotifierItem;
namespace Ui {
class MainWindow;
}
@@ -37,23 +39,24 @@ class MainWindow : public QMainWindow
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
- void notification(QString arg1, QString arg2, QString arg3, QString arg4);
+ void notification(QString type, QString title, QString message, QString image);
+ void triggerVisible();
+ void activate();
+ void unreadAlert(QString number);
protected Q_SLOTS:
void loadFinished(bool ok);
- void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
- void messageClicked();
protected:
void initDatabases();
void closeEvent(QCloseEvent *evnet);
private:
Ui::MainWindow *ui;
- QSystemTrayIcon* m_trayicon;
HototWebPage* m_page;
QWebView* m_webView;
QMenu* m_menu;
+ TrayIconBackend* m_tray;
};
#endif // MAINWINDOW_H
View
56 qt/src/qttraybackend.cpp
@@ -0,0 +1,56 @@
+#include "common.h"
+
+// Qt
+#include <QSystemTrayIcon>
+
+// Hotot
+#include "qttraybackend.h"
+#include "mainwindow.h"
+
+QtTrayBackend::QtTrayBackend(MainWindow* parent):
+ TrayIconBackend(parent),
+ m_mainWindow(parent),
+ m_trayicon(new QSystemTrayIcon(this))
+{
+ m_trayicon->setIcon(QIcon::fromTheme("hotot-qt", QIcon("share/hotot-qt/html/image/ic64_hotot_classics.png" )));
+ m_trayicon->show();
+ connect(m_trayicon,
+ SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
+ this,
+ SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason)));
+ connect(m_trayicon,
+ SIGNAL(messageClicked()),
+ this,
+ SLOT(messageClicked()));
+}
+
+void QtTrayBackend::setContextMenu(QMenu* menu)
+{
+ m_trayicon->setContextMenu(menu);
+}
+
+void QtTrayBackend::showMessage(QString type, QString title, QString message, QString image)
+{
+ Q_UNUSED(type)
+ Q_UNUSED(image)
+ m_trayicon->showMessage(title, message);
+}
+
+void QtTrayBackend::messageClicked()
+{
+ m_mainWindow->activate();
+}
+
+void QtTrayBackend::trayIconClicked(QSystemTrayIcon::ActivationReason reason)
+{
+ if (reason == QSystemTrayIcon::Trigger)
+ m_mainWindow->triggerVisible();
+}
+
+void QtTrayBackend::unreadAlert(QString number)
+{
+ m_trayicon->setToolTip(i18n("%1 unread Messages").arg(number));
+}
+
+
+#include "qttraybackend.moc"
View
26 qt/src/qttraybackend.h
@@ -0,0 +1,26 @@
+#ifndef QTTRAY_BACKEND_H
+#define QTTRAY_BACKEND_H
+
+// Qt
+#include <QSystemTrayIcon>
+
+// Hotot
+#include "trayiconbackend.h"
+
+class QtTrayBackend : public TrayIconBackend
+{
+ Q_OBJECT
+public:
+ QtTrayBackend(MainWindow* parent = 0);
+ virtual void setContextMenu(QMenu* menu);
+ virtual void showMessage(QString type, QString title, QString message, QString image);
+ virtual void unreadAlert(QString number);
+protected Q_SLOTS:
+ void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
+ void messageClicked();
+private:
+ MainWindow* m_mainWindow;
+ QSystemTrayIcon* m_trayicon;
+};
+
+#endif
View
28 qt/src/trayiconbackend.cpp
@@ -0,0 +1,28 @@
+#include "trayiconbackend.h"
+#include "mainwindow.h"
+
+TrayIconBackend::TrayIconBackend(MainWindow* parent): QObject(parent)
+{
+
+}
+
+void TrayIconBackend::setContextMenu(QMenu* menu)
+{
+ Q_UNUSED(menu)
+}
+
+void TrayIconBackend::showMessage(QString type, QString title, QString message, QString image)
+{
+ Q_UNUSED(type)
+ Q_UNUSED(image)
+ Q_UNUSED(title)
+ Q_UNUSED(message)
+}
+
+void TrayIconBackend::unreadAlert(QString number)
+{
+ Q_UNUSED(number)
+}
+
+
+#include "trayiconbackend.moc"
View
36 qt/src/trayiconbackend.h
@@ -0,0 +1,36 @@
+/***************************************************************************
+ * Copyright (C) 2011~2011 by CSSlayer *
+ * wengxt@gmail.com *
+ * *
+ * This program 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, version 2 of the License. *
+ * *
+ * This program 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 this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef TRAYICON_BACKEND_H
+#define TRAYICON_BACKEND_H
+#include <QObject>
+
+class MainWindow;
+class QMenu;
+class TrayIconBackend : public QObject
+{
+ Q_OBJECT
+public:
+ TrayIconBackend(MainWindow* parent = 0);
+ virtual void setContextMenu(QMenu* menu);
+ virtual void showMessage(QString type, QString title, QString message, QString image);
+ virtual void unreadAlert(QString number);
+};
+
+#endif

0 comments on commit 43abe3d

Please sign in to comment.