summaryrefslogtreecommitdiffabout
path: root/libkabcwrap/addresseedialog.cpp
blob: e0fe354f72b068c691c76d68d8ae9f3e0214260c (plain)
1
2
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <qlistview.h>
#include <qmessagebox.h>
#include <qapplication.h>
#include "addresseedialog.h"
#include "select_addressee_base.h"

using namespace KABC;

Addressee AddresseeDialog::getAddressee( QWidget *parent ) {
 
  Addressee result;
  if (!getInterface()) {
    QMessageBox::warning(parent,"Plugin missing", "Plugins for Qtopia/Opie\naddressbook missing.\nPlease install\nlibqtopiakabc.so/libopiekabc.so\nunder $QPEDIR/plugins/korganizer.\nQtopia-plugin needs libqpepim.", 0L );
  } else {

      // qDebug("Start: AddresseeDialog::getAddressee");

  Addressee::List list = getAddresseesFromPlugin();

   SelectAddressee *selAddressee = new SelectAddressee(parent,"SelectAddressee", true);
   QListView *contactList = selAddressee->contactList;
   contactList->setSelectionMode(QListView::Single);
   if (!contactList) {
     Addressee emptyAddressee;
     return emptyAddressee;
   }

   for (uint i=0; i < list.count(); i++) {
     Addressee a = list[i];
     QString fullName = a.formattedName();
     QString defaultEmail = a.preferredEmail();
     //qDebug("Adding " + fullName);
     QListViewItem *item = new QListViewItem(contactList, fullName, defaultEmail);
   } 
   if ( QApplication::desktop()->width() < 480 ) {
       selAddressee->setMinimumWidth( 220 ); 
   } else {
       selAddressee->setMinimumWidth( 440 ); 
   }
   if (selAddressee->exec()) {
     QListViewItem *selectedItem = contactList->selectedItem();
     if (selectedItem) {
       uint i=0;
       for (i=0; i < list.count() && (list[i].formattedName() != selectedItem->text(0)); i++);
       if (i<list.count()) { 
         result = list[i];
       }
     }
   }
   delete selAddressee;
   //qDebug("End: AddresseeDialog::getAddressee");
}  
  return result;

}

Addressee::List AddresseeDialog::getAddressees( QWidget *parent ) {
    //qDebug("Start: AddresseeDialog::getAddressees");
  
  KOAddressBookInterface *iface = getInterface();

  Addressee::List results;
  if (iface) {
    Addressee a = getAddressee(parent);
    results.append(a);
  }
  //qDebug("End: AddresseeDialog::getAddressees");
  return results;
}