~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

Viewing changes to kde/src/widgets/ContactDock.cpp

  • Committer: Package Import Robot
  • Author(s): Francois Marier
  • Date: 2012-02-18 21:47:09 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120218214709-6362d71gqdsdkrj5
Tags: 1.0.2-1
* New upstream release
  - remove logging patch (applied upstream)
  - update s390 patch since it was partially applied upstream
* Include the Evolution plugin as a separate binary package

* Fix compilation issues on SH4 (closes: #658987)
* Merge Ubuntu's binutils-gold linking fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2009-2012 by Savoir-Faire Linux                         *
 
3
 *   Author : Emmanuel Lepage Valle <emmanuel.lepage@savoirfairelinux.com >*
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 3 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU General Public License     *
 
16
 *   along with this program; if not, write to the                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
19
 **************************************************************************/
 
20
 
 
21
//Parent
 
22
#include "ContactDock.h"
 
23
 
 
24
//Qt
 
25
#include <QtCore/QDateTime>
 
26
#include <QtGui/QVBoxLayout>
 
27
#include <QtGui/QListWidget>
 
28
#include <QtGui/QTreeWidget>
 
29
#include <QtGui/QHeaderView>
 
30
#include <QtGui/QCheckBox>
 
31
#include <QtGui/QSplitter>
 
32
#include <QtGui/QLabel>
 
33
#include <QtGui/QComboBox>
 
34
 
 
35
//KDE
 
36
#include <KDebug>
 
37
#include <KLineEdit>
 
38
#include <KLocalizedString>
 
39
#include <KIcon>
 
40
 
 
41
//SFLPhone
 
42
#include "AkonadiBackend.h"
 
43
#include "ContactItemWidget.h"
 
44
#include "SFLPhone.h"
 
45
#include "conf/ConfigurationSkeleton.h"
 
46
 
 
47
//SFLPhone library
 
48
#include "lib/Call.h"
 
49
#include "lib/Contact.h"
 
50
 
 
51
///@class QNumericTreeWidgetItem_hist TreeWidget using different sorting criterias
 
52
class QNumericTreeWidgetItem_hist : public QTreeWidgetItem {
 
53
   public:
 
54
      QNumericTreeWidgetItem_hist(QTreeWidget* parent):QTreeWidgetItem(parent),widget(0),weight(-1){}
 
55
      QNumericTreeWidgetItem_hist(QTreeWidgetItem* parent):QTreeWidgetItem(parent),widget(0),weight(-1){}
 
56
      ContactItemWidget* widget;
 
57
      QString number;
 
58
      int weight;
 
59
   private:
 
60
      bool operator<(const QTreeWidgetItem & other) const {
 
61
         int column = treeWidget()->sortColumn();
 
62
         //if (dynamic_cast<QNumericTreeWidgetItem_hist*>((QTreeWidgetItem*)&other)) {
 
63
            //if (widget !=0 && dynamic_cast<QNumericTreeWidgetItem_hist*>((QTreeWidgetItem*)&other)->widget != 0)
 
64
            //   return widget->getTimeStamp() < dynamic_cast<QNumericTreeWidgetItem_hist*>((QTreeWidgetItem*)&other)->widget->getTimeStamp();
 
65
            //else if (weight > 0 && dynamic_cast<QNumericTreeWidgetItem_hist*>((QTreeWidgetItem*)&other)->weight > 0)
 
66
            //   return weight > dynamic_cast<QNumericTreeWidgetItem_hist*>((QTreeWidgetItem*)&other)->weight;
 
67
         //}
 
68
         return text(column) < other.text(column);
 
69
      }
 
70
};
 
71
 
 
72
///Forward keypresses to the filter line edit
 
73
bool KeyPressEaterC::eventFilter(QObject *obj, QEvent *event)
 
74
{
 
75
   if (event->type() == QEvent::KeyPress) {
 
76
      m_pDock->keyPressEvent((QKeyEvent*)event);
 
77
      return true;
 
78
   } else {
 
79
      // standard event processing
 
80
      return QObject::eventFilter(obj, event);
 
81
   }
 
82
}
 
83
 
 
84
///Constructor
 
85
ContactDock::ContactDock(QWidget* parent) : QDockWidget(parent)
 
86
{
 
87
   setObjectName("contactDock");
 
88
   m_pFilterLE     = new KLineEdit   (                   );
 
89
   m_pSplitter     = new QSplitter   ( Qt::Vertical,this );
 
90
   m_pSortByCBB    = new QComboBox   ( this              );
 
91
   m_pContactView  = new ContactTree ( this              );
 
92
   m_pCallView     = new QListWidget ( this              );
 
93
   m_pShowHistoCK  = new QCheckBox   ( this              );
 
94
 
 
95
 
 
96
   QStringList sortType;
 
97
   sortType << "Name" << "Organisation" << "Phone number type" << "Rencently used" << "Group";
 
98
   m_pSortByCBB->addItems(sortType);
 
99
   m_pSortByCBB->setDisabled(true);
 
100
 
 
101
   QWidget* mainWidget = new QWidget(this);
 
102
   setWidget(mainWidget);
 
103
 
 
104
   m_pContactView->headerItem()->setText(0,i18n("Contacts"));
 
105
   m_pContactView->header()->setClickable(true);
 
106
   m_pContactView->header()->setSortIndicatorShown(true);
 
107
   m_pContactView->setAcceptDrops(true);
 
108
   m_pContactView->setDragEnabled(true);
 
109
   KeyPressEaterC *keyPressEater = new KeyPressEaterC(this);
 
110
   m_pContactView->installEventFilter(keyPressEater);
 
111
 
 
112
   m_pContactView->setAlternatingRowColors(true);
 
113
 
 
114
   m_pFilterLE->setPlaceholderText(i18n("Filter"));
 
115
   m_pFilterLE->setClearButtonShown(true);
 
116
 
 
117
   m_pShowHistoCK->setChecked(ConfigurationSkeleton::displayContactCallHistory());
 
118
   m_pShowHistoCK->setText(i18n("Display history"));
 
119
 
 
120
   setHistoryVisible(ConfigurationSkeleton::displayContactCallHistory());
 
121
 
 
122
   QVBoxLayout* mainLayout = new QVBoxLayout(mainWidget);
 
123
 
 
124
   mainLayout->addWidget  ( m_pSortByCBB   );
 
125
   mainLayout->addWidget  ( m_pShowHistoCK );
 
126
   mainLayout->addWidget  ( m_pSplitter    );
 
127
   m_pSplitter->addWidget ( m_pContactView );
 
128
   m_pSplitter->addWidget ( m_pCallView    );
 
129
   mainLayout->addWidget  ( m_pFilterLE    );
 
130
 
 
131
   m_pSplitter->setChildrenCollapsible(true);
 
132
   m_pSplitter->setStretchFactor(0,7);
 
133
 
 
134
   connect (AkonadiBackend::getInstance(),SIGNAL(collectionChanged()),                                   this,        SLOT(reloadContact()                      ));
 
135
   connect (m_pContactView,               SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),this,        SLOT(loadContactHistory(QTreeWidgetItem*) ));
 
136
   connect (m_pFilterLE,                  SIGNAL(textChanged(QString)),                                  this,        SLOT(filter(QString)                      ));
 
137
   connect (m_pShowHistoCK,               SIGNAL(toggled(bool)),                                         this,        SLOT(setHistoryVisible(bool)              ));
 
138
   setWindowTitle(i18n("Contact"));
 
139
}
 
