added tray icon and possebility to select backend

This commit is contained in:
Patrick von Reth 2010-10-24 20:13:58 +02:00
parent b591336d16
commit 431bf01e85
8 changed files with 115 additions and 10 deletions

View File

@ -49,7 +49,7 @@ option(WITH_WEBINTERFACE "Buld with WebInterface" OFF)
set(PLUGIN_INSTALL_PATH LIBRARY DESTINATION bin/snoreplugins) set(PLUGIN_INSTALL_PATH LIBRARY DESTINATION bin/snoreplugins)
add_subdirectory(data)
add_subdirectory(src) add_subdirectory(src)
install(FILES share/FindLibsnore.cmake DESTINATION share/apps/cmake/modules) install(FILES share/FindLibsnore.cmake DESTINATION share/apps/cmake/modules)

1
data/CMakeLists.txt Normal file
View File

@ -0,0 +1 @@
set(SNORE_RCS ${SNORE_RCS} ../data/snore.qrc PARENT_SCOPE)

5
data/snore.qrc Normal file
View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/root">
<file>zzz.png</file>
</qresource>
</RCC>

BIN
data/zzz.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -5,8 +5,10 @@ include_directories(
add_subdirectory(core) add_subdirectory(core)
add_executable ( snorenotify main.cpp ) QT4_ADD_RESOURCES(snorenotify_DEPS ${SNORE_RCS})
target_link_libraries ( snorenotify snorecore ${QT_QTGUI_LIBRARY}) automoc4_add_executable( snorenotify main.cpp trayicon.cpp ${snorenotify_DEPS})
target_link_libraries( snorenotify snorecore ${QT_QTGUI_LIBRARY} )
add_dependencies(snorenotify snorecore) add_dependencies(snorenotify snorecore)
install(TARGETS snorenotify RUNTIME DESTINATION bin install(TARGETS snorenotify RUNTIME DESTINATION bin
@ -16,4 +18,3 @@ install(TARGETS snorenotify RUNTIME DESTINATION bin
#add_subdirectory(webinterface) #add_subdirectory(webinterface)
add_subdirectory(plugins) add_subdirectory(plugins)

View File

@ -1,5 +1,8 @@
#include <QtGui/QApplication>
#include "core/snoreserver.h" #include "core/snoreserver.h"
#include "trayicon.h"
#include <QtGui/QApplication>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QList> #include <QList>
@ -10,17 +13,19 @@
int main ( int argc, char *argv[] ) int main ( int argc, char *argv[] )
{ {
QApplication a ( argc, argv ); QApplication a ( argc, argv );
QSystemTrayIcon *trayIcon=new QSystemTrayIcon(); QSystemTrayIcon *trayIcon=new QSystemTrayIcon(QIcon(":/root/zzz.png"));
trayIcon->show(); trayIcon->setVisible(true);
SnoreServer s ( trayIcon );
SnoreServer *s = new SnoreServer( trayIcon );
QDir pluginsDir ( a.applicationDirPath() +"/snoreplugins" ); QDir pluginsDir ( a.applicationDirPath() +"/snoreplugins" );
foreach ( QString fileName, pluginsDir.entryList ( QDir::Files ) ) foreach ( QString fileName, pluginsDir.entryList ( QDir::Files ) )
{ {
s.publicatePlugin ( pluginsDir.absoluteFilePath ( fileName ) ); s->publicatePlugin ( pluginsDir.absoluteFilePath ( fileName ) );
} }
TrayIcon *i = new TrayIcon(trayIcon,s);
i->initConextMenu();
return a.exec(); return a.exec();
} }

54
src/trayicon.cpp Normal file
View File

@ -0,0 +1,54 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@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; either version 2 of the License, or (at your option) any later *
* version. *
* *
* 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, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "trayicon.h"
#include "snore/core/snoreserver.h"
#include <QSystemTrayIcon>
#include <QMenu>
#include <QAction>
TrayIcon::TrayIcon(QSystemTrayIcon *trayIcon, SnoreServer *snore ):
_trayIcon(trayIcon),
_snore(snore)
{
}
void TrayIcon::initConextMenu(){
_trayMenu = new QMenu("SnoreNotify");
_trayMenu->addAction("SnoreNotify");
_trayMenu->addSeparator();
foreach(Notification_Backend *back,_snore->primaryNotificationBackends()){
QAction *b= new QAction(back->name(),this);
connect(b,SIGNAL(triggered()),this,SLOT(setPrimaryBackend()));
_trayMenu->addAction(b);
}
_trayMenu->addSeparator();
_trayMenu->addAction("Exit",qApp,SLOT(quit()));
_trayIcon->setContextMenu(_trayMenu);
}
void TrayIcon::setPrimaryBackend(){
QAction *a= dynamic_cast<QAction*>(sender());
_snore->setPrimaryNotificationBackend(_snore->primaryNotificationBackends().value(a->text()));
}
#include "trayicon.moc"

39
src/trayicon.h Normal file
View File

@ -0,0 +1,39 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@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; either version 2 of the License, or (at your option) any later *
* version. *
* *
* 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, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#ifndef TRAYICON_H
#define TRAYICON_H
#include <QtCore>
class TrayIcon:public QObject
{
Q_OBJECT
public:
TrayIcon(class QSystemTrayIcon *trayIcon,class SnoreServer *snore);
void initConextMenu();
private:
class QSystemTrayIcon *_trayIcon;
class QMenu *_trayMenu;
class SnoreServer *_snore;
public slots:
void setPrimaryBackend();
};
#endif // TRAYICON_H