qtGUImainwindow.cpp 36.4 KB
Newer Older
savoirfairelinux's avatar
savoirfairelinux committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/**
 *  Copyright (C) 2004 Savoir-Faire Linux inc.
 *  Author: Laurielle Lea <laurielle.lea@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.
 */


////////////////////////////////////////////////////////////////////////////////
// QtGUIMainWindow Implementation                                             //
////////////////////////////////////////////////////////////////////////////////
24 25

#include "configurationtree.h"
savoirfairelinux's avatar
savoirfairelinux committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include <stdio.h>

#include <qbitmap.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qevent.h>
#include <qinputdialog.h>
#include <qlineedit.h>
#include <qmessagebox.h>
#include <qpushbutton.h>
#include <qregexp.h>
#include <qsettings.h>
#include <qspinbox.h>
#include <qtimer.h>
#include <qtooltip.h>

#include "audiodrivers.h"
#include "configuration.h"
#include "configurationpanelui.h"
#include "global.h"
#include "jpushbutton.h"
#include "manager.h"
#include "numerickeypadtools.h"
llea's avatar
llea committed
49
#include "point.h"
savoirfairelinux's avatar
savoirfairelinux committed
50 51
#include "skin.h"
#include "qtGUImainwindow.h"
52 53
#include "vector.h"
#include "volumecontrol.h"
savoirfairelinux's avatar
savoirfairelinux committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 112 113 114 115 116

#define QCHAR_TO_STRIP	"-"
#define REG_EXPR		"(-|\\(|\\)| )"
	

///////////////////////////////////////////////////////////////////////////////
// Tray Icon implementation
///////////////////////////////////////////////////////////////////////////////
MyTrayIcon::MyTrayIcon(const QPixmap &icon, const QString &tooltip, 
		QPopupMenu *mypop, QObject *parent, const char *name)
		: TrayIcon (icon, tooltip, mypop, parent, name)
{
	menu = mypop;
}

void
MyTrayIcon::mousePressEvent (QMouseEvent *e) 
{
	switch ( e->button() ) {
		case RightButton:
			menu->popup( e->globalPos() );
			e->accept();
			break;
			
		case LeftButton:
			emit clickedLeft();
			break;
			
		case MidButton:
			break;
			
		default:
			break;
	}
}

///////////////////////////////////////////////////////////////////////////////
// QtGUIMainWindow implementation
///////////////////////////////////////////////////////////////////////////////

/**
 * Default Constructor
 * Init, Connections
 */
QtGUIMainWindow::QtGUIMainWindow (QWidget *parent, const char *name, WFlags f, 
									Manager *mngr) 
									: TransQWidget (parent, name, f) {
	// Create configuration panel
	panel = new ConfigurationPanel (0, 0, false);

	// Address book dialog
	phonebook = new PhoneBook (0, 0, false);

	// URL input dialog
	urlinput = new URL_Input (this);
	
	// For managing 
	this->callmanager = mngr;

	// For DTMF
	key = new DTMF ();
	buf = new short[SIZEBUF];

llea's avatar
llea committed
117 118 119 120 121 122
	// Create new display and numeric keypad
	lcd = new MyDisplay(this, 0, this);
	keypad = new NumericKeypad (this, NULL, Qt::WDestructiveClose |
                    					Qt::WStyle_Customize |
                    					Qt::WStyle_NoBorder);
 	// Initialisation of variables
savoirfairelinux's avatar
savoirfairelinux committed
123 124 125 126 127 128
	currentLineNumber = -1;
	onLine = currentLineNumber;
	chosenLine = -1;
	choose = false;
	noChoose = false;
	transfer = false;
llea's avatar
llea committed
129 130 131 132
	msgVar = false;
	b_dialtone = false;
	apply = false;
	this->first = true;
savoirfairelinux's avatar
savoirfairelinux committed
133
	
llea's avatar
llea committed
134 135 136
	// Initialisation of all that concern the skin
	initSkin();
	this->initBlinkTimer();
savoirfairelinux's avatar
savoirfairelinux committed
137

llea's avatar
llea committed
138 139 140
	
	// By default, keyboard mapping mode is numerical mode
	this->setMode(NUM_MODE);
savoirfairelinux's avatar
savoirfairelinux committed
141 142 143 144 145 146 147 148 149 150 151 152
	
	// Move 
	setMainLCD ();
	
	// Change window title and Icon.
	this->setCaption(PROGNAME);
	this->setIcon(QPixmap(Skin::getPathPixmap(QString(PIXDIR), 
				QString(SFLPHONE_LOGO))));

	// Show the GUI
	this->show();	

153
	// Handle the tray icon system
savoirfairelinux's avatar
savoirfairelinux committed
154 155 156 157 158 159 160
	mypop = new QPopupMenu(this);
	mypop->insertItem ("Quit", qApp, SLOT(quit()));

	trayicon = new MyTrayIcon(QPixmap(
				Skin::getPathPixmap(QString(PIXDIR), QString(TRAY_ICON))), 
				NULL, mypop, parent, name);
	trayicon->show();
llea's avatar
llea committed
161
	
llea's avatar
llea committed
162 163 164 165 166 167 168 169 170 171 172 173
	// Connect to handle trayicon
	connect(trayicon, SIGNAL(clickedLeft()), this, SLOT(clickHandle()));
	// Connect blinkTimer signals to blink slot
    connect(blinkTimer, SIGNAL(timeout()),this, SLOT(blinkMessageSlot()));
	connect (blinkTimer, SIGNAL(timeout()), this, SLOT(blinkRingSlot()) );
	connect (blinkTimer, SIGNAL(timeout()), this, SLOT(blinkLineSlot()));
	// Connect to append url in display
	connect (urlinput->buttonOK, SIGNAL(clicked()), this, SLOT(stripSlot()));
	// Connect to save settings
	connect (panel->buttonSave, SIGNAL(clicked()), this, SLOT(save()));
	// Connect to apply skin
	connect (panel->buttonApplySkin, SIGNAL(clicked()), this,SLOT(applySkin()));
174 175
	// Connect to register manually
	connect (panel->Register, SIGNAL(clicked()), this, SLOT(registerSlot()));
savoirfairelinux's avatar
savoirfairelinux committed
176 177 178 179 180 181
}

/**
 * Destructor
 */
QtGUIMainWindow::~QtGUIMainWindow(void) {
llea's avatar
llea committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195
	deleteButtons();
	delete	panel;
	delete  blinkTimer;
	delete  keypad;
	delete	lcd;
	delete  urlinput;
	delete	callmanager;
	delete 	mypop;
	delete 	trayicon;
	delete  pt;
}