140
 
 
141
///Destructor
 
142
ContactDock::~ContactDock()
 
143
{
 
144
 
 
145
}
 
146
 
 
147
 
 
148
/*****************************************************************************
 
149
 *                                                                           *
 
150
 *                                  Mutator                                  *
 
151
 *                                                                           *
 
152
 ****************************************************************************/
 
153
 
 
154
///Reload the contact
 
155
void ContactDock::reloadContact()
 
156
{
 
157
   ContactList list = AkonadiBackend::getInstance()->update();
 
158
   foreach (Contact* cont, list) {
 
159
      ContactItemWidget* aContact  = new ContactItemWidget(m_pContactView);
 
160
      QNumericTreeWidgetItem_hist* item = new QNumericTreeWidgetItem_hist(m_pContactView);
 
161
      item->widget = aContact;
 
162
      aContact->setItem(item);
 
163
      aContact->setContact(cont);
 
164
 
 
165
      PhoneNumbers numbers =  aContact->getContact()->getPhoneNumbers();
 
166
      kDebug() << "Phone count" << numbers.count();
 
167
      if (numbers.count() > 1) {
 
168
         foreach (Contact::PhoneNumber* number, numbers) {
 
169
            QNumericTreeWidgetItem_hist* item2 = new QNumericTreeWidgetItem_hist(item);
 
170
            QLabel* numberL = new QLabel("<b>"+number->getType()+":</b>"+number->getNumber(),this);
 
171
            item2->number = number->getNumber();
 
172
            m_pContactView->setItemWidget(item2,0,numberL);
 
173
         }
 
174
      }
 
175
      else if (numbers.count() == 1) {
 
176
         item->number = numbers[0]->getNumber();
 
177
      }
 
178
 
 
179
      m_pContactView->addTopLevelItem(item);
 
180
      m_pContactView->setItemWidget(item,0,aContact);
 
181
      m_Contacts << aContact;
 
182
   }
 
183
}
 
184
 
 
185
///Query the call history for all items related to this contact
 
186
void ContactDock::loadContactHistory(QTreeWidgetItem* item)
 
