Diffstat (limited to 'noncore/net/linphone/qlinphone.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/linphone/qlinphone.cpp | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/noncore/net/linphone/qlinphone.cpp b/noncore/net/linphone/qlinphone.cpp new file mode 100644 index 0000000..3cc2ebc --- a/dev/null +++ b/noncore/net/linphone/qlinphone.cpp | |||
@@ -0,0 +1,210 @@ | |||
1 | /*************************************************************************** | ||
2 | qlinphone.cpp - description | ||
3 | ------------------- | ||
4 | begin : sam mai 24 2003 | ||
5 | copyright : (C) 2003 by Simon Morlat, 2004 Maximilian Reiss | ||
6 | email : simon.morlat@linphone.org, harlekin@handhelds.org | ||
7 | ***************************************************************************/ | ||
8 | |||
9 | /*************************************************************************** | ||
10 | * * | ||
11 | * This program is free software; you can redistribute it and/or modify * | ||
12 | * it under the terms of the GNU General Public License as published by * | ||
13 | * the Free Software Foundation; either version 2 of the License, or * | ||
14 | * (at your option) any later version. * | ||
15 | * * | ||
16 | ***************************************************************************/ | ||
17 | |||
18 | #include "qlinphone.h" | ||
19 | #include <qlineedit.h> | ||
20 | #include <qlabel.h> | ||
21 | #include <qwidget.h> | ||
22 | #include <qslider.h> | ||
23 | #include <qtabwidget.h> | ||
24 | #include <qcheckbox.h> | ||
25 | #include <qmessagebox.h> | ||
26 | #include <qpe/config.h> | ||
27 | #include <qpe/qpeapplication.h> | ||
28 | #include <linphonecore.h> | ||
29 | |||
30 | extern "C" { | ||
31 | static void stub(LinphoneCore*lc, char*msg) {} | ||
32 | |||
33 | static void qt_show(LinphoneCore *lc) { | ||
34 | QLinphoneMainWidget *w=(QLinphoneMainWidget*)lc->data; | ||
35 | w->pushGuiTask(new ShowTask(w)); | ||
36 | } | ||
37 | |||
38 | static void qt_inv_recv(LinphoneCore *lc, char *from) { | ||
39 | QLinphoneMainWidget *w=(QLinphoneMainWidget*)lc->data; | ||
40 | QString tmp(from); | ||
41 | w->pushGuiTask(new InviteReceivedTask(w,tmp)); | ||
42 | } | ||
43 | |||
44 | static void qt_display_status(LinphoneCore *lc, char *status) { | ||
45 | QLinphoneMainWidget *w=(QLinphoneMainWidget*)lc->data; | ||
46 | QString tmp(status); | ||
47 | w->pushGuiTask(new UpdateStatusBarTask(w,tmp)); | ||
48 | } | ||
49 | static void qt_display_message(LinphoneCore *lc, char *message) { | ||
50 | QString qmsg(message); | ||
51 | QLinphoneMainWidget *w=(QLinphoneMainWidget*)lc->data; | ||
52 | w->pushGuiTask(new DisplayMessageTask(w,qmsg,DisplayMessageTask::Info)); | ||
53 | } | ||
54 | static void qt_display_warning(LinphoneCore *lc, char *message) { | ||
55 | QLinphoneMainWidget *w=(QLinphoneMainWidget*)lc->data; | ||
56 | QString qmsg(message); | ||
57 | w->pushGuiTask(new DisplayMessageTask(w,qmsg,DisplayMessageTask::Warn)); | ||
58 | } | ||
59 | static void qt_display_url(LinphoneCore *lc, char *message, char *url) { | ||
60 | QLinphoneMainWidget *w=(QLinphoneMainWidget*)lc->data; | ||
61 | QString qmsg=QString(message)+QString(url); | ||
62 | w->pushGuiTask(new DisplayMessageTask(w,qmsg,DisplayMessageTask::Info)); | ||
63 | } | ||
64 | static void qt_notify_recv(LinphoneCore *lc, const char *url, const char *status) { | ||
65 | } | ||
66 | |||
67 | LinphoneCoreVTable lcvtable={ | ||
68 | show: | ||
69 | qt_show, | ||
70 | inv_recv: | ||
71 | qt_inv_recv, | ||
72 | bye_recv : | ||
73 | stub, | ||
74 | notify_recv : | ||
75 | qt_notify_recv, | ||
76 | display_status : | ||
77 | qt_display_status, | ||
78 | display_message : | ||
79 | qt_display_message, | ||
80 | display_warning : | ||
81 | qt_display_warning, | ||
82 | display_url : | ||
83 | qt_display_url, | ||
84 | display_question : | ||
85 | stub | ||
86 | }; | ||
87 | |||
88 | |||
89 | } //extern "C" | ||
90 | |||
91 | void UpdateStatusBarTask::execute() { | ||
92 | static_cast<QLinphoneMainWidget*>(_w)->displayStatus(_msg); | ||
93 | } | ||
94 | |||
95 | void InviteReceivedTask::execute() { | ||
96 | static_cast<QLinphoneMainWidget*>(_w)->inviteReceived(_msg); | ||
97 | } | ||
98 | |||
99 | void DisplayMessageTask::execute() { | ||
100 | switch(_msgtype) { | ||
101 | case Info: | ||
102 | QMessageBox::information(0,QObject::tr("Information"),_msg); | ||
103 | break; | ||
104 | case Warn: | ||
105 | QMessageBox::warning(0,QObject::tr("Warning"),_msg); | ||
106 | break; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | QLinphoneMainWidget::QLinphoneMainWidget(QWidget* parent , const char* name , WFlags fl ) : | ||
111 | _QLinphoneMainWidget( parent, name, fl ) { | ||
112 | |||
113 | readConfig(); | ||
114 | createLinphoneCore(); | ||
115 | connect( CheckBox1, SIGNAL( toggled( bool ) ), this, SLOT( slotHide( bool ) ) ); | ||
116 | CheckBox1->setChecked( true ); | ||
117 | } | ||
118 | |||
119 | QLinphoneMainWidget::~QLinphoneMainWidget() { | ||
120 | linphone_core_destroy(_core); | ||
121 | writeConfig(); | ||
122 | } | ||
123 | |||
124 | void QLinphoneMainWidget::slotHide( bool show ) { | ||
125 | if ( show ) { | ||
126 | TabWidget2->show(); | ||
127 | } else { | ||
128 | TabWidget2->hide(); | ||
129 | } | ||
130 | } | ||
131 | |||
132 | void QLinphoneMainWidget::callOrAccept() { | ||
133 | if (linphone_core_inc_invite_pending(_core)) { | ||
134 | linphone_core_accept_dialog(_core,NULL); | ||
135 | return; | ||
136 | } | ||
137 | QString url=sip_url->text(); | ||
138 | linphone_core_invite(_core,(char*)url.ascii()); | ||
139 | } | ||
140 | void QLinphoneMainWidget::terminateCall() { | ||
141 | linphone_core_terminate_dialog(_core,NULL); | ||
142 | } | ||
143 | |||
144 | void QLinphoneMainWidget::inviteReceived(QString &tmp) { | ||
145 | sip_url->setText(tmp); | ||
146 | } | ||
147 | |||
148 | void QLinphoneMainWidget::displayStatus(QString &msg) { | ||
149 | status_bar->setText(msg); | ||
150 | } | ||
151 | |||
152 | void QLinphoneMainWidget::pushGuiTask(GuiTask* g) { | ||
153 | _mutex.lock(); | ||
154 | _actionq.enqueue(g); | ||
155 | _mutex.unlock(); | ||
156 | printf("New action added to task list.\n"); | ||
157 | } | ||
158 | |||
159 | void QLinphoneMainWidget::processGuiTasks() { | ||
160 | GuiTask *g; | ||
161 | _mutex.lock(); | ||
162 | while(!_actionq.isEmpty()) { | ||
163 | g=_actionq.dequeue(); | ||
164 | printf("Executing action...\n"); | ||
165 | g->execute(); | ||
166 | delete g; | ||
167 | } | ||
168 | _mutex.unlock(); | ||
169 | } | ||
170 | |||
171 | void QLinphoneMainWidget::timerEvent(QTimerEvent *t) { | ||
172 | processGuiTasks(); | ||
173 | } | ||
174 | |||
175 | void QLinphoneMainWidget::readConfig() { | ||
176 | Config cfg( "opie-phone" ); | ||
177 | cfg.setGroup( "audio" ); | ||
178 | SliderInput->setValue( cfg.readNumEntry( "rec_lev", 50 ) ); | ||
179 | SliderOutput->setValue( cfg.readNumEntry( "play_lev", 50 ) ); | ||
180 | } | ||
181 | |||
182 | void QLinphoneMainWidget::writeConfig() { | ||
183 | Config cfg( "opie-phone" ); | ||
184 | cfg.setGroup( "audio" ); | ||
185 | cfg.writeEntry( "rec_lev", SliderInput->value() ); | ||
186 | cfg.writeEntry( "playlev", SliderOutput->value() ); | ||
187 | } | ||
188 | |||
189 | void QLinphoneMainWidget::helpAbout() { | ||
190 | QMessageBox::about(this,tr("About Linphone"),tr("QT version of linphone\nJuly 2003 - Made in old Europe.")); | ||
191 | } | ||
192 | |||
193 | void QLinphoneMainWidget::createLinphoneCore() { | ||
194 | if ( _core ) { | ||
195 | linphone_core_destroy(_core); | ||
196 | } | ||
197 | |||
198 | gchar *home=getenv("HOME"); | ||
199 | gchar *suffix="/Settings/opie-phone.conf"; | ||
200 | if (home==0) | ||
201 | home=strdup("/root"); | ||
202 | gchar *config=new char[strlen(home)+strlen(suffix)+2]; | ||
203 | sprintf(config,"%s/%s",home,suffix); | ||
204 | /* tracing for osip */ | ||
205 | TRACE_INITIALIZE((trace_level_t)5,stdout); | ||
206 | _core=linphone_core_new(&lcvtable,config,(gpointer)this); | ||
207 | delete [] config; | ||
208 | startTimer(10); | ||
209 | } | ||
210 | |||