void
QtGUIMainWindow::deleteButtons (void) {
savoirfairelinux's avatar
savoirfairelinux committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
	delete  phoneKey_transf;
	delete  phoneKey_msg;
	delete  phoneKey_conf;
	delete  phoneKey_line0;
	delete  phoneKey_line1;
	delete  phoneKey_line2;
	delete  phoneKey_line3;
	delete  reduce_button;
	delete  quit_button;
	delete  addr_book_button;
	delete  configuration_button;
	delete  hangup_button;
	delete  dial_button;
	delete  mute_button;
	delete	dtmf_button;
	delete	vol_mic;
	delete 	vol_spkr;
213 214
	delete	micVolVector;
	delete	spkrVolVector;
savoirfairelinux's avatar
savoirfairelinux committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
	for (int j = 0; j < NUMBER_OF_LINES; j++) {
		delete callmanager->phLines[j]->button();
	}
}

///////////////////////////////////////////////////////////////////////////////
// Private Methods implementations     	                               	     
///////////////////////////////////////////////////////////////////////////////
/**
 * Init and start blink timer for all blinking pixmap, with 500 ms timeout.
 */
void
QtGUIMainWindow::initBlinkTimer(void) {
	blinkTimer = new QTimer(this);
	blinkTimer->start(500);
}

/**
 * Init variable with skin choice
 */
QString
QtGUIMainWindow::setPathSkin (void) {
237 238
	return QString(Config::getchar(
					"Preferences", "Themes.skinChoice", "metal"));
savoirfairelinux's avatar
savoirfairelinux committed
239 240
}

llea's avatar
llea committed
241 242 243
/**
 * Init variable with ring choice
 */
llea's avatar
llea committed
244 245 246 247 248 249
QString
QtGUIMainWindow::ringFile(void) {
	return QString(Config::getchar(
					"Audio", "Rings.ringChoice", "konga.ul"));
}

llea's avatar
llea committed
250 251 252
/**
 * Get whole path for rings
 */
llea's avatar
llea committed
253 254 255 256 257 258
QString
QtGUIMainWindow::getRingFile (void) {
	QString ringFilename(Skin::getPathRing(QString(RINGDIR), ringFile()));
	return ringFilename;
}

llea's avatar
llea committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
void
QtGUIMainWindow::initSkin (void) {
	// Load file configuration skin
	QString skinfilename(Skin::getPath(QString(SKINDIR), setPathSkin(),
				QString(FILE_INI)));
	
	if (!apply) {
		this->pt = new Point(skinfilename.ascii());	
	} else {
		// If click on apply button
		delete pt;
		deleteButtons();
		this->pt = new Point(skinfilename.ascii());	
	}
	// Initialisation of the buttons
	this->initSpkrVolumePosition();
	this->initMicVolumePosition();
	this->initButtons();
	// Connections of the buttons
	this->connections();
	
	// Load background image phone
	setbgPixmap (new QPixmap (Skin::getPath(QString(SKINDIR), 
											setPathSkin(),
											QString(PIXMAP_PHONE))));
	// Transform pixmap to QImage
	setSourceImage ();
	this->setMaximumSize (getSourceImage().width(), getSourceImage().height());
	this->setGeometry (MAIN_INITIAL_POSITION, 
					   MAIN_INITIAL_POSITION, 
					   getSourceImage().width(),
					   getSourceImage().height());
	// Calculate just one time the transparency mask bit to bit
	transparencyMask ();

	// Line pixmaps initialisation
	for (int i = 0; i < NUMBER_OF_LINES; i++) {
		for (int j = 0; j < NUMBER_OF_STATES; j++) {
	 		TabLinePixmap[i][j] = QPixmap(Skin::getPath(QString(SKINDIR),
												setPathSkin(), 
												QString(PIXMAP_LINE(i, j))));
	 	}
	}
	// Message pixmaps initialisation
	TabMsgPixmap[0] = QPixmap(Skin::getPath(QString(SKINDIR), setPathSkin(), 
						PIXMAP_MESSAGE_OFF));
	TabMsgPixmap[1] = QPixmap(Skin::getPath(QString(SKINDIR), setPathSkin(), 
						PIXMAP_MESSAGE_ON));
}

llea's avatar
llea committed
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
void
QtGUIMainWindow::initSpkrVolumePosition (void) {
	if (pt->getDirection(VOL_SPKR) == VERTICAL) {
		vol_spkr_x = Config::get("Audio", "Volume.speakers_x", 
				pt->getX(VOL_SPKR));
		vol_spkr_y = Config::get("Audio", "Volume.speakers_y",
				pt->getVariation(VOL_SPKR));
	} else if (pt->getDirection(VOL_SPKR) == HORIZONTAL) {
		vol_spkr_x = Config::get("Audio", "Volume.speakers_x",
				pt->getX(VOL_SPKR) + pt->getVariation(VOL_SPKR));
		vol_spkr_y = Config::get("Audio", "Volume.speakers_y", 
				pt->getY(VOL_SPKR));
	} 
}

void
QtGUIMainWindow::initMicVolumePosition (void) {
	if (pt->getDirection(VOL_MIC) == VERTICAL) {
		vol_mic_x = Config::get("Audio", "Volume.micro_x", pt->getX(VOL_MIC));
		vol_mic_y = Config::get("Audio", "Volume.micro_y",
				pt->getVariation(VOL_MIC));
	} else if (pt->getDirection(VOL_MIC) == HORIZONTAL) {
		vol_mic_x = Config::get("Audio", "Volume.micro_x",
				pt->getX(VOL_MIC) + pt->getVariation(VOL_MIC));
		vol_mic_y = Config::get("Audio", "Volume.micro_y", pt->getY(VOL_MIC));
	} 
}

savoirfairelinux's avatar
savoirfairelinux committed
337 338 339 340 341 342 343 344
/**
 * Inits all phonekey buttons.
 * Create new QPushButtons, set up tool tip, disable focus, set button geometry
 * set palette.
 */
