summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/TODO17
-rw-r--r--libopie/ofileselector.cc191
-rw-r--r--libopie/ofileselector.h37
3 files changed, 233 insertions, 12 deletions
diff --git a/libopie/TODO b/libopie/TODO
new file mode 100644
index 0000000..c1bf6d1
--- a/dev/null
+++ b/libopie/TODO
@@ -0,0 +1,17 @@
1- xmltree done
2
3- tododb
4 - set Alarms
5 - multiple categories
6 - Attendees
7
8- OFileSelector
9 - DocLnk when not in Document Mode
10 - TreeView have a own OFileSelectorItem for this
11 - IconView add a QIconView to the widgetstack
12 - Move OFileSelectorItem to it's own files
13 - add functions to access the member variables
14 - debug
15
16- Clickable labels?
17 Harlekin you wanted them in the libs? \ No newline at end of file
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc
index 128292f..b583125 100644
--- a/libopie/ofileselector.cc
+++ b/libopie/ofileselector.cc
@@ -38,16 +38,23 @@
38#include <qlabel.h> 38#include <qlabel.h>
39#include <qheader.h> 39#include <qheader.h>
40#include <qdir.h> 40#include <qdir.h>
41#include <qpainter.h> 41#include <qpainter.h>
42#include <qaction.h>
43#include <qpopupmenu.h>
44#include <qcursor.h>
42 45
43#include <qpe/qpeapplication.h> 46#include <qpe/qpeapplication.h>
44#include <qpe/fileselector.h> 47#include <qpe/fileselector.h>
45#include <qpe/applnk.h> 48#include <qpe/applnk.h>
46#include <qpe/global.h> 49#include <qpe/global.h>
47#include <qpe/mimetype.h> 50#include <qpe/mimetype.h>
48#include <qpe/resource.h> 51#include <qpe/resource.h>
49 52
53#include <unistd.h>
54#include <stdlib.h>
55#include <sys/stat.h>
56
50#include "ofileselector.h" 57#include "ofileselector.h"
51 58
52QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; 59QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0;
53 60
@@ -110,8 +117,9 @@ OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString
110 m_viewCheck = 0; 117 m_viewCheck = 0;
111 118
112 m_dir = true; 119 m_dir = true;
113 m_files = true; 120 m_files = true;
121 m_custom = 0;
114 122
115 if(m_pixmaps == 0 ) // init the pixmaps 123 if(m_pixmaps == 0 ) // init the pixmaps
116 initPics(); 124 initPics();
117 125
@@ -177,8 +185,9 @@ void OFileSelector::init()
177 m_select = new FileSelector( currMime == "All" ? QString::null : currMime , m_stack, "fileselector", FALSE, FALSE ); 185 m_select = new FileSelector( currMime == "All" ? QString::null : currMime , m_stack, "fileselector", FALSE, FALSE );
178 m_stack->addWidget(m_select, NORMAL ); 186 m_stack->addWidget(m_select, NORMAL );
179 m_lay->addWidget(m_stack ); 187 m_lay->addWidget(m_stack );
180 m_stack->raiseWidget(NORMAL ); 188 m_stack->raiseWidget(NORMAL );
189 connect(m_select, SIGNAL(fileSelected( const DocLnk &) ), this, SLOT(slotFileBridgeSelected(const DocLnk &) ) );
181 }else { 190 }else {
182 initializeListView(); 191 initializeListView();
183 } 192 }
184 193
@@ -276,12 +285,12 @@ void OFileSelector::setCaseSensetive( bool caSe )
276void OFileSelector::setShowFiles(bool files ){ 285void OFileSelector::setShowFiles(bool files ){
277 m_files = files; 286 m_files = files;
278 reparse(); 287 reparse();
279} 288}
280void OFileSelector::setPopupMenu(const QPopupMenu * ) 289void OFileSelector::setPopupMenu(QPopupMenu *pop )
281{ 290{
282 //delete oldpopup; 291 //delete oldpopup;
283 292 m_custom = pop;
284} 293}
285bool OFileSelector::setPermission( ) const 294bool OFileSelector::setPermission( ) const
286{ 295{
287 if( m_checkPerm == 0 ) 296 if( m_checkPerm == 0 )
@@ -556,9 +565,9 @@ void OFileSelector::slotViewCheck(const QString &view ){
556 m_selector = NORMAL; 565 m_selector = NORMAL;
557 updateMimes(); 566 updateMimes();
558 m_mimeCheck->insertStringList( m_mimetypes ); 567 m_mimeCheck->insertStringList( m_mimetypes );
559 m_stack->raiseWidget( NORMAL ); 568 m_stack->raiseWidget( NORMAL );
560 569 connect(m_select, SIGNAL(fileSelected( const DocLnk &) ), this, SLOT(slotFileBridgeSelected(const DocLnk &) ) );
561 570
562 }else if(view == QString::fromLatin1("Files") ){ 571 }else if(view == QString::fromLatin1("Files") ){
563 // remove from the stack 572 // remove from the stack
564 delete m_select; 573 delete m_select;
@@ -618,8 +627,15 @@ void OFileSelector::initializeListView()
618 m_View->addColumn(tr("Mime Type") ); 627 m_View->addColumn(tr("Mime Type") );
619 QHeader *header = m_View->header(); 628 QHeader *header = m_View->header();
620 header->hide(); 629 header->hide();
621 m_View->setSorting(1 ); 630 m_View->setSorting(1 );
631 // connect now
632 connect(m_View, SIGNAL(selectionChanged() ), this, SLOT(slotSelectionChanged() ) );
633 connect(m_View, SIGNAL(currentChanged(QListViewItem *) ), this, SLOT(slotCurrentChanged(QListViewItem * ) ) );
634 connect(m_View, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int) ),
635 this, SLOT(slotClicked( int, QListViewItem *, const QPoint &, int) ) );
636 connect(m_View, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int )),
637 this, SLOT(slotRightButton(int, QListViewItem *, const QPoint &, int ) ) );
622}; 638};
623/* If a item is locked depends on the mode 639/* If a item is locked depends on the mode
624 if we're in OPEN !isReadable is locked 640 if we're in OPEN !isReadable is locked
625 if we're in SAVE !isWriteable is locked 641 if we're in SAVE !isWriteable is locked
@@ -675,9 +691,9 @@ void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink )
675 if(!m_dir ) 691 if(!m_dir )
676 return; 692 return;
677 //if( showDirs ) 693 //if( showDirs )
678 { 694 {
679 bool locked; 695 bool locked=false;
680 QString name; 696 QString name;
681 QPixmap pix; 697 QPixmap pix;
682 if( ( m_mode == OPEN && !info->isReadable() ) || ( m_mode == SAVE && !info->isWritable() ) ){ 698 if( ( m_mode == OPEN && !info->isReadable() ) || ( m_mode == SAVE && !info->isWritable() ) ){
683 locked = true; 699 locked = true;
@@ -712,6 +728,173 @@ void OFileSelector::setShowDirs(bool dir )
712 m_dir = dir; 728 m_dir = dir;
713 reparse(); 729 reparse();
714} 730}
715 731
732void OFileSelector::slotFileSelected(const QString &string )
733{
734 if(m_shLne )
735 m_edit->setText( string );
736
737 emit fileSelected( string );
738 // do AppLnk stuff
739}
740void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk )
741{
742 slotFileSelected(lnk.name() );
743 emit fileSelected( lnk );
744}
745void OFileSelector::slotSelectionChanged() // get the current items
746 // fixme
747{
748 qWarning("selection changed" );
749}
750void OFileSelector::slotCurrentChanged(QListViewItem *item )
751{
752 qWarning("current changed" );
753 if( item == 0 )
754 return;
755
756 if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){
757 OFileSelectorItem *sel = (OFileSelectorItem*)item;
758 if(!sel->isDir() ){
759 qWarning("is not dir" );
760 if(m_shLne ){
761 m_edit->setText(sel->text(1) );
762 qWarning("setTexy" );
763 }
764 }
765 }else {
766 qWarning("mode not extended" );
767 }
768}
769// either select or change dir
770void OFileSelector::slotClicked( int button, QListViewItem *item, const QPoint &point, int )
771{
772 if( item == 0 )
773 return;
774
775 if( button != Qt::LeftButton )
776 return;
777
778 qWarning("clicked" );
779 if(m_selector == EXTENDED || m_selector == EXTENDED_ALL ){
780 qWarning("inside" );
781 OFileSelectorItem *sel = (OFileSelectorItem*)item;
782 if(!sel->isLocked() ){ // not locked either changedir or open
783 QStringList str = QStringList::split("->", sel->text(1) );
784 if(sel->isDir() ){
785 cd( sel->directory() + "/" + str[0] );
786 }else{
787 qWarning("file" );
788 if(m_shLne )
789 m_edit->setText(str[0] );
790 emit fileSelected(str[0] );
791 // emit DocLnk need to do it
792 }
793 }else{
794 qWarning( "locked" );
795 }
796 };
797}
798void OFileSelector::slotRightButton(int button, QListViewItem *item, const QPoint &, int )
799{
800 if( button != Qt::RightButton )
801 return;
802 qWarning("right button" );
803 slotContextMenu(item);
804}
805void OFileSelector::slotContextMenu(QListViewItem *item)
806{
807 qWarning("context menu" );
808 if( m_custom !=0){
809 m_custom->exec();
810 }else{
811 QPopupMenu menu;
812 QAction act;
813 OFileSelectorItem *sel = (OFileSelectorItem*)item;
814 if(sel->isDir() ){
815 act.setText( tr("Change Directory") );
816 act.addTo(&menu );
817 connect(&act, SIGNAL(activated() ),
818 this, SLOT(slotChangedDir() ) );
819 }else{
820 act.setText( tr("Open file" ) );
821 act.addTo( &menu );
822 connect(&act, SIGNAL(activated() ),
823 this, SLOT(slotOpen() ) );
824 }
825 QAction rescan;
826 rescan.setText( tr("Rescan") );
827 rescan.addTo( &menu );
828 connect(&act, SIGNAL(activated() ),
829 this, SLOT(slotRescan() ) );
830
831 QAction rename;
832 rename.setText( tr("Rename") );
833 rename.addTo( &menu );
834 connect(&act, SIGNAL(activated() ),
835 this, SLOT(slotRename() ) );
836
837 menu.insertSeparator();
838 QAction delItem;
839 delItem.setText( tr("Delete") );
840 delItem.addTo(&menu );
841 connect(&act, SIGNAL(activated() ),
842 this, SLOT(slotDelete() ) );
843
844 menu.exec(QCursor::pos() );
845 }
846}
847bool OFileSelector::cd(const QString &str )
848{
849 qWarning(" dir %s", str.latin1() );
850 QDir dir( str);
851 if(dir.exists() ){
852 m_currentDir = str;
853 reparse();
854 return true;
855 }
856 return false;
857}
858
859void OFileSelector::slotChangedDir()
860{
861 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
862 if(sel->isDir() ){
863 QStringList str = QStringList::split("->", sel->text(1) );
864 cd( sel->directory() + "/" + str[0] );
865 }
866}
867void OFileSelector::slotOpen()
868{
869 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
870 if(!sel->isDir() ){
871 QStringList str = QStringList::split("->", sel->text(1) );
872 slotFileSelected( str[0] );
873 }
874}
875void OFileSelector::slotRescan()
876{
877 reparse();
878}
879void OFileSelector::slotRename()
880{
881 // rename inline
882}
883void OFileSelector::slotDelete()
884{
885 qWarning("delete slot" );
886 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
887 QStringList list = QStringList::split("->", sel->text(1) );
888 if( sel->isDir() ){
889 QString str = QString::fromLatin1("rm -rf ") + list[0];
890 ::system(str.utf8().data() );
891 }else{
892 QFile::remove( list[0] );
893 }
894 m_View->takeItem( sel );
895 delete sel;
896}
897
898
716 899
717 900
diff --git a/libopie/ofileselector.h b/libopie/ofileselector.h
index 6936773..458e552 100644
--- a/libopie/ofileselector.h
+++ b/libopie/ofileselector.h
@@ -77,9 +77,9 @@ class OFileSelectorItem : public QListViewItem {
77 m_dir = mDir; 77 m_dir = mDir;
78 dir = isDir; 78 dir = isDir;
79 mLocked = isLocked; 79 mLocked = isLocked;
80 } 80 }
81 bool locked() const{ 81 bool isLocked() const{
82 return mLocked; 82 return mLocked;
83 } 83 }
84 QString directory()const{ 84 QString directory()const{
85 return m_dir; 85 return m_dir;
@@ -147,17 +147,17 @@ class OFileSelector : public QWidget {
147 void setCaseSensetive(bool caSe ); 147 void setCaseSensetive(bool caSe );
148 148
149 bool showFiles()const { return m_files; }; 149 bool showFiles()const { return m_files; };
150 void setShowFiles(bool ); 150 void setShowFiles(bool );
151 151 bool cd(const QString &path );
152 152
153 153
154 int mode()const { return m_mode; }; 154 int mode()const { return m_mode; };
155 int selector()const { return m_selector; }; 155 int selector()const { return m_selector; };
156 void setSelector( int ); 156 void setSelector( int );
157 157
158 158
159 void setPopupMenu( const QPopupMenu * ); 159 void setPopupMenu( QPopupMenu * );
160 160
161 void updateLay(); 161 void updateLay();
162 162
163 void reparse(); // re reads the dir 163 void reparse(); // re reads the dir
@@ -190,9 +190,13 @@ class OFileSelector : public QWidget {
190 void slotMimeCheck(const QString & ); 190 void slotMimeCheck(const QString & );
191 protected: 191 protected:
192 void init(); 192 void init();
193 void updateMimes(); 193 void updateMimes();
194 int m_mode, m_selector; 194
195 protected:
196
197 private:
198int m_mode, m_selector;
195 QComboBox *m_location, *m_mimeCheck, *m_viewCheck; 199 QComboBox *m_location, *m_mimeCheck, *m_viewCheck;
196 QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel; 200 QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel;
197 QPushButton *m_reread, *m_up; 201 QPushButton *m_reread, *m_up;
198 QListView *m_View; 202 QListView *m_View;
@@ -211,8 +215,10 @@ class OFileSelector : public QWidget {
211 QHBoxLayout *m_boxOk; 215 QHBoxLayout *m_boxOk;
212 QHBoxLayout *m_boxName; 216 QHBoxLayout *m_boxName;
213 QHBoxLayout *m_boxView; 217 QHBoxLayout *m_boxView;
214 218
219 QPopupMenu *m_custom;
220
215 QLineEdit *m_edit; 221 QLineEdit *m_edit;
216 QLabel *m_fnLabel; 222 QLabel *m_fnLabel;
217 bool m_shTool:1; 223 bool m_shTool:1;
218 bool m_shPerm:1; 224 bool m_shPerm:1;
@@ -224,15 +230,12 @@ class OFileSelector : public QWidget {
224 bool m_case:1; 230 bool m_case:1;
225 bool m_dir:1; 231 bool m_dir:1;
226 bool m_files:1; 232 bool m_files:1;
227 233
228 protected:
229
230 private:
231 // implementation todo 234 // implementation todo
232 virtual void addFile(const QString &mime, QFileInfo *info, bool symlink = FALSE ); 235 virtual void addFile(const QString &mime, QFileInfo *info, bool symlink = FALSE );
233 virtual void addDir( const QString &mime, QFileInfo *info , bool symlink = FALSE ); 236 virtual void addDir( const QString &mime, QFileInfo *info , bool symlink = FALSE );
234 virtual void addSymlink(const QString &mime, QFileInfo *info, bool broken = FALSE ){}; 237 virtual void addSymlink(const QString &, QFileInfo *, bool = FALSE ){};
235 void delItems(); 238 void delItems();
236 void initializeName(); 239 void initializeName();
237 void initializeYes(); 240 void initializeYes();
238 void initializeChooser(); 241 void initializeChooser();
@@ -242,8 +245,26 @@ class OFileSelector : public QWidget {
242 245
243 class OFileSelectorPrivate; 246 class OFileSelectorPrivate;
244 OFileSelectorPrivate *d; 247 OFileSelectorPrivate *d;
245 static QMap<QString,QPixmap> *m_pixmaps; 248 static QMap<QString,QPixmap> *m_pixmaps;
249
250private slots:
251 void slotFileSelected(const QString & ); // not really meant to be a slot
252 void slotFileBridgeSelected( const DocLnk & );
253 virtual void slotSelectionChanged();
254 virtual void slotCurrentChanged(QListViewItem* );
255 virtual void slotClicked( int, QListViewItem *item, const QPoint &, int);
256 virtual void slotRightButton(int, QListViewItem *, const QPoint &, int );
257 virtual void slotContextMenu( QListViewItem *item);
258 // listview crap see above
259 // PopupMenu crap
260 virtual void slotChangedDir();
261 virtual void slotOpen();
262 virtual void slotRescan();
263 virtual void slotRename();
264 virtual void slotDelete();
265
246}; 266};
247 267
248 268
249#endif 269#endif
270