From 89bba742f9af29787eccc8b67f12408039a19e6c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Quentin?=
 <jquentin@jquentin-laptop-kub2.(none)>
Date: Thu, 30 Apr 2009 13:54:42 -0400
Subject: [PATCH] [#1307] Implement "edit before call" in history and address
 book.

---
 sflphone_kde/sflphone_kdeview.cpp | 70 ++++++++++++++++++++++++++++---
 sflphone_kde/sflphone_kdeview.h   | 42 +++++++++----------
 2 files changed, 85 insertions(+), 27 deletions(-)

diff --git a/sflphone_kde/sflphone_kdeview.cpp b/sflphone_kde/sflphone_kdeview.cpp
index e2a697cca0..fed6ded89d 100644
--- a/sflphone_kde/sflphone_kdeview.cpp
+++ b/sflphone_kde/sflphone_kdeview.cpp
@@ -26,6 +26,7 @@
 #include <QtGui/QMenu>
 #include <QtGui/QBrush>
 #include <QtGui/QPalette>
+#include <QtGui/QInputDialog>
 
 #include <kstandardaction.h>
 #include <kactioncollection.h>
@@ -332,12 +333,27 @@ void sflphone_kdeView::enter()
 	if(stackedWidget_screen->currentWidget() == page_callHistory)
 	{
 		qDebug() << "In call history.";
-		lineEdit_searchHistory->clear();
+		action_history->setChecked(false);
+		stackedWidget_screen->setCurrentWidget(page_callList);
+		
+		Call * pastCall = callList->findCallByHistoryItem(listWidget_callHistory->currentItem());
+		Call * call = callList->addDialingCall(pastCall->getPeerName());
+		call->appendItemText(pastCall->getPeerPhoneNumber());
+		addCallToCallList(call);
+		listWidget_callList->setCurrentRow(listWidget_callList->count() - 1);
+		actionb(call, CALL_ACTION_ACCEPT);
 	}
 	if(stackedWidget_screen->currentWidget() == page_addressBook)
 	{
 		qDebug() << "In address book.";
-		lineEdit_addressBook->clear();
+		action_addressBook->setChecked(false);
+		stackedWidget_screen->setCurrentWidget(page_callList);
+		ContactItemWidget * w = (ContactItemWidget *) (listWidget_addressBook->itemWidget(listWidget_addressBook->currentItem()));
+		Call * call = callList->addDialingCall(w->getContactName());
+		call->appendItemText(w->getContactNumber());
+		addCallToCallList(call);
+		listWidget_callList->setCurrentRow(listWidget_callList->count() - 1);
+		actionb(call, CALL_ACTION_ACCEPT);
 	}
 }
 
@@ -958,12 +974,20 @@ void sflphone_kdeView::on_stackedWidget_screen_currentChanged(int index)
 void sflphone_kdeView::contextMenuEvent(QContextMenuEvent *event)
 {
 	QMenu menu(this);
+	if(stackedWidget_screen->currentWidget() == page_callHistory || stackedWidget_screen->currentWidget() == page_addressBook)
+	{
+		QAction * action_edit = new QAction(&menu);
+		action_edit->setText(tr2i18n("Edit before call", 0));
+		connect(action_edit, SIGNAL(triggered()),
+		        this  , SLOT(editBeforeCall()));
+		menu.addAction(action_edit);
+	}
+	
 	menu.addAction(action_accept);
 	menu.addAction(action_refuse);
 	menu.addAction(action_hold);
 	menu.addAction(action_transfer);
 	menu.addAction(action_record);
-	//TODO accounts to choose
 	menu.addSeparator();
 	QVector<Account *> accounts = registeredAccounts();
 	for (int i = 0 ; i < accounts.size() ; i++)
@@ -984,6 +1008,43 @@ void sflphone_kdeView::contextMenuEvent(QContextMenuEvent *event)
 	
 }
 