void
QtGUIMainWindow::initButtons (void) {
	// Buttons initialisation
llea's avatar
llea committed
345 346 347 348 349 350 351 352 353 354 355
	phoneKey_msg= new JPushButton(this, NULL, VOICEMAIL);
	phoneKey_transf = new JPushButton(this, NULL, TRANSFER);
	phoneKey_conf = new JPushButton(this, NULL, CONFERENCE);
	reduce_button = new JPushButton(this, NULL, MINIMIZE);
	quit_button = new JPushButton(this, NULL, CLOSE);
	addr_book_button = new JPushButton(this, NULL, DIRECTORY);
	configuration_button = new JPushButton(this, NULL, SETUP);
	hangup_button = new JPushButton(this, NULL, HANGUP);
	dial_button = new JPushButton(this, NULL, CONNECT);
	mute_button = new JPushButton(this, NULL, MUTE);
	dtmf_button = new JPushButton(this, NULL, DTMF_SHOW);
savoirfairelinux's avatar
savoirfairelinux committed
356 357 358 359 360 361 362 363 364 365 366 367

	// Set tooltip buttons
	QToolTip::add(reduce_button, tr("Minimize window"));
	QToolTip::add(quit_button, tr("Close window (Ctrl+Q)"));
	QToolTip::add(phoneKey_msg, tr("Get your message"));
	QToolTip::add(phoneKey_transf, tr("Call transfer"));
	QToolTip::add(phoneKey_conf, tr("Conference"));
	QToolTip::add(addr_book_button, tr("Address book"));
	QToolTip::add(configuration_button, tr("Configuration tools (Ctrl+C)"));
	QToolTip::add(hangup_button, tr("Hangup"));
	QToolTip::add(dial_button, tr("Dial"));
	QToolTip::add(mute_button, tr("Mute"));
368
	QToolTip::add(dtmf_button, tr("Show DTMF keypad (Ctrl+D)"));
llea's avatar
llea committed
369

savoirfairelinux's avatar
savoirfairelinux committed
370
	// Buttons position
llea's avatar
llea committed
371 372 373 374 375 376 377 378 379 380 381 382
	phoneKey_msg->move (pt->getX(VOICEMAIL), pt->getY(VOICEMAIL));
	phoneKey_transf->move (pt->getX(TRANSFER), pt->getY(TRANSFER));
	phoneKey_conf->move (pt->getX(CONFERENCE), pt->getY(CONFERENCE));
	reduce_button->move (pt->getX(MINIMIZE), pt->getY(MINIMIZE));
	addr_book_button->move (pt->getX(DIRECTORY), pt->getY(DIRECTORY));
	quit_button->move (pt->getX(CLOSE), pt->getY(CLOSE));
	configuration_button->move (pt->getX(SETUP), pt->getY(SETUP));
	hangup_button->move (pt->getX(HANGUP), pt->getY(HANGUP));
	dial_button->move (pt->getX(CONNECT), pt->getY(CONNECT));
	mute_button->move (pt->getX(MUTE), pt->getY(MUTE));
	dtmf_button->move (pt->getX(DTMF_SHOW), pt->getY(DTMF_SHOW));
	
savoirfairelinux's avatar
savoirfairelinux committed
383
	// Loop for line buttons
llea's avatar
llea committed
384
	// Initialisation, set no focus, set geometry, set palette, pixmap
savoirfairelinux's avatar
savoirfairelinux committed
385 386 387 388 389 390
	for (int j = 0; j < NUMBER_OF_LINES; j++) {
		QString lnum;

		lnum = "l" + lnum.setNum (j + 1);
		callmanager->phLines[j]->setButton(new JPushButton(
					this, NULL, lnum.ascii()));
llea's avatar
llea committed
391
		callmanager->phLines[j]->button()->move (pt->getX(lnum),pt->getY(lnum));
savoirfairelinux's avatar
savoirfairelinux committed
392 393
	}

394 395 396 397 398 399
	// Set pixmaps volume 
	micVolVector = new Vector(this, VOL_MIC, pt);
	spkrVolVector = new Vector(this, VOL_SPKR, pt);

	vol_mic = new VolumeControl(this, NULL, VOLUME, micVolVector);
	vol_spkr = new VolumeControl(this, NULL, VOLUME, spkrVolVector);
llea's avatar
llea committed
400 401
	vol_mic->move(vol_mic_x, vol_mic_y);
	vol_spkr->move(vol_spkr_x, vol_spkr_y);
savoirfairelinux's avatar
savoirfairelinux committed
402 403
}

llea's avatar
llea committed
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
void
QtGUIMainWindow::connections (void) {
	// Connect for clicked numeric keypad button 
	connect ((QObject*)keypad->key0, SIGNAL(clicked()), this, 
			SLOT(pressedKey0()));
	connect ((QObject*)keypad->key1, SIGNAL(clicked()), this, 
			SLOT(pressedKey1()));
	connect ((QObject*)keypad->key2, SIGNAL(clicked()), this, 
			SLOT(pressedKey2()));
	connect ((QObject*)keypad->key3, SIGNAL(clicked()), this, 
			SLOT(pressedKey3()));
	connect ((QObject*)keypad->key4, SIGNAL(clicked()), this, 
			SLOT(pressedKey4()));
	connect ((QObject*)keypad->key5, SIGNAL(clicked()), this, 
			SLOT(pressedKey5()));
	connect ((QObject*)keypad->key6, SIGNAL(clicked()), this, 
			SLOT(pressedKey6()));
	connect ((QObject*)keypad->key7, SIGNAL(clicked()), this, 
			SLOT(pressedKey7()));
	connect ((QObject*)keypad->key8, SIGNAL(clicked()), this, 
			SLOT(pressedKey8()));
	connect ((QObject*)keypad->key9, SIGNAL(clicked()), this, 
			SLOT(pressedKey9()));
	connect ((QObject*)keypad->keyStar, SIGNAL(clicked()), this, 
			SLOT(pressedKeyStar()));
	connect ((QObject*)keypad->keyHash, SIGNAL(clicked()), this, 
			SLOT(pressedKeyHash()));
	connect ((QObject*)keypad->keyClose, SIGNAL(clicked()), this, 
			SLOT(dtmfKeypad()));

	// Connections for the lines 
	connect (callmanager->phLines[0]->button(), SIGNAL(clicked()), this, 
			SLOT(button_line0()));
	connect (callmanager->phLines[1]->button(), SIGNAL(clicked()), this, 
			SLOT(button_line1()));
	connect (callmanager->phLines[2]->button(), SIGNAL(clicked()), this, 
			SLOT(button_line2()));
	connect (callmanager->phLines[3]->button(), SIGNAL(clicked()), this, 
			SLOT(button_line3()));
	connect (callmanager->phLines[4]->button(), SIGNAL(clicked()), this, 
			SLOT(button_line4()));
	connect (callmanager->phLines[5]->button(), SIGNAL(clicked()), this, 
			SLOT(button_line5()));

	// Misc 
	connect (phoneKey_msg, SIGNAL(clicked()), this, SLOT(button_msg()));
	connect (phoneKey_transf, SIGNAL(clicked()), this, SLOT(button_transfer()));
	connect (phoneKey_conf, SIGNAL(clicked()), this, SLOT(button_conf()));
	connect (dial_button, SIGNAL(clicked()), this, SLOT(dial()));
	connect (mute_button, SIGNAL(clicked()), this, SLOT(button_mute()));
	connect (hangup_button, SIGNAL(clicked()), this, SLOT(hangupLine()));
	connect (configuration_button,SIGNAL(clicked()),this,SLOT(configuration()));
	connect (addr_book_button, SIGNAL(clicked()), this,SLOT(addressBook()));
	connect (dtmf_button, SIGNAL(clicked()), this, SLOT(dtmfKeypad()));

	// Connect to reduce
	connect (reduce_button, SIGNAL(clicked()), this, SLOT(reduceHandle()));
	// Connect to quit with keyboard
	connect (this, SIGNAL(keyPressed(int)), this, SLOT(quitApplication()));
   	// Connect to quit with quit button
	connect (quit_button, SIGNAL(clicked()), this, SLOT(quitApplication()));

	// Connections for volume control
	connect(vol_spkr, SIGNAL(setVolumeValue(int)), this, 
			SLOT(volumeSpkrChanged(int)));
	connect(vol_mic, SIGNAL(setVolumeValue(int)), this, 
			SLOT(volumeMicChanged(int)));
}

