-rw-r--r-- | libopie/libopie.pro | 33 | ||||
-rw-r--r-- | libopie/ofileselector/ofileselector.cpp | 249 | ||||
-rw-r--r-- | libopie/ofileselector/ofileselector.h | 17 | ||||
-rw-r--r-- | libopie/ofileselector/olister.h | 1 | ||||
-rw-r--r-- | libopie/pim/opimrecord.cpp | 26 | ||||
-rw-r--r-- | libopie/pim/opimrecord.h | 4 | ||||
-rw-r--r-- | libopie/pim/otodo.cpp | 265 | ||||
-rw-r--r-- | libopie/pim/otodo.h | 22 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimrecord.cpp | 26 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimrecord.h | 4 | ||||
-rw-r--r-- | libopie2/opiepim/otodo.cpp | 265 | ||||
-rw-r--r-- | libopie2/opiepim/otodo.h | 22 |
12 files changed, 337 insertions, 597 deletions
diff --git a/libopie/libopie.pro b/libopie/libopie.pro index 6c47e86..70be6ac 100644 --- a/libopie/libopie.pro +++ b/libopie/libopie.pro @@ -1,40 +1,61 @@ TEMPLATE = lib CONFIG += qte warn_on release -HEADERS = ofontmenu.h ofileselector.h \ - ofiledialog.h tododb.h \ +HEADERS = ofontmenu.h \ + tododb.h \ todoevent.h todoresource.h \ todovcalresource.h xmltree.h \ colordialog.h colorpopupmenu.h \ oclickablelabel.h oprocctrl.h \ oprocess.h odevice.h \ otimepicker.h otabwidget.h \ - otabbar.h otabinfo.h -SOURCES = ofontmenu.cc ofileselector.cc \ - ofiledialog.cc xmltree.cc \ + otabbar.h otabinfo.h \ + ofileselector/ofiledialog.h \ + ofileselector/ofilelistview.h \ + ofileselector/ofileselector.h \ + ofileselector/ofileselectoritem.h \ + ofileselector/ofileview.h \ + ofileselector/olister.h \ + ofileselector/olocallister.h \ + ofileselector/ofileselectormain.h \ + pim/opimrecord.h \ + pim/otodo.h + +SOURCES = ofontmenu.cc \ + xmltree.cc \ tododb.cpp todoevent.cpp \ todovcalresource.cpp colordialog.cpp \ colorpopupmenu.cpp oclickablelabel.cpp \ oprocctrl.cpp oprocess.cpp \ odevice.cpp otimepicker.cpp \ - otabwidget.cpp otabbar.cpp + otabwidget.cpp otabbar.cpp \ + ofileselector/ofiledialog.cpp \ + ofileselector/ofilelistview.cpp \ + ofileselector/ofileselector.cpp \ + ofileselector/ofileselectoritem.cpp \ + ofileselector/ofileview.cpp \ + ofileselector/olister.cpp \ + ofileselector/olocallister.cpp \ + ofileselector/ofileselectormain.cpp \ + pim/opimrecord.cpp \ + pim/otodo.cpp TARGET = opie INCLUDEPATH += $(OPIEDIR)/include DESTDIR = $(QTDIR)/lib$(PROJMAK) #VERSION = 1.0.0 INTERFACES = otimepickerbase.ui TRANSLATIONS = ../i18n/de/libopie.ts \ ../i18n/en/libopie.ts \ ../i18n/es/libopie.ts \ ../i18n/fr/libopie.ts \ ../i18n/hu/libopie.ts \ ../i18n/ja/libopie.ts \ ../i18n/ko/libopie.ts \ ../i18n/no/libopie.ts \ ../i18n/pl/libopie.ts \ ../i18n/pt/libopie.ts \ ../i18n/pt_BR/libopie.ts \ ../i18n/sl/libopie.ts \ ../i18n/zh_CN/libopie.ts \ ../i18n/zh_TW/libopie.ts diff --git a/libopie/ofileselector/ofileselector.cpp b/libopie/ofileselector/ofileselector.cpp index 98b61f7..c52aa62 100644 --- a/libopie/ofileselector/ofileselector.cpp +++ b/libopie/ofileselector/ofileselector.cpp @@ -1,1051 +1,1022 @@ #include <qcheckbox.h> #include <qcombobox.h> #include <qheader.h> #include <qlabel.h> #include <qabstractlayout.h> #include <qlayout.h> #include <qlineedit.h> #include <qlistview.h> #include <qmessagebox.h> #include <qpainter.h> #include <qpushbutton.h> #include <qwidgetstack.h> #include <qpopupmenu.h> #include <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include <qtimer.h> #include <qpe/qpeapplication.h> #include <qpe/applnk.h> #include <qpe/global.h> #include <qpe/mimetype.h> #include <qpe/resource.h> #include <qpe/storage.h> #include <unistd.h> #include <stdlib.h> #include <sys/stat.h> #include "ofileview.h" +#include "ofileselectormain.h" #include "ofileselector.h" +#include "olocallister.h" #include "olister.h" QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; namespace { /* let's find the index for a specified string */ int indexByString( const QComboBox *box, const QString &str ){ int index= 0; for(int i= 0; i < box->count(); i++ ){ /* found */ if( str == box->text(i ) ){ index= i; break; } } return index; } } OFileSelector::OFileSelector( QWidget *wid, int mode, int selector, const QString &dirName, const QString &fileName, const QMap<QString,QStringList>& mimeTypes) : QWidget( wid, "OFileSelector") { m_mimetypes = mimeTypes; if (mode == Save ) m_name = fileName; initVars(); m_mode = mode; m_selector = selector; m_currentDir = dirName; init(); } OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent, const char *name, bool newVisible, bool closeVisible ) : QWidget( parent, name ) { /* update the mimefilter */ if (!mimeFilter.isEmpty() ) { QStringList list = QStringList::split(";", mimeFilter ); m_mimetypes.insert(mimeFilter, list ); } initVars(); m_currentDir = QPEApplication::documentDir(); m_mode = Fileselector; m_selector = Normal; m_shClose = closeVisible; m_shNew = newVisible; m_shLne = false; m_shPerm = false; m_shYesNo = false; init(); } OFileSelector::~OFileSelector() { } void OFileSelector::setNewVisible( bool visible ) { m_shNew = visible; - if( m_selector == Normal ){ - delete m_select; - // we need to initialize but keep the selected mimetype - QString mime = currentMimeType(); - m_select = new FileSelector( mime , - m_stack, "fileselector", - m_shNew, m_shClose); - - connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), - this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); - connect(m_select, SIGNAL(closeMe() ), - this, SIGNAL(closeMe() ) ); - //connect to close me and other signals as well - m_stack->addWidget( m_select, Normal ); - }else{ + if (m_new ) m_new->show(); } -} void OFileSelector::setCloseVisible( bool visible ) { m_shClose = visible; - if( m_selector == Normal ){ - setNewVisible( m_shNew ); // yeah baby - }else{ + + if( m_close ) m_close->show(); } -} void OFileSelector::reread() { - if( m_selector == Normal ){ - setNewVisible( m_shNew ); // make it a initializeSelector - }else { + if( m_selector == Normal ) + initializeOldSelector(); + else reparse(); } -} const DocLnk *OFileSelector::selected() { DocLnk *lnk = new DocLnk(selectedDocument() ); return lnk; } void OFileSelector::setYesCancelVisible( bool show ) { initializeYes(); // FIXME if YesCancel is not shown we will initialize it to hide it :( m_shYesNo = show; + if( m_shYesNo ) m_boxOk->show(); else m_boxOk->hide(); } void OFileSelector::setToolbarVisible( bool show ) { m_shTool = show; - initializeListView(); // FIXME see above waste of memory if(!m_shTool ){ m_location->hide(); m_up->hide(); m_homeButton->hide(); m_docButton->hide(); }else{ m_location->show(); m_up->show(); m_homeButton->show(); m_docButton->show(); } } void OFileSelector::setPermissionBarVisible( bool show ) { m_shPerm = show; initializePerm(); + if( m_shPerm ) m_checkPerm->show(); else m_checkPerm->hide(); } void OFileSelector::setLineEditVisible( bool show ) { if( show ){ initializeName(); m_boxName->show(); }else{ - if( m_shLne && m_boxName != 0 ){ // check if we showed before this is the way to go + // check if we showed before this is the way to go + if( m_shLne && m_boxName != 0 ) m_boxName->hide(); } - } m_shLne = show; } void OFileSelector::setChooserVisible( bool show ) { m_shChooser = show; initializeChooser(); - if( m_shChooser ){ + + if( m_shChooser ) m_boxView->hide(); - }else{ + else m_boxView->show(); - } + } QCheckBox* OFileSelector::permissionCheckbox() { if( m_selector == Normal ) return 0l; else return m_checkPerm; } bool OFileSelector::setPermission()const { return m_checkPerm == 0 ? false : m_checkPerm->isChecked(); } void OFileSelector::setPermissionChecked( bool check ) { if( m_checkPerm ) m_checkPerm->setChecked( check ); } void OFileSelector::setMode(int mode) // FIXME do direct raising { m_mode = mode; if( m_selector == Normal ) return; } -void OFileSelector::setShowDirs(bool ) +void OFileSelector::setShowDirs(bool dir) { - m_dir = true; + m_dir = dir; + if ( m_selector != Fileselector ) reparse(); } void OFileSelector::setCaseSensetive(bool caSe ) { m_case = caSe; + + if ( m_selector != Fileselector ) reparse(); } void OFileSelector::setShowFiles(bool show ) { m_files = show; reparse(); } /// bool OFileSelector::cd(const QString &path ) { m_currentDir = path; reparse(); return true; } void OFileSelector::setSelector(int mode ) { QString text; switch( mode ){ case Normal: text = tr("Documents"); break; case Extended: text = tr("Files"); break; case ExtendedAll: text = tr("All Files"); break; } slotViewCheck( text ); } void OFileSelector::setPopupFactory(OPopupMenuFactory */*popup*/ ) { /* m_custom = popup; m_showPopup = true; */ } //void OFileSelector::updateL QString OFileSelector::selectedName() const { QString name; if( m_selector == Normal ){ DocLnk lnk = m_select->selectedDocument(); name = lnk.file(); }else { if ( m_shLne ) { name = m_currentDir + "/" +m_edit->text(); }else{ name = m_currentDir + "/" + currentView()->selectedName(); } } return name; } QStringList OFileSelector::selectedNames()const { QStringList list; if( m_selector == Normal ){ list << selectedName(); }else { list << selectedName(); // FIXME implement multiple Selections } return list; } /** If mode is set to the Dir selection this will return the selected path. * * */ QString OFileSelector::selectedPath()const { QString path; if( m_selector == Normal ){ path = QPEApplication::documentDir(); } /*else if( m_selector == Extended || m_selector == ExtendedAll ){ ; }*/ return path; } QStringList OFileSelector::selectedPaths() const { QStringList list; list << selectedPath(); return list; } QString OFileSelector::directory()const { if( m_selector == Normal ) return QPEApplication::documentDir(); return QDir(m_currentDir).absPath(); } int OFileSelector::fileCount() { int count; switch( m_selector ){ case Normal: count = m_select->fileCount(); break; case Extended: case ExtendedAll: default: count = currentView()->fileCount(); break; } return count; } DocLnk OFileSelector::selectedDocument() const { DocLnk lnk; switch( m_selector ){ case Normal:{ lnk = m_select->selectedDocument(); break; } case Extended: case ExtendedAll: default: lnk = DocLnk( selectedName() ); break; } return lnk; } QValueList<DocLnk> OFileSelector::selectedDocuments() const { QValueList<DocLnk> docs; docs.append( selectedDocument() ); return docs; } // slots internal void OFileSelector::slotOk() { emit ok(); } void OFileSelector::slotCancel() { emit cancel(); } /* switch the views */ void OFileSelector::slotViewCheck(const QString &sel) { if( sel == tr("Documents" ) ){ - if( m_select == 0 ){ - // autMime? fix cause now we use All and not the current - // yes currentMime fixes that for us - QString mime = currentMimeType(); - m_select = new FileSelector(mime, - m_stack, "fileselector", - m_shNew, m_shClose); - connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), - this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); - connect(m_select, SIGNAL(closeMe() ), - this, SIGNAL(closeMe() ) ); - //connect to close me and other signals as well - - m_stack->addWidget( m_select, Normal ); - } - m_stack->raiseWidget( Normal ); + initializeOldSelector(); m_selector = Normal; + }else if( sel == tr("Files") ){ m_selector = Extended; - initializeListView(); - reparse(); - m_stack->raiseWidget( Extended ); + + // FIXME call the factory + //reparse(); }else if( sel == tr("All Files") ){ m_selector = ExtendedAll; - initializeListView(); - reparse(); - m_stack->raiseWidget( Extended ); // same widget other QFileFilter +/* see above + reparse(); */ } } QString OFileSelector::currentMimeType() const{ QString mime; QString currentText; - if (m_shChooser ) + if (m_shChooser && m_mimeCheck ) currentText = m_mimeCheck->currentText(); + qWarning("CurrentText" + currentText ); if (tr("All") == currentText ) return QString::null; else if (currentText.isEmpty() ) { ; }else { QMap<QString, QStringList>::ConstIterator it; it = m_mimetypes.find( currentText ); - if ( it == m_mimetypes.end() ) { + if ( it != m_mimetypes.end() ) { mime = it.data().join(";"); }else{ mime = currentText; } } return mime; } void OFileSelector::slotMimeCheck(const QString &mime) { if( m_selector == Normal ){ - //if( m_autoMime ){ - QString newMimeType; - if (mime != tr("All") ) { - QMap<QString, QStringList>::Iterator it; - it = m_mimetypes.find(mime); - if ( it != m_mimetypes.end() ) { - newMimeType = it.data().join(";"); - }else{ - newMimeType = mime; - } - } - delete m_select; - m_select = new FileSelector( newMimeType, - m_stack, "fileselector", - m_shNew, m_shClose); + initializeOldSelector(); - connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), - this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); - connect(m_select, SIGNAL(closeMe() ), - this, SIGNAL(closeMe() ) ); - //connect to close me and other signals as well - m_stack->addWidget( m_select, Normal ); - m_stack->raiseWidget( Normal ); updateMimes(); updateMimeCheck(); m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) ); - //} }else{ // others qWarning("Mime %s", mime.latin1() ); if(m_shChooser ){ qWarning("Current Text %s", m_mimeCheck->currentText().latin1() ); //m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) ); } reparse(); } } /* * Ok if a non dir gets inserted into this combobox * we need to change it * QFileInfo and dirPath will give us the right Dir */ void OFileSelector::slotLocationActivated(const QString &file) { qWarning("slotLocationActivated"); QString name = file.left( file.find("<-", 0, TRUE ) ); QFileInfo info( name ); if ( info.isFile() ) cd(info.dirPath( TRUE ) ); //absolute else cd(name ); reparse(); } void OFileSelector::slotInsertLocationPath(const QString ¤tPath, int count) { QStringList pathList; bool underDog = FALSE; for(int i=0;i<count;i++) { pathList << m_location->text(i); if( m_location->text(i) == currentPath) underDog = TRUE; } if( !underDog) { m_location->clear(); if( currentPath.left(2)=="//") pathList.append( currentPath.right(currentPath.length()-1) ); else pathList.append( currentPath ); m_location->insertStringList( pathList,-1); } } /* * Do not crash anymore * don't try to change dir to a file */ void OFileSelector::locationComboChanged() { QFileInfo info( m_location->lineEdit()->text() ); qWarning("info %s %s", info.dirPath(true).latin1(), m_location->lineEdit()->text().latin1() ); if (info.isFile() ) cd(info.dirPath(TRUE) ); //absolute path else cd( m_location->lineEdit()->text() ); reparse(); } void OFileSelector::init() { m_lay = new QVBoxLayout( this ); m_lay->setSpacing(0 ); - m_stack = new QWidgetStack( this ); + /* take care of the main view... */ + initToolbar(); + + /* initialize the file lister */ + initLister(); if( m_selector == Normal ){ QString mime; if (!m_autoMime) { if (!m_mimetypes.isEmpty() ) { QMap<QString, QStringList>::Iterator it; it = m_mimetypes.begin(); // cause we're in the init mime = it.data().join(";"); } } - m_select = new FileSelector(mime, - m_stack, "fileselector", - m_shNew, m_shClose); - - connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), - this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); - connect(m_select, SIGNAL(closeMe() ), - this, SIGNAL( closeMe() ) ); - //connect to close me and other signals as well - - m_stack->addWidget( m_select, Normal ); - m_stack->raiseWidget( Normal ); - }else{ // we're in init so it will be EXTENDED or EXTENDED_ALL - // and initializeListview will take care of those - // toolbar get's generade in initializeListView - initializeListView( ); // will raise the widget as well - m_stack->raiseWidget( Extended ); + initializeOldSelector(); + }else{ + initializeView(); } - m_lay->addWidget( m_stack, 100 ); // add to the layout 10 = stretch if( m_shLne ) // the LineEdit with the current FileName initializeName(); if( m_shPerm ) // the Permission QCheckBox initializePerm(); if( m_shChooser ) // the Chooser for the view and Mimetypes initializeChooser(); if( m_shYesNo ) // the Yes No button row initializeYes( ); if (m_selector != Normal ) reparse(); } void OFileSelector::updateMimes() { if( m_autoMime ){ m_mimetypes.clear(); m_mimetypes.insert( tr("All"), QString::null ); if( m_selector == Normal ){ DocLnkSet set; Global::findDocuments(&set, QString::null ); QListIterator<DocLnk> dit( set.children() ); for( ; dit.current(); ++dit ){ if( !m_mimetypes.contains( (*dit)->type() ) ) m_mimetypes.insert( (*dit)->type(), (*dit)->type() ); } }// else done in reparse } } void OFileSelector::initVars() { if( m_mimetypes.isEmpty() ) m_autoMime = true; else m_autoMime = false; m_shClose = false; m_shNew = false; m_shTool = true; m_shPerm = false; m_shLne = true; m_shChooser = true; m_shYesNo = true; m_case = false; m_dir = true; m_files = true; m_showPopup = false; + m_mainView = 0l; + m_fileView = 0l; + m_lister = 0l; if(m_pixmaps == 0 ) // init the pixmaps initPics(); // pointers m_location = 0; m_mimeCheck = 0; m_viewCheck = 0; m_homeButton = 0; m_docButton = 0; m_hideButton = 0; m_ok = 0; m_cancel = 0; m_reread = 0; m_up = 0; m_View = 0; m_checkPerm = 0; m_pseudo = 0; m_pseudoLayout = 0; m_select = 0; - m_stack = 0; m_lay = 0; m_Oselector = 0; m_boxToolbar = 0; m_boxOk = 0; m_boxName = 0; m_boxView = 0; - m_custom = 0; m_edit = 0; m_fnLabel = 0; m_new = 0; m_close = 0; } void OFileSelector::initializeName() { /** Name Layout Line * This is the Layout line arranged in * horizontal way each components * are next to each other * but we will only do this if * we didn't initialize a while ago. */ if( m_boxName == 0 ){ m_boxName = new QHBox( this ); // remove this this? or use a QHBox m_fnLabel = new QLabel( m_boxName ); m_fnLabel->setText( tr("Name:") ); m_edit = new QLineEdit( m_boxName ); m_edit->setText( m_name ); //m_boxName->addWidget( m_fnLabel ); m_boxName->setMargin( 5 ); m_boxName->setSpacing( 8 ); //m_boxName->setStretchFactor(m_edit, 100 ); // 100 is stretch factor m_lay->addWidget( m_boxName, 0 ); // add it to the topLevel layout }// else we already initialized // maybe show the components? // } void OFileSelector::initializeYes() { /** The Save Cancel bar * */ if( m_boxOk == 0 ){ m_boxOk = new QHBox( this ); m_ok = new QPushButton( tr("&Save"),m_boxOk , "save" ); m_cancel = new QPushButton( tr("C&ancel"), m_boxOk, "cancel" ); //m_boxOk->addWidget( m_ok ); //m_boxOk->addWidget( m_cancel ); m_boxOk->setMargin( 5 ); m_boxOk->setSpacing( 10 ); m_lay->addWidget( m_boxOk, 0 ); connect( m_ok, SIGNAL( clicked() ), this, SLOT(slotOk() ) ); connect( m_cancel, SIGNAL( clicked() ), this, SLOT( slotCancel() ) ); } } /* * OK m_mimeCheck is a QComboBox we now want to fill * out that combobox * if automime we need to update the mimetypes */ void OFileSelector::updateMimeCheck() { m_mimeCheck->clear(); if (m_autoMime ) { //m_mimeCheck->insertItem( tr("All") ); updateMimes(); } QMap<QString, QStringList>::Iterator it; for (it = m_mimetypes.begin(); it != m_mimetypes.end(); ++it ) { m_mimeCheck->insertItem( it.key() ); } } void OFileSelector::initializeChooser() { if( m_boxView == 0 ){ m_boxView = new QHBox( this ); m_viewCheck = new QComboBox( m_boxView, "view check"); m_mimeCheck = new QComboBox( m_boxView, "mime check"); m_boxView->setSpacing( 8 ); m_lay->addWidget(m_boxView, 0 ); m_viewCheck->insertItem( tr("Documents") ); m_viewCheck->insertItem( tr("Files") ); m_viewCheck->insertItem( tr("All Files") ); /* update to custom views */ + updateMimeCheck(); connect( m_viewCheck, SIGNAL( activated(const QString & ) ), this, SLOT( slotViewCheck(const QString & ) ) ); connect( m_mimeCheck, SIGNAL( activated(const QString & ) ), this, SLOT( slotMimeCheck( const QString & ) ) ); } } -void OFileSelector::initializeListView() -{ - qWarning("initializeListView"); - if( m_pseudo == 0 ){ - qWarning("init"); - m_pseudo = new QWidget( m_stack, "Pseudo Widget"); +/* generate the buttons for the toolbar */ +void OFileSelector::initToolbar() { + m_mainView = new OFileSelectorMain( this ); + + /* now generate the tool bar */ + qWarning( "toolbar" ); + m_pseudo = new QWidget( m_mainView, "Pseudo Widget" ); m_pseudoLayout = new QVBoxLayout( m_pseudo ); - // toolbar + m_boxToolbar = new QHBox( m_pseudo ); - m_boxToolbar->setSpacing(0 ); // next to each other please + m_boxToolbar->setSpacing( 0 ); - // toolbar members - { - // location QComboBox + // tool bar members now m_location = new QComboBox( m_boxToolbar ); m_location->setEditable( TRUE ); m_location->setDuplicatesEnabled( FALSE ); connect( m_location, SIGNAL(activated(const QString &) ), this, SLOT( slotLocationActivated(const QString &) ) ); connect( m_location->lineEdit(), SIGNAL(returnPressed() ), this, SLOT(locationComboChanged() ) ); + // UP Button - m_up = new QPushButton(Resource::loadIconSet("up"),"", + m_up = new QPushButton( Resource::loadIconSet("up"), QString::null, m_boxToolbar,"cdUpButton"); m_up->setFixedSize( QSize( 20, 20 ) ); connect(m_up ,SIGNAL(clicked()),this,SLOT(cdUP() ) ); m_up->setFlat(TRUE); // Home Button m_homeButton = new QPushButton(Resource::loadIconSet("home") , - "", m_boxToolbar); + QString::null, m_boxToolbar ); m_homeButton->setFixedSize( QSize( 20, 20 ) ); connect(m_homeButton,SIGNAL(clicked()),this,SLOT(slotHome() ) ); m_homeButton->setFlat(TRUE); + // Documents Button - m_docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"", - m_boxToolbar,"docsButton"); + m_docButton = new QPushButton( Resource::loadIconSet("DocsIcon"), + QString::null, m_boxToolbar, + "docsButton" ); m_docButton->setFixedSize( QSize( 20, 20 ) ); - connect(m_homeButton,SIGNAL(clicked()),this,SLOT(slotDoc() ) ); - m_docButton->setFlat(TRUE); + m_docButton->setFlat( true ); + connect( m_docButton, SIGNAL(clicked() ), + this, SLOT(slotDoc() ) ); - // Close button + // close button m_close = new QPushButton( Resource::loadIconSet( "close"), "", m_boxToolbar ); connect( m_close, SIGNAL(clicked() ), this, SIGNAL(closeMe() ) ); m_close->setFixedSize( 20, 20 ); m_boxToolbar->setFixedHeight( 20 ); m_pseudoLayout->addWidget(m_boxToolbar ); + /* init the locations */ + initLocations(); + + if( !m_shTool ){ + m_location->hide( ); + m_up->hide( ); + m_homeButton->hide( ); + m_docButton->hide( ); + } + if(!m_shClose ) + m_close->hide(); + + m_mainView->setToolbar( m_pseudo ); + m_lay->addWidget( m_mainView, 100 ); +} +/* initialize the OLocalLister */ +void OFileSelector::initLister() { + m_lister = new OLocalLister(this); +} +/* put default locations into the bar */ +void OFileSelector::initLocations () { + // let;s fill the Location ComboBox StorageInfo storage; const QList<FileSystem> &fs = storage.fileSystems(); QListIterator<FileSystem> it ( fs ); for( ; it.current(); ++it ){ const QString disk = (*it)->name(); const QString path = (*it)->path(); m_location->insertItem(path+ "<-"+disk ); } int count = m_location->count(); m_location->insertItem( m_currentDir ); m_location->setCurrentItem( count ); - // due to the New and Close button we can not simply hide m_boxToolBar to not show it - if( !m_shTool ){ - m_location->hide( ); - m_up->hide( ); - m_homeButton->hide( ); - m_docButton->hide( ); - } - if(!m_shClose ) - m_close->hide(); - //if(!m_shNew) - //m_close->hide(); - - } // off toolbar - // the Main ListView - // make a QWidgetStack first so Views can share the Toolbar - // m_pseudoLayout->addWidget( m_View, 288 ); - m_stack->addWidget( m_pseudo, Extended ); - } } void OFileSelector::initializePerm() { if( m_checkPerm == 0 ){ m_checkPerm = new QCheckBox(tr("Set Permission"), this, "perm"); m_checkPerm->setChecked( false ); m_lay->addWidget( m_checkPerm ); } } void OFileSelector::initPics() { m_pixmaps = new QMap<QString,QPixmap>; QPixmap pm = Resource::loadPixmap( "folder" ); QPixmap lnk = Resource::loadPixmap( "opie/symlink" ); QPainter painter( &pm ); painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); pm.setMask( pm.createHeuristicMask( FALSE ) ); m_pixmaps->insert("dirsymlink", pm ); QPixmap pm2 = Resource::loadPixmap( "lockedfolder" ); QPainter pen(&pm2 ); pen.drawPixmap(pm2.width()-lnk.width(), pm2.height()-lnk.height(), lnk ); pm2.setMask( pm2.createHeuristicMask( FALSE ) ); m_pixmaps->insert("symlinkedlocked", pm2 ); } // if a mime complies with the m_mimeCheck->currentItem bool OFileSelector::compliesMime( const QString &path, const QString &mime ) { if( mime == "All" ) return true; MimeType type( path ); if( type.id() == mime ) return true; return false; } /* check if the mimetype in mime * complies with the one which is current */ /* * We've the mimetype of the file * We need to get the stringlist of the current mimetype * * mime = image/jpeg * QStringList = 'image/*' * or QStringList = image/jpeg;image/png;application/x-ogg * or QStringList = application/x-ogg;image/*; * with all these mime filters it should get acceptes * to do so we need to look if mime is contained inside * the stringlist * if it's contained return true * if not ( I'm no RegExp expert at all ) we'll look if a '/*' * is contained in the mimefilter and then we will * look if both are equal until the '/' */ bool OFileSelector::compliesMime( const QString& mime ) { qWarning("mimetype is %s", mime.latin1() ); QString currentText; if (m_shChooser ) currentText = m_mimeCheck->currentText(); qWarning("current text is %s", currentText.latin1() ); QMap<QString, QStringList>::Iterator it; QStringList list; if ( currentText == tr("All") ) return true; else if ( currentText.isEmpty() && !m_mimetypes.isEmpty() ) { it = m_mimetypes.begin(); list = it.data(); }else if ( currentText.isEmpty() ) return true; else{ it = m_mimetypes.find(currentText ); if ( it == m_mimetypes.end() ) qWarning("not there"), list << currentText; else qWarning("found"), list = it.data(); } if ( list.contains(mime) ) return true; qWarning("list doesn't contain it "); QStringList::Iterator it2; int pos; for ( it2 = list.begin(); it2 != list.end(); ++it2 ) { pos = (*it2).findRev("/*"); if ( pos >= 0 ) { if ( mime.contains( (*it2).left(pos) ) ) return true; } } return false; } void OFileSelector::slotFileSelected( const QString &string ) { if( m_shLne ) m_edit->setText( string ); emit fileSelected( string ); } void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk ) { slotFileSelected( lnk.name() ); // emit fileSelected( lnk ); } void OFileSelector::slotDelete() { /* OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); QStringList list = QStringList::split("->", sel->text(1) ); if( sel->isDir() ){ QString str = QString::fromLatin1("rm -rf ") + sel->directory() +"/" + list[0]; //better safe than sorry switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+list[0], tr("Yes"),tr("No"),0,1,1) ) { case 0: ::system(str.utf8().data() ); break; } } else { QFile::remove( list[0] ); } m_View->takeItem( sel ); delete sel; */ } void OFileSelector::cdUP() { QDir dir( m_currentDir ); dir.cdUp(); if(dir.exists() ){ m_currentDir = dir.absPath(); reparse(); int count = m_location->count(); slotInsertLocationPath( m_currentDir, count); m_location->setCurrentItem( indexByString( m_location, m_currentDir)); //this wont work in all instances // FIXME } } void OFileSelector::slotHome() { cd(QDir::homeDirPath() ); } void OFileSelector::slotDoc() { cd(QPEApplication::documentDir() ); } void OFileSelector::slotNavigate( ) { } // fill the View with life void OFileSelector::reparse() { if( m_selector == Normal ) return; currentView()->clear(); if( m_shChooser) qWarning("reparse %s", m_mimeCheck->currentText().latin1() ); QString currentMimeType; // let's update the mimetype if( m_autoMime ){ m_mimetypes.clear(); // ok we can change mimetype so we need to be able to give a selection if( m_shChooser ) { currentMimeType = m_mimeCheck->currentText(); m_mimeCheck->clear(); // let's find possible mimetypes m_mimetypes = currentLister()->mimeTypes( m_currentDir ); // add them to the chooser updateMimeCheck(); m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currentMimeType ) ); currentMimeType = m_mimeCheck->currentText(); } }else { // no autoMime // let the mimetype be set from out side the m_mimeCheck FEATURE if( m_shChooser ) currentMimeType = m_mimeCheck->currentText(); } // now we got our mimetypes we can add the files currentLister()->reparse( m_currentDir ); /* we're done with adding let's sort */ currentView()->sort(); if( m_shTool ){ m_location->insertItem( m_currentDir ); } // reenable painting and updates } OFileView* OFileSelector::currentView() { - return 0l; + return m_fileView; } OFileView* OFileSelector::currentView() const{ - return 0l; + return m_fileView; } int OFileSelector::filter() { int filter; if ( m_selector == ExtendedAll ) filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; else filter = QDir::Files | QDir::Dirs | QDir::All ; return filter; } int OFileSelector::sorting() { int sort; if (m_case ) sort = ( QDir::IgnoreCase | QDir::Name | QDir::DirsFirst | QDir::Reversed ); else sort = ( QDir::Name | QDir::DirsFirst | QDir::Reversed ); return sort; } void OFileSelector::internFileSelected( const QString& s) { emit fileSelected( s ); } void OFileSelector::internFileSelected( const DocLnk& d ) { emit fileSelected( d ); } void OFileSelector::internContextMenu() { emit contextMenu(); } void OFileSelector::internChangedDir( const QString& s) { emit dirSelected( s ); cd(s ); } void OFileSelector::internChangedDir( const QDir& s) { emit dirSelected( s ); } QPixmap OFileSelector::pixmap( const QString& s ) { return (*m_pixmaps)[s]; } OLister* OFileSelector::currentLister()const { - return 0l; + return m_lister; +} +void OFileSelector::initializeOldSelector() { + qWarning("initializeOldSelector"); + + delete m_select; + + // we need to initialize but keep the selected mimetype + /* we default not to show close and new buttons */ + QString mime = currentMimeType(); + qWarning("MimeType " + mime ); + m_select = new FileSelector( mime , + m_mainView, "fileselector", + FALSE, FALSE); + + connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), + this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); + connect(m_select, SIGNAL(closeMe() ), + this, SIGNAL(closeMe() ) ); + //connect to close me and other signals as well + m_mainView->setWidget( m_select ); } diff --git a/libopie/ofileselector/ofileselector.h b/libopie/ofileselector/ofileselector.h index a7b363f..bf9a26b 100644 --- a/libopie/ofileselector/ofileselector.h +++ b/libopie/ofileselector/ofileselector.h @@ -1,475 +1,484 @@ /* This is based on code and ideas of L. J. Potter ljp@llornkcor.com Thanks a lot =. This file is part of the OPIE Project .=l. Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> .>+-= _;:, .> :=|. This library is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This library is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef opiefileselector_h #define opiefileselector_h #include <qpe/fileselector.h> #include <qdir.h> #include <qwidget.h> #include <qstring.h> #include <qpixmap.h> #include <qstringlist.h> #include <qmap.h> #include <qvaluelist.h> #include <qpe/applnk.h> #include <qlistview.h> /** This is OPIEs FileDialog Widget. You can use it * as a dropin replacement of the fileselector and * or use any of the new features. * This is also a complete FileSave and FileLoad widget * If you look for a Dialog check OFileDialog * */ class DocLnk; class QCheckBox; class QComboBox; class QPushButton; class QGridLayout; class QLineEdit; class QLabel; class QWidgetStack; class QHBoxLayout; class QVBoxLayout; class QPopupMenu; class QFileInfo; class QHBox; class OFileView; class OLister; +class OFileSelectorMain; // /* the mimetypes one name and a list of mimetypes */ typedef QMap< QString, QStringList> MimeTypes; /** * FIXME later */ struct OPopupMenuFactory { OPopupMenuFactory() {} }; /** * Opie the default OFileSelector * It features multiple views. */ class OFileSelector : public QWidget { Q_OBJECT /* friends are evil but I don't want to make the * methods public */ friend class OLister; friend class OFileView; public: /** * The mode of the file selector * Either open, save, fileselector or dir browsing mode * */ enum Mode {Open = 1, Save = 2, Fileselector = 4, Dir = 8 }; /** * Selector. Either Normal for the one shipped with * libqpe or Extended. for the Extended * ExtendedAll also shows 'hidden' files */ enum Selector{Normal=0, Extended = 1, ExtendedAll =2 }; /** * This is reserved for futrue views */ enum View { Dirs = 1, Files = 2, Tree = 4, Icon = 8 }; /** * A c'tor which should be used for advanced mode * @param wid the parent * @param mode the Mode of the Selector * @param selector the current View of the Selector * @param dirName in which dir to start * @param fileName a proposed filename * @param mimetypes A list of mimetypes \ * QString is for a identifier name like "Text files" * the coresponding QStringList is used for the mimetypes * if empty it'll fill the list of mimetypes depending * on the content of the current directory */ OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, const QString &fileName = QString::null, const MimeTypes &mimetypes = MimeTypes() ); /** * This is a QPE compatible c'tor */ OFileSelector(const QString &mimeFilter, QWidget *parent, const char *name, bool newVisible = TRUE, bool closeVisible = FALSE ); ~OFileSelector(); // currently only for the FileSelector Mode /* compability mode but only work * with FileSelector */ void setNewVisible( bool /*b*/ ); void setCloseVisible(bool /*b*/ ); // end file selector mode // deprecated void reread(); // make sure not to leak please const DocLnk *selected(); // end deprecated /** * @return if the toolbar is visible */ bool isToolbarVisible() const { return m_shTool; }; /** * @return if the permissionBas is visible */ bool isPermissionBarVisible() const { return m_shPerm; }; /** * @return if the lineEdit is visible */ bool isLineEditVisible()const { return m_shLne; }; /** * if the chooser is visible */ bool isChooserVisible( )const { return m_shChooser; }; /** * @return if the yesCancel Bar is visible */ bool isYesCancelVisible()const { return m_shYesNo; }; /** * set Yes/Cancel visible */ void setYesCancelVisible( bool show ); /** * set the toolbar visible */ void setToolbarVisible( bool show ); /** * set the permissionBar to be visible */ void setPermissionBarVisible( bool show ); /** * set the lineedit for file entering visible */ void setLineEditVisible(bool show) ; /** * set the chooser is visible */ void setChooserVisible( bool chooser ); /** * The permissionCheckbox * */ QCheckBox* permissionCheckbox(); /** * setPermission */ bool setPermission() const; /** * set ther permission to bool */ void setPermissionChecked( bool check ); /** * set the Selector Mode */ void setMode( int ); /** * whether or not to show dirs */ bool showDirs()const { return m_dir; } /** * setShowDirs */ void setShowDirs(bool ); /** * set CaseSensetive */ bool isCaseSensetive()const { return m_case; } /** * set if to be case sensetive */ void setCaseSensetive(bool caSe ); /** * @return if to show files */ bool showFiles()const { return m_files; }; /** * set if files should be shown */ void setShowFiles(bool ); /** * change dir to path */ bool cd(const QString &path ); /** * return the mode of the fileselector */ int mode()const { return m_mode; }; /** * return the selector */ int selector()const { return m_selector; }; /** * set the Selector */ void setSelector( int ); /** * wether or not to show popups */ bool showPopup()const { return m_showPopup; }; /** * set show popups */ void setShowPopup( bool pop ) { m_showPopup = pop; } /** * set the popup factory */ void setPopupFactory( OPopupMenuFactory * ); /** * reparse the current directory and updates * the views + mimetypes */ void reparse(); // re reads the dir /** * return the selected name */ QString selectedName( )const; /** * for multiple selections return multiple * filenames */ QStringList selectedNames()const; /** * return the complete to the file */ QString selectedPath() const; /** * return the completed paths */ QStringList selectedPaths() const; /** * the current directory */ QString directory()const; /** * fileCount */ int fileCount(); DocLnk selectedDocument()const; QValueList<DocLnk> selectedDocuments()const; OFileView* currentView(); OFileView* currentView()const; OLister* currentLister()const; int filter(); int sorting(); QPixmap pixmap( const QString& ); + /* our tool bar */ + QWidget* toolBar(); signals: void fileSelected( const DocLnk & ); void fileSelected( const QString & ); void dirSelected(const QString &dir ); void dirSelected( const QDir& ); void closeMe(); void ok(); void cancel(); void contextMenu(); private slots: void slotOk(); void slotCancel(); void slotViewCheck(const QString & ); void slotMimeCheck(const QString & ); void slotLocationActivated(const QString & ); void slotInsertLocationPath(const QString &, int); void locationComboChanged(); private: void init(); void updateMimes(); private: + OFileSelectorMain* m_mainView; + OLister* m_lister; + OFileView* m_fileView; FileSelector* m_select; int m_mode, m_selector; QComboBox *m_location, *m_mimeCheck, *m_viewCheck; QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel; QPushButton *m_reread, *m_up, *m_new, *m_close; QListView *m_View; QCheckBox *m_checkPerm; QWidget *m_pseudo; QVBoxLayout *m_pseudoLayout; QString m_currentDir; QString m_name; - QMap<QString, QStringList> m_mimetypes; + QMap<QString, QStringList> m_mimetypes; - QWidgetStack *m_stack; QVBoxLayout *m_lay; QGridLayout *m_Oselector; QHBox *m_boxToolbar; QHBox *m_boxOk; QHBox *m_boxName; QHBox *m_boxView; - QPopupMenu *m_custom; QLineEdit *m_edit; QLabel *m_fnLabel; bool m_shClose : 1; bool m_shNew : 1; bool m_shTool : 1; bool m_shPerm : 1; bool m_shLne : 1; bool m_shChooser : 1; bool m_shYesNo : 1; bool m_boCheckPerm : 1; bool m_autoMime : 1; bool m_case : 1; bool m_dir : 1; bool m_files : 1; bool m_showPopup : 1; + bool m_showHidden : 1; void initVars(); void delItems(); void initializeName(); void initializeYes(); void initializeChooser(); - void initializeListView(); void initializePerm(); void initPics(); bool compliesMime(const QString &path, const QString &mime); bool compliesMime(const QString& mime ); /** * Updates the QComboBox with the current mimetypes */ void updateMimeCheck(); + void initializeOldSelector(); + void initLister(); + void initToolbar(); + void initLocations(); + void initializeView() {}; // FIXME /** * Returns the current mimetype */ QString currentMimeType()const; class OFileSelectorPrivate; OFileSelectorPrivate *d; static QMap<QString,QPixmap> *m_pixmaps; private slots: void slotFileSelected(const QString & ); // not really meant to be a slot void slotFileBridgeSelected( const DocLnk & ); // listview above // popup below virtual void slotDelete(); virtual void cdUP(); virtual void slotHome(); virtual void slotDoc(); virtual void slotNavigate( ); /* for OLister */ private: /* for OFileView */ private: void internFileSelected( const QString& ); void internFileSelected( const DocLnk& ); void internContextMenu(); void internChangedDir( const QString& ); void internChangedDir( const QDir& ) ; }; #endif diff --git a/libopie/ofileselector/olister.h b/libopie/ofileselector/olister.h index 081b876..ef61cab 100644 --- a/libopie/ofileselector/olister.h +++ b/libopie/ofileselector/olister.h @@ -1,59 +1,60 @@ #ifndef OPIE_FILE_LISTER_H #define OPIE_FILE_LISTER_H #include <qfileinfo.h> #include <qmap.h> #include <qstring.h> +#include <qstringlist.h> class OFileSelector; /** * lister is something like KIO but very * very basic and currently only for * populating our views. * This is a base class which needs to be implemented. * @see OLocalLister for a filesystem based implementation */ class OLister { public: OLister( OFileSelector* ); virtual ~OLister(); virtual void reparse(const QString& path) = 0; /** * return a list of available mimetypes */ virtual QMap<QString, QStringList> mimeTypes( const QString& dir ) = 0; protected: bool showFiles()const; bool showDirs()const; bool compliesMime( const QString& mime ); void addFile( const QString& mine, QFileInfo*, bool isSymlink = FALSE ); void addFile( const QString& mine, const QString& path, const QString& file, bool isSymlink = FALSE ); void addDir( const QString& mine, QFileInfo*, bool isSymlink = FALSE ); void addDir( const QString& mine, const QString& path, const QString& dir, bool isSymlink = FALSE ); void addSymlink( const QString& mine, QFileInfo* info, bool isSymlink = FALSE); void addSymlink( const QString& mine, const QString& path, const QString& name, bool isSymlink = FALSE ); OFileSelector* view(); private: OFileSelector* m_view; }; #endif diff --git a/libopie/pim/opimrecord.cpp b/libopie/pim/opimrecord.cpp index 95de1df..d8f73c7 100644 --- a/libopie/pim/opimrecord.cpp +++ b/libopie/pim/opimrecord.cpp @@ -1,90 +1,106 @@ #include "opimrecord.h" OPimRecord::OPimRecord( int uid ) : Qtopia::Record() { + setUid( uid ); + /* assign a new UID */ if ( uid == 1 ) assignUid(); } OPimRecord::~OPimRecord() { } -OPimRecord::OPimRecord( OPimRecord& rec ) +OPimRecord::OPimRecord( const OPimRecord& rec ) : Qtopia::Record( rec ) { (*this) = rec; } OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { - /* how do I call the parent copy operator ? */ - setUid( rec.uid() ); - setCategories( rec.categories() ); + Qtopia::Record::operator=( rec ); + m_relations = rec.m_relations; + return *this; } QStringList OPimRecord::categoryNames()const { QStringList list; return list; } -void OPimRecord::setCategoryName( const QStringList& ) { +void OPimRecord::setCategoryNames( const QStringList& ) { } void OPimRecord::addCategoryName( const QString& ) { } bool OPimRecord::isEmpty()const { return ( uid() == 0 ); } QStringList OPimRecord::relatedApps()const{ QStringList list; QMap<QString, QArray<int> >::ConstIterator it; for ( it = m_relations.begin(); it != m_relations.end(); ++it ) { list << it.key(); } return list; } QArray<int> OPimRecord::relations(const QString& app )const { QArray<int> tmp; QMap<QString, QArray<int> >::ConstIterator it; it = m_relations.find( app); if ( it != m_relations.end() ) tmp = it.data(); return tmp; } void OPimRecord::clearRelation( const QString& app ) { m_relations.remove( app ); } void OPimRecord::addRelation( const QString& app, int id ) { QMap<QString, QArray<int> >::Iterator it; QArray<int> tmp; it = m_relations.find( app ); if ( it == m_relations.end() ) { tmp.resize(1 ); tmp[0] = id; }else{ tmp = it.data(); tmp.resize( tmp.size() + 1 ); tmp[tmp.size() - 1] = id; } m_relations.replace( app, tmp ); } void OPimRecord::setRelations( const QString& app, QArray<int> ids ) { QMap<QString, QArray<int> >::Iterator it; QArray<int> tmp; it = m_relations.find( app); if ( it == m_relations.end() ) { tmp = ids; }else{ tmp = it.data(); int offset = tmp.size()-1; tmp.resize( tmp.size() + ids.size() ); for (uint i = 0; i < ids.size(); i++ ) { tmp[offset+i] = ids[i]; } } m_relations.replace( app, tmp ); } +QString OPimRecord::crossToString()const { + QString str; + QMap<QString, QArray<int> >::ConstIterator it; + for (it = m_relations.begin(); it != m_relations.end(); ++it ) { + QArray<int> id = it.data(); + for ( uint i = 0; i < id.size(); ++i ) { + str += it.key() + "," + QString::number( i ) + ";"; + } + } + str = str.remove( str.length()-1, 1); // strip the ; + //qWarning("IDS " + str ); + + return str; +} diff --git a/libopie/pim/opimrecord.h b/libopie/pim/opimrecord.h index a0e0413..18112d4 100644 --- a/libopie/pim/opimrecord.h +++ b/libopie/pim/opimrecord.h @@ -1,117 +1,117 @@ #ifndef OPIE_PIM_RECORD_H #define OPIE_PIM_RECORD_H #include <qmap.h> #include <qstring.h> #include <qstringlist.h> #include <qpe/palmtoprecord.h> class OPimRecord : public Qtopia::Record { public: /** * uid of 0 isEmpty * uid of 1 will be assigned a new one */ OPimRecord(int uid = 0); ~OPimRecord(); /** * copy c'tor */ - OPimRecord( OPimRecord& rec ); + OPimRecord( const OPimRecord& rec ); /** * copy operator */ OPimRecord &operator=( const OPimRecord& ); /** * category names resolved */ QStringList categoryNames()const; /** * set category names they will be resolved */ - void setCategoryName( const QStringList& ); + void setCategoryNames( const QStringList& ); /** * addCategoryName adds a name * to the internal category list */ void addCategoryName( const QString& ); /** * if a Record isEmpty */ virtual bool isEmpty()const; /** * toRichText summary */ virtual QString toRichText()const = 0; /** * a small one line summary */ virtual QString toShortText()const = 0; /** * the name of the Record */ virtual QString type()const = 0; /** * converts the internal structure to a map */ virtual QMap<int, QString> toMap()const = 0; /** * key value representation of extra items */ virtual QMap<QString, QString> toExtraMap()const = 0; /** * the name for a recordField */ virtual QString recordField(int)const = 0; /** * the related apps names */ QStringList relatedApps()const; /** * the realtions between an app */ QArray<int> relations( const QString& app )const; /** * */ void clearRelation( const QString& app ); /** * */ void addRelation( const QString& app, int id ); /** * */ void setRelations( const QString&, QArray<int> ids ); protected: QString crossToString()const; private: class OPimRecordPrivate; OPimRecordPrivate *d; QMap<QString, QArray<int> > m_relations; }; #endif diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp index d8e0447..3c93838 100644 --- a/libopie/pim/otodo.cpp +++ b/libopie/pim/otodo.cpp @@ -1,507 +1,354 @@ #include <qobject.h> #include <qshared.h> #include <qpe/palmtopuidgen.h> #include <qpe/stringutil.h> #include <qpe/palmtoprecord.h> #include <qpe/stringutil.h> #include <qpe/categories.h> #include <qpe/categoryselect.h> -#include "todoevent.h" -using namespace Opie; -Qtopia::UidGen ToDoEvent::m_gen; +#include "otodo.h" -struct ToDoEvent::ToDoEventData : public QShared { - ToDoEventData() : QShared() { + +struct OTodo::OTodoData : public QShared { + OTodoData() : QShared() { }; QDate date; bool isCompleted:1; bool hasDate:1; int priority; QStringList category; QString desc; QString sum; QMap<QString, QString> extra; - QMap<QString, QArray<int> > relations; - int uid; ushort prog; bool hasAlarmDateTime :1; QDateTime alarmDateTime; }; -ToDoEvent::ToDoEvent(const ToDoEvent &event ) - : data( event.data ) +OTodo::OTodo(const OTodo &event ) + : OPimRecord( event ), data( event.data ) { data->ref(); //qWarning("ref up"); } -ToDoEvent::~ToDoEvent() { +OTodo::~OTodo() { if ( data->deref() ) { - //qWarning("ToDoEvent::dereffing"); + //qWarning("OTodo::dereffing"); delete data; data = 0l; } } -ToDoEvent::ToDoEvent(bool completed, int priority, +OTodo::OTodo(bool completed, int priority, const QStringList &category, const QString& summary, const QString &description, ushort progress, bool hasDate, QDate date, int uid ) + : OPimRecord( uid ) { - //qWarning("ToDoEventData"); - data = new ToDoEventData; + //qWarning("OTodoData"); + setCategories( idsFromString( category.join(";") ) ); + data = new OTodoData; data->date = date; data->isCompleted = completed; data->hasDate = hasDate; data->priority = priority; - data->category = category; data->sum = summary; data->prog = progress; data->desc = Qtopia::simplifyMultiLineSpace(description ); - if (uid == -1 ) { - uid = m_gen.generate(); - - }// generated the ids - m_gen.store( uid ); - - data->uid = uid; data->hasAlarmDateTime = false; } -QArray<int> ToDoEvent::categories()const -{ - qWarning( "ToDoEvent:cats" + data->category.join(";") ); - QArray<int> array(data->category.count() ); // currently the datebook can be only in one category - array = Qtopia::Record::idsFromString( data->category.join(";") ); - return array; -} -bool ToDoEvent::match( const QRegExp ®Exp )const +bool OTodo::match( const QRegExp ®Exp )const { if( QString::number( data->priority ).find( regExp ) != -1 ){ return true; }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ return true; }else if(data->desc.find( regExp ) != -1 ){ return true; + }else if(data->sum.find( regExp ) != -1 ) { + return true; } return false; } -bool ToDoEvent::isCompleted() const +bool OTodo::isCompleted() const { return data->isCompleted; } -bool ToDoEvent::hasDueDate() const +bool OTodo::hasDueDate() const { return data->hasDate; } -bool ToDoEvent::hasAlarmDateTime() const +bool OTodo::hasAlarmDateTime() const { return data->hasAlarmDateTime; } -int ToDoEvent::priority()const +int OTodo::priority()const { return data->priority; } -QStringList ToDoEvent::allCategories()const -{ - return data->category; -} -QString ToDoEvent::extra(const QString& )const -{ - return QString::null; -} -QString ToDoEvent::summary() const +QString OTodo::summary() const { return data->sum; } -ushort ToDoEvent::progress() const +ushort OTodo::progress() const { return data->prog; } -QStringList ToDoEvent::relatedApps() const -{ - QStringList list; - QMap<QString, QArray<int> >::ConstIterator it; - for ( it = data->relations.begin(); it != data->relations.end(); ++it ) { - list << it.key(); - } - return list; -} -QArray<int> ToDoEvent::relations( const QString& app)const -{ - QArray<int> tmp; - QMap<QString, QArray<int> >::ConstIterator it; - it = data->relations.find( app); - if ( it != data->relations.end() ) - tmp = it.data(); - return tmp; -} -void ToDoEvent::insertCategory(const QString &str ) -{ - changeOrModify(); - qWarning("insert category;" + str ); - data->category.append( str ); -} -void ToDoEvent::clearCategories() -{ - changeOrModify(); - data->category.clear(); -} -void ToDoEvent::setCategories(const QStringList &list ) -{ - changeOrModify(); - qWarning("set categories" + list.join(";") ); - data->category = list; -} -QDate ToDoEvent::dueDate()const +QDate OTodo::dueDate()const { return data->date; } -QDateTime ToDoEvent::alarmDateTime() const +QDateTime OTodo::alarmDateTime() const { return data->alarmDateTime; } -QString ToDoEvent::description()const +QString OTodo::description()const { return data->desc; } -void ToDoEvent::setCompleted( bool completed ) +void OTodo::setCompleted( bool completed ) { changeOrModify(); data->isCompleted = completed; } -void ToDoEvent::setHasDueDate( bool hasDate ) +void OTodo::setHasDueDate( bool hasDate ) { changeOrModify(); data->hasDate = hasDate; } -void ToDoEvent::setHasAlarmDateTime( bool hasAlarmDateTime ) +void OTodo::setHasAlarmDateTime( bool hasAlarmDateTime ) { changeOrModify(); data->hasAlarmDateTime = hasAlarmDateTime; } -void ToDoEvent::setDescription(const QString &desc ) +void OTodo::setDescription(const QString &desc ) { changeOrModify(); data->desc = Qtopia::simplifyMultiLineSpace(desc ); } -void ToDoEvent::setExtra( const QString&, const QString& ) -{ - -} -void ToDoEvent::setSummary( const QString& sum ) +void OTodo::setSummary( const QString& sum ) { changeOrModify(); data->sum = sum; } -void ToDoEvent::setCategory( const QString &cat ) -{ - changeOrModify(); - //qWarning("setCategory %s", cat.latin1() ); - data->category.clear(); - data->category << cat; -} -void ToDoEvent::setPriority(int prio ) +void OTodo::setPriority(int prio ) { changeOrModify(); data->priority = prio; } -void ToDoEvent::setDueDate( QDate date ) +void OTodo::setDueDate( QDate date ) { changeOrModify(); data->date = date; } -void ToDoEvent::setAlarmDateTime( const QDateTime& alarm ) +void OTodo::setAlarmDateTime( const QDateTime& alarm ) { changeOrModify(); data->alarmDateTime = alarm; } -void ToDoEvent::addRelated( const QString &app, int id ) -{ - changeOrModify(); - - QMap<QString, QArray<int> >::Iterator it; - QArray<int> tmp; - it = data->relations.find( app ); - if ( it == data->relations.end() ) { - tmp.resize(1 ); - tmp[0] = id; - }else{ - tmp = it.data(); - tmp.resize( tmp.size() + 1 ); - tmp[tmp.size() - 1] = id; - } - data->relations.replace( app, tmp ); -} -void ToDoEvent::addRelated(const QString& app, QArray<int> ids ) -{ - changeOrModify(); - - QMap<QString, QArray<int> >::Iterator it; - QArray<int> tmp; - it = data->relations.find( app); - if ( it == data->relations.end() ) { // not there - /** tmp.resize( ids.size() ); stupid?? - */ - tmp = ids; - }else{ - tmp = it.data(); - int offset = tmp.size()-1; - tmp.resize( tmp.size() + ids.size() ); - for (uint i = 0; i < ids.size(); i++ ) { - tmp[offset+i] = ids[i]; - } - - } - data->relations.replace( app, tmp ); -} -void ToDoEvent::clearRelated( const QString& app ) -{ - changeOrModify(); - data->relations.remove( app ); -} -bool ToDoEvent::isOverdue( ) +bool OTodo::isOverdue( ) { if( data->hasDate ) return QDate::currentDate() > data->date; return false; } -void ToDoEvent::setProgress(ushort progress ) +void OTodo::setProgress(ushort progress ) { changeOrModify(); data->prog = progress; } +QString OTodo::toShortText() const { + return summary(); +} /*! Returns a richt text string */ -QString ToDoEvent::richText() const +QString OTodo::toRichText() const { QString text; QStringList catlist; // Description of the todo if ( !summary().isEmpty() ) { text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; } if( !description().isEmpty() ){ text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; } text += "<br><br><br>"; text += "<b>" + QObject::tr( "Priority:") +" </b>" + QString::number( priority() ) + " <br>"; text += "<b>" + QObject::tr( "Progress:") + " </b>" + QString::number( progress() ) + " %<br>"; if (hasDueDate() ){ text += "<b>" + QObject::tr( "Deadline:") + " </b>"; text += dueDate().toString(); text += "<br>"; } if (hasAlarmDateTime() ){ text += "<b>" + QObject::tr( "Alarmed Notification:") + " </b>"; text += alarmDateTime().toString(); text += "<br>"; } - // Open database of all categories and get the list of - // the categories this todoevent belongs to. - // Then print them... - // I am not sure whether there is no better way doing this !? - Categories catdb; - bool firstloop = true; - catdb.load( categoryFileName() ); - catlist = allCategories(); - text += "<b>" + QObject::tr( "Category:") + "</b> "; - for ( QStringList::Iterator it = catlist.begin(); it != catlist.end(); ++it ) { - if (!firstloop){ - text += ", "; - } - firstloop = false; - text += catdb.label ("todo", (*it).toInt()); - } + text += categoryNames().join(", "); text += "<br>"; + return text; } -bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ +bool OTodo::operator<( const OTodo &toDoEvent )const{ if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; if( hasDueDate() && toDoEvent.hasDueDate() ){ if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide return priority() < toDoEvent.priority(); }else{ return dueDate() < toDoEvent.dueDate(); } } return false; } -bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const +bool OTodo::operator<=(const OTodo &toDoEvent )const { if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; if( hasDueDate() && toDoEvent.hasDueDate() ){ if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide return priority() <= toDoEvent.priority(); }else{ return dueDate() <= toDoEvent.dueDate(); } } return true; } -bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const +bool OTodo::operator>(const OTodo &toDoEvent )const { if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; if( hasDueDate() && toDoEvent.hasDueDate() ){ if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide return priority() > toDoEvent.priority(); }else{ return dueDate() > toDoEvent.dueDate(); } } return false; } -bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const +bool OTodo::operator>=(const OTodo &toDoEvent )const { if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; if( hasDueDate() && toDoEvent.hasDueDate() ){ if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide return priority() > toDoEvent.priority(); }else{ return dueDate() > toDoEvent.dueDate(); } } return true; } -bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const +bool OTodo::operator==(const OTodo &toDoEvent )const { if( data->priority == toDoEvent.data->priority && data->priority == toDoEvent.data->prog && data->isCompleted == toDoEvent.data->isCompleted && data->hasDate == toDoEvent.data->hasDate && data->date == toDoEvent.data->date && data->category == toDoEvent.data->category && data->sum == toDoEvent.data->sum && data->desc == toDoEvent.data->desc && data->hasAlarmDateTime == toDoEvent.data->hasAlarmDateTime && data->alarmDateTime == toDoEvent.data->alarmDateTime ) return true; return false; } -void ToDoEvent::deref() { +void OTodo::deref() { //qWarning("deref in ToDoEvent"); if ( data->deref() ) { //qWarning("deleting"); delete data; d= 0; } } -ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item ) +OTodo &OTodo::operator=(const OTodo &item ) { + OPimRecord::operator=( item ); //qWarning("operator= ref "); item.data->ref(); deref(); - data = item.data; - - return *this; } -QMap<int, QString> ToDoEvent::toMap() const { +QMap<int, QString> OTodo::toMap() const { QMap<int, QString> map; - map.insert( Uid, QString::number( data->uid ) ); - map.insert( Category, data->category.join(";") ); + map.insert( Uid, QString::number( uid() ) ); + map.insert( Category, idsToString( categories() ) ); map.insert( HasDate, QString::number( data->hasDate ) ); map.insert( Completed, QString::number( data->isCompleted ) ); map.insert( Description, data->desc ); map.insert( Summary, data->sum ); map.insert( Priority, QString::number( data->priority ) ); map.insert( DateDay, QString::number( data->date.day() ) ); map.insert( DateMonth, QString::number( data->date.month() ) ); map.insert( DateYear, QString::number( data->date.year() ) ); map.insert( Progress, QString::number( data->prog ) ); map.insert( CrossReference, crossToString() ); map.insert( HasAlarmDateTime, QString::number( data->hasAlarmDateTime ) ); map.insert( AlarmDateTime, data->alarmDateTime.toString() ); return map; } - -QString ToDoEvent::crossToString()const { - QString str; - QMap<QString, QArray<int> >::ConstIterator it; - for (it = data->relations.begin(); it != data->relations.end(); ++it ) { - QArray<int> id = it.data(); - for ( uint i = 0; i < id.size(); ++i ) { - str += it.key() + "," + QString::number( i ) + ";"; - } - } - str = str.remove( str.length()-1, 1); // strip the ; - //qWarning("IDS " + str ); - - return str; -} -int ToDoEvent::uid()const { - return data->uid; -} -void ToDoEvent::setUid( int id ) { - if ( id == -1 ) - id = m_gen.generate(); - m_gen.store(id ); - changeOrModify(); - data->uid = id; -} -QMap<QString, QString> ToDoEvent::extras()const { +QMap<QString, QString> OTodo::toExtraMap()const { return data->extra; } /** * change or modify looks at the ref count and either * creates a new QShared Object or it can modify it * right in place */ -void ToDoEvent::changeOrModify() { +void OTodo::changeOrModify() { if ( data->count != 1 ) { //qWarning("changeOrModify"); data->deref(); - ToDoEventData* d2 = new ToDoEventData(); + OTodoData* d2 = new OTodoData(); copy(data, d2 ); data = d2; } } -void ToDoEvent::copy( ToDoEventData* src, ToDoEventData* dest ) { +void OTodo::copy( OTodoData* src, OTodoData* dest ) { dest->date = src->date; dest->isCompleted = src->isCompleted; dest->hasDate = src->hasDate; dest->priority = src->priority; - dest->category = src->category; dest->desc = src->desc; dest->sum = src->sum; dest->extra = src->extra; - dest->relations = src->relations; - dest->uid = src->uid; dest->prog = src->prog; dest->hasAlarmDateTime = src->hasAlarmDateTime; dest->alarmDateTime = src->alarmDateTime; } diff --git a/libopie/pim/otodo.h b/libopie/pim/otodo.h index 429108a..e1729db 100644 --- a/libopie/pim/otodo.h +++ b/libopie/pim/otodo.h @@ -1,205 +1,211 @@ #ifndef OPIE_TODO_EVENT_H #define OPIE_TODO_EVENT_H #include <qarray.h> #include <qmap.h> #include <qregexp.h> #include <qstringlist.h> #include <qdatetime.h> #include <qvaluelist.h> #include <qpe/recordfields.h> #include <qpe/palmtopuidgen.h> #include <opie/opimrecord.h> class OTodo : public OPimRecord { public: - typedef QValueList<ToDoEvent> ValueList; + typedef QValueList<OTodo> ValueList; enum RecordFields { Uid = Qtopia::UID_ID, Category = Qtopia::CATEGORY_ID, HasDate, Completed, Description, Summary, Priority, DateDay, DateMonth, DateYear, Progress, CrossReference, HasAlarmDateTime, AlarmDateTime }; public: // priorities from Very low to very high enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow }; /* Constructs a new ToDoEvent @param completed Is the TodoEvent completed @param priority What is the priority of this ToDoEvent @param category Which category does it belong( uid ) @param summary A small summary of the todo @param description What is this ToDoEvent about @param hasDate Does this Event got a deadline @param date what is the deadline? @param uid what is the UUID of this Event **/ OTodo( bool completed = false, int priority = Normal, const QStringList &category = QStringList(), const QString &summary = QString::null , const QString &description = QString::null, ushort progress = 0, bool hasDate = false, QDate date = QDate::currentDate(), int uid = -1 ); /* Copy c'tor **/ OTodo(const OTodo & ); /** *destructor */ ~OTodo(); /** * Is this event completed? */ bool isCompleted() const; /** * Does this Event have a deadline */ bool hasDueDate() const; /** * Does this Event has an alarm time ? */ bool hasAlarmDateTime() const; /** * What is the priority? */ int priority()const ; /** * progress as ushort 0, 20, 40, 60, 80 or 100% */ ushort progress() const; /** * The due Date */ QDate dueDate()const; /** * Alarm Date and Time */ QDateTime alarmDateTime()const; /** * The description of the todo */ QString description()const; /** * A small summary of the todo */ QString summary() const; /** * @reimplemented * Return this todoevent in a RichText formatted QString */ QString toRichText() const; + /** + * reimplementation + */ + QString type()const; + QString toShortText()const; + QMap<QString, QString> toExtraMap()const; + QString recordField(int id )const; /** * returns a list of apps which have related items */ QStringList relatedApps()const; /** * returns all relations for one app */ QArray<int> relations( const QString& app )const; /** * toMap puts all data into the map. int relates * to ToDoEvent RecordFields enum */ QMap<int, QString> toMap()const; /** * Set if this Todo is completed */ void setCompleted(bool completed ); /** * set if this todo got an end data */ void setHasDueDate( bool hasDate ); /** * set if this todo has an alarm time and date */ void setHasAlarmDateTime ( bool hasAlarm ); /** * Set the priority of the Todo */ void setPriority(int priority ); /** * Set the progress. */ void setProgress( ushort progress ); /** * set the end date */ void setDueDate( QDate date ); /** * set the alarm time */ void setAlarmDateTime ( const QDateTime& alarm ); void setDescription(const QString& ); void setSummary(const QString& ); bool isOverdue(); bool match( const QRegExp &r )const; bool operator<(const OTodo &toDoEvent )const; bool operator<=(const OTodo &toDoEvent )const; bool operator!=(const OTodo &toDoEvent )const; bool operator>(const OTodo &toDoEvent )const; bool operator>=(const OTodo &toDoEvent)const; bool operator==(const OTodo &toDoEvent )const; - ToDoEvent &operator=(const OTodo &toDoEvent ); + OTodo &operator=(const OTodo &toDoEvent ); private: class OTodoPrivate; - struct OTodoEventData; + struct OTodoData; void deref(); void changeOrModify(); void copy( OTodoData* src, OTodoData* dest ); - ToDoEventPrivate *d; - ToDoEventData *data; + OTodoPrivate *d; + OTodoData *data; - static Qtopia::UidGen m_gen; }; - inline bool ToDoEvent::operator!=(const ToDoEvent &toDoEvent )const { +inline bool OTodo::operator!=(const OTodo &toDoEvent )const { return !(*this == toDoEvent); } -}; + #endif diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp index 95de1df..d8f73c7 100644 --- a/libopie2/opiepim/core/opimrecord.cpp +++ b/libopie2/opiepim/core/opimrecord.cpp @@ -1,90 +1,106 @@ #include "opimrecord.h" OPimRecord::OPimRecord( int uid ) : Qtopia::Record() { + setUid( uid ); + /* assign a new UID */ if ( uid == 1 ) assignUid(); } OPimRecord::~OPimRecord() { } -OPimRecord::OPimRecord( OPimRecord& rec ) +OPimRecord::OPimRecord( const OPimRecord& rec ) : Qtopia::Record( rec ) { (*this) = rec; } OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { - /* how do I call the parent copy operator ? */ - setUid( rec.uid() ); - setCategories( rec.categories() ); + Qtopia::Record::operator=( rec ); + m_relations = rec.m_relations; + return *this; } QStringList OPimRecord::categoryNames()const { QStringList list; return list; } -void OPimRecord::setCategoryName( const QStringList& ) { +void OPimRecord::setCategoryNames( const QStringList& ) { } void OPimRecord::addCategoryName( const QString& ) { } bool OPimRecord::isEmpty()const { return ( uid() == 0 ); } QStringList OPimRecord::relatedApps()const{ QStringList list; QMap<QString, QArray<int> >::ConstIterator it; for ( it = m_relations.begin(); it != m_relations.end(); ++it ) { list << it.key(); } return list; } QArray<int> OPimRecord::relations(const QString& app )const { QArray<int> tmp; QMap<QString, QArray<int> >::ConstIterator it; it = m_relations.find( app); if ( it != m_relations.end() ) tmp = it.data(); return tmp; } void OPimRecord::clearRelation( const QString& app ) { m_relations.remove( app ); } void OPimRecord::addRelation( const QString& app, int id ) { QMap<QString, QArray<int> >::Iterator it; QArray<int> tmp; it = m_relations.find( app ); if ( it == m_relations.end() ) { tmp.resize(1 ); tmp[0] = id; }else{ tmp = it.data(); tmp.resize( tmp.size() + 1 ); tmp[tmp.size() - 1] = id; } m_relations.replace( app, tmp ); } void OPimRecord::setRelations( const QString& app, QArray<int> ids ) { QMap<QString, QArray<int> >::Iterator it; QArray<int> tmp; it = m_relations.find( app); if ( it == m_relations.end() ) { tmp = ids; }else{ tmp = it.data(); int offset = tmp.size()-1; tmp.resize( tmp.size() + ids.size() ); for (uint i = 0; i < ids.size(); i++ ) { tmp[offset+i] = ids[i]; } } m_relations.replace( app, tmp ); } +QString OPimRecord::crossToString()const { + QString str; + QMap<QString, QArray<int> >::ConstIterator it; + for (it = m_relations.begin(); it != m_relations.end(); ++it ) { + QArray<int> id = it.data(); + for ( uint i = 0; i < id.size(); ++i ) { + str += it.key() + "," + QString::number( i ) + ";"; + } + } + str = str.remove( str.length()-1, 1); // strip the ; + //qWarning("IDS " + str ); + + return str; +} diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h index a0e0413..18112d4 100644 --- a/libopie2/opiepim/core/opimrecord.h +++ b/libopie2/opiepim/core/opimrecord.h @@ -1,117 +1,117 @@ #ifndef OPIE_PIM_RECORD_H #define OPIE_PIM_RECORD_H #include <qmap.h> #include <qstring.h> #include <qstringlist.h> #include <qpe/palmtoprecord.h> class OPimRecord : public Qtopia::Record { public: /** * uid of 0 isEmpty * uid of 1 will be assigned a new one */ OPimRecord(int uid = 0); ~OPimRecord(); /** * copy c'tor */ - OPimRecord( OPimRecord& rec ); + OPimRecord( const OPimRecord& rec ); /** * copy operator */ OPimRecord &operator=( const OPimRecord& ); /** * category names resolved */ QStringList categoryNames()const; /** * set category names they will be resolved */ - void setCategoryName( const QStringList& ); + void setCategoryNames( const QStringList& ); /** * addCategoryName adds a name * to the internal category list */ void addCategoryName( const QString& ); /** * if a Record isEmpty */ virtual bool isEmpty()const; /** * toRichText summary */ virtual QString toRichText()const = 0; /** * a small one line summary */ virtual QString toShortText()const = 0; /** * the name of the Record */ virtual QString type()const = 0; /** * converts the internal structure to a map */ virtual QMap<int, QString> toMap()const = 0; /** * key value representation of extra items */ virtual QMap<QString, QString> toExtraMap()const = 0; /** * the name for a recordField */ virtual QString recordField(int)const = 0; /** * the related apps names */ QStringList relatedApps()const; /** * the realtions between an app */ QArray<int> relations( const QString& app )const; /** * */ void clearRelation( const QString& app ); /** * */ void addRelation( const QString& app, int id ); /** * */ void setRelations( const QString&, QArray<int> ids ); protected: QString crossToString()const; private: class OPimRecordPrivate; OPimRecordPrivate *d; QMap<QString, QArray<int> > m_relations; }; #endif diff --git a/libopie2/opiepim/otodo.cpp b/libopie2/opiepim/otodo.cpp index d8e0447..3c93838 100644 --- a/libopie2/opiepim/otodo.cpp +++ b/libopie2/opiepim/otodo.cpp @@ -1,507 +1,354 @@ #include <qobject.h> #include <qshared.h> #include <qpe/palmtopuidgen.h> #include <qpe/stringutil.h> #include <qpe/palmtoprecord.h> #include <qpe/stringutil.h> #include <qpe/categories.h> #include <qpe/categoryselect.h> -#include "todoevent.h" -using namespace Opie; -Qtopia::UidGen ToDoEvent::m_gen; +#include "otodo.h" -struct ToDoEvent::ToDoEventData : public QShared { - ToDoEventData() : QShared() { + +struct OTodo::OTodoData : public QShared { + OTodoData() : QShared() { }; QDate date; bool isCompleted:1; bool hasDate:1; int priority; QStringList category; QString desc; QString sum; QMap<QString, QString> extra; - QMap<QString, QArray<int> > relations; - int uid; ushort prog; bool hasAlarmDateTime :1; QDateTime alarmDateTime; }; -ToDoEvent::ToDoEvent(const ToDoEvent &event ) - : data( event.data ) +OTodo::OTodo(const OTodo &event ) + : OPimRecord( event ), data( event.data ) { data->ref(); //qWarning("ref up"); } -ToDoEvent::~ToDoEvent() { +OTodo::~OTodo() { if ( data->deref() ) { - //qWarning("ToDoEvent::dereffing"); + //qWarning("OTodo::dereffing"); delete data; data = 0l; } } -ToDoEvent::ToDoEvent(bool completed, int priority, +OTodo::OTodo(bool completed, int priority, const QStringList &category, const QString& summary, const QString &description, ushort progress, bool hasDate, QDate date, int uid ) + : OPimRecord( uid ) { - //qWarning("ToDoEventData"); - data = new ToDoEventData; + //qWarning("OTodoData"); + setCategories( idsFromString( category.join(";") ) ); + data = new OTodoData; data->date = date; data->isCompleted = completed; data->hasDate = hasDate; data->priority = priority; - data->category = category; data->sum = summary; data->prog = progress; data->desc = Qtopia::simplifyMultiLineSpace(description ); - if (uid == -1 ) { - uid = m_gen.generate(); - - }// generated the ids - m_gen.store( uid ); - - data->uid = uid; data->hasAlarmDateTime = false; } -QArray<int> ToDoEvent::categories()const -{ - qWarning( "ToDoEvent:cats" + data->category.join(";") ); - QArray<int> array(data->category.count() ); // currently the datebook can be only in one category - array = Qtopia::Record::idsFromString( data->category.join(";") ); - return array; -} -bool ToDoEvent::match( const QRegExp ®Exp )const +bool OTodo::match( const QRegExp ®Exp )const { if( QString::number( data->priority ).find( regExp ) != -1 ){ return true; }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ return true; }else if(data->desc.find( regExp ) != -1 ){ return true; + }else if(data->sum.find( regExp ) != -1 ) { + return true; } return false; } -bool ToDoEvent::isCompleted() const +bool OTodo::isCompleted() const { return data->isCompleted; } -bool ToDoEvent::hasDueDate() const +bool OTodo::hasDueDate() const { return data->hasDate; } -bool ToDoEvent::hasAlarmDateTime() const +bool OTodo::hasAlarmDateTime() const { return data->hasAlarmDateTime; } -int ToDoEvent::priority()const +int OTodo::priority()const { return data->priority; } -QStringList ToDoEvent::allCategories()const -{ - return data->category; -} -QString ToDoEvent::extra(const QString& )const -{ - return QString::null; -} -QString ToDoEvent::summary() const +QString OTodo::summary() const { return data->sum; } -ushort ToDoEvent::progress() const +ushort OTodo::progress() const { return data->prog; } -QStringList ToDoEvent::relatedApps() const -{ - QStringList list; - QMap<QString, QArray<int> >::ConstIterator it; - for ( it = data->relations.begin(); it != data->relations.end(); ++it ) { - list << it.key(); - } - return list; -} -QArray<int> ToDoEvent::relations( const QString& app)const -{ - QArray<int> tmp; - QMap<QString, QArray<int> >::ConstIterator it; - it = data->relations.find( app); - if ( it != data->relations.end() ) - tmp = it.data(); - return tmp; -} -void ToDoEvent::insertCategory(const QString &str ) -{ - changeOrModify(); - qWarning("insert category;" + str ); - data->category.append( str ); -} -void ToDoEvent::clearCategories() -{ - changeOrModify(); - data->category.clear(); -} -void ToDoEvent::setCategories(const QStringList &list ) -{ - changeOrModify(); - qWarning("set categories" + list.join(";") ); - data->category = list; -} -QDate ToDoEvent::dueDate()const +QDate OTodo::dueDate()const { return data->date; } -QDateTime ToDoEvent::alarmDateTime() const +QDateTime OTodo::alarmDateTime() const { return data->alarmDateTime; } -QString ToDoEvent::description()const +QString OTodo::description()const { return data->desc; } -void ToDoEvent::setCompleted( bool completed ) +void OTodo::setCompleted( bool completed ) { changeOrModify(); data->isCompleted = completed; } -void ToDoEvent::setHasDueDate( bool hasDate ) +void OTodo::setHasDueDate( bool hasDate ) { changeOrModify(); data->hasDate = hasDate; } -void ToDoEvent::setHasAlarmDateTime( bool hasAlarmDateTime ) +void OTodo::setHasAlarmDateTime( bool hasAlarmDateTime ) { changeOrModify(); data->hasAlarmDateTime = hasAlarmDateTime; } -void ToDoEvent::setDescription(const QString &desc ) +void OTodo::setDescription(const QString &desc ) { changeOrModify(); data->desc = Qtopia::simplifyMultiLineSpace(desc ); } -void ToDoEvent::setExtra( const QString&, const QString& ) -{ - -} -void ToDoEvent::setSummary( const QString& sum ) +void OTodo::setSummary( const QString& sum ) { changeOrModify(); data->sum = sum; } -void ToDoEvent::setCategory( const QString &cat ) -{ - changeOrModify(); - //qWarning("setCategory %s", cat.latin1() ); - data->category.clear(); - data->category << cat; -} -void ToDoEvent::setPriority(int prio ) +void OTodo::setPriority(int prio ) { changeOrModify(); data->priority = prio; } -void ToDoEvent::setDueDate( QDate date ) +void OTodo::setDueDate( QDate date ) { changeOrModify(); data->date = date; } -void ToDoEvent::setAlarmDateTime( const QDateTime& alarm ) +void OTodo::setAlarmDateTime( const QDateTime& alarm ) { changeOrModify(); data->alarmDateTime = alarm; } -void ToDoEvent::addRelated( const QString &app, int id ) -{ - changeOrModify(); - - QMap<QString, QArray<int> >::Iterator it; - QArray<int> tmp; - it = data->relations.find( app ); - if ( it == data->relations.end() ) { - tmp.resize(1 ); - tmp[0] = id; - }else{ - tmp = it.data(); - tmp.resize( tmp.size() + 1 ); - tmp[tmp.size() - 1] = id; - } - data->relations.replace( app, tmp ); -} -void ToDoEvent::addRelated(const QString& app, QArray<int> ids ) -{ - changeOrModify(); - - QMap<QString, QArray<int> >::Iterator it; - QArray<int> tmp; - it = data->relations.find( app); - if ( it == data->relations.end() ) { // not there - /** tmp.resize( ids.size() ); stupid?? - */ - tmp = ids; - }else{ - tmp = it.data(); - int offset = tmp.size()-1; - tmp.resize( tmp.size() + ids.size() ); - for (uint i = 0; i < ids.size(); i++ ) { - tmp[offset+i] = ids[i]; - } - - } - data->relations.replace( app, tmp ); -} -void ToDoEvent::clearRelated( const QString& app ) -{ - changeOrModify(); - data->relations.remove( app ); -} -bool ToDoEvent::isOverdue( ) +bool OTodo::isOverdue( ) { if( data->hasDate ) return QDate::currentDate() > data->date; return false; } -void ToDoEvent::setProgress(ushort progress ) +void OTodo::setProgress(ushort progress ) { changeOrModify(); data->prog = progress; } +QString OTodo::toShortText() const { + return summary(); +} /*! Returns a richt text string */ -QString ToDoEvent::richText() const +QString OTodo::toRichText() const { QString text; QStringList catlist; // Description of the todo if ( !summary().isEmpty() ) { text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; } if( !description().isEmpty() ){ text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; } text += "<br><br><br>"; text += "<b>" + QObject::tr( "Priority:") +" </b>" + QString::number( priority() ) + " <br>"; text += "<b>" + QObject::tr( "Progress:") + " </b>" + QString::number( progress() ) + " %<br>"; if (hasDueDate() ){ text += "<b>" + QObject::tr( "Deadline:") + " </b>"; text += dueDate().toString(); text += "<br>"; } if (hasAlarmDateTime() ){ text += "<b>" + QObject::tr( "Alarmed Notification:") + " </b>"; text += alarmDateTime().toString(); text += "<br>"; } - // Open database of all categories and get the list of - // the categories this todoevent belongs to. - // Then print them... - // I am not sure whether there is no better way doing this !? - Categories catdb; - bool firstloop = true; - catdb.load( categoryFileName() ); - catlist = allCategories(); - text += "<b>" + QObject::tr( "Category:") + "</b> "; - for ( QStringList::Iterator it = catlist.begin(); it != catlist.end(); ++it ) { - if (!firstloop){ - text += ", "; - } - firstloop = false; - text += catdb.label ("todo", (*it).toInt()); - } + text += categoryNames().join(", "); text += "<br>"; + return text; } -bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ +bool OTodo::operator<( const OTodo &toDoEvent )const{ if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; if( hasDueDate() && toDoEvent.hasDueDate() ){ if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide return priority() < toDoEvent.priority(); }else{ return dueDate() < toDoEvent.dueDate(); } } return false; } -bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const +bool OTodo::operator<=(const OTodo &toDoEvent )const { if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; if( hasDueDate() && toDoEvent.hasDueDate() ){ if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide return priority() <= toDoEvent.priority(); }else{ return dueDate() <= toDoEvent.dueDate(); } } return true; } -bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const +bool OTodo::operator>(const OTodo &toDoEvent )const { if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; if( hasDueDate() && toDoEvent.hasDueDate() ){ if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide return priority() > toDoEvent.priority(); }else{ return dueDate() > toDoEvent.dueDate(); } } return false; } -bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const +bool OTodo::operator>=(const OTodo &toDoEvent )const { if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; if( hasDueDate() && toDoEvent.hasDueDate() ){ if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide return priority() > toDoEvent.priority(); }else{ return dueDate() > toDoEvent.dueDate(); } } return true; } -bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const +bool OTodo::operator==(const OTodo &toDoEvent )const { if( data->priority == toDoEvent.data->priority && data->priority == toDoEvent.data->prog && data->isCompleted == toDoEvent.data->isCompleted && data->hasDate == toDoEvent.data->hasDate && data->date == toDoEvent.data->date && data->category == toDoEvent.data->category && data->sum == toDoEvent.data->sum && data->desc == toDoEvent.data->desc && data->hasAlarmDateTime == toDoEvent.data->hasAlarmDateTime && data->alarmDateTime == toDoEvent.data->alarmDateTime ) return true; return false; } -void ToDoEvent::deref() { +void OTodo::deref() { //qWarning("deref in ToDoEvent"); if ( data->deref() ) { //qWarning("deleting"); delete data; d= 0; } } -ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item ) +OTodo &OTodo::operator=(const OTodo &item ) { + OPimRecord::operator=( item ); //qWarning("operator= ref "); item.data->ref(); deref(); - data = item.data; - - return *this; } -QMap<int, QString> ToDoEvent::toMap() const { +QMap<int, QString> OTodo::toMap() const { QMap<int, QString> map; - map.insert( Uid, QString::number( data->uid ) ); - map.insert( Category, data->category.join(";") ); + map.insert( Uid, QString::number( uid() ) ); + map.insert( Category, idsToString( categories() ) ); map.insert( HasDate, QString::number( data->hasDate ) ); map.insert( Completed, QString::number( data->isCompleted ) ); map.insert( Description, data->desc ); map.insert( Summary, data->sum ); map.insert( Priority, QString::number( data->priority ) ); map.insert( DateDay, QString::number( data->date.day() ) ); map.insert( DateMonth, QString::number( data->date.month() ) ); map.insert( DateYear, QString::number( data->date.year() ) ); map.insert( Progress, QString::number( data->prog ) ); map.insert( CrossReference, crossToString() ); map.insert( HasAlarmDateTime, QString::number( data->hasAlarmDateTime ) ); map.insert( AlarmDateTime, data->alarmDateTime.toString() ); return map; } - -QString ToDoEvent::crossToString()const { - QString str; - QMap<QString, QArray<int> >::ConstIterator it; - for (it = data->relations.begin(); it != data->relations.end(); ++it ) { - QArray<int> id = it.data(); - for ( uint i = 0; i < id.size(); ++i ) { - str += it.key() + "," + QString::number( i ) + ";"; - } - } - str = str.remove( str.length()-1, 1); // strip the ; - //qWarning("IDS " + str ); - - return str; -} -int ToDoEvent::uid()const { - return data->uid; -} -void ToDoEvent::setUid( int id ) { - if ( id == -1 ) - id = m_gen.generate(); - m_gen.store(id ); - changeOrModify(); - data->uid = id; -} -QMap<QString, QString> ToDoEvent::extras()const { +QMap<QString, QString> OTodo::toExtraMap()const { return data->extra; } /** * change or modify looks at the ref count and either * creates a new QShared Object or it can modify it * right in place */ -void ToDoEvent::changeOrModify() { +void OTodo::changeOrModify() { if ( data->count != 1 ) { //qWarning("changeOrModify"); data->deref(); - ToDoEventData* d2 = new ToDoEventData(); + OTodoData* d2 = new OTodoData(); copy(data, d2 ); data = d2; } } -void ToDoEvent::copy( ToDoEventData* src, ToDoEventData* dest ) { +void OTodo::copy( OTodoData* src, OTodoData* dest ) { dest->date = src->date; dest->isCompleted = src->isCompleted; dest->hasDate = src->hasDate; dest->priority = src->priority; - dest->category = src->category; dest->desc = src->desc; dest->sum = src->sum; dest->extra = src->extra; - dest->relations = src->relations; - dest->uid = src->uid; dest->prog = src->prog; dest->hasAlarmDateTime = src->hasAlarmDateTime; dest->alarmDateTime = src->alarmDateTime; } diff --git a/libopie2/opiepim/otodo.h b/libopie2/opiepim/otodo.h index 429108a..e1729db 100644 --- a/libopie2/opiepim/otodo.h +++ b/libopie2/opiepim/otodo.h @@ -1,205 +1,211 @@ #ifndef OPIE_TODO_EVENT_H #define OPIE_TODO_EVENT_H #include <qarray.h> #include <qmap.h> #include <qregexp.h> #include <qstringlist.h> #include <qdatetime.h> #include <qvaluelist.h> #include <qpe/recordfields.h> #include <qpe/palmtopuidgen.h> #include <opie/opimrecord.h> class OTodo : public OPimRecord { public: - typedef QValueList<ToDoEvent> ValueList; + typedef QValueList<OTodo> ValueList; enum RecordFields { Uid = Qtopia::UID_ID, Category = Qtopia::CATEGORY_ID, HasDate, Completed, Description, Summary, Priority, DateDay, DateMonth, DateYear, Progress, CrossReference, HasAlarmDateTime, AlarmDateTime }; public: // priorities from Very low to very high enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow }; /* Constructs a new ToDoEvent @param completed Is the TodoEvent completed @param priority What is the priority of this ToDoEvent @param category Which category does it belong( uid ) @param summary A small summary of the todo @param description What is this ToDoEvent about @param hasDate Does this Event got a deadline @param date what is the deadline? @param uid what is the UUID of this Event **/ OTodo( bool completed = false, int priority = Normal, const QStringList &category = QStringList(), const QString &summary = QString::null , const QString &description = QString::null, ushort progress = 0, bool hasDate = false, QDate date = QDate::currentDate(), int uid = -1 ); /* Copy c'tor **/ OTodo(const OTodo & ); /** *destructor */ ~OTodo(); /** * Is this event completed? */ bool isCompleted() const; /** * Does this Event have a deadline */ bool hasDueDate() const; /** * Does this Event has an alarm time ? */ bool hasAlarmDateTime() const; /** * What is the priority? */ int priority()const ; /** * progress as ushort 0, 20, 40, 60, 80 or 100% */ ushort progress() const; /** * The due Date */ QDate dueDate()const; /** * Alarm Date and Time */ QDateTime alarmDateTime()const; /** * The description of the todo */ QString description()const; /** * A small summary of the todo */ QString summary() const; /** * @reimplemented * Return this todoevent in a RichText formatted QString */ QString toRichText() const; + /** + * reimplementation + */ + QString type()const; + QString toShortText()const; + QMap<QString, QString> toExtraMap()const; + QString recordField(int id )const; /** * returns a list of apps which have related items */ QStringList relatedApps()const; /** * returns all relations for one app */ QArray<int> relations( const QString& app )const; /** * toMap puts all data into the map. int relates * to ToDoEvent RecordFields enum */ QMap<int, QString> toMap()const; /** * Set if this Todo is completed */ void setCompleted(bool completed ); /** * set if this todo got an end data */ void setHasDueDate( bool hasDate ); /** * set if this todo has an alarm time and date */ void setHasAlarmDateTime ( bool hasAlarm ); /** * Set the priority of the Todo */ void setPriority(int priority ); /** * Set the progress. */ void setProgress( ushort progress ); /** * set the end date */ void setDueDate( QDate date ); /** * set the alarm time */ void setAlarmDateTime ( const QDateTime& alarm ); void setDescription(const QString& ); void setSummary(const QString& ); bool isOverdue(); bool match( const QRegExp &r )const; bool operator<(const OTodo &toDoEvent )const; bool operator<=(const OTodo &toDoEvent )const; bool operator!=(const OTodo &toDoEvent )const; bool operator>(const OTodo &toDoEvent )const; bool operator>=(const OTodo &toDoEvent)const; bool operator==(const OTodo &toDoEvent )const; - ToDoEvent &operator=(const OTodo &toDoEvent ); + OTodo &operator=(const OTodo &toDoEvent ); private: class OTodoPrivate; - struct OTodoEventData; + struct OTodoData; void deref(); void changeOrModify(); void copy( OTodoData* src, OTodoData* dest ); - ToDoEventPrivate *d; - ToDoEventData *data; + OTodoPrivate *d; + OTodoData *data; - static Qtopia::UidGen m_gen; }; - inline bool ToDoEvent::operator!=(const ToDoEvent &toDoEvent )const { +inline bool OTodo::operator!=(const OTodo &toDoEvent )const { return !(*this == toDoEvent); } -}; + #endif |