00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qpe/resource.h>
00021 #include "viewatt.h"
00022 #include <qwhatsthis.h>
00023 #include <qpe/applnk.h>
00024 #include <qpe/mimetype.h>
00025
00026 ViewAtt::ViewAtt(QWidget *parent, const char *name, WFlags f)
00027 : QMainWindow(parent, name, f)
00028 {
00029 setCaption(tr("Exploring attatchments"));
00030
00031 setToolBarsMovable( FALSE );
00032 bar = new QToolBar(this);
00033 installButton = new QAction( tr( "Install" ), Resource::loadPixmap( "exec" ), QString::null, CTRL + Key_C, this, 0 );
00034 connect(installButton, SIGNAL(activated()), this, SLOT(install()) );
00035 installButton->setWhatsThis(tr("Click here to install the attachment to your Documents"));
00036
00037 listView = new QListView(this, "AttView");
00038 listView->addColumn( tr("Attatchment") );
00039 listView->addColumn( tr("Type") );
00040 listView->addColumn( tr("Installed") );
00041 setCentralWidget(listView);
00042 QWhatsThis::add(listView,QWidget::tr("This is an overview about all attachments in the mail"));
00043 }
00044
00045 void ViewAtt::update(Email *mailIn, bool inbox)
00046 {
00047 QListViewItem *item;
00048 Enclosure *ePtr;
00049
00050
00051
00052 listView->clear();
00053 if (inbox) {
00054 bar->clear();
00055 installButton->addTo( bar );
00056 bar->show();
00057 } else {
00058 bar->hide();
00059 }
00060
00061 mail = mailIn;
00062 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
00063
00064 QString isInstalled = tr("No");
00065 if (ePtr->installed)
00066 isInstalled = tr("Yes");
00067 item = new QListViewItem(listView, ePtr->originalName, ePtr->contentType, isInstalled);
00068
00069 const QString& mtypeDef=(const QString&) ePtr->contentType+"/"+ePtr->contentAttribute;
00070
00071 MimeType mt(mtypeDef);
00072
00073 item->setPixmap(0, mt.pixmap());
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 }
00091 }
00092
00093 void ViewAtt::install()
00094 {
00095 Enclosure *ePtr, *selPtr;
00096 QListViewItem *item;
00097 QString filename;
00098 DocLnk d;
00099
00100 item = listView->selectedItem();
00101 if (item != NULL) {
00102 filename = item->text(0);
00103 selPtr = NULL;
00104 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
00105 if (ePtr->originalName == filename)
00106 selPtr = ePtr;
00107 }
00108
00109 if (selPtr == NULL) {
00110 qWarning("Internal error, file is not installed to documents");
00111 return;
00112 }
00113
00114 d.setName(selPtr->originalName);
00115 d.setFile(selPtr->path + selPtr->name);
00116 d.setType(selPtr->contentType + "/" + selPtr->contentAttribute);
00117 d.writeLink();
00118 selPtr->installed = TRUE;
00119 item->setText(2, tr("Yes"));
00120 }
00121 }