savoirfairelinux's avatar
savoirfairelinux committed
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
/**
 * Returns true if the keyboard mapping returns letters. 
 *
 * @return	bool
 */
bool
QtGUIMainWindow::isInTextMode (void) {
	if (modeType == TEXT_MODE) {
		return true;
	} else {
		return false;
	}
}

/**
 * Returns true if the keyboard mapping returns digits. 
 *
 * @return	bool
 */
bool
QtGUIMainWindow::isInNumMode (void) {
	if (modeType == NUM_MODE) {
		return true;
	} else {
		return false;
	}
}

/**
 * Sets up the keyboard mapping mode.
 */
void
QtGUIMainWindow::setMode (int mode) {
	this->modeType = mode;
}

/**
 * Search the busy line number among all lines and different of current line
 * number.
 *
 * @return	number of busy line
 */
int
QtGUIMainWindow::numLineBusy(void) {
	int temp = -1;
	for (int i = 0; i < NUMBER_OF_LINES; i++) {
		if (callmanager->phLines[i]->isBusy() && i != currentLineNumber) {
			temp = i;	
		} 
	}
	return temp;
}

void
QtGUIMainWindow::dialTone (bool var) {
	if (this->b_dialtone != var) {
		this->b_dialtone = var;
	}
	callmanager->tonezone = var;
	callmanager->tone->toneHandle(ZT_TONE_DIALTONE); 
	
}
///////////////////////////////////////////////////////////////////////////////
// Public Methods implementations                                            //
///////////////////////////////////////////////////////////////////////////////

/**
 * Initializes LCD display, and move it at the configuration file position.
 */
void
QtGUIMainWindow::setMainLCD (void) {
	// Screen initialisation
llea's avatar
llea committed
545
	this->lcd->move (pt->getX(SCREEN), pt->getY(SCREEN));
savoirfairelinux's avatar
savoirfairelinux committed
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
}

void
QtGUIMainWindow::setCurrentLineNumber(int newcur) {
	this->currentLineNumber = newcur;
}

/**
 * Sets the corresponding pixmap button according to its state.
 * Handle operations between lines (on hold, off hold) and dial tone 
 * 
 * @param	num_line: number of the current line
 */
void
QtGUIMainWindow::toggleLine (int num_line) {
	if ( num_line == -1 ){
		qDebug("Should not arrived !!!!!!!%d\n", num_line);
		return ;
	}
	//Current line number
	currentLineNumber = num_line;
	// Change state when click on line button
	callmanager->phLines[currentLineNumber]->toggleState();
	// If another line is busy
	busyNum = numLineBusy();

	if (callmanager->isNotUsedLine(currentLineNumber) and busyNum == -1) {
llea's avatar
llea committed
573
		qDebug("GUI: FIRST LINE IN USED %d", currentLineNumber);
savoirfairelinux's avatar
savoirfairelinux committed
574 575 576 577
		lcd->setStatus("Enter Phone Number:");
		chosenLine = currentLineNumber;
		if (!noChoose) {
			choose = true; 
llea's avatar
llea committed
578 579 580
			if (!callmanager->phLines[currentLineNumber]->getbDial()) {
				this->dialTone(true);
			}
savoirfairelinux's avatar
savoirfairelinux committed
581 582 583 584 585 586 587
		}
		callmanager->phLines[currentLineNumber]->setStateLine(BUSY);
	} 

	// Occurs when newly off-hook line replaces another one.
	if (busyNum != currentLineNumber && busyNum != -1) {
		if (callmanager->isNotUsedLine(currentLineNumber)) {
llea's avatar
llea committed
588
			qDebug("GUI: Line %d replaces another one", currentLineNumber);
savoirfairelinux's avatar
savoirfairelinux committed
589 590
			lcd->clear(QString("Enter Phone Number:"));
			chosenLine = currentLineNumber;
llea's avatar
llea committed
591
			lcd->inFunction = false;
savoirfairelinux's avatar
savoirfairelinux committed
592 593 594 595 596 597 598 599
			if (!noChoose) {
				choose = true;
			}	
		}
		// Change state to ONHOLD
		callmanager->phLines[busyNum]->setState(ONHOLD);
		callmanager->phLines[busyNum]->setStateLine(ONHOLD);
		callmanager->actionHandle (busyNum, ONHOLD_CALL);
llea's avatar
llea committed
600
		if (!callmanager->phLines[currentLineNumber]->getbDial()) {
llea's avatar
llea committed
601 602 603 604
			if (callmanager->sip->call[busyNum] == NULL) {
				setInactiveLine(busyNum);
			}
			this->dialTone(true);			
llea's avatar
llea committed
605
		}
savoirfairelinux's avatar
savoirfairelinux committed
606 607 608 609 610 611
		callmanager->phLines[currentLineNumber]->setState(BUSY);
		qDebug("GUI: state ON-HOLD line busyNum %d", busyNum);
	}

	if (callmanager->phLines[currentLineNumber]->isBusy()) {
		qDebug("GUI: isBusy line %d", currentLineNumber);
llea's avatar
llea committed
612
		
savoirfairelinux's avatar
savoirfairelinux committed
613 614 615 616 617 618 619 620
		// Change line button pixmap to "line in use" state.
		callmanager->phLines[currentLineNumber]->button()->setPixmap(
				TabLinePixmap[currentLineNumber][BUSY]);
		callmanager->phLines[currentLineNumber]->setState(BUSY);
		
		// Answer new call
		if (callmanager->isRingingLine(currentLineNumber) and 
			callmanager->phLines[currentLineNumber]->getStateLine() != ONHOLD){
llea's avatar
llea committed
621
			qDebug("GUI: -- New answered call %d --", currentLineNumber);
savoirfairelinux's avatar
savoirfairelinux committed
622 623 624 625 626 627 628 629
			callmanager->actionHandle (currentLineNumber, ANSWER_CALL);
			callmanager->phLines[currentLineNumber]->setState(BUSY);
			callmanager->phLines[currentLineNumber]->setStateLine(BUSY);
		} 
		else if (callmanager->phLines[currentLineNumber]->getStateLine() 
																== ONHOLD) {
			qDebug("GUI: state OFF-HOLD line %d", currentLineNumber);
			lcd->clear(QString("Connected"));
630 631 632
			if (callmanager->sip->call[currentLineNumber] != NULL) {
				lcd->inFunction = true;
			}
savoirfairelinux's avatar
savoirfairelinux committed
633 634 635 636 637 638 639 640 641 642 643
			callmanager->phLines[currentLineNumber]->setStateLine(OFFHOLD);
			callmanager->actionHandle (currentLineNumber, OFFHOLD_CALL);
			lcd->appendText(callmanager->phLines[currentLineNumber]->text);
		}
	} 
	else if (callmanager->phLines[currentLineNumber]->isOnHold()){
		// Change state to ONHOLD
		callmanager->phLines[currentLineNumber]->setState(ONHOLD);
		callmanager->phLines[currentLineNumber]->setStateLine(ONHOLD);
		// Change status to ONHOLD
		qDebug("GUI: state ON-HOLD line %d", currentLineNumber);
llea's avatar
llea committed
644
		lcd->setStatus(ONHOLD_STATUS);
savoirfairelinux's avatar
savoirfairelinux committed
645
		callmanager->actionHandle (currentLineNumber, ONHOLD_CALL);
llea's avatar
llea committed
646 647 648 649
		if (callmanager->sip->call[currentLineNumber] == NULL) {
			setInactiveLine(currentLineNumber);
			lcd->setStatus("Enter Phone Number:");
		}
savoirfairelinux's avatar
savoirfairelinux committed
650 651 652 653 654 655 656 657 658 659
	}
}

