Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

addatt.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2001 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qt Palmtop Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 #include <qlayout.h>
00021 #include <qhbox.h>
00022 #include <qdir.h>
00023 #include <qstringlist.h>
00024 #include <qpe/resource.h>
00025 #include "addatt.h"
00026 
00027 FileItem::FileItem(QListView *parent, DocLnk* dl)
00028                 : QListViewItem(parent)
00029 {
00030         /*file = fileInfo;
00031         type = fileType;*/
00032         
00033         doclnk=dl;
00034 
00035         setText(0, doclnk->name());
00036         
00037 /*      if (fileType == "Picture") {
00038                 setPixmap(0, Resource::loadPixmap("pixmap"));
00039         } else if (fileType == "Document") {
00040                 setPixmap(0, Resource::loadPixmap("txt"));      
00041         } else if (fileType == "Sound") {
00042                 setPixmap(0, Resource::loadPixmap("play"));
00043         } else if (fileType == "Movie") {
00044                 setPixmap(0, Resource::loadPixmap("MPEGPlayer"));
00045         } else if (fileType == "File") {
00046                 setPixmap(0, Resource::loadPixmap("exec"));
00047         }*/
00048 }
00049 
00050 FileItem::~FileItem()
00051 {
00052         if (doclnk!=NULL) delete doclnk;
00053         doclnk=NULL;
00054 }
00055 
00056 AddAtt::AddAtt(QWidget *parent, const char *name, WFlags f)
00057         : QDialog(parent, name, f)
00058 {
00059         setCaption(tr("Adding attachments") );
00060 
00061         QGridLayout *top = new QGridLayout(this, 1,1 );
00062         
00063         QHBox *buttons=new QHBox(this);
00064         /*fileCategoryButton = new QPushButton(this);*/
00065         attachButton = new QPushButton(tr("attach..."), buttons);
00066         removeButton = new QPushButton(tr("Remove"), buttons);
00067 
00068         /*fileCategories = new QPopupMenu(fileCategoryButton);
00069         fileCategoryButton->setPopup(fileCategories);
00070         fileCategories->insertItem("Document");
00071         fileCategories->insertItem("Picture");
00072         fileCategories->insertItem("Sound");
00073         fileCategories->insertItem("Movie");
00074         fileCategories->insertItem("File");
00075 
00076         fileCategoryButton->setText("Document");
00077         top->addWidget(fileCategoryButton, 0, 0);*/
00078         
00079 
00080         top->addWidget(buttons,1,0);
00081         //buttons->addWidget(attachButton,0,0);
00082         //buttons->addWidget(removeButton,0,1);
00083 
00084         //connect(fileCategories, SIGNAL(activated(int)), this,
00085         //      SLOT(fileCategorySelected(int)) );*/
00086         connect(attachButton, SIGNAL(clicked()), this,
00087                 SLOT(addattachment()) );
00088         connect(removeButton, SIGNAL(clicked()), this,
00089                 SLOT(removeattachment()) );
00090         
00091         /*listView = new QListView(this, "AttView");
00092         listView->addColumn("Documents");*
00093         connect(listView, SIGNAL(doubleClicked(QListViewItem*)), this,
00094                 SLOT(addattachment()) );*/
00095         
00096         
00097         attView = new QListView(this, "Selected");
00098         attView->addColumn(tr("Attached"));
00099         attView->addColumn(tr("File type"));
00100         connect(attView, SIGNAL(doubleClicked(QListViewItem*)), this,
00101                 SLOT(removeattachment()) );
00102 
00103         //top->addWidget(ofs, 0,0);
00104         top->addWidget(attView, 0,0);
00105         
00106         clear();
00107         
00108 
00109 }
00110 
00111 void AddAtt::clear()
00112 {
00113         attView->clear();
00114         //getFiles();
00115         modified = FALSE;
00116 }
00117 
00118 /*void AddAtt::fileCategorySelected(int id)
00119 {
00120         fileCategoryButton->setText(fileCategories->text(id));
00121         getFiles();
00122 }*/
00123 
00124 void AddAtt::addattachment()
00125 {       // ### FIXME wrong use -zecke
00126         OFileDialog ofs("Attachments",this,0,0,"/root/Documents");
00127         
00128         ofs.showMaximized();
00129         
00130         if (ofs.exec()==QDialog::Accepted)
00131         {
00132                 DocLnk* dl=new DocLnk(ofs.selectedDocument());
00133                 FileItem* fi=new FileItem(attView,dl);
00134                 fi->setPixmap(0,dl->pixmap());
00135                 fi->setText(1,dl->type());
00136                 attView->insertItem(fi);
00137                 modified = TRUE;        
00138         }
00139 }
00140 
00141 void AddAtt::removeattachment()
00142 {
00143         if (attView->selectedItem() != NULL) 
00144         {
00145                 attView->takeItem(attView->selectedItem());
00146         }
00147         modified = TRUE;
00148 }
00149 
00150 void AddAtt::reject()
00151 {
00152         if (modified) {
00153                 attView->clear();
00154                 modified = FALSE;
00155         }
00156 }
00157 
00158 void AddAtt::accept()
00159 {
00160         modified = FALSE;
00161         hide();
00162 }
00163 
00164 void AddAtt::getFiles()
00165 {
00166         QString path, selected;
00167         
00168         /*listView->clear();
00169         
00170         selected = fileCategoryButton->text();
00171         if (selected == "Picture") {
00172                 path = "../pics/";
00173         } else if (selected == "Document") {
00174                 path = ""                       ;                                       //sub-dirs not decided
00175         } else if (selected == "Sound") {
00176                 path = "../sounds/";                                    //sub-dirs not decided
00177         } else if (selected == "Movie") {
00178                 path = "";                                                              //sub-dirs not decided
00179         } else if (selected == "File") {
00180                 path = "";                                                              //sub-dirs not decided
00181         }
00182 
00183         dir = new QDir(path);
00184         dir->setFilter(QDir::Files);
00185         const QFileInfoList *dirInfoList = dir->entryInfoList();
00186 
00187         QFileInfoListIterator it(*dirInfoList);      // create list iterator
00188 
00189         while ( (fi=it.current()) ) {           // for each file...
00190                 item = new FileItem(lis+ütView, *fi, selected);
00191                 ++it;                               // goto next list element
00192         }*/
00193 }
00194 
00195 QStringList AddAtt::returnattachedFiles()
00196 {
00197         QFileInfo info;
00198         QStringList list;
00199         
00200         item = (FileItem *) attView->firstChild();
00201         
00202         
00203         while (item != NULL) {
00204                 DocLnk* dl=item->getDocLnk();
00205                 list+=dl->file();
00206                 /*info = item->getFileInfo();
00207                 list += info.filePath();*/
00208                 item = (FileItem *) item->nextSibling();
00209         }
00210         return list;
00211 }
00212 
00213 QStringList AddAtt::returnFileTypes()
00214 {
00215         QStringList list;
00216                 
00217         item = (FileItem *) attView->firstChild();
00218                         
00219         while (item != NULL) {
00220                 list += item->getDocLnk()->type();
00221                 item = (FileItem *) item->nextSibling();
00222         }
00223         return list;
00224 }

Generated on Sat Nov 5 16:18:08 2005 for OPIE by  doxygen 1.4.2