~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to src/infodlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2006-01-20 00:20:36 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060120002036-7nw6yo6totip0ee5
Tags: 0.10-2
* Added upstream changelog (Closes: Bug#327748)
* Mention --no-gpg and --no-gpg-agent in manpage (Closes: Bug#204416)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include<qlineedit.h>
28
28
#include<qmessagebox.h>
29
29
#include<qtextedit.h>
 
30
#include<qfiledialog.h> 
 
31
#include<qbuffer.h>
30
32
#include"xmpp.h"
 
33
#include"msgmle.h"
 
34
#include"userlist.h"
31
35
#include"xmpp_vcard.h"
32
36
#include"xmpp_tasks.h"
33
37
#include"psiaccount.h"
36
40
#include"vcardfactory.h"
37
41
#include"iconwidget.h"
38
42
 
 
43
 
39
44
using namespace XMPP;
40
 
 
 
45
                
41
46
class InfoDlg::Private
42
47
{
43
48
public:
52
57
        int actionType;
53
58
        JT_VCard *jt;
54
59
        bool cacheVCard;
 
60
        PsiTextView* te_status;
 
61
        QByteArray photo;
55
62
};
56
63
 
57
64
InfoDlg::InfoDlg(int type, const Jid &j, const VCard &vcard, PsiAccount *pa, QWidget *parent, const char *name, bool cacheVCard)
66
73
        d->jt = 0;
67
74
        d->pa->dialogRegister(this, j);
68
75
        d->cacheVCard = cacheVCard;
69
 
 
 
76
        d->te_status = NULL;
70
77
        d->busy = busy;
71
78
 
72
79
        te_desc->setTextFormat(QTextEdit::PlainText);
77
84
#endif
78
85
 
79
86
        connect(pb_refresh, SIGNAL(clicked()), this, SLOT(doRefresh()));
 
87
        connect(pb_refresh, SIGNAL(clicked()), this, SLOT(updateStatus()));
80
88
        connect(te_desc, SIGNAL(textChanged()), this, SLOT(textChanged()));
 
89
        connect(pb_open, SIGNAL(clicked()), this, SLOT(selectPhoto()));
 
90
        connect(pb_clear, SIGNAL(clicked()), this, SLOT(clearPhoto()));
81
91
 
82
92
        if(d->type == Self) {
83
93
                connect(pb_submit, SIGNAL(clicked()), this, SLOT(doSubmit()));
84
94
        }
85
95
        else {
 
96
                // Add a status tab
 
97
                d->te_status = new PsiTextView(tabwidget);
 
98
                d->te_status->setReadOnly(true);
 
99
                d->te_status->setTextFormat(RichText);
 
100
                tabwidget->addTab(d->te_status, tr("Status"));
 
101
                updateStatus();
 
102
 
 
103
                // Hide buttons
86
104
                pb_submit->hide();
 
105
                pb_open->hide();
 
106
                pb_clear->hide();
 
107
                ly_photo->setSpacing(0);
87
108
                setReadOnly(true);
88
109
        }
89
110
 
206
227
        le_title->setText( i.title() );
207
228
        le_role->setText( i.role() );
208
229
        te_desc->setText( i.desc() );
 
230
        
 
231
        if ( !i.photo().isEmpty() ) {
 
232
                //printf("There is a picture...\n");
 
233
                d->photo = i.photo();
 
234
                updatePhoto();
 
235
        }
 
236
        else
 
237
                clearPhoto();
209
238
 
210
239
        setEdited(false);
211
240
}
212
241
 
 
242
void InfoDlg::updatePhoto() 
 
243
{
 
244
        int max_width = label_photo->width() - 20; // FIXME: Ugly magic number
 
245
        int max_height = label_photo->height() - 20; // FIXME: Ugly magic number
 
246
        
 
247
        QImage img(d->photo);
 
248
        QImage img_scaled;
 
249
        if (img.width() > max_width || img.height() > max_height) {
 
250
                img_scaled = img.smoothScale(max_width, max_height,QImage::ScaleMin);
 
251
        }
 
252
        else {
 
253
                img_scaled = img;
 
254
        }
 
255
        label_photo->setPixmap(QPixmap(img_scaled));
 
256
}
 
257
 
213
258
void InfoDlg::fieldsEnable(bool x)
214
259
{
215
260
        le_fullname->setEnabled(x);
218
263
        le_email->setEnabled(x);
219
264
        le_homepage->setEnabled(x);
220
265
        le_phone->setEnabled(x);
 
266
        pb_open->setEnabled(x);
 
267
        pb_clear->setEnabled(x);
221
268
 
222
269
        le_street->setEnabled(x);
223
270
        le_ext->setEnabled(x);
377
424
                list << p;
378
425
                v.setPhoneList( list );
379
426
        }
 
427
        
 
428
        if ( !d->photo.isEmpty() ) {
 
429
                //printf("Adding a pixmap to the vCard...\n");
 
430
                v.setPhoto( d->photo );
 
431
        }
380
432
 
381
433
        if ( !le_street->text().isEmpty() ||
382
434
             !le_ext->text().isEmpty()    ||
419
471
{
420
472
        d->te_edited = true;
421
473
}
 
474
 
 
475
/*!
 
476
 * Opens a file browser dialog, and if selected, calls the setPreviewPhoto with the consecuent path.
 
477
 * \see setPreviewPhoto(const QString& path)
 
478
*/
 
479
void InfoDlg::selectPhoto()
 
480
{
 
481
        while(1) {
 
482
                if(option.lastPath.isEmpty())
 
483
                        option.lastPath = QDir::homeDirPath();
 
484
                QString str = QFileDialog::getOpenFileName(option.lastPath, tr("Images (*.png *.xpm *.jpg *.PNG *.XPM *.JPG)"), this, 0, tr("Choose a file"));
 
485
                if(!str.isEmpty()) {
 
486
                        QFileInfo fi(str);
 
487
                        if(!fi.exists()) {
 
488
                                QMessageBox::information(this, tr("Error"), tr("The file specified does not exist."));
 
489
                                continue;
 
490
                        }
 
491
                        option.lastPath = fi.dirPath();
 
492
                        //printf(QDir::convertSeparators(fi.filePath()));
 
493
                        
 
494
                        // put the image in the preview box
 
495
                        setPreviewPhoto(str);
 
496
                }
 
497
                break;
 
498
        }
 
499
        
 
500
}
 
501
 
 
502
/*!
 
503
 * Loads the image from the requested URL, and inserts the resized image into the preview box.
 
504
 * \param path image file to load
 
505
*/
 
506
void InfoDlg::setPreviewPhoto(const QString& path)
 
507
{
 
508
        QFile photo_file(path);
 
509
        if (!photo_file.open(IO_ReadOnly))
 
510
                return;
 
511
        
 
512
        QByteArray photo_data = photo_file.readAll();
 
513
        QImage photo_image(photo_data);
 
514
        if(!photo_image.isNull()) {
 
515
                d->photo = photo_data;
 
516
                updatePhoto();
 
517
                d->te_edited = true;
 
518
        }
 
519
}
 
520
 
 
521
/*!
 
522
 * Clears the preview image box and marks the te_edited signal in the private.
 
523
*/
 
524
void InfoDlg::clearPhoto()
 
525
{
 
526
        // this will cause the pixmap disappear
 
527
        label_photo->setText(tr("Picture not\navailable"));
 
528
        d->photo = QByteArray();
 
529
        
 
530
        // the picture changed, so notify there are some changes done
 
531
        d->te_edited = true;
 
532
}
 
533
 
 
534
/*!
 
535
 * Updates the status info of the contact
 
536
 */
 
537
void InfoDlg::updateStatus()
 
538
{
 
539
        if (!d->te_status)
 
540
                return;
 
541
 
 
542
        UserListItem *u = d->pa->find(d->jid);
 
543
        if(u) {
 
544
                d->te_status->setText(u->makeDesc());
 
545
        }
 
546
        else {
 
547
                d->te_status->clear();
 
548
        }
 
549
}