/**
 * Actions occur when click on hang off button. 
 * Use for validate incoming and outgoing call, transfer call.
 */
void
QtGUIMainWindow::dial (void) {
	int i = 0;
llea's avatar
llea committed
660
	
savoirfairelinux's avatar
savoirfairelinux committed
661 662
	if (transfer and callmanager->sip->call[currentLineNumber] != NULL
			and currentLineNumber != -1) {
llea's avatar
llea committed
663
		// If transfer button clicked, validate the number for transfer.
savoirfairelinux's avatar
savoirfairelinux committed
664 665 666 667
		callmanager->actionHandle (currentLineNumber, TRANSFER_CALL);
		transfer = false;
	} else {
		qDebug("GUI: LINE CURRENT %d", currentLineNumber);
668
		 
llea's avatar
llea committed
669 670
		 if (callmanager->ringing()) {
			// If new incoming call
savoirfairelinux's avatar
savoirfairelinux committed
671 672
			currentLineNumber = callmanager->newCallLineNumber();
			toggleLine (currentLineNumber);
llea's avatar
llea committed
673 674 675 676 677 678 679 680 681 682
			// Set used-state pixmap 'currentLineNumber' line
			callmanager->phLines[currentLineNumber]->button()->setPixmap(
						TabLinePixmap[currentLineNumber][BUSY]);
			callmanager->phLines[currentLineNumber]->setState(BUSY);
		} else if (callmanager->phLines[currentLineNumber]->isOnHold() or
			callmanager->phLines[currentLineNumber]->getStateLine() == OFFHOLD
			or (callmanager->phLines[currentLineNumber]->isBusy() and
				callmanager->sip->call[currentLineNumber] != NULL)){
			// If line is used
			// NOTHING
savoirfairelinux's avatar
savoirfairelinux committed
683 684 685 686 687
		} else {
			// If new outgoing call
			// For new outgoing call with INVITE SIP request
			i = callmanager->outgoingNewCall();
			if (i == 0) {
llea's avatar
llea committed
688
				// If outgoing call succeeded
savoirfairelinux's avatar
savoirfairelinux committed
689
				if (!choose) {
llea's avatar
llea committed
690
					// If find not used line
savoirfairelinux's avatar
savoirfairelinux committed
691
					noChoose = true;
llea's avatar
llea committed
692 693
					currentLineNumber = callmanager->findLineNumberNotUsedSIP();				} else {
					// If choose line
savoirfairelinux's avatar
savoirfairelinux committed
694 695 696 697
					currentLineNumber = chosenLine;
				}
				callmanager->phLines[currentLineNumber]->text = 
								callmanager->bufferTextRender();
llea's avatar
llea committed
698
				callmanager->phLines[currentLineNumber]->setbDial(true);
savoirfairelinux's avatar
savoirfairelinux committed
699
				toggleLine (currentLineNumber);
700
				callmanager->phLines[currentLineNumber]->setbInProgress(true);
llea's avatar
llea committed
701 702 703 704
				// Set used-state pixmap 'currentLineNumber' line
				callmanager->phLines[currentLineNumber]->button()->setPixmap(
						TabLinePixmap[currentLineNumber][BUSY]);
				callmanager->phLines[currentLineNumber]->setState(BUSY);
savoirfairelinux's avatar
savoirfairelinux committed
705 706 707 708 709 710 711 712 713
			}
		}	
	}
}

/**
 * Hangup the current call.
 */