187
{
 
188
   if (m_pShowHistoCK->isChecked()) {
 
189
      m_pCallView->clear();
 
190
      if (dynamic_cast<QNumericTreeWidgetItem_hist*>(item) != NULL) {
 
191
         QNumericTreeWidgetItem_hist* realItem = dynamic_cast<QNumericTreeWidgetItem_hist*>(item);
 
192
         foreach (Call* call, SFLPhone::app()->model()->getHistory()) {
 
193
            if (realItem->widget != 0) {
 
194
               foreach (Contact::PhoneNumber* number, realItem->widget->getContact()->getPhoneNumbers()) {
 
195
                  if (number->getNumber() == call->getPeerPhoneNumber()) {
 
196
                     m_pCallView->addItem(QDateTime::fromTime_t(call->getStartTimeStamp().toUInt()).toString());
 
197
                  }
 
198
               }
 
199
            }
 
200
         }
 
201
      }
 
202
   }
 
203
}
 
204
 
 
205
///Filter contact
 
206
void ContactDock::filter(const QString& text)
 
207
{
 
208
   foreach(ContactItemWidget* item, m_Contacts) {
 
209
      bool foundNumber = false;
 
210
      foreach (Contact::PhoneNumber* number, item->getContact()->getPhoneNumbers()) {
 
211
         foundNumber |= number->getNumber().toLower().indexOf(text) != -1;
 
212
      }
 
213
      bool visible = (item->getContact()->getFormattedName().toLower().indexOf(text) != -1)
 
214
                  || (item->getContact()->getOrganization().toLower().indexOf(text) != -1)
 
215
                  || (item->getContact()->getPreferredEmail().toLower().indexOf(text) != -1)
 
216
                  || foundNumber;
 
217
      item->getItem()->setHidden(!visible);
 
218
   }
 
219
   m_pContactView->expandAll();
 
220
}
 
221
 
 
222
 
 
223
/*****************************************************************************
 
224
 *                                                                           *
 
225
 *                                Drag and Drop                              *
 
226
 *                                                                           *
 
227
 ****************************************************************************/
 
228
 
 
229
///Serialize informations to be used for drag and drop
 
230
QMimeData* ContactTree::mimeData( const QList<QTreeWidgetItem *> items) const
 
231
{
 
232
   kDebug() << "An history call is being dragged";
 
233
   if (items.size() < 1) {
 
234
      return NULL;
 
235
   }
 
236
 
 
237
   QMimeData *mimeData = new QMimeData();
 
238
 
 
239
   //Contact
 
240
   if (dynamic_cast<QNumericTreeWidgetItem_hist*>(items[0])) {
 
241
      QNumericTreeWidgetItem_hist* item = dynamic_cast<QNumericTreeWidgetItem_hist*>(items[0]);
 
242
      if (item->widget != 0) {
 
243
         mimeData->setData(MIME_CONTACT, item->widget->getContact()->getUid().toUtf8());
 
244
      }
 
245
      else if (!item->number.isEmpty()) {
 
246
         mimeData->setData(MIME_PHONENUMBER, item->number.toUtf8());
 
247
      }
 
248
   }
 
249
   else {
 
250
      kDebug() << "the item is not a call";
 
251
   }
 
252
   return mimeData;
 
253
}
 
254
 
 
255
///Handle data being dropped on the widget
 
256
bool ContactTree::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action)
 
257
{
 
258
   Q_UNUSED(index)
 
259
   Q_UNUSED(action)
 
260
   Q_UNUSED(parent)
 
261
 
 
262
   QByteArray encodedData = data->data(MIME_CALLID);
 
263
 
 
264
   kDebug() << "In history import"<< QString(encodedData);
 
265
 
 
266
   return false;
 
267
}
 
268
 
 
269
 
 
270
/*****************************************************************************
 
271
 *                                                                           *
 
272
 *                                  Setters                                  *
 
273
 *                                                                           *
 
274
 ****************************************************************************/
 
275
 
 
276
///Show or hide the history list
 
277
void ContactDock::setHistoryVisible(bool visible)
 
278
{
 
279
   kDebug() << "Toggling history visibility";
 
280
   m_pCallView->setVisible(visible);
 
281
   ConfigurationSkeleton::setDisplayContactCallHistory(visible);
 
282
}
 
283
 
 
284
 
 
285
/*****************************************************************************
 
286
 *                                                                           *
 
287
 *                             Keyboard handling                             *
 
288
 *                                                                           *
 
289
 ****************************************************************************/
 
290
 
 
291
///Handle keypresses ont the dock
 
292
void ContactDock::keyPressEvent(QKeyEvent* event) {
 
293
   int key = event->key();
 
294
   if(key == Qt::Key_Escape)
 
295
      m_pFilterLE->setText(QString());
 
296
   else if(key == Qt::Key_Return || key == Qt::Key_Enter) {}
 
297
   else if((key == Qt::Key_Backspace) && (m_pFilterLE->text().size()))
 
298
      m_pFilterLE->setText(m_pFilterLE->text().left( m_pFilterLE->text().size()-1 ));
 
299
   else if (!event->text().isEmpty() && !(key == Qt::Key_Backspace))
 
300
      m_pFilterLE->setText(m_pFilterLE->text()+event->text());
 
301
}
 
 
b'\\ No newline at end of file'