+void sflphone_kdeView::editBeforeCall()
+{
+	qDebug() << "editBeforeCall";
+	QString name;
+	QString number;
+	if(stackedWidget_screen->currentWidget() == page_callHistory)
+	{
+		QListWidgetItem * item = listWidget_callHistory->currentItem();
+		if(item)
+		{
+			Call * call = callList->findCallByHistoryItem(item);
+			name = call->getPeerName();
+			number = call->getPeerPhoneNumber();
+		}
+	}
+	if(stackedWidget_screen->currentWidget() == page_addressBook)
+	{
+		QListWidgetItem * item = listWidget_addressBook->currentItem();
+		if(item)
+		{
+			ContactItemWidget * w = (ContactItemWidget *) (listWidget_addressBook->itemWidget(listWidget_addressBook->currentItem()));
+			name = w->getContactName();
+			number = w->getContactNumber();
+		}
+	}
+	QString newNumber = QInputDialog::getText(this, tr2i18n("Edit before call", 0), QString(), QLineEdit::Normal, number);
+	
+	action_history->setChecked(false);
+	action_addressBook->setChecked(false);
+	stackedWidget_screen->setCurrentWidget(page_callList);
+	Call * call = callList->addDialingCall(name);
+	call->appendItemText(newNumber);
+	addCallToCallList(call);
+	listWidget_callList->setCurrentRow(listWidget_callList->count() - 1);
+	actionb(call, CALL_ACTION_ACCEPT);
+}
+
 void sflphone_kdeView::setAccountFirst(Account * account)
 {
 	qDebug() << "setAccountFirst : " << account->getAlias();
@@ -1073,8 +1134,6 @@ void sflphone_kdeView::on_action_accept_triggered()
 		Call * pastCall = callList->findCallByHistoryItem(listWidget_callHistory->currentItem());
 		Call * call = callList->addDialingCall(pastCall->getPeerName());
 		call->appendItemText(pastCall->getPeerPhoneNumber());
-// 		if(!pastCall->getPeerName().isEmpty())
-// 			call->setPeerName(pastCall->getPeerName());
 		addCallToCallList(call);
 		listWidget_callList->setCurrentRow(listWidget_callList->count() - 1);
 		actionb(call, CALL_ACTION_ACCEPT);
@@ -1085,7 +1144,6 @@ void sflphone_kdeView::on_action_accept_triggered()
 		stackedWidget_screen->setCurrentWidget(page_callList);
 		ContactItemWidget * w = (ContactItemWidget *) (listWidget_addressBook->itemWidget(listWidget_addressBook->currentItem()));
 		Call * call = callList->addDialingCall(w->getContactName());
-// 		call->setPeerName(w->getContactName());
 		call->appendItemText(w->getContactNumber());
 		addCallToCallList(call);
 		listWidget_callList->setCurrentRow(listWidget_callList->count() - 1);
diff --git a/sflphone_kde/sflphone_kdeview.h b/sflphone_kde/sflphone_kdeview.h
index 436719d32f..0ea615965f 100644
--- a/sflphone_kde/sflphone_kdeview.h
+++ b/sflphone_kde/sflphone_kdeview.h
@@ -57,7 +57,6 @@ class sflphone_kdeView : public QWidget, public Ui::SFLPhone
     Q_OBJECT
     
 private:
-	//Ui::SFLPhone ui_sflphone_kdeview_base;
 
 	static ConfigurationDialog * configDialog;
 	AccountWizard * wizard;
@@ -81,11 +80,17 @@ public:
 	QErrorMessage * getErrorWindow();
 
 private slots:
+	void actionb(Call * call, call_action action);
+	void action(QListWidgetItem * item, call_action action);
+	
+	void setAccountFirst(Account * account);
+	
 	//void typeChar(QChar c);
 	void typeString(QString str);
 	void backspace();
-	void actionb(Call * call, call_action action);
-	void action(QListWidgetItem * item, call_action action);
+	void escape();
+	void enter();
+	void editBeforeCall();
 	
 	void alternateColors(QListWidget * listWidget);
 	
@@ -106,29 +111,26 @@ private slots:
 	void updateVolumeControls();
 	void updateDialpad();
 	
-	void escape();
-	void enter();
 	
 	virtual void keyPressEvent(QKeyEvent *event)
-{
-	int key = event->key();
-	if(key == Qt::Key_Escape)
-		escape();
-	else if(key == Qt::Key_Return || key == Qt::Key_Enter)
-		on_action_accept_triggered();
-	else if(key == Qt::Key_Backspace)
-		backspace();
-	else
 	{
-		QString text = event->text();
-		if(! event->text().isEmpty())
+		int key = event->key();
+		if(key == Qt::Key_Escape)
+			escape();
+		else if(key == Qt::Key_Return || key == Qt::Key_Enter)
+			enter();
+		else if(key == Qt::Key_Backspace)
+			backspace();
+		else
 		{
-			typeString(text);
+			QString text = event->text();
+			if(! event->text().isEmpty())
+			{
+				typeString(text);
+			}
 		}
 	}
-}
 
-	
 	void on_action_displayVolumeControls_toggled();
 	void on_action_displayDialpad_toggled();
 	void on_action_configureAccounts_triggered();
@@ -143,7 +145,6 @@ private slots:
 	void on_action_history_triggered(bool checked);
 	void on_action_addressBook_triggered(bool checked);
 	void on_action_mailBox_triggered();
-	//void on_actionAbout();
 	
 	void on_pushButton_1_clicked();
 	void on_pushButton_2_clicked();
@@ -184,7 +185,6 @@ private slots:
 	void on1_voiceMailNotify(const QString &accountID, int count);
 	void on1_volumeChanged(const QString &device, double value);
 	
-	void setAccountFirst(Account * account);
 
 };
 
-- 
GitLab