void
savoirfairelinux's avatar
savoirfairelinux committed
714
QtGUIMainWindow::hangupLine (void) {  
savoirfairelinux's avatar
savoirfairelinux committed
715
	qDebug("HANGUP: line %d", currentLineNumber);
llea's avatar
llea committed
716
	
savoirfairelinux's avatar
savoirfairelinux committed
717 718
	if (currentLineNumber != -1 and 
			!(callmanager->phLines[currentLineNumber]->isOnHold())) {
llea's avatar
llea committed
719
	// If there is current line opened and state line not onHold
savoirfairelinux's avatar
savoirfairelinux committed
720 721 722
		// set free pixmap
		setFreeStateLine (currentLineNumber);
		
723
		if (callmanager->phLines[currentLineNumber]->getbInProgress()) {
llea's avatar
llea committed
724
			// If call is progressing, cancel the call
savoirfairelinux's avatar
savoirfairelinux committed
725 726 727
			callmanager->actionHandle (currentLineNumber, CANCEL_CALL);
		} else {
			// Hang up the call
llea's avatar
llea committed
728
			this->dialTone(false);		
savoirfairelinux's avatar
savoirfairelinux committed
729
			callmanager->actionHandle (currentLineNumber, CLOSE_CALL);
llea's avatar
llea committed
730
			callmanager->phLines[currentLineNumber]->setbDial(false);
savoirfairelinux's avatar
savoirfairelinux committed
731 732 733
		}
		lcd->clear(QString("Hung up"));
		setCurrentLineNumber(-1);
llea's avatar
llea committed
734 735 736
	} else if (callmanager->sip->call[currentLineNumber] == NULL and 
			callmanager->phLines[currentLineNumber]->isOnHold()) {
	// If there isn't call on the current line and state line onHold
llea's avatar
llea committed
737 738
		setInactiveLine(currentLineNumber);
		// Stop congestion sound
739 740
		callmanager->congestion(false);
		lcd->clear(QString("Hung up"));
savoirfairelinux's avatar
savoirfairelinux committed
741 742 743 744 745 746 747 748 749 750 751
	}
	
	choose = false;
	noChoose = false;

	// Just to test when  receive a message
#if 0
	msgVar = true;
#endif
}

llea's avatar
llea committed
752 753 754 755 756 757 758 759 760
void
QtGUIMainWindow::setInactiveLine (int num) {
	// set free pixmap
	setFreeStateLine (num);
	// Stop dial tone
	this->dialTone(false);
	callmanager->phLines[num]->setbDial(false);
}

savoirfairelinux's avatar
savoirfairelinux committed
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
/**
 * Stop the blinking message slot and load the message-off button pixmap.
 */
void
QtGUIMainWindow::stopTimerMessage (void) {
	msgVar = false;	
	phoneKey_msg->setPixmap(TabMsgPixmap[FREE]);
}

/**
 * Set pixamp of free state.
 */
void
QtGUIMainWindow::setFreeStateLine (int line) {
	// Set free-status for current line
	callmanager->phLines[line]->setState (FREE);
llea's avatar
llea committed
777
	callmanager->phLines[line]->setStateLine (FREE);
savoirfairelinux's avatar
savoirfairelinux committed
778
	// Set free-pixmap
llea's avatar
llea committed
779
	callmanager->phLines[line]->button()->setPixmap(TabLinePixmap[line][FREE]);
savoirfairelinux's avatar
savoirfairelinux committed
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
}

/**
 * Stop the call timer.
 * 
 * @param	line: number of line 
 */
void
QtGUIMainWindow::stopCallTimer (int line) {
	// Stop the call timer when hang up
	if (callmanager->phLines[line]->timer != NULL) {
		callmanager->phLines[line]->stopTimer();
	}
	// No display call timer, display current hour
	lcd->inFunction = false;
	callmanager->phLines[line]->first = true;
}

/**
 * Start the call timer.
 * 
 * @param	line: number of line 
 */
void
QtGUIMainWindow::startCallTimer (int line) {
	// Call-timer enable
	lcd->inFunction = true;
	
	// To start the timer for display text just one time
	if (callmanager->phLines[line]->first) {
		callmanager->phLines[line]->startTimer();
		callmanager->phLines[line]->first = false;
	}
}

///////////////////////////////////////////////////////////////////////////////
// Public slot implementations                                               //
///////////////////////////////////////////////////////////////////////////////
llea's avatar
llea committed
818
void
819 820
QtGUIMainWindow::volumeSpkrChanged (int val) {
	callmanager->spkrSoundVolume (val);
llea's avatar
llea committed
821 822 823
}

void
824 825 826 827 828 829 830
QtGUIMainWindow::volumeMicChanged (int val) {
	callmanager->micSoundVolume (val);
}

void
QtGUIMainWindow::registerSlot (void) {
	callmanager->sip->setRegister();
llea's avatar
llea committed
831 832
}

savoirfairelinux's avatar
savoirfairelinux committed
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
/**
 * Slot to blink with free and busy pixmaps when line is hold.
 */
void
QtGUIMainWindow::blinkLineSlot (void) {
	static bool isOn = false;
	int state = BUSY;
	
	if	(!isOn) {
		state = FREE;	
	}

	for (int i = 0; i < NUMBER_OF_LINES; i++) {
		// If lines are hold on, set blinking pixmap
		if (callmanager->phLines[i]->isOnHold()) {
			callmanager->phLines[i]->button()->setPixmap(TabLinePixmap[i][state]);
		}
	}
	isOn = !isOn;
}

// Dial the voicemail Number automatically when button is clicked
void
QtGUIMainWindow::button_msg (void) {
	 stopTimerMessage();
	 lcd->clear("Voicemail");
859
	 lcd->appendText(Config::getchar("Preferences","Options.voicemailNumber",""));
savoirfairelinux's avatar
savoirfairelinux committed
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
	 dial();
}

// Allow to enter a phone number to transfer the current call.
// This number is validated by ok-button or typing Enter
void
QtGUIMainWindow::button_transfer (void) {
	if (currentLineNumber != -1) {
		transfer = true;
		callmanager->actionHandle (currentLineNumber, ONHOLD_CALL);
		lcd->clear(QString("Transfer to:"));
	}
}

void
QtGUIMainWindow::button_conf (void) {
//TODO: This feature is not implemented yet
}

void
QtGUIMainWindow::button_line0 (void) {
 	toggleLine (0);
	 
}

void
QtGUIMainWindow::button_line1 (void) {
	toggleLine (1);
}

void
QtGUIMainWindow::button_line2 (void) {
	toggleLine (2);
}

void
QtGUIMainWindow::button_line3 (void) {
	toggleLine (3);
}

void
QtGUIMainWindow::button_line4 (void) {
	toggleLine (4);
}

void
QtGUIMainWindow::button_line5 (void) {
	toggleLine (5);
}

void
QtGUIMainWindow::button_mute(void) {
	// Disable micro sound 
	static bool isOn = true;
	
	if(!isOn) {
		callmanager->mute = false;	
		lcd->clear("Mute off");
	} else { 
		callmanager->mute = true;	
		lcd->clear("Mute on");		
	}
	
	isOn = !isOn;
}

// Show the setup panel
void
QtGUIMainWindow::configuration (void) {
	 panel->show();
}

void
QtGUIMainWindow::addressBook (void) {
//	TODO: phonebook->show();
	QMessageBox::information(this, "Information",
		"This feature is not implemented yet", QMessageBox::Yes);
}

// Handle the dtmf-button click
void
QtGUIMainWindow::dtmfKeypad (void) {
	if (keypad->isVisible()) {
		// Hide keypad if it's visible.
		keypad->hide();
	} else {
		
		if (this->first and !getMoved()) {
			// If it's the first time that keypad is shown.
			// The position is fixed with the main initial position.
			this->first = false;
			keypad->setGeometry (MAIN_INITIAL_POSITION + 
									this->getSourceImage().width(), 
							 	MAIN_INITIAL_POSITION, 
							 	keypad->getSourceImage().width(),
							 	keypad->getSourceImage().height());
		} else {
			// If main window is moved, we calculate the keypad new position 
			// to fix it with main window
			if (getMoved()) {
				keypad->setGeometry (positionOffsetX(), 
							 	getGlobalMouseY() - getMouseY(), 
							 	keypad->getSourceImage().width(),
							 	keypad->getSourceImage().height());
			}
			if (keypad->getMoved()) {
				// If keypad is moved, it shows at the previous position
				keypad->setGeometry (
								keypad->getGlobalMouseX()-keypad->getMouseX(), 
							 	keypad->getGlobalMouseY()-keypad->getMouseY(), 
							 	keypad->getSourceImage().width(),
							 	keypad->getSourceImage().height());
			}
		}

		// Show keypad if it's hidden.		
	 	keypad->show();
	}
}

// Get x-position offset, related to the screen size, to show numeric keypad
int
QtGUIMainWindow::positionOffsetX (void) {
	QRect screenRect;
	int offset;

	// Get the screen geometry
	screenRect = (QApplication::desktop())->screenGeometry (0);
	
	offset = this->getSourceImage().width() - getMouseX() + getGlobalMouseX();
	if (offset + keypad->getSourceImage().width() > screenRect.right()) {
		return getGlobalMouseX() - (
								getMouseX() + keypad->getSourceImage().width());
	} else {
		return offset;
	}
}

/**
 * Slot when receive a message, blink pixmap.
 */
void
QtGUIMainWindow::blinkMessageSlot (void) {
	static bool isOn = false;
	int stateMsg = BUSY;
	
	if(!isOn) {
		stateMsg = FREE;
	}
	
	if (msgVar) {
		phoneKey_msg->setPixmap(TabMsgPixmap[stateMsg]);
	}
	isOn = !isOn;
}


/**
 * Slot when phone is ringing, blink pixmap.
 */
void
QtGUIMainWindow::blinkRingSlot (void) {
	static bool isOn = false;
	int state = BUSY;
	int line = callmanager->sip->notUsedLine;
	if ( line == -1 ) 
		return;

1028 1029
	//if (callmanager->ringing()) {
	if (callmanager->phLines[line]->getbRinging()) {
savoirfairelinux's avatar
savoirfairelinux committed
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047
		// For the line
		if	(!isOn) {
			state = FREE;	
		}

		callmanager->phLines[line]->button()->setPixmap(
				TabLinePixmap[line][state]);
		isOn = !isOn;
	}
}


/**
 * Slot to quit application with or without QMessageBox confirmation
 */
void
QtGUIMainWindow::quitApplication (void) {
	bool confirm;
llea's avatar
llea committed
1048 1049 1050 1051

	// Save volume positions
	// TODO: save position if direction is horizontal
	Config::set("Audio", "Volume.speakers_x",  pt->getX(VOL_SPKR));
llea's avatar
llea committed
1052
	if (vol_spkr->getValue() != 0) { 
llea's avatar
llea committed
1053 1054 1055 1056
		Config::set("Audio", "Volume.speakers_y",  pt->getY(VOL_SPKR) - 
			vol_spkr->getValue());
	}
	Config::set("Audio", "Volume.micro_x",  pt->getX(VOL_MIC)); 
llea's avatar
llea committed
1057
	if (vol_mic->getValue() != 0) {
llea's avatar
llea committed
1058 1059 1060
		Config::set("Audio", "Volume.micro_y",  pt->getY(VOL_MIC) - 
			vol_mic->getValue());
	}
llea's avatar
llea committed
1061
	// Save current position of the controls volume
llea's avatar
llea committed
1062
	save();
1063
		
llea's avatar
llea committed
1064 1065
	// Show QMessageBox
	confirm = Config::get("Preferences", "Options.confirmQuit", (int)true);
savoirfairelinux's avatar
savoirfairelinux committed
1066 1067 1068
	if (confirm) {
		if (QMessageBox::question(this, "Confirm quit",
			"Are you sure you want to quit SFLPhone ?",
llea's avatar
llea committed
1069
			 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
savoirfairelinux's avatar
savoirfairelinux committed
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
				QApplication::exit(0);
				callmanager->quitLibrary();
		}
	} 
	// No QMessageBox
	else {
		QApplication::exit(0);
		callmanager->quitLibrary();
		qDebug("QUIT");
	}
}

/**
 * Slot to strip urlinput.
 */
void
QtGUIMainWindow::stripSlot (void) {
	QRegExp rx(REG_EXPR);
	lcd->appendText(urlinput->url->text().remove(rx));
	urlinput->close();
}

/**
 * Slot when numeric keypad phonekey is pressed, append the key text and setup 
 * the DTMF keypad .
 *
 * @param	button group id 
 */ 
void
QtGUIMainWindow::pressedKeySlot (int id) {
	char code = 0;
	int pulselen = 0;
llea's avatar
llea committed
1102
	int a = 0;
savoirfairelinux's avatar
savoirfairelinux committed
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122
	
	// Stop dial tone
 	if (b_dialtone) {
		this->dialTone(false);
	}

	switch (id) {
		case KEYPAD_ID_0:		code = '0'; break;
		case KEYPAD_ID_1:		code = '1'; break;
		case KEYPAD_ID_2:		code = '2'; break;
		case KEYPAD_ID_3:		code = '3'; break;
		case KEYPAD_ID_4:		code = '4'; break;
		case KEYPAD_ID_5:		code = '5'; break;
		case KEYPAD_ID_6:		code = '6'; break;
		case KEYPAD_ID_7:		code = '7'; break;
		case KEYPAD_ID_8:		code = '8'; break;
		case KEYPAD_ID_9:		code = '9'; break;
		case KEYPAD_ID_STAR:	code = '*'; break;
		case KEYPAD_ID_HASH:	code = '#'; break;
	}
llea's avatar
llea committed
1123
	
savoirfairelinux's avatar
savoirfairelinux committed
1124 1125 1126 1127 1128 1129 1130 1131
	onLine = currentLineNumber;
	if (onLine != -1) {
		callmanager->dtmf(onLine, code);
	} 

	// Handle dtmf
	key->startTone(code);
	key->generateDTMF(buf, SAMPLING_RATE);
llea's avatar
llea committed
1132
	callmanager->audiodriver->audio_buf.resize(SAMPLING_RATE);
llea's avatar
llea committed
1133 1134
	callmanager->audiodriver->audio_buf.setData(
										buf, callmanager->getSpkrVolume());
llea's avatar
llea committed
1135
	pulselen = Config::get("Signalisations", "DTMF.pulseLength", 250);
llea's avatar
llea committed
1136 1137
	callmanager->audiodriver->audio_buf.resize(pulselen * (OCTETS/1000));
	a = callmanager->audiodriver->writeBuffer();
llea's avatar
llea committed
1138 1139 1140 1141 1142
	if (a == 1) {
		pressedKeySlot(id);
	} else {
		lcd->appendText (code);		
	}
savoirfairelinux's avatar
savoirfairelinux committed
1143 1144
}

llea's avatar
llea committed
1145
// Save settings in config-file
1146 1147 1148 1149 1150
void 
QtGUIMainWindow::save() {
	Config::tree()->saveToFile(callmanager->path.data());
}

llea's avatar
llea committed
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161
void
QtGUIMainWindow::applySkin (void) {
	apply = true;
	// For skin of the screen
	lcd->initGraphics();
	setMainLCD();
	// For skin of the gui
	initSkin();
}


llea's avatar
llea committed
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171
// Handle operation to minimize the application
void 
QtGUIMainWindow::reduceHandle (void) {
	if (Config::getb("Preferences", "Options.checkedTray")) {
		clickHandle();
	} else {
		showMinimized();
	}
}

savoirfairelinux's avatar
savoirfairelinux committed
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301
// Handle mouse left-button click to minimize/maximize the application
void
QtGUIMainWindow::clickHandle (void) {
	if (this->isShown()) {
		hide();
	}
	
	else if (this->isMinimized()) {
		showMaximized();
	}
	
	else {
		show();
	}
}

void
QtGUIMainWindow::pressedKey0 (void) {
	pressedKeySlot (KEYPAD_ID_0);
}

void
QtGUIMainWindow::pressedKey1 (void) {
	pressedKeySlot (KEYPAD_ID_1);
}

void
QtGUIMainWindow::pressedKey2 (void) {
	pressedKeySlot (KEYPAD_ID_2);
}
void
QtGUIMainWindow::pressedKey3 (void) {
	pressedKeySlot (KEYPAD_ID_3);
}
void
QtGUIMainWindow::pressedKey4 (void) {
	pressedKeySlot (KEYPAD_ID_4);
}
void
QtGUIMainWindow::pressedKey5 (void) {
	pressedKeySlot (KEYPAD_ID_5);
}
void
QtGUIMainWindow::pressedKey6 (void) {
	pressedKeySlot (KEYPAD_ID_6);
}
void
QtGUIMainWindow::pressedKey7 (void) {
	pressedKeySlot (KEYPAD_ID_7);
}
void
QtGUIMainWindow::pressedKey8 (void) {
	pressedKeySlot (KEYPAD_ID_8);
}
void
QtGUIMainWindow::pressedKey9 (void) {
	pressedKeySlot (KEYPAD_ID_9);
}
void
QtGUIMainWindow::pressedKeyStar  (void) {
	pressedKeySlot (KEYPAD_ID_STAR);
}
void
QtGUIMainWindow::pressedKeyHash (void) {
	pressedKeySlot (KEYPAD_ID_HASH);
}

///////////////////////////////////////////////////////////////////////////////
// Protected Methods implementations                                         //
///////////////////////////////////////////////////////////////////////////////
/**
 * Reimplementation of keyPressEvent() to handle the keyboard mapping.
 */
void
QtGUIMainWindow::keyPressEvent(QKeyEvent *e) {
	// Misc. key	  
	switch (e->key()) {
	case Qt::Key_At:
	case Qt::Key_Colon:
	case Qt::Key_Period:
	case Qt::Key_Comma:
	case Qt::Key_Plus:
	case Qt::Key_Minus:
	case Qt::Key_Slash:
		lcd->appendText(QChar(e->key()));
		return;
	   	break;

	case Qt::Key_Backspace:
		lcd->backspace();
		return;
	   	break;	

	case Qt::Key_Escape:
		lcd->clear();
		return;
	   	break;
	
	case Qt::Key_Return:
	case Qt::Key_Enter:
		dial();
		return;
		break;	

	case Qt::Key_F1:
	case Qt::Key_F2:
	case Qt::Key_F3:
	case Qt::Key_F4:
		this->toggleLine(e->key() - Qt::Key_F1);
		return;
	   	break;

	case Qt::Key_Q :
 		if (e->state() == Qt::ControlButton ) {
			emit keyPressed(e->key());
			return;			
		}			
		break;
	case Qt::Key_L :
 		if (e->state() == Qt::ControlButton ) {
		 	urlinput->show();
			return;			
		}			
		break;
	case Qt::Key_C :
 		if (e->state() == Qt::ControlButton ) {
		 	configuration();
			return;			
		}			
		break;
1302 1303 1304 1305 1306 1307
	case Qt::Key_D :
 		if (e->state() == Qt::ControlButton ) {
		 	dtmfKeypad();
			return;			
		}			
		break;
savoirfairelinux's avatar
savoirfairelinux committed
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358
	case Qt::Key_Space:
		if (this->isInNumMode()) {
			this->setMode(TEXT_MODE);
		} else {
			this->setMode(NUM_MODE);
		}
		return;
		break;

	case Qt::Key_Alt:
	case Qt::Key_CapsLock:
	case Qt::Key_Shift:
	case Qt::Key_Tab:
	case Qt::Key_Control:
		return;
		break;

	default:
		break;
	 }

	if (QChar(e->key()).isDigit() ) {
		// Numeric keypad
		if (e->key() == Qt::Key_0) {
			pressedKeySlot(KEYPAD_ID_0);
		} else {
			pressedKeySlot(e->key() - Qt::Key_0 - 1);
		}
	}
	
	// Handle * and # too.
	else if ((e->key() == Qt::Key_Asterisk)
							or (e->key() == Qt::Key_NumberSign)) {
		(e->key() == Qt::Key_Asterisk) ? 
			pressedKeySlot(KEYPAD_ID_STAR)
			: pressedKeySlot(KEYPAD_ID_HASH);
	}
	
	// If letter keypad and numeric mode, display digit.
	else if (QChar(e->key()).isLetter() && this->isInNumMode() ) {
		pressedKeySlot(
			(NumericKeypadTools::keyToNumber(e->key())- Qt::Key_0) - 1);
	}
	
	// If letter keypad and text mode, display letter.
	else if (QChar(e->key()).isLetter() && this->isInTextMode()) {
		lcd->appendText(QChar(e->key()).lower());
	}  
}

// EOF