Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qlinphone.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           qlinphone.cpp  -  description
00003                              -------------------
00004     begin                : sam mai 24 2003
00005     copyright            : (C) 2003 by Simon Morlat, 2004 Maximilian Reiss
00006     email                : simon.morlat@linphone.org, harlekin@handhelds.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "qlinphone.h"
00019 #include <qlineedit.h>
00020 #include <qlabel.h>
00021 #include <qwidget.h>
00022 #include <qslider.h>
00023 #include <qtabwidget.h>
00024 #include <qcheckbox.h>
00025 #include <qmessagebox.h>
00026 #include <qpe/config.h>
00027 #include <qpe/qpeapplication.h>
00028 #include <linphonecore.h>
00029 
00030 extern "C" {
00031     static void stub(LinphoneCore*lc, char*msg) {}
00032 
00033     static void qt_show(LinphoneCore *lc) {
00034         QLinphoneMainWidget *w=(QLinphoneMainWidget*)lc->data;
00035         w->pushGuiTask(new ShowTask(w));
00036     }
00037 
00038     static void qt_inv_recv(LinphoneCore *lc, char *from) {
00039         QLinphoneMainWidget *w=(QLinphoneMainWidget*)lc->data;
00040         QString tmp(from);
00041         w->pushGuiTask(new InviteReceivedTask(w,tmp));
00042     }
00043 
00044     static void qt_display_status(LinphoneCore *lc, char *status) {
00045         QLinphoneMainWidget *w=(QLinphoneMainWidget*)lc->data;
00046         QString tmp(status);
00047         w->pushGuiTask(new UpdateStatusBarTask(w,tmp));
00048     }
00049     static void qt_display_message(LinphoneCore *lc, char *message) {
00050         QString qmsg(message);
00051         QLinphoneMainWidget *w=(QLinphoneMainWidget*)lc->data;
00052         w->pushGuiTask(new DisplayMessageTask(w,qmsg,DisplayMessageTask::Info));
00053     }
00054     static void qt_display_warning(LinphoneCore *lc, char *message) {
00055         QLinphoneMainWidget *w=(QLinphoneMainWidget*)lc->data;
00056         QString qmsg(message);
00057         w->pushGuiTask(new DisplayMessageTask(w,qmsg,DisplayMessageTask::Warn));
00058     }
00059     static void qt_display_url(LinphoneCore *lc, char *message, char *url) {
00060         QLinphoneMainWidget *w=(QLinphoneMainWidget*)lc->data;
00061         QString qmsg=QString(message)+QString(url);
00062         w->pushGuiTask(new DisplayMessageTask(w,qmsg,DisplayMessageTask::Info));
00063     }
00064     static void qt_notify_recv(LinphoneCore *lc, const char *url, const char *status) {
00065     }
00066 
00067     LinphoneCoreVTable lcvtable={
00068                                 show:
00069                                     qt_show,
00070                                 inv_recv:
00071                                     qt_inv_recv,
00072                                 bye_recv :
00073                                     stub,
00074                                 notify_recv :
00075                                     qt_notify_recv,
00076                                 display_status :
00077                                     qt_display_status,
00078                                 display_message :
00079                                     qt_display_message,
00080                                 display_warning :
00081                                     qt_display_warning,
00082                                 display_url :
00083                                     qt_display_url,
00084                                 display_question :
00085                                     stub
00086                                 };
00087 
00088 
00089 } //extern "C"
00090 
00091 void UpdateStatusBarTask::execute() {
00092     static_cast<QLinphoneMainWidget*>(_w)->displayStatus(_msg);
00093 }
00094 
00095 void InviteReceivedTask::execute() {
00096     static_cast<QLinphoneMainWidget*>(_w)->inviteReceived(_msg);
00097 }
00098 
00099 void DisplayMessageTask::execute() {
00100     switch(_msgtype) {
00101     case Info:
00102         QMessageBox::information(0,QObject::tr("Information"),_msg);
00103         break;
00104     case Warn:
00105         QMessageBox::warning(0,QObject::tr("Warning"),_msg);
00106         break;
00107     }
00108 }
00109 
00110 QLinphoneMainWidget::QLinphoneMainWidget(QWidget* parent , const char* name , WFlags fl ) :
00111 _QLinphoneMainWidget( parent, name, fl ) {
00112 
00113      readConfig();
00114      createLinphoneCore();
00115      connect( CheckBox1,  SIGNAL( toggled(bool) ), this,  SLOT( slotHide(bool) ) );
00116      CheckBox1->setChecked( true );
00117 }
00118 
00119 QLinphoneMainWidget::~QLinphoneMainWidget() {
00120     linphone_core_destroy(_core);
00121     writeConfig();
00122 }
00123 
00124 void QLinphoneMainWidget::slotHide( bool show ) {
00125     if (  show )  {
00126          TabWidget2->show();
00127     } else {
00128        TabWidget2->hide();
00129     }
00130 }
00131 
00132 void QLinphoneMainWidget::callOrAccept() {
00133     if (linphone_core_inc_invite_pending(_core)) {
00134         linphone_core_accept_dialog(_core,NULL);
00135         return;
00136     }
00137     QString url=sip_url->text();
00138     linphone_core_invite(_core,(char*)url.ascii());
00139 }
00140 void QLinphoneMainWidget::terminateCall() {
00141     linphone_core_terminate_dialog(_core,NULL);
00142 }
00143 
00144 void QLinphoneMainWidget::inviteReceived(QString &tmp) {
00145     sip_url->setText(tmp);
00146 }
00147 
00148 void QLinphoneMainWidget::displayStatus(QString &msg) {
00149     status_bar->setText(msg);
00150 }
00151 
00152 void QLinphoneMainWidget::pushGuiTask(GuiTask* g) {
00153     _mutex.lock();
00154     _actionq.enqueue(g);
00155     _mutex.unlock();
00156     printf("New action added to task list.\n");
00157 }
00158 
00159 void QLinphoneMainWidget::processGuiTasks() {
00160     GuiTask *g;
00161     _mutex.lock();
00162     while(!_actionq.isEmpty()) {
00163         g=_actionq.dequeue();
00164         printf("Executing action...\n");
00165         g->execute();
00166         delete g;
00167     }
00168     _mutex.unlock();
00169 }
00170 
00171 void QLinphoneMainWidget::timerEvent(QTimerEvent *t) {
00172     processGuiTasks();
00173 }
00174 
00175 void QLinphoneMainWidget::readConfig() {
00176    Config cfg( "opie-phone" );
00177    cfg.setGroup( "audio" );
00178    SliderInput->setValue(  cfg.readNumEntry( "rec_lev", 50 ) );
00179    SliderOutput->setValue( cfg.readNumEntry( "play_lev", 50 ) );
00180 }
00181 
00182 void QLinphoneMainWidget::writeConfig() {
00183    Config cfg( "opie-phone" );
00184    cfg.setGroup( "audio" );
00185    cfg.writeEntry(  "rec_lev",  SliderInput->value() );
00186    cfg.writeEntry(  "playlev",  SliderOutput->value() );
00187 }
00188 
00189 void QLinphoneMainWidget::helpAbout() {
00190     QMessageBox::about(this,tr("About Linphone"),tr("QT version of linphone\nJuly 2003 - Made in old Europe."));
00191 }
00192 
00193 void QLinphoneMainWidget::createLinphoneCore() {
00194     if ( _core ) {
00195          linphone_core_destroy(_core);
00196     }
00197 
00198     gchar *home=getenv("HOME");
00199     gchar *suffix="/Settings/opie-phone.conf";
00200     if (home==0)
00201         home=strdup("/root");
00202     gchar *config=new char[strlen(home)+strlen(suffix)+2];
00203     sprintf(config,"%s/%s",home,suffix);
00204     /* tracing for osip */
00205     TRACE_INITIALIZE((trace_level_t)5,stdout);
00206     _core=linphone_core_new(&lcvtable,config,(gpointer)this);
00207     delete [] config;
00208     startTimer(10);
00209 }
00210 

Generated on Sat Nov 5 16:17:35 2005 for OPIE by  doxygen 1.4.2