SFLPhoneWindow.cpp 7.63 KB
Newer Older
jpbl's avatar
jpbl committed
1
/*
yanmorin's avatar
   
yanmorin committed
2
 *  Copyright (C) 2004-2006 Savoir-Faire Linux inc.
jpbl's avatar
jpbl committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
 *  Author: Jean-Philippe Barrette-LaPierre
 *             <jean-philippe.barrette-lapierre@savoirfairelinux.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, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "SFLPhoneWindow.hpp"

#include <qbitmap.h>

//To test if we are in QT4
#ifdef QT3_SUPPORT 
#include <QIcon>
#endif


#include <qlabel.h>
#include <qmessagebox.h>
#include <qevent.h>
#include <qpixmap.h>
#include <iostream>

#include "globals.h"
#include "JPushButton.hpp"
#include "PhoneLineButton.hpp"
#include "SFLLcd.hpp"
#include "VolumeControl.hpp"
43
#include "NumericKeypad.hpp"
jpbl's avatar
jpbl committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

#define LOGO_IMAGE "logo_ico.png"
#define BACKGROUND_IMAGE "main.png"
#define VOLUME_IMAGE "volume.png"

			    
SFLPhoneWindow::SFLPhoneWindow()
#ifdef QT3_SUPPORT
  : QMainWindow(NULL, Qt::FramelessWindowHint)
#else
    : QMainWindow(NULL, NULL, 
		  Qt::WDestructiveClose | 
		  Qt::WStyle_Customize | 
		  Qt::WStyle_NoBorder)
#endif
{
  mLastWindowPos = pos();
  mSetupPanel = new ConfigurationPanel(this, "ConfigurationPanel");
62
63
64
65
  mKeypad = new NumericKeypad(NULL, false);
  mKeypad->setWindowReference(this);
  

yanmorin's avatar
   
yanmorin committed
66
67
68
69
70
71
  connect(this, SIGNAL(ringtonesUpdated()),      mSetupPanel, SLOT(updateRingtones()));
  connect(this, SIGNAL(audioDevicesUpdated()),   mSetupPanel, SLOT(updateAudioDevices()));
  connect(this, SIGNAL(audioDevicesInUpdated()), mSetupPanel, SLOT(updateAudioDevicesIn()));
  connect(this, SIGNAL(audioDevicesOutUpdated()),mSetupPanel, SLOT(updateAudioDevicesOut()));
  connect(this, SIGNAL(codecsUpdated()),         mSetupPanel, SLOT(updateCodecs()));

72
  connect(mSetupPanel, SIGNAL(needRegister(const QString&)), this, SIGNAL(needRegister(const QString&)));
yanmorin's avatar
   
yanmorin committed
73
74
75
76
77
78
79
  connect(this, SIGNAL(registerReturn(bool, QString)),  mSetupPanel, SLOT(slotRegisterReturn(bool, QString)));
  
  // when we receive a signal from mSetupPanel, we should resend one to...
  connect(mSetupPanel, SIGNAL(soundDriverChanged()), this, SIGNAL(soundDriverChanged()));

  // we are an intermediate... 
  connect(this, SIGNAL(testSoundDriverReturn(bool, QString)),  mSetupPanel, SLOT(slotSoundDriverReturn(bool, QString)));
jpbl's avatar
jpbl committed
80
81

  // Initialize the background image
jpbl's avatar
jpbl committed
82
  setName("main");
jpbl's avatar
jpbl committed
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

  mPaintTimer = new QTimer(this);
  connect(mPaintTimer, SIGNAL(timeout()),
	  this, SLOT(delayedPaint()));
  mPaintTimer->start(50);
  


  QPixmap logo(QPixmap::fromMimeSource(LOGO_IMAGE));
#ifdef QIcon
  setWindowIcon(QIcon(logo));
#else
  setIcon(logo);
#endif

  mLastPos = pos();
  
  initGUIButtons();
  initWindowButtons();
  initLineButtons();
  initLCD();
}

SFLPhoneWindow::~SFLPhoneWindow()
{}

void
SFLPhoneWindow::initLCD()
{
jpbl's avatar
jpbl committed
112
  mLcd = new SFLLcd(this);
jpbl's avatar
jpbl committed
113
114
115
116
117
118
  mLcd->show();
}

void
SFLPhoneWindow::initGUIButtons()
{
jpbl's avatar
jpbl committed
119
120
121
122
123
  mHangup = new QPushButton(QObject::tr("Hangup"), this, "hangup");
  mHold = new QPushButton(QObject::tr("Hold"), this, "hold");
  mOk = new QPushButton(QObject::tr("Ok"), this, "ok");
  mClear = new QPushButton(QObject::tr("Clear"), this, "clear");
  mMute = new QPushButton(QObject::tr("Mute"), this, "mute");
jpbl's avatar
jpbl committed
124
  mMute->setToggleButton(true);
jpbl's avatar
jpbl committed
125
  mDtmf = new QPushButton(QObject::tr("DTMF"), this, "dtmf");
jpbl's avatar
jpbl committed
126
  mDtmf->setToggleButton(true);
127
128
129
  connect(mKeypad, SIGNAL(isShown(bool)), mDtmf, SLOT(setOn(bool)));
  connect(mDtmf,   SIGNAL(toggled(bool)), this, SLOT(toggleDtmf(bool)));

jpbl's avatar
jpbl committed
130
131
132
  mSetup = new QPushButton(QObject::tr("Setup"), this, "setup");
  mTransfer = new QPushButton(QObject::tr("Transfer"), this, "transfer");
  mRedial = new QPushButton(QObject::tr("Redial"), this, "redial");
jpbl's avatar
jpbl committed
133
  mVolume = new VolumeControl(QString(VOLUME_IMAGE),
jpbl's avatar
jpbl committed
134
			      this);
jpbl's avatar
jpbl committed
135
136
137
138
139
140
  mVolume->setOrientation(VolumeControl::Vertical);
  mVolume->move(365,91);
  QObject::connect(mVolume, SIGNAL(valueUpdated(int)),
		   this, SIGNAL(volumeUpdated(int)));
  
  mMicVolume = new VolumeControl(QString(VOLUME_IMAGE),
jpbl's avatar
jpbl committed
141
				 this);
jpbl's avatar
jpbl committed
142
143
144
145
146
147
148
149
150
151
152
  mMicVolume->setOrientation(VolumeControl::Vertical);
  mMicVolume->move(347,91);
  QObject::connect(mVolume, SIGNAL(valueUpdated(int)),
		   this, SIGNAL(micVolumeUpdated(int)));
			      
}

void 
SFLPhoneWindow::initLineButtons()
{
  for(int i = 0; i < NB_PHONELINES; i++) {
jpbl's avatar
jpbl committed
153
    PhoneLineButton *line = new PhoneLineButton(i, this);
jpbl's avatar
jpbl committed
154
155
156
157
158
159
    mPhoneLineButtons.push_back(line);
  }
}

void SFLPhoneWindow::initWindowButtons()
{
jpbl's avatar
jpbl committed
160
  mCloseButton = new QPushButton(QObject::tr("Close"), this, "close");
jpbl's avatar
jpbl committed
161
162
  QObject::connect(mCloseButton, SIGNAL(clicked()),
		   this, SLOT(finish()));
jpbl's avatar
jpbl committed
163
  mMinimizeButton = new QPushButton(QObject::tr("Minimize"), this, "minimize");
jpbl's avatar
jpbl committed
164
165
166
167
168
169
170
171
172
  QObject::connect(mMinimizeButton, SIGNAL(clicked()),
		   this, SLOT(showMinimized()));
}

void
SFLPhoneWindow::keyPressEvent(QKeyEvent *e) {
  // Misc. key	  
  if (e->state() & Qt::ControlButton || e->key() == Qt::Key_Control) {
    emit shortcutPressed(e);
yanmorin's avatar
   
yanmorin committed
173
  } else if (e->key() != Qt::Key_Shift) {
jpbl's avatar
jpbl committed
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
    emit keyPressed(Qt::Key(e->key()));
  }
}

void 
SFLPhoneWindow::finish()
{
  emit needToCloseDaemon();
}

void 
SFLPhoneWindow::askReconnect()
{
  QMessageBox::critical(NULL,
			tr("SFLPhone error"),
			tr("We got an error launching sflphone. Check the debug \n"
			   "output with \"[sflphoned]\" for more details. The \n"
			   "application will close."),
			tr("Quit"));
  close();
}

void 
SFLPhoneWindow::askLaunch()
{
  QMessageBox::critical(NULL,
			tr("SFLPhone daemon problem"),
			tr("The SFLPhone daemon couldn't be started. Check \n"
			   "if sflphoned is in your PATH. The application will \n"
			   "close.\n"),
			tr("Quit"));
  close();
}


void
SFLPhoneWindow::showSetup()
{
  mSetupPanel->generate();
  mSetupPanel->show();
}

void
SFLPhoneWindow::hideSetup()
{
  mSetupPanel->hide();
}

void 
SFLPhoneWindow::askResendStatus(QString message)
{
  int ret = QMessageBox::critical(NULL, 
				  tr("SFLPhone status error"),
				  tr("The server returned an error for the lines status.\n"
				     "\n%1\n\n"
				     "Do you want to try to resend this command? If not,\n"
				     "the application will close.").arg(message),
				  QMessageBox::Retry | QMessageBox::Default,
				  QMessageBox::No | QMessageBox::Escape);
  if (ret == QMessageBox::Retry) {
    emit resendStatusAsked();
  }
  else {
    close();
  }
}

void 
SFLPhoneWindow::mousePressEvent(QMouseEvent *e)
{
244
  mLastPos = e->pos(); // this is relative to the widget
jpbl's avatar
jpbl committed
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
}

void 
SFLPhoneWindow::mouseMoveEvent(QMouseEvent *e)
{
  // Note that moving the windows is very slow
  // 'cause it redraw the screen each time.
  // Usually it doesn't. We could do it by a timer.
  delayedMove(e->globalPos() - mLastPos);
}

void 
SFLPhoneWindow::delayedMove(const QPoint &point) 
{
  mLastWindowPos = point;
}

void
SFLPhoneWindow::delayedPaint()
{
  if(pos() != mLastWindowPos) {
    move(mLastWindowPos);
  }
}
269
270
271
272
273
274
275
276
277
278
279

void
SFLPhoneWindow::toggleDtmf(bool toggle) 
{
  if (mKeypad) {
    if (toggle) {
      mKeypad->setDefaultPosition(QPoint(pos().x()+width(), pos().y())); 
    }
    mKeypad->setShown(toggle);
  }
}