Skip to content
Snippets Groups Projects
Commit 07233388 authored by tcohen's avatar tcohen
Browse files

[#2566] Begining of use of kapplication

parent 4a288644
No related branches found
No related tags found
No related merge requests found
......@@ -3,4 +3,5 @@ add_subdirectory(icons)
INSTALL( FILES sflphone-client-kde.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} )
INSTALL( FILES sflphone-client-kdeui.rc DESTINATION ${DATA_INSTALL_DIR}/sflphone-client-kde )
INSTALL( FILES sflphone-client-kde.notifyrc DESTINATION ${DATA_INSTALL_DIR}/sflphone-client-kde)
[Global]
Name=sflphone-client-kde
IconName=sflphone-client-kde
Comment=SFLphone VoIP KDE4 client
[Event/contact online]
Name=Contact Online
Comment=A contact has come online
Sound=
Action=Sound|Popup
[Event/test_notification]
Name=test message
Comment=Test message
Contexts=call
Action=Sound|Popup|Taskbar
Persistant=true
Sound=
[Event/test_notification2]
Name=test message2
Comment=Test message2
Sound=KDE-Im-New-Mail.ogg
Action=None
......@@ -19,6 +19,7 @@ SET ( KDE4_KABC_LIBS -lkabc )
SET( sflphone_client_kde_SRCS
SFLPhoneView.cpp
SFLPhone.cpp
SFLPhoneapplication.cpp
main.cpp
sflphone_const.h
Account.cpp
......
/***************************************************************************
/************************************** *************************************
* Copyright (C) 2009 by Savoir-Faire Linux *
* Author : Jérémy Quentin *
* jeremy.quentin@savoirfairelinux.com *
......@@ -31,6 +31,7 @@
#include <QtGui/QStatusBar>
#include <QtGui/QCursor>
#include <KActionCollection>
#include <KNotification>
#include "sflphone_const.h"
#include "instance_interface_singleton.h"
......@@ -39,43 +40,59 @@
SFLPhone::SFLPhone(QWidget *parent)
: KXmlGuiWindow(parent),
initialized_(false),
view(new SFLPhoneView(this))
{
ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
// accept dnd
setAcceptDrops(true);
// tell the KXmlGuiWindow that this is indeed the main widget
setCentralWidget(view);
setWindowIcon(QIcon(ICON_SFLPHONE));
setWindowTitle(i18n("SFLphone"));
setupActions();
setObjectNames();
QMetaObject::connectSlotsByName(this);
view->on_stackedWidget_screen_currentChanged(SCREEN_MAIN);
view->loadWindow();
move(QCursor::pos().x() - geometry().width()/2, QCursor::pos().y() - geometry().height()/2);
if( ! configurationManager.isStartHidden())
{
show();
}
if(configurationManager.getAccountList().value().isEmpty())
{
(new AccountWizard())->show();
}
KNotification *notification = new KNotification( "contact online" );
notification->setText( "text" );
notification->sendEvent();
}
SFLPhone::~SFLPhone()
{
}
bool SFLPhone::initialize()
{
if ( initialized_ )
{
qDebug() << "Already initialized.";
return false;
}
ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
// accept dnd
setAcceptDrops(true);
// tell the KXmlGuiWindow that this is indeed the main widget
setCentralWidget(view);
setWindowIcon(QIcon(ICON_SFLPHONE));
setWindowTitle(i18n("SFLphone"));
setupActions();
setObjectNames();
QMetaObject::connectSlotsByName(this);
view->on_stackedWidget_screen_currentChanged(SCREEN_MAIN);
view->loadWindow();
move(QCursor::pos().x() - geometry().width()/2, QCursor::pos().y() - geometry().height()/2);
if( ! configurationManager.isStartHidden())
{
show();
}
if(configurationManager.getAccountList().value().isEmpty())
{
(new AccountWizard())->show();
}
return true;
}
void SFLPhone::setObjectNames()
{
view->setObjectName("view");
......@@ -158,7 +175,8 @@ void SFLPhone::setupActions()
trayIconMenu = new QMenu(this);
trayIconMenu->addAction(action_quit);
trayIcon = new QSystemTrayIcon(this->windowIcon(), this);
trayIcon = new KSystemTrayIcon(this->windowIcon(), this);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->show();
......@@ -224,11 +242,37 @@ void SFLPhone::trayIconSignal()
void SFLPhone::sendNotif(QString caller)
{
trayIcon->showMessage(
KComponentData m_instance = KGlobal::mainComponent();
KNotification::event("test_notification2", i18n("Feeds added:\n %1", "message"), QPixmap() , this, KNotification::CloseOnTimeout, m_instance);
//--------------------------------
KNotification::event( "test_notification2",
QString("summary"),
QPixmap(),
topLevelWidget());
KNotification::beep();
//--------------------------------
notification = new KNotification ( QString("test_notification2"), 0l );
notification->setActions( QStringList( i18n( "View" ) ) );
notification->setText(QString("messageText"));
notification->sendEvent();
//--------------------------------
notification = new KNotification ( QString("test_notification"), this );
notification->setText("messageText") ;
notification->setPixmap( QPixmap( this->windowIcon().pixmap(32, 32) ));
// notification->setActions( QStringList( i18n( "Open chat" ) ) );
notification->addContext( QString::fromLatin1("call") , "caller" ) ;
// connect(notification, SIGNAL(activated(unsigned int )), this , SLOT(sendNotif()) );
qDebug() << notification->contexts();
qDebug() << notification->eventId();
notification->sendEvent();
//--------------------------------
trayIcon->showMessage(
i18n("Incoming call"),
i18n("You have an incoming call from") + " " + caller + ".\n" + i18n("Click to accept or refuse it."),
QSystemTrayIcon::Warning,
20000);
KSystemTrayIcon::Warning,
20000);
}
void SFLPhone::on_trayIcon_messageClicked()
......@@ -246,12 +290,12 @@ void SFLPhone::changeEvent(QEvent * event)
}
}
void SFLPhone::on_trayIcon_activated(QSystemTrayIcon::ActivationReason reason)
void SFLPhone::on_trayIcon_activated(KSystemTrayIcon::ActivationReason reason)
{
qDebug() << "on_trayIcon_activated";
switch (reason) {
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick:
case KSystemTrayIcon::Trigger:
case KSystemTrayIcon::DoubleClick:
qDebug() << "Tray icon clicked.";
if(isActiveWindow())
{
......
......@@ -27,7 +27,8 @@
#include <QtGui/QListWidgetItem>
#include <QtGui/QKeyEvent>
#include <QErrorMessage>
#include <QSystemTrayIcon>
#include <KSystemTrayIcon>
#include <KNotification>
#include <KXmlGuiWindow>
#include <KAction>
......@@ -70,6 +71,8 @@ enum CallAction {
NumberOfCallActions};
private:
// Whether or not the object has been initialized
bool initialized_;
KAction * action_accept;
KAction * action_refuse;
KAction * action_hold;
......@@ -90,7 +93,8 @@ private:
SFLPhoneView * view;
QMenu *trayIconMenu;
bool iconChanged;
QSystemTrayIcon *trayIcon;
KSystemTrayIcon *trayIcon;
KNotification *notification;
QLabel * statusBarWidget;
private:
......@@ -104,6 +108,7 @@ protected:
public:
SFLPhone(QWidget *parent = 0);
~SFLPhone();
bool initialize();
void setupActions();
void sendNotif(QString caller);
void putForeground();
......@@ -113,7 +118,7 @@ public:
private slots:
void on_trayIcon_activated(QSystemTrayIcon::ActivationReason reason);
void on_trayIcon_activated(KSystemTrayIcon::ActivationReason reason);
void on_trayIcon_messageClicked();
void on_view_statusMessageChangeAsked(const QString & message);
void on_view_windowTitleChangeAsked(const QString & message);
......
#include "SFLPhoneapplication.h"
#include <KCmdLineArgs>
#include <KIconLoader>
#include <KStandardDirs>
#include <KNotification>
#include <KMainWindow>
#include "SFLPhone.h"
/**
* The application constructor
*/
SFLPhoneApplication::SFLPhoneApplication()
: KApplication()
, sflphoneWindow_(0)
// , quitSelected_(false)
{
// SFLPhoneApplication is created from main.cpp.
// It continues the initialisation of the application.
// Install a message handler, so KMESS_ASSERT won't do a exit(1) or abort()
// It makes debugging output on Windows disappear, so don't use it there
// test notif
KNotification *notification = new KNotification( "contact online" );
notification->setText( "text" );
notification->sendEvent();
// Start remaining initialisation
// initializePaths();
// initializeMainWindow();
}
/**
* Destructor
*/
SFLPhoneApplication::~SFLPhoneApplication()
{
// automatically destroyed
sflphoneWindow_ = 0;
}
/**
* Return the sflphone window
*/
SFLPhone* SFLPhoneApplication::getSFLPhoneWindow() const
{
return sflphoneWindow_;
}
/**
* Initialisation of the main window.
*/
void SFLPhoneApplication::initializeMainWindow()
{
// Fetch the command line arguments
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
// Enable KDE session restore.
int restoredWindow = -1;
if( kapp->isSessionRestored() )
{
int n = 0;
while( KMainWindow::canBeRestored( ++n ) )
{
if( KMainWindow::classNameOfToplevel( n ) != QLatin1String( "SFLPhone" ) )
{
continue;
}
restoredWindow = n;
break;
}
}
// Create the main window and initialize it
sflphoneWindow_ = new SFLPhone();
if( ! sflphoneWindow_->initialize() )
{
exit(1);
return;
}
// Initialize KApplication
//setTopWidget( sflphoneWindow_ );
// We found session data for the Contact List, to restore it
if( kapp->isSessionRestored() && restoredWindow != -1 )
{
sflphoneWindow_->restore( restoredWindow, false );
}
else
{
if( ! args->isSet( "hidden" ) )
{
sflphoneWindow_->show();
}
}
}
/**
* Initialize additional paths
*/
void SFLPhoneApplication::initializePaths()
{
// Add compile time paths as fallback
//KGlobal::dirs() -> addPrefix( SFLPHONE_PREFIX );
//KIconLoader::global() -> addAppDir( SFLPHONE_PREFIX "/share" );
// Test whether the prefix is correct.
if( KGlobal::dirs()->findResource( "appdata", "icons/hi128-apps-sflphone-client-kde.png" ).isNull() )
{
kWarning() << "SFLPhone could not find resources in the search paths: "
<< KGlobal::dirs()->findDirs( "appdata", QString::null ).join(", ") << endl;
}
}
#include "SFLPhoneapplication.moc"
#ifndef SFLPHONEAPPLICATION_H
#define SFLPHONEAPPLICATION_H
#include <KApplication>
class SFLPhone;
class SFLPhoneApplication : public KApplication
{
Q_OBJECT
public:
// Constructor
SFLPhoneApplication();
// Destructor
virtual ~SFLPhoneApplication();
// Return the contact list window
SFLPhone* getSFLPhoneWindow() const;
// Return true if quit was selected
//bool quitSelected() const;
// Tell the application that quit was selected
//void setQuitSelected(bool quitSelected);
// private slots:
//void slotAboutToQuit();
// void slotLastWindowClosed();
private: // private methods
void initializeMainWindow();
void initializePaths();
private:
// Reference to the sflphone window
SFLPhone *sflphoneWindow_;
// True when quit was selected
//bool quitSelected_;
};
#endif // SFLPHONEAPPLICATION_H
......@@ -4,16 +4,14 @@
#include <QtGui/QMenuBar>
#include <QtGui/QAction>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <klocale.h>
#include "SFLPhone.h"
#include "AccountWizard.h"
#include "instance_interface_singleton.h"
#include "sflphone_const.h"
#include "SFLPhoneapplication.h"
#include "conf/ConfigurationDialog.h"
#include <QTableView>
......@@ -50,24 +48,15 @@ int main(int argc, char **argv)
//options.add("+[URL]", ki18n( "Document to open" ));
KCmdLineArgs::addCmdLineOptions(options);
KApplication app;
SFLPhoneApplication app;
return app.exec();
//configuration dbus
registerCommTypes();
new SFLPhone();
InstanceInterface & instance = InstanceInterfaceSingleton::getInstance();
instance.Register(getpid(), APP_NAME);
// SortableCodecListWidget * cl = new SortableCodecListWidget();
// cl->show();
// QListView * v = new QListView();
// v->setFlow(QListView::TopToBottom);
// v->setModel(new AccountListModel());
// v->show();
return app.exec();
}
catch(const char * msg)
{
......
// ADD PREDEFINED MACROS HERE!
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment