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

doc_lister.cpp

Go to the documentation of this file.
00001 /*
00002  * GPLv2 zecke@handhelds.org
00003  */
00004 
00005 #include "doc_lister.h"
00006 
00007 #include <lib/slavemaster.h>
00008 
00009 /* OPIE */
00010 #include <opie2/odebug.h>
00011 #include <qpe/config.h>
00012 #include <qpe/qpeapplication.h>
00013 #include <qpe/applnk.h>
00014 #include <opie2/oglobal.h>
00015 
00016 #include <qtopia/private/categories.h>
00017 #include <qtopia/categoryselect.h>
00018 
00019 using namespace Opie::Core;
00020 
00021 /* QT */
00022 #include <qdir.h>
00023 #include <qfileinfo.h>
00024 #include <qtopia/qcopenvelope_qws.h>
00025 
00026 Doc_DirLister::Doc_DirLister()
00027     : PDirLister( "doc_dir_lister" )
00028 {
00029     /* connect the signals */
00030     m_catFilter = 0;
00031     SlaveMaster* master = SlaveMaster::self();
00032     connect( master, SIGNAL(sig_start()), this, SIGNAL(sig_start()) );
00033     connect( master, SIGNAL(sig_end()),   this, SIGNAL(sig_end()) );
00034     connect( master, SIGNAL(sig_thumbInfo(const QString&, const QString&)),
00035              this, SLOT(slotThumbInfo(const QString&, const QString&)) );
00036     connect( master, SIGNAL(sig_fullInfo(const QString&, const QString&)),
00037              this, SLOT(slotFullInfo(const QString&, const QString&)) );
00038     connect( master, SIGNAL(sig_thumbNail(const QString&, const QPixmap&)),
00039              this, SLOT(slotThumbNail(const QString&, const QPixmap&)) );
00040     m_docreads = false;
00041     syschannel = new QCopChannel("QPE/System", this);
00042     connect(syschannel, SIGNAL(received(const QCString&,const QByteArray&)),
00043         this, SLOT(systemMsg(const QCString&,const QByteArray&)) );
00044 }
00045 
00046 Doc_DirLister::~Doc_DirLister()
00047 {
00048 }
00049 
00050 QString Doc_DirLister::defaultPath()const {
00051     return QString::null;
00052 }
00053 
00054 bool Doc_DirLister::matchCat(const AppLnk* app)const
00055 {
00056     if (!app) return false;
00057     if (m_catFilter==0 || app->categories().contains(m_catFilter) || m_catFilter == -1 && app->categories().count() == 0 ) {
00058         return true;
00059     }
00060     return false;
00061 }
00062 
00063 QString Doc_DirLister::setStartPath(const QString&) {
00064     static const QString Mtype_str("image/jpeg;image/gif;image/bmp;image/png");
00065     if (!m_docreads) {
00066         Global::findDocuments(&m_ds,Mtype_str);
00067         m_docreads = true;
00068     }
00069     return QString::null;
00070 }
00071 
00072 QString Doc_DirLister::currentPath()const
00073 {
00074     return QString::null;
00075 }
00076 
00077 
00078 QStringList Doc_DirLister::folders()const {
00079     return QStringList();
00080 }
00081 
00082 QStringList Doc_DirLister::files()const {
00083     QStringList out;
00084     QListIterator<DocLnk> dit(m_ds.children());
00085     for( ; dit.current(); ++dit) {
00086         /* check if the real file exists! */
00087         if (!(*dit)->fileKnown()||!QFile::exists( (*dit)->file())) continue;
00088         if (!matchCat((*dit))) continue;
00089         QString s = (*dit)->name();
00090         s+=char(0);
00091         s+=(*dit)->file();
00092         out.append(s);
00093     }
00094     return out;
00095 }
00096 
00097 void Doc_DirLister::deleteImage( const QString& f)
00098 {
00099     /*
00100      * find the file in the set of doclnks
00101      */
00102     QListIterator<DocLnk> dit(m_ds.children());
00103     for( ; dit.current(); ++dit) {
00104         if ( f == (*dit)->file() ) {
00105             (*dit)->removeFiles();
00106             return;
00107         }
00108     }
00109 }
00110 
00111 void Doc_DirLister::thumbNail( const QString& str, int w, int h)
00112 {
00113     SlaveMaster::self()->thumbNail( str, w, h );
00114 }
00115 
00116 QImage Doc_DirLister::image( const QString& str, Factor f, int m)
00117 {
00118     return SlaveMaster::self()->image(str, f, m );
00119 }
00120 
00121 void Doc_DirLister::imageInfo( const QString& str) {
00122     SlaveMaster::self()->thumbInfo( str );
00123 }
00124 
00125 void Doc_DirLister::fullImageInfo( const QString& str) {
00126     SlaveMaster::self()->imageInfo(str);
00127 }
00128 
00129 void Doc_DirLister::slotFullInfo(const QString&f, const QString&t)
00130 {
00131     emit sig_fullInfo(f, t);
00132 }
00133 
00134 void Doc_DirLister::slotThumbInfo(const QString&f, const QString&t)
00135 {
00136     emit sig_thumbInfo(f, t);
00137 }
00138 
00139 void Doc_DirLister::slotThumbNail(const QString&f, const QPixmap&p)
00140 {
00141     emit sig_thumbNail(f, p);
00142 }
00143 
00144 QString Doc_DirLister::nameToFname(const QString&name)const
00145 {
00146     return name;
00147 }
00148 
00149 QString Doc_DirLister::dirUp( const QString& p ) const{
00150     return p;
00151 }
00152 
00153 QWidget* Doc_DirLister::widget(QWidget*parent)
00154 {
00155     CategorySelect * catmb = new CategorySelect(parent);
00156     Categories cats( 0 );
00157     cats.load( categoryFileName() );
00158     QArray<int> vl( 0 );
00159     catmb->setCategories( vl, "Document View", // No tr
00160         "Document View" );
00161     catmb->setRemoveCategoryEdit( TRUE );
00162     catmb->setAllCategories( TRUE );
00163     connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int)));
00164     catmb->setCurrentCategory(-2);
00165     return catmb;
00166 }
00167 
00168 void Doc_DirLister::showCategory(int which)
00169 {
00170     odebug<<"Show cat " << which << oendl;
00171     m_catFilter = which==-2?0:which;
00172     setStartPath("");
00173     odebug<<"Show cat before emit" << oendl;
00174     emit sig_reloadDir();
00175     odebug<<"Show cat - emit signal finished" << oendl;
00176 }
00177 
00178 void Doc_DirLister::systemMsg(const QCString &msg, const QByteArray &data)
00179 {
00180     if ( msg != "linkChanged(QString)"||!m_docreads) {
00181         return;
00182     }
00183 #if 0
00184     // makes big problems on zaurus!
00185     QString link;
00186     QDataStream stream( data, IO_ReadOnly );
00187     stream >> link;
00188     odebug << "Doc_DirLister systemMsg -> linkchanged( " << link << " )" << oendl;
00189     if ( link.isNull() || OGlobal::isAppLnkFileName(link) ) {
00190         return;
00191     }
00192     QListIterator<DocLnk> dit(m_ds.children());
00193     bool must_reload = false;
00194     bool found = false;
00195     while ( dit.current() ) {
00196         DocLnk *doc = dit.current();
00197         ++dit;
00198         if (doc->linkFile() == link) {
00199             found = true;
00200             DocLnk* dl = new DocLnk(link);
00201             if (dl->fileKnown()) {
00202                 // changing
00203                 m_ds.add(dl);
00204             } else {
00205                 delete dl;
00206             }
00207             if (matchCat(doc) || matchCat(dl)) {
00208                 must_reload = true;
00209             }
00210             m_ds.remove( doc ); // remove old link from docLnkSet
00211             delete doc;
00212         }
00213     }
00214     if (must_reload) {
00215         setStartPath("");
00216         emit sig_reloadDir();
00217     }
00218 #endif
00219 }

Generated on Sat Nov 5 16:17:30 2005 for OPIE by  doxygen 1.4.2