summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/libopie.pro3
-rw-r--r--libopie/libopie1.control4
-rw-r--r--libopie/odevice.cpp111
-rw-r--r--libopie/ofiledialog.cc81
-rw-r--r--libopie/ofiledialog.h3
-rw-r--r--libopie/ofileselector.cc1310
-rw-r--r--libopie/ofileselector.cpp856
-rw-r--r--libopie/ofileselector.h362
-rw-r--r--libopie/ofileselector_p.h151
-rw-r--r--libopie/orecurrancewidget.cpp56
-rw-r--r--libopie/oticker.h4
-rw-r--r--libopie/todayplugininterface.h42
12 files changed, 1319 insertions, 1664 deletions
diff --git a/libopie/libopie.pro b/libopie/libopie.pro
index 4535c4e..6fbd449 100644
--- a/libopie/libopie.pro
+++ b/libopie/libopie.pro
@@ -4,4 +4,5 @@ HEADERS = ofontmenu.h \
4 ocolorbutton.h \ 4 ocolorbutton.h \
5 ofiledialog.h ofileselector.h \ 5 ofiledialog.h ofileselector.h \
6 ofileselector_p.h \
6 ocheckitem.h \ 7 ocheckitem.h \
7 xmltree.h \ 8 xmltree.h \
@@ -50,5 +51,5 @@ SOURCES = ofontmenu.cc \
50 sharp_compat.cpp \ 51 sharp_compat.cpp \
51 xmltree.cc \ 52 xmltree.cc \
52 ofiledialog.cc ofileselector.cc \ 53 ofiledialog.cc ofileselector.cpp \
53 ocheckitem.cpp \ 54 ocheckitem.cpp \
54 colordialog.cpp \ 55 colordialog.cpp \
diff --git a/libopie/libopie1.control b/libopie/libopie1.control
index 1e75df3..76e4c7a 100644
--- a/libopie/libopie1.control
+++ b/libopie/libopie1.control
@@ -5,7 +5,7 @@ Section: opie/system
5Maintainer: Opie Team <opie@handhelds.org> 5Maintainer: Opie Team <opie@handhelds.org>
6Architecture: arm 6Architecture: arm
7Version: $QPE_VERSION-$SUB_VERSION.1 7Depends: libqte2 (>=$QTE_VERSION), libqpe1, opie-pics
8Depends: libqte2 (>=$QTE_VERSION), libqpe1
9Provides: libopie 8Provides: libopie
10Replaces: libopie 9Replaces: libopie
11Description: Opie library 10Description: Opie library
11Version: $QPE_VERSION$EXTRAVERSION
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 62dc9d4..17ae389 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -473,4 +473,7 @@ void ODevice::initButtons ( )
473ODevice::~ODevice ( ) 473ODevice::~ODevice ( )
474{ 474{
475// we leak m_devicebuttons and m_cpu_frequency
476// but it's a singleton and it is not so importantant
477// -zecke
475 delete d; 478 delete d;
476} 479}
@@ -786,5 +789,5 @@ const QStrList &ODevice::allowedCpuFrequencies ( ) const
786/** 789/**
787 * Set desired CPU frequency 790 * Set desired CPU frequency
788 * 791 *
789 * @param index index into d->m_cpu_frequencies of the frequency to be set 792 * @param index index into d->m_cpu_frequencies of the frequency to be set
790 */ 793 */
@@ -921,9 +924,7 @@ void ODevice::remapHeldAction ( int button, const OQCopMessage &action )
921 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 924 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
922} 925}
923void ODevice::virtual_hook( int id, void* data ) { 926void ODevice::virtual_hook(int, void* ){
924 Q_UNUSED(id);
925 Q_UNUSED(data);
926}
927 927
928}
928 929
929 930
@@ -1649,5 +1650,4 @@ int Zaurus::displayBrightnessResolution ( ) const
1649} 1650}
1650 1651
1651
1652/************************************************** 1652/**************************************************
1653 * 1653 *
@@ -1890,5 +1890,5 @@ bool SIMpad::suspend ( ) // Must override because SIMpad does NOT have apm
1890 1890
1891 ::sync ( ); // flush fs caches 1891 ::sync ( ); // flush fs caches
1892 res = ( ::system ( "echo > /proc/sys/pm/suspend" ) == 0 ); //TODO make better :) 1892 res = ( ::system ( "cat /dev/fb/0 >/tmp/.buffer; echo > /proc/sys/pm/suspend; cat /tmp/.buffer >/dev/fb/0" ) == 0 ); //TODO make better :)
1893 1893
1894 return res; 1894 return res;
@@ -1912,8 +1912,6 @@ bool SIMpad::setDisplayStatus ( bool on )
1912 QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :) 1912 QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :)
1913 1913
1914 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { 1914 res = ( ::system( (const char*) cmdline ) == 0 );
1915 res = ( ::system( (const char*) cmdline ) == 0 ); 1915
1916 ::close ( fd );
1917 }
1918 return res; 1916 return res;
1919} 1917}
@@ -1928,5 +1926,5 @@ bool SIMpad::setDisplayBrightness ( int bright )
1928 if ( bright > 255 ) 1926 if ( bright > 255 )
1929 bright = 255; 1927 bright = 255;
1930 if ( bright < 0 ) 1928 if ( bright < 1 )
1931 bright = 0; 1929 bright = 0;
1932 1930
@@ -1947,14 +1945,5 @@ bool SIMpad::setDisplayBrightness ( int bright )
1947int SIMpad::displayBrightnessResolution ( ) const 1945int SIMpad::displayBrightnessResolution ( ) const
1948{ 1946{
1949 switch ( model ( )) { 1947 return 255; // All SIMpad models share the same display
1950 case Model_SIMpad_CL4:
1951 case Model_SIMpad_SL4:
1952 case Model_SIMpad_SLC:
1953 case Model_SIMpad_TSinus:
1954 return 255; //TODO find out if this is save
1955
1956 default:
1957 return 2;
1958 }
1959} 1948}
1960 1949
@@ -1975,7 +1964,6 @@ void Ramses::init()
1975 d->m_model = Model_Ramses_MNCI; 1964 d->m_model = Model_Ramses_MNCI;
1976 1965
1977 d->m_rotation = Rot180; 1966 d->m_rotation = Rot0;
1978 d->m_direction = CW; 1967 d->m_holdtime = 1000;
1979 d->m_holdtime = 1000;
1980 1968
1981 f.setName("/etc/oz_version"); 1969 f.setName("/etc/oz_version");
@@ -2035,22 +2023,43 @@ void Ramses::timerEvent(QTimerEvent *)
2035bool Ramses::setSoftSuspend(bool soft) 2023bool Ramses::setSoftSuspend(bool soft)
2036{ 2024{
2037 Q_UNUSED(soft); 2025 qDebug("Ramses::setSoftSuspend(%d)", soft);
2038 return true; 2026#if 0
2039}
2040
2041bool Ramses::suspend()
2042{
2043 //qDebug("Ramses::suspend()");
2044 if ( !isQWS() ) // only qwsserver is allowed to suspend
2045 return false;
2046
2047 bool res = false; 2027 bool res = false;
2048 int fd; 2028 int fd;
2049 2029
2050 if ((fd = ::open("/proc/sys/pm/suspend", O_WRONLY)) >= 0) { 2030 if (((fd = ::open("/dev/apm_bios", O_RDWR)) >= 0) ||
2051 res = ( ::write ( fd, "1", 1 ) != -1 ); 2031 ((fd = ::open("/dev/misc/apm_bios",O_RDWR)) >= 0)) {
2032
2033 int sources = ::ioctl(fd, APM_IOCGEVTSRC, 0); // get current event sources
2034
2035 if (sources >= 0) {
2036 if (soft)
2037 sources &= ~APM_EVT_POWER_BUTTON;
2038 else
2039 sources |= APM_EVT_POWER_BUTTON;
2040
2041 if (::ioctl(fd, APM_IOCSEVTSRC, sources) >= 0) // set new event sources
2042 res = true;
2043 else
2044 perror("APM_IOCGEVTSRC");
2045 }
2046 else
2047 perror("APM_IOCGEVTSRC");
2048
2052 ::close(fd); 2049 ::close(fd);
2053 } 2050 }
2054 return res; 2051 else
2052 perror("/dev/apm_bios or /dev/misc/apm_bios");
2053
2054 return res;
2055#else
2056 return true;
2057#endif
2058}
2059
2060bool Ramses::suspend ( )
2061{
2062 qDebug("Ramses::suspend");
2063 return false;
2055} 2064}
2056 2065
@@ -2060,13 +2069,17 @@ bool Ramses::suspend()
2060bool Ramses::setDisplayStatus(bool on) 2069bool Ramses::setDisplayStatus(bool on)
2061{ 2070{
2062 //qDebug("Ramses::setDisplayStatus(%d)", on); 2071 qDebug("Ramses::setDisplayStatus(%d)", on);
2072#if 0
2063 bool res = false; 2073 bool res = false;
2064 int fd; 2074 int fd;
2065 2075
2066 if ((fd = ::open ("/dev/fb/1", O_RDWR)) >= 0) { 2076 if ((fd = ::open ("/dev/fb/0", O_RDWR)) >= 0) {
2067 res = (::ioctl(fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN) == 0); 2077 res = (::ioctl(fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN) == 0);
2068 ::close(fd); 2078 ::close(fd);
2069 } 2079 }
2070 return res; 2080 return res;
2081#else
2082 return true;
2083#endif
2071} 2084}
2072 2085
@@ -2077,5 +2090,5 @@ bool Ramses::setDisplayStatus(bool on)
2077bool Ramses::setDisplayBrightness(int bright) 2090bool Ramses::setDisplayBrightness(int bright)
2078{ 2091{
2079 //qDebug("Ramses::setDisplayBrightness(%d)", bright); 2092 qDebug("Ramses::setDisplayBrightness(%d)", bright);
2080 bool res = false; 2093 bool res = false;
2081 int fd; 2094 int fd;
@@ -2097,6 +2110,7 @@ bool Ramses::setDisplayBrightness(int bright)
2097 2110
2098 // scale backlight brightness to hardware 2111 // scale backlight brightness to hardware
2099 if ((fd = ::open("/proc/sys/board/lcd_brightness", O_WRONLY)) >= 0) { 2112 bright = 500-(bright * 500 / 255);
2100 //qDebug(" %d -> pwm1", bright); 2113 if ((fd = ::open("/proc/sys/board/pwm1", O_WRONLY)) >= 0) {
2114 qDebug(" %d -> pwm1", bright);
2101 char writeCommand[100]; 2115 char writeCommand[100];
2102 const int count = sprintf(writeCommand, "%d\n", bright); 2116 const int count = sprintf(writeCommand, "%d\n", bright);
@@ -2110,10 +2124,10 @@ bool Ramses::setDisplayBrightness(int bright)
2110int Ramses::displayBrightnessResolution() const 2124int Ramses::displayBrightnessResolution() const
2111{ 2125{
2112 return 256; 2126 return 32;
2113} 2127}
2114 2128
2115bool Ramses::setDisplayContrast(int contr) 2129bool Ramses::setDisplayContrast(int contr)
2116{ 2130{
2117 //qDebug("Ramses::setDisplayContrast(%d)", contr); 2131 qDebug("Ramses::setDisplayContrast(%d)", contr);
2118 bool res = false; 2132 bool res = false;
2119 int fd; 2133 int fd;
@@ -2125,7 +2139,8 @@ bool Ramses::setDisplayContrast(int contr)
2125 if (contr < 0) 2139 if (contr < 0)
2126 contr = 0; 2140 contr = 0;
2141 contr = 90 - (contr * 20 / 255);
2127 2142
2128 if ((fd = ::open("/proc/sys/board/lcd_contrast", O_WRONLY)) >= 0) { 2143 if ((fd = ::open("/proc/sys/board/pwm0", O_WRONLY)) >= 0) {
2129 //qDebug(" %d -> pwm0", contr); 2144 qDebug(" %d -> pwm0", contr);
2130 char writeCommand[100]; 2145 char writeCommand[100];
2131 const int count = sprintf(writeCommand, "%d\n", contr); 2146 const int count = sprintf(writeCommand, "%d\n", contr);
@@ -2140,4 +2155,4 @@ bool Ramses::setDisplayContrast(int contr)
2140int Ramses::displayContrastResolution() const 2155int Ramses::displayContrastResolution() const
2141{ 2156{
2142 return 256; 2157 return 20;
2143} 2158}
diff --git a/libopie/ofiledialog.cc b/libopie/ofiledialog.cc
index 9e725c2..5511b24 100644
--- a/libopie/ofiledialog.cc
+++ b/libopie/ofiledialog.cc
@@ -1,5 +1,5 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 <> 3             .=l. Copyright (c) 2002,2003 <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
@@ -28,10 +28,46 @@
28 28
29#include <qpe/applnk.h> 29#include <qpe/applnk.h>
30#include <qpe/config.h>
31#include <qpe/qpeapplication.h>
32
33#include <qfileinfo.h>
30#include <qstring.h> 34#include <qstring.h>
31#include <qapplication.h> 35#include <qapplication.h>
32#include <qlayout.h> 36#include <qlayout.h>
33 37
38
34#include "ofiledialog.h" 39#include "ofiledialog.h"
35 40
41
42namespace {
43 /*
44 * helper functions to load the start dir
45 * and to save it
46 * helper to extract the dir out of a file name
47 */
48 /**
49 * This method will use Config( argv[0] );
50 * @param key The group key used
51 */
52 QString lastUsedDir( const QString& key ) {
53 if ( qApp->argc() < 1 )
54 return QString::null;
55
56 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname
57 cfg.setGroup( key );
58 return cfg.readEntry("LastDir", QPEApplication::documentDir() );
59 }
60
61 void saveLastDir( const QString& key, const QString& file ) {
62 if ( qApp->argc() < 1 )
63 return;
64
65 Config cfg( QFileInfo(qApp->argv()[0]).fileName() );
66 cfg.setGroup( key );
67 QFileInfo inf( file );
68 cfg.writeEntry("LastDir", inf.dirPath( true ) );
69 }
70};
71
36/** 72/**
37 * This constructs a modal dialog 73 * This constructs a modal dialog
@@ -65,10 +101,13 @@ OFileDialog::OFileDialog(const QString &caption,
65 connect(file, SIGNAL(fileSelected(const QString&) ), 101 connect(file, SIGNAL(fileSelected(const QString&) ),
66 this, SLOT(slotFileSelected(const QString&) ) ); 102 this, SLOT(slotFileSelected(const QString&) ) );
103 connect(file, SIGNAL(ok() ),
104 this, SLOT(slotSelectorOk()) ) ;
67 105
106 connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) );
107
108#if 0
68 connect(file, SIGNAL(dirSelected(const QString &) ), 109 connect(file, SIGNAL(dirSelected(const QString &) ),
69 this, SLOT(slotDirSelected(const QString &) ) ); 110 this, SLOT(slotDirSelected(const QString &) ) );
70 111#endif
71
72 file->setYesCancelVisible( false ); // relayout
73} 112}
74/** 113/**
@@ -109,5 +148,5 @@ DocLnk OFileDialog::selectedDocument()const
109 */ 148 */
110QString OFileDialog::getOpenFileName(int selector, 149QString OFileDialog::getOpenFileName(int selector,
111 const QString &startDir, 150 const QString &_startDir,
112 const QString &file, 151 const QString &file,
113 const MimeTypes &mimes, 152 const MimeTypes &mimes,
@@ -116,9 +155,16 @@ QString OFileDialog::getOpenFileName(int selector,
116{ 155{
117 QString ret; 156 QString ret;
157 QString startDir = _startDir;
158 if (startDir.isEmpty() )
159 startDir = lastUsedDir( "FileDialog-OPEN" );
160
161
118 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption, 162 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption,
119 wid, OFileSelector::OPEN, selector, startDir, file, mimes); 163 wid, OFileSelector::Open, selector, startDir, file, mimes);
120 dlg.showMaximized(); 164 dlg.showMaximized();
121 if( dlg.exec() ) 165 if( dlg.exec() ) {
122 ret = dlg.fileName(); 166 ret = dlg.fileName();
167 saveLastDir( "FileDialog-OPEN", ret );
168 }
123 169
124 return ret; 170 return ret;
@@ -130,5 +176,5 @@ QString OFileDialog::getOpenFileName(int selector,
130 */ 176 */
131QString OFileDialog::getSaveFileName(int selector, 177QString OFileDialog::getSaveFileName(int selector,
132 const QString &startDir, 178 const QString &_startDir,
133 const QString &file, 179 const QString &file,
134 const MimeTypes &mimes, 180 const MimeTypes &mimes,
@@ -137,9 +183,15 @@ QString OFileDialog::getSaveFileName(int selector,
137{ 183{
138 QString ret; 184 QString ret;
185 QString startDir = _startDir;
186 if (startDir.isEmpty() )
187 startDir = lastUsedDir( "FileDialog-SAVE" );
188
139 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption, 189 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption,
140 wid, OFileSelector::SAVE, selector, startDir, file, mimes); 190 wid, OFileSelector::Save, selector, startDir, file, mimes);
141 dlg.showMaximized(); 191 dlg.showMaximized();
142 if( dlg.exec() ) 192 if( dlg.exec() ) {
143 ret = dlg.fileName(); 193 ret = dlg.fileName();
194 saveLastDir( "FileDialog-SAVE", ret );
195 }
144 196
145 return ret; 197 return ret;
@@ -150,6 +202,13 @@ void OFileDialog::slotFileSelected(const QString & )
150 accept(); 202 accept();
151} 203}
152void OFileDialog::slotDirSelected(const QString & ) 204
205void OFileDialog::slotSelectorOk( )
206{
207 accept();
208}
209
210void OFileDialog::slotDirSelected(const QString &dir )
153{ 211{
212 setCaption( dir );
154 // if mode 213 // if mode
155 //accept(); 214 //accept();
diff --git a/libopie/ofiledialog.h b/libopie/ofiledialog.h
index 309086b..91e0586 100644
--- a/libopie/ofiledialog.h
+++ b/libopie/ofiledialog.h
@@ -45,5 +45,5 @@
45 * QMap<QString, QStringList> mimeTypes; 45 * QMap<QString, QStringList> mimeTypes;
46 * QStringList types; 46 * QStringList types;
47 * types << "text/* "; 47 * types << "text[slash]* ";
48 * mimeTypes.insert( tr("Text"), types ); 48 * mimeTypes.insert( tr("Text"), types );
49 * mimeTypes.insert( tr("All"), " * / * " ); // remove the spaces in the 2nd comment 49 * mimeTypes.insert( tr("All"), " * / * " ); // remove the spaces in the 2nd comment
@@ -97,4 +97,5 @@ class OFileDialog : public QDialog {
97 void slotFileSelected( const QString & ); 97 void slotFileSelected( const QString & );
98 void slotDirSelected(const QString & ); 98 void slotDirSelected(const QString & );
99 void slotSelectorOk();
99}; 100};
100#endif 101#endif
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc
deleted file mode 100644
index 6748bec..0000000
--- a/libopie/ofileselector.cc
+++ b/dev/null
@@ -1,1310 +0,0 @@
1
2
3#include <qwmatrix.h>
4#include <qcheckbox.h>
5#include <qcombobox.h>
6#include <qheader.h>
7#include <qlabel.h>
8#include <qabstractlayout.h>
9#include <qlayout.h>
10#include <qlineedit.h>
11#include <qlistview.h>
12#include <qmessagebox.h>
13#include <qpainter.h>
14#include <qpushbutton.h>
15#include <qwidgetstack.h>
16#include <qpopupmenu.h>
17#include <qdir.h>
18#include <qfile.h>
19#include <qfileinfo.h>
20#include <qtimer.h>
21
22#include <qpe/qpeapplication.h>
23#include <qpe/applnk.h>
24#include <qpe/fileselector.h>
25#include <qpe/global.h>
26#include <qpe/mimetype.h>
27#include <qpe/resource.h>
28#include <qpe/storage.h>
29
30#include <unistd.h>
31#include <stdlib.h>
32#include <sys/stat.h>
33
34#include "ofileselector.h"
35
36
37QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0;
38
39namespace {
40 int indexByString( const QComboBox *box, const QString &str ){
41 int index= 0;
42 for(int i= 0; i < box->count(); i++ ){
43 if( str == box->text(i ) ){
44 index= i;
45 break;
46 }
47 }
48 return index;
49 }
50 class OFileSelectorItem : public QListViewItem {
51 public:
52 OFileSelectorItem(QListView *view, const QPixmap &pixmap, const QString &path,
53 const QString &date, const QString &size, const QString &mDir,
54 bool isLocked=false, bool isDir=false ): QListViewItem(view) {
55 setPixmap(0, pixmap );
56 setText(1, path );
57 setText(2, size );
58 setText(3, date );
59 //setText(4, mDir );
60 m_dir = mDir;
61 dir = isDir;
62 mLocked = isLocked;
63 }
64 bool isLocked() const{
65 return mLocked;
66 }
67 QString directory()const{
68 return m_dir;
69 }
70 bool isDir()const{
71 return dir;
72 }
73 QString path()const{
74 return text(1 );
75 }
76 QString key(int id, bool )const {
77 QString ke;
78 if( id == 0 || id == 1 ){ // name
79 if( dir ){
80 ke.append("0" );
81 ke.append( text(1) );
82 }else{
83 ke.append("1" );
84 ke.append( text(1) );
85 }
86 }else if( id == 2 ){ // size
87 return text(2);
88 }else if( id == 3 ){ // date
89 return text(3);
90 }
91 return ke;
92 };
93 private:
94 bool mLocked:1;
95 bool dir:1;
96 QString m_dir;
97 };
98};
99
100
101OFileSelector::OFileSelector( QWidget *wid, int mode, int selector,
102 const QString &dirName,
103 const QString &fileName,
104 const QMap<QString,QStringList>& mimeTypes)
105 : QWidget( wid, "OFileSelector")
106{
107 m_mimetypes = mimeTypes;
108 if (mode == SAVE )
109 m_name = fileName;
110 initVars();
111 m_mode = mode;
112 m_selector = selector;
113 m_currentDir = dirName;
114 init();
115 //QTimer::singleShot(6*1000, this, SLOT( slotTest() ) );
116}
117
118OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent,
119 const char *name, bool newVisible,
120 bool closeVisible )
121 : QWidget( parent, name )
122{
123 if (!mimeFilter.isEmpty() ) {
124 QStringList list = QStringList::split(";", mimeFilter );
125 m_mimetypes.insert(mimeFilter, list );
126 }
127 initVars();
128 m_currentDir = QPEApplication::documentDir();
129 m_mode = FILESELECTOR;
130 m_selector = NORMAL;
131 m_shClose = closeVisible;
132 m_shNew = newVisible;
133 m_shLne = false;
134 m_shPerm = false;
135 m_shYesNo = false;
136 init();
137
138}
139
140OFileSelector::~OFileSelector()
141{
142
143
144}
145
146void OFileSelector::setNewVisible( bool visible )
147{
148 m_shNew = visible;
149 if( m_selector == NORMAL ){
150 delete m_select;
151 // we need to initialize but keep the selected mimetype
152 QString mime = currentMimeType();
153 m_select = new FileSelector( mime ,
154 m_stack, "fileselector",
155 m_shNew, m_shClose);
156 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
157 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
158 connect(m_select, SIGNAL(closeMe() ),
159 this, SIGNAL(closeMe() ) );
160 //connect to close me and other signals as well
161 m_stack->addWidget( m_select, NORMAL );
162 }else{
163 m_new->show();
164 }
165}
166void OFileSelector::setCloseVisible( bool visible )
167{
168 m_shClose = visible;
169 if( m_selector == NORMAL ){
170 setNewVisible( m_shNew ); // yeah baby
171 }else{
172 m_close->show();
173 }
174}
175void OFileSelector::reread()
176{
177 if( m_selector == NORMAL ){
178 setNewVisible( m_shNew ); // make it a initializeSelector
179 }else if ( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){
180 reparse();
181 //}else{
182 //;
183 }
184}
185
186const DocLnk *OFileSelector::selected()
187{
188 DocLnk *lnk = new DocLnk(selectedDocument() );
189 return lnk;
190}
191
192void OFileSelector::setYesCancelVisible( bool show )
193{
194 initializeYes(); // FIXME if YesCancel is not shown we will initialize it to hide it :(
195 m_shYesNo = show;
196 if( m_shYesNo )
197 m_boxOk->show();
198 else
199 m_boxOk->hide();
200
201}
202void OFileSelector::setToolbarVisible( bool show )
203{
204 m_shTool = show;
205 initializeListView(); // FIXME see above waste of memory
206 if(!m_shTool ){
207 m_location->hide();
208 m_up->hide();
209 m_homeButton->hide();
210 m_docButton->hide();
211 }else{
212 m_location->show();
213 m_up->show();
214 m_homeButton->show();
215 m_docButton->show();
216 }
217}
218void OFileSelector::setPermissionBarVisible( bool show )
219{
220 m_shPerm = show;
221 initializePerm();
222 if( m_shPerm )
223 m_checkPerm->show();
224 else
225 m_checkPerm->hide();
226}
227void OFileSelector::setLineEditVisible( bool show )
228{
229 if( show ){
230 initializeName();
231 m_boxName->show();
232 }else{
233 if( m_shLne && m_boxName != 0 ){ // check if we showed before this is the way to go
234 m_boxName->hide();
235 }
236 }
237 m_shLne = show;
238}
239
240void OFileSelector::setChooserVisible( bool show )
241{
242 m_shChooser = show;
243 initializeChooser();
244 if( m_shChooser ){
245 m_boxView->hide();
246 }else{
247 m_boxView->show();
248 }
249}
250
251QCheckBox* OFileSelector::permissionCheckbox()
252{
253 if( m_selector == NORMAL )
254 return 0l;
255 else
256 return m_checkPerm;
257}
258bool OFileSelector::setPermission()const
259{
260 return m_checkPerm == 0 ? false : m_checkPerm->isChecked();
261}
262void OFileSelector::setPermissionChecked( bool check )
263{
264 if( m_checkPerm )
265 m_checkPerm->setChecked( check );
266}
267
268void OFileSelector::setMode(int mode) // FIXME do direct raising
269{
270 m_mode = mode;
271 if( m_selector == NORMAL )
272 return;
273}
274void OFileSelector::setShowDirs(bool )
275{
276 m_dir = true;
277 reparse();
278}
279void OFileSelector::setCaseSensetive(bool caSe )
280{
281 m_case = caSe;
282 reparse();
283}
284void OFileSelector::setShowFiles(bool show )
285{
286 m_files = show;
287 reparse();
288}
289///
290bool OFileSelector::cd(const QString &path )
291{
292 m_currentDir = path;
293 reparse();
294 return true;
295}
296void OFileSelector::setSelector(int mode )
297{
298QString text;
299 switch( mode ){
300 case NORMAL:
301 text = tr("Documents");
302 break;
303 case EXTENDED:
304 text = tr("Files");
305 break;
306 case EXTENDED_ALL:
307 text = tr("All Files");
308 break;
309 }
310 slotViewCheck( text );
311}
312
313void OFileSelector::setPopupMenu(QPopupMenu *popup )
314{
315 m_custom = popup;
316 m_showPopup = true;
317}
318
319//void OFileSelector::updateL
320
321QString OFileSelector::selectedName() const
322{
323 QString name;
324 if( m_selector == NORMAL ){
325 DocLnk lnk = m_select->selectedDocument();
326 name = lnk.file();
327 }else if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){
328 if ( m_shLne ) {
329 name = m_currentDir + "/" +m_edit->text();
330 }else{
331 QListViewItem *item = m_View->currentItem();
332 if( item != 0 )
333 name = m_currentDir + "/" + item->text( 1 );
334 }
335 }else { // installed view
336 ;
337 }
338 return name;
339}
340QStringList OFileSelector::selectedNames()const
341{
342 QStringList list;
343 if( m_selector == NORMAL ){
344 list << selectedName();
345 }else if ( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) {
346 list << selectedName(); // FIXME implement multiple Selections
347 }
348 return list;
349}
350/** If mode is set to the Dir selection this will return the selected path.
351 *
352 *
353 */
354QString OFileSelector::selectedPath()const
355{
356 QString path;
357 if( m_selector == NORMAL ){
358 path = QPEApplication::documentDir();
359 }else if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){
360 ;
361 }
362 return path;
363}
364QStringList OFileSelector::selectedPaths() const
365{
366 QStringList list;
367 list << selectedPath();
368 return list;
369}
370QString OFileSelector::directory()const
371{
372 if( m_selector == NORMAL )
373 return QPEApplication::documentDir();
374
375 return QDir(m_currentDir).absPath();
376}
377
378int OFileSelector::fileCount() const
379{
380 int count;
381 switch( m_selector ){
382 case NORMAL:
383 count = m_select->fileCount();
384 break;
385 //case CUSTOM:
386 case EXTENDED:
387 case EXTENDED_ALL:
388 default:
389 count = m_View->childCount();
390 break;
391 }
392 return count;
393}
394DocLnk OFileSelector::selectedDocument() const
395{
396 DocLnk lnk;
397 switch( m_selector ){
398 case NORMAL:{
399 lnk = m_select->selectedDocument();
400 break;
401 }
402 case EXTENDED:
403 case EXTENDED_ALL:
404 default:
405 lnk = DocLnk( selectedName() ); // new DocLnk
406 break;
407 }
408 return lnk;
409}
410QValueList<DocLnk> OFileSelector::selectedDocuments() const
411{
412 QValueList<DocLnk> docs;
413 docs.append( selectedDocument() );
414 return docs;
415}
416
417
418// slots internal
419
420void OFileSelector::slotOk()
421{
422 emit ok();
423}
424void OFileSelector::slotCancel()
425{
426 emit cancel();
427}
428void OFileSelector::slotViewCheck(const QString &sel)
429{
430 if( sel == tr("Documents" ) ){
431 if( m_select == 0 ){
432 // autMime? fix cause now we use All and not the current
433 // yes currentMime fixes that for us
434 QString mime = currentMimeType();
435 m_select = new FileSelector(mime,
436 m_stack, "fileselector",
437 m_shNew, m_shClose);
438 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
439 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
440 connect(m_select, SIGNAL(closeMe() ),
441 this, SIGNAL(closeMe() ) );
442 //connect to close me and other signals as well
443
444 m_stack->addWidget( m_select, NORMAL );
445 }
446 m_stack->raiseWidget( NORMAL );
447 m_selector = NORMAL;
448 }else if( sel == tr("Files") ){
449 m_selector = EXTENDED;
450 initializeListView();
451 reparse();
452 m_stack->raiseWidget( EXTENDED );
453 }else if( sel == tr("All Files") ){
454 m_selector = EXTENDED_ALL;
455 initializeListView();
456 reparse();
457 m_stack->raiseWidget( EXTENDED ); // same widget other QFileFilter
458 }
459}
460// not yet finished.....
461QString OFileSelector::currentMimeType() const{
462 QString mime;
463 QString currentText;
464 if (m_shChooser )
465 currentText = m_mimeCheck->currentText();
466
467 if (tr("All") == currentText ) return QString::null;
468 else if (currentText.isEmpty() ) {
469 ;
470 }else {
471 QMap<QString, QStringList>::ConstIterator it;
472 it = m_mimetypes.find( currentText );
473 if ( it == m_mimetypes.end() ) {
474 mime = it.data().join(";");
475 }else{
476 mime = currentText;
477 }
478 }
479 return mime;
480}
481void OFileSelector::slotMimeCheck(const QString &mime)
482{
483 if( m_selector == NORMAL ){
484 //if( m_autoMime ){
485 QString newMimeType;
486 if (mime != tr("All") ) {
487 QMap<QString, QStringList>::Iterator it;
488 it = m_mimetypes.find(mime);
489 if ( it != m_mimetypes.end() ) {
490 newMimeType = it.data().join(";");
491 }else{
492 newMimeType = mime;
493 }
494 }
495 delete m_select;
496 m_select = new FileSelector( newMimeType,
497 m_stack, "fileselector",
498 m_shNew, m_shClose);
499
500 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
501 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
502 connect(m_select, SIGNAL(closeMe() ),
503 this, SIGNAL(closeMe() ) );
504 //connect to close me and other signals as well
505 m_stack->addWidget( m_select, NORMAL );
506 m_stack->raiseWidget( NORMAL );
507 updateMimes();
508 updateMimeCheck();
509 m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) );
510 //}
511 }else{ // others
512 qWarning("Mime %s", mime.latin1() );
513 if(m_shChooser ){
514 qWarning("Current Text %s", m_mimeCheck->currentText().latin1() );
515 //m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) );
516 }
517 reparse();
518 }
519
520}
521/*
522 * Ok if a non dir gets inserted into this combobox
523 * we need to change it
524 * QFileInfo and dirPath will give us the right Dir
525 */
526void OFileSelector::slotLocationActivated(const QString &file)
527{
528 qWarning("slotLocationActivated");
529 QString name = file.left( file.find("<-", 0, TRUE ) );
530 QFileInfo info( name );
531 if ( info.isFile() )
532 cd(info.dirPath( TRUE ) ); //absolute
533 else
534 cd(name );
535 reparse();
536}
537void OFileSelector::slotInsertLocationPath(const QString &currentPath, int count)
538{
539 QStringList pathList;
540 bool underDog = FALSE;
541 for(int i=0;i<count;i++) {
542 pathList << m_location->text(i);
543 if( m_location->text(i) == currentPath)
544 underDog = TRUE;
545 }
546 if( !underDog) {
547 m_location->clear();
548 if( currentPath.left(2)=="//")
549 pathList.append( currentPath.right(currentPath.length()-1) );
550 else
551 pathList.append( currentPath );
552 m_location->insertStringList( pathList,-1);
553 }
554}
555/*
556 * Do not crash anymore
557 * don't try to change dir to a file
558 */
559void OFileSelector::locationComboChanged()
560{
561 QFileInfo info( m_location->lineEdit()->text() );
562 qWarning("info %s %s", info.dirPath(true).latin1(), m_location->lineEdit()->text().latin1() );
563 if (info.isFile() )
564 cd(info.dirPath(TRUE) ); //absolute path
565 else
566 cd( m_location->lineEdit()->text() );
567
568 reparse();
569}
570void OFileSelector::init()
571{
572 m_lay = new QVBoxLayout( this );
573 m_lay->setSpacing(0 );
574
575 m_stack = new QWidgetStack( this );
576 if( m_selector == NORMAL ){
577 QString mime;
578 if (!m_autoMime) {
579 if (!m_mimetypes.isEmpty() ) {
580 QMap<QString, QStringList>::Iterator it;
581 it = m_mimetypes.begin(); // cause we're in the init
582 mime = it.data().join(";");
583 }
584 }
585 m_select = new FileSelector(mime,
586 m_stack, "fileselector",
587 m_shNew, m_shClose);
588
589 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
590 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
591 connect(m_select, SIGNAL(closeMe() ),
592 this, SIGNAL( closeMe() ) );
593 //connect to close me and other signals as well
594
595 m_stack->addWidget( m_select, NORMAL );
596 m_stack->raiseWidget( NORMAL );
597 }else{ // we're in init so it will be EXTENDED or EXTENDED_ALL
598 // and initializeListview will take care of those
599 // toolbar get's generade in initializeListView
600 initializeListView( ); // will raise the widget as well
601 m_stack->raiseWidget( EXTENDED );
602 }
603 m_lay->addWidget( m_stack, 100 ); // add to the layout 10 = stretch
604
605 if( m_shLne ) // the LineEdit with the current FileName
606 initializeName();
607
608 if( m_shPerm ) // the Permission QCheckBox
609 initializePerm();
610
611 if( m_shChooser ) // the Chooser for the view and Mimetypes
612 initializeChooser();
613
614 if( m_shYesNo ) // the Yes No button row
615 initializeYes( );
616
617 if (m_selector != NORMAL )
618 reparse();
619}
620void OFileSelector::updateMimes()
621{
622 if( m_autoMime ){
623 m_mimetypes.clear();
624 m_mimetypes.insert( tr("All"), QString::null );
625 if( m_selector == NORMAL ){
626 DocLnkSet set;
627 Global::findDocuments(&set, QString::null );
628 QListIterator<DocLnk> dit( set.children() );
629 for( ; dit.current(); ++dit ){
630 if( !m_mimetypes.contains( (*dit)->type() ) )
631 m_mimetypes.insert( (*dit)->type(), (*dit)->type() );
632 }
633 }// else done in reparse
634 }
635}
636void OFileSelector::initVars()
637{
638 if( m_mimetypes.isEmpty() )
639 m_autoMime = true;
640 else
641 m_autoMime = false;
642 m_shClose = false;
643 m_shNew = false;
644 m_shTool = true;
645 m_shPerm = false;
646 m_shLne = true;
647 m_shChooser = true;
648 m_shYesNo = true;
649 m_case = false;
650 m_dir = true;
651 m_files = true;
652 m_showPopup = false;
653 if(m_pixmaps == 0 ) // init the pixmaps
654 initPics();
655
656 // pointers
657 m_location = 0;
658 m_mimeCheck = 0;
659 m_viewCheck = 0;
660 m_homeButton = 0;
661 m_docButton = 0;
662 m_hideButton = 0;
663 m_ok = 0;
664 m_cancel = 0;
665 m_reread = 0;
666 m_up = 0;
667 m_View = 0;
668 m_checkPerm = 0;
669 m_pseudo = 0;
670 m_pseudoLayout = 0;
671 m_select = 0;
672 m_stack = 0;
673 m_lay = 0;
674 m_Oselector = 0;
675 m_boxToolbar = 0;
676 m_boxOk = 0;
677 m_boxName = 0;
678 m_boxView = 0;
679 m_custom = 0;
680 m_edit = 0;
681 m_fnLabel = 0;
682 m_new = 0;
683 m_close = 0;
684}
685void OFileSelector::addFile(const QString &/*mime*/, QFileInfo *info, bool symlink)
686{
687 if(!m_files)
688 return;
689 // if( !compliesMime(info->absFilePath(), mime ) )
690 // return;
691 MimeType type( info->absFilePath() );
692 if (!compliesMime( type.id() ) )
693 return;
694
695 QPixmap pix = type.pixmap();
696 QString dir;
697 QString name;
698 bool locked;
699 if( pix.isNull() ) {
700 //TODO make this scaled pixmap global, so we dont have to keep doing this
701 QWMatrix matrix;
702 QPixmap pixer(Resource::loadPixmap( "UnknownDocument" ));
703 matrix.scale( .4, .4);
704 pix = pixer.xForm(matrix);
705// pix = Resource::loadPixmap( "UnknownDocument-14");
706 }
707 dir = info->dirPath( true );
708 if( symlink )
709 name = info->fileName() + " -> " +info->dirPath() + "/" + info->readLink();
710 else {
711 name = info->fileName();
712 if( ( m_mode == OPEN && !info->isReadable() )||
713 ( m_mode == SAVE && !info->isWritable() ) ){
714
715 locked = true; pix = Resource::loadPixmap("locked");
716 }
717 }
718 new OFileSelectorItem( m_View, pix, name,
719 info->lastModified().toString(),
720 QString::number( info->size() ),
721 dir, locked );
722}
723void OFileSelector::addDir(const QString &/*mime*/, QFileInfo *info, bool symlink )
724{
725 if(!m_dir)
726 return;
727 if( m_selector == EXTENDED_ALL || m_selector == EXTENDED ){
728 bool locked = false;
729 QString name;
730 QPixmap pix;
731 if( ( m_mode == OPEN && !info->isReadable() ) || ( m_mode == SAVE && !info->isWritable() ) ){
732 locked = true;
733 if( symlink )
734 pix = (*m_pixmaps)["symlinkedlocked"];
735 else
736 pix = Resource::loadPixmap("lockedfolder");
737 }else { // readable
738 pix = symlink ? (*m_pixmaps)["dirsymlink"] : Resource::loadPixmap("folder") ;
739 }
740 name = symlink ? info->fileName() + "->" + info->dirPath(true) + "/" +info->readLink() : info->fileName() ;
741 new OFileSelectorItem( m_View, pix, name,
742 info->lastModified().toString(),
743 QString::number( info->size() ),
744 info->dirPath( true ), locked,
745 true );
746
747 }// else CUSTOM View
748}
749void OFileSelector::delItems()
750{
751
752}
753void OFileSelector::initializeName()
754{
755 /** Name Layout Line
756 * This is the Layout line arranged in
757 * horizontal way each components
758 * are next to each other
759 * but we will only do this if
760 * we didn't initialize a while ago.
761 */
762 if( m_boxName == 0 ){
763 m_boxName = new QHBox( this ); // remove this this? or use a QHBox
764 m_fnLabel = new QLabel( m_boxName );
765 m_fnLabel->setText( tr("Name:") );
766 m_edit = new QLineEdit( m_boxName );
767 m_edit->setText( m_name );
768 //m_boxName->addWidget( m_fnLabel );
769 m_boxName->setMargin( 5 );
770 m_boxName->setSpacing( 8 );
771 //m_boxName->setStretchFactor(m_edit, 100 ); // 100 is stretch factor
772
773 m_lay->addWidget( m_boxName, 0 ); // add it to the topLevel layout
774 }// else we already initialized
775 // maybe show the components?
776 //
777}
778void OFileSelector::initializeYes()
779{
780 /** The Save Cancel bar
781 *
782 */
783 if( m_boxOk == 0 ){
784 m_boxOk = new QHBox( this );
785 m_ok = new QPushButton( tr("&Save"),m_boxOk , "save" );
786 m_cancel = new QPushButton( tr("C&ancel"), m_boxOk, "cancel" );
787
788 //m_boxOk->addWidget( m_ok );
789 //m_boxOk->addWidget( m_cancel );
790 m_boxOk->setMargin( 5 );
791 m_boxOk->setSpacing( 10 );
792 m_lay->addWidget( m_boxOk, 0 );
793
794 connect( m_ok, SIGNAL( clicked() ),
795 this, SLOT(slotOk() ) );
796 connect( m_cancel, SIGNAL( clicked() ),
797 this, SLOT( slotCancel() ) );
798 }
799}
800/*
801 * OK m_mimeCheck is a QComboBox we now want to fill
802 * out that combobox
803 * if automime we need to update the mimetypes
804 */
805void OFileSelector::updateMimeCheck() {
806 m_mimeCheck->clear();
807 if (m_autoMime ) {
808 //m_mimeCheck->insertItem( tr("All") );
809 updateMimes();
810 }
811
812 QMap<QString, QStringList>::Iterator it;
813 for (it = m_mimetypes.begin(); it != m_mimetypes.end(); ++it ) {
814 m_mimeCheck->insertItem( it.key() );
815 }
816}
817
818void OFileSelector::initializeChooser()
819{
820 if( m_boxView == 0 ){
821 m_boxView = new QHBox( this );
822 m_viewCheck = new QComboBox( m_boxView, "view check");
823 m_mimeCheck = new QComboBox( m_boxView, "mime check");
824 m_boxView->setSpacing( 8 );
825 m_lay->addWidget(m_boxView, 0 );
826
827 m_viewCheck->insertItem( tr("Documents") );
828 m_viewCheck->insertItem( tr("Files") );
829 m_viewCheck->insertItem( tr("All Files") );
830 updateMimeCheck();
831
832 connect( m_viewCheck, SIGNAL( activated(const QString & ) ),
833 this, SLOT( slotViewCheck(const QString & ) ) );
834 connect( m_mimeCheck, SIGNAL( activated(const QString & ) ),
835 this, SLOT( slotMimeCheck( const QString & ) ) );
836 }
837}
838void OFileSelector::initializeListView()
839{
840 qWarning("initializeListView");
841 if( m_pseudo == 0 ){
842 qWarning("init");
843 m_pseudo = new QWidget( m_stack, "Pseudo Widget");
844 m_pseudoLayout = new QVBoxLayout( m_pseudo );
845 // toolbar
846 m_boxToolbar = new QHBox( m_pseudo );
847 m_boxToolbar->setSpacing(0 ); // next to each other please
848
849 // toolbar members
850 {
851 // location QComboBox
852 m_location = new QComboBox( m_boxToolbar );
853 m_location->setEditable( TRUE );
854 m_location->setDuplicatesEnabled( FALSE );
855 connect( m_location, SIGNAL(activated(const QString &) ),
856 this, SLOT( slotLocationActivated(const QString &) ) );
857 connect( m_location->lineEdit(), SIGNAL(returnPressed() ),
858 this, SLOT(locationComboChanged() ) );
859 // UP Button
860 m_up = new QPushButton(Resource::loadIconSet("up"),"",
861 m_boxToolbar,"cdUpButton");
862 m_up->setFixedSize( QSize( 20, 20 ) );
863 connect(m_up ,SIGNAL(clicked()),this,SLOT(cdUP() ) );
864 m_up->setFlat(TRUE);
865
866 // Home Button
867 m_homeButton = new QPushButton(Resource::loadIconSet("home") ,
868 "", m_boxToolbar);
869 m_homeButton->setFixedSize( QSize( 20, 20 ) );
870 connect(m_homeButton,SIGNAL(clicked()),this,SLOT(slotHome() ) );
871 m_homeButton->setFlat(TRUE);
872 // Documents Button
873 m_docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",
874 m_boxToolbar,"docsButton");
875 m_docButton->setFixedSize( QSize( 20, 20 ) );
876 connect(m_homeButton,SIGNAL(clicked()),this,SLOT(slotDoc() ) );
877 m_docButton->setFlat(TRUE);
878
879 // Close button
880 m_close = new QPushButton( Resource::loadIconSet( "close"), "",
881 m_boxToolbar );
882 connect( m_close, SIGNAL(clicked() ), this, SIGNAL(closeMe() ) );
883 m_close->setFixedSize( 20, 20 );
884
885 m_boxToolbar->setFixedHeight( 20 );
886 m_pseudoLayout->addWidget(m_boxToolbar );
887
888 // let;s fill the Location ComboBox
889 StorageInfo storage;
890 const QList<FileSystem> &fs = storage.fileSystems();
891 QListIterator<FileSystem> it ( fs );
892 for( ; it.current(); ++it ){
893 const QString disk = (*it)->name();
894 const QString path = (*it)->path();
895 m_location->insertItem(path+ "<-"+disk );
896 }
897 int count = m_location->count();
898 m_location->insertItem( m_currentDir );
899 m_location->setCurrentItem( count );
900 // due to the New and Close button we can not simply hide m_boxToolBar to not show it
901 if( !m_shTool ){
902 m_location->hide( );
903 m_up->hide( );
904 m_homeButton->hide( );
905 m_docButton->hide( );
906 }
907 if(!m_shClose )
908 m_close->hide();
909 //if(!m_shNew)
910 //m_close->hide();
911
912 } // off toolbar
913 // the Main ListView
914 // make a QWidgetStack first so Views can share the Toolbar
915 m_View = new QListView( m_pseudo, "Extended view");
916 QPEApplication::setStylusOperation( m_View->viewport(),
917 QPEApplication::RightOnHold);
918 m_View->addColumn(" " );
919 m_View->addColumn(tr("Name"), 135 );
920 m_View->addColumn(tr("Size"), -1 );
921 m_View->addColumn(tr("Date"), 60 );
922 m_View->addColumn(tr("Mime Type"), -1 );
923 QHeader *header = m_View->header();
924 header->hide();
925 m_View->setSorting( 1 );
926 m_View->setAllColumnsShowFocus( TRUE );
927
928 connect(m_View, SIGNAL(selectionChanged() ),
929 this, SLOT(slotSelectionChanged() ) );
930
931 connect(m_View, SIGNAL(clicked(QListViewItem *) ),
932// connect(m_View, SIGNAL(currentChanged(QListViewItem *) ),
933 this, SLOT(slotCurrentChanged(QListViewItem * ) ) );
934
935 connect(m_View, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int) ),
936 this, SLOT(slotClicked( int, QListViewItem *, const QPoint &, int) ) );
937
938 connect(m_View, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int )),
939 this, SLOT(slotRightButton(int, QListViewItem *, const QPoint &, int ) ) );
940
941 m_pseudoLayout->addWidget( m_View, 288 );
942 m_stack->addWidget( m_pseudo, EXTENDED );
943 }
944}
945void OFileSelector::initializePerm()
946{
947 if( m_checkPerm == 0 ){
948 m_checkPerm = new QCheckBox(tr("Ser Permission"), this, "perm");
949 m_checkPerm->setChecked( false );
950 m_lay->addWidget( m_checkPerm );
951
952 }
953}
954void OFileSelector::initPics()
955{
956 m_pixmaps = new QMap<QString,QPixmap>;
957 QPixmap pm = Resource::loadPixmap( "folder" );
958 QPixmap lnk = Resource::loadPixmap( "opie/symlink" );
959 QPainter painter( &pm );
960 painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk );
961 pm.setMask( pm.createHeuristicMask( FALSE ) );
962 m_pixmaps->insert("dirsymlink", pm );
963
964 QPixmap pm2 = Resource::loadPixmap( "lockedfolder" );
965 QPainter pen(&pm2 );
966 pen.drawPixmap(pm2.width()-lnk.width(), pm2.height()-lnk.height(), lnk );
967 pm2.setMask( pm2.createHeuristicMask( FALSE ) );
968 m_pixmaps->insert("symlinkedlocked", pm2 );
969}
970// if a mime complies with the m_mimeCheck->currentItem
971bool OFileSelector::compliesMime( const QString &path, const QString &mime )
972{
973 if( mime == "All" )
974 return true;
975 MimeType type( path );
976 if( type.id() == mime )
977 return true;
978 return false;
979}
980/* check if the mimetype in mime
981 * complies with the one which is current
982 */
983/*
984 * We've the mimetype of the file
985 * We need to get the stringlist of the current mimetype
986 *
987 * mime = image/jpeg
988 * QStringList = 'image/*'
989 * or QStringList = image/jpeg;image/png;application/x-ogg
990 * or QStringList = application/x-ogg;image/*;
991 * with all these mime filters it should get acceptes
992 * to do so we need to look if mime is contained inside
993 * the stringlist
994 * if it's contained return true
995 * if not ( I'm no RegExp expert at all ) we'll look if a '/*'
996 * is contained in the mimefilter and then we will
997 * look if both are equal until the '/'
998 */
999bool OFileSelector::compliesMime( const QString& mime ) {
1000 qWarning("mimetype is %s", mime.latin1() );
1001 QString currentText;
1002 if (m_shChooser )
1003 currentText = m_mimeCheck->currentText();
1004
1005 qWarning("current text is %s", currentText.latin1() );
1006 QMap<QString, QStringList>::Iterator it;
1007 QStringList list;
1008 if ( currentText == tr("All") ) return true;
1009 else if ( currentText.isEmpty() && !m_mimetypes.isEmpty() ) {
1010 it = m_mimetypes.begin();
1011 list = it.data();
1012 }else if ( currentText.isEmpty() ) return true;
1013 else{
1014 it = m_mimetypes.find(currentText );
1015 if ( it == m_mimetypes.end() ) qWarning("not there"), list << currentText;
1016 else qWarning("found"), list = it.data();
1017 }
1018 // dump it now
1019 //for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
1020 // qWarning( "%s", (*it).latin1() );
1021 //}
1022
1023
1024 if ( list.contains(mime) ) return true;
1025 qWarning("list doesn't contain it ");
1026 QStringList::Iterator it2;
1027 int pos;
1028 for ( it2 = list.begin(); it2 != list.end(); ++it2 ) {
1029 pos = (*it2).findRev("/*");
1030 if ( pos >= 0 ) {
1031 if ( mime.contains( (*it2).left(pos) ) ) return true;
1032 }
1033 }
1034 return false;
1035}
1036void OFileSelector::slotFileSelected( const QString &string )
1037{
1038 if( m_shLne )
1039 m_edit->setText( string );
1040 emit fileSelected( string );
1041}
1042void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk )
1043{
1044 slotFileSelected( lnk.name() );
1045 emit fileSelected( lnk );
1046}
1047void OFileSelector::slotSelectionChanged()
1048{
1049
1050}
1051void OFileSelector::slotCurrentChanged(QListViewItem* item )
1052{
1053 if( item == 0 )
1054 return;
1055 if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) {
1056 OFileSelectorItem *sel = (OFileSelectorItem*) item; // start to use the C++ casts ;)
1057 qWarning("current changed");
1058 if(!sel->isDir() ){
1059 if( m_shLne )
1060 m_edit->setText( sel->text(1) );
1061
1062 if (m_mode == FILESELECTOR ) {
1063 QStringList str = QStringList::split("->", sel->text(1) );
1064 QString path =sel->directory() + "/" + str[0].stripWhiteSpace();
1065 emit fileSelected(path );
1066 DocLnk lnk( path );
1067 emit fileSelected(lnk );
1068 }
1069 }
1070 }
1071}
1072void OFileSelector::slotClicked( int button, QListViewItem *item, const QPoint &, int)
1073{
1074 if ( item == 0 )
1075 return;
1076
1077 if( button != Qt::LeftButton )
1078 return;
1079
1080 switch( m_selector ){
1081 default:
1082 break;
1083 case EXTENDED: // fall through
1084 case EXTENDED_ALL:{
1085 OFileSelectorItem *sel = (OFileSelectorItem*)item;
1086 if(!sel->isLocked() ){
1087 QStringList str = QStringList::split("->", sel->text(1) );
1088 if( sel->isDir() ){
1089 cd( sel->directory() + "/" + str[0].stripWhiteSpace() );
1090 // if MODE Dir m_shLne set the Text
1091 }else{
1092 if( m_shLne )
1093 m_edit->setText( str[0].stripWhiteSpace() );
1094 qWarning("selected here in slot clicked");
1095 emit fileSelected( sel->directory() + "/" + str[0].stripWhiteSpace() );
1096 DocLnk lnk( sel->directory() + "/" + str[0].stripWhiteSpace() );
1097 qWarning("file selected");
1098 emit fileSelected( lnk );
1099 }
1100 }
1101 break;
1102 }
1103 }
1104}
1105void OFileSelector::slotRightButton(int button, QListViewItem *item, const QPoint &, int )
1106{
1107 if( item == 0 )
1108 return;
1109
1110 if( button != Qt::RightButton )
1111 return;
1112 slotContextMenu( item );
1113}
1114void OFileSelector::slotContextMenu( QListViewItem * /*item*/)
1115{
1116
1117}
1118void OFileSelector::slotChangedDir()
1119{
1120 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
1121 if(sel->isDir() ){
1122 QStringList str = QStringList::split("->", sel->text(1) );
1123 cd( sel->directory() + "/" + str[0].stripWhiteSpace() );
1124 }
1125}
1126void OFileSelector::slotOpen()
1127{
1128 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
1129 if(!sel->isDir() ){
1130 QStringList str = QStringList::split("->", sel->text(1) );
1131 slotFileSelected( sel->directory() +"/" +str[0].stripWhiteSpace() );
1132 qWarning("slot open");
1133 // DocLnk lnk( sel->directory() + "/" + str[0].stripWhiteSpace() );
1134 //emit fileSelected( lnk );
1135 }
1136}
1137void OFileSelector::slotRescan()
1138{
1139
1140}
1141void OFileSelector::slotRename()
1142{
1143 reparse();
1144}
1145void OFileSelector::slotDelete()
1146{
1147 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
1148 QStringList list = QStringList::split("->", sel->text(1) );
1149 if( sel->isDir() ){
1150 QString str = QString::fromLatin1("rm -rf ") + sel->directory() +"/" + list[0]; //better safe than sorry
1151 switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+list[0],
1152 tr("Yes"),tr("No"),0,1,1) ) {
1153 case 0:
1154 ::system(str.utf8().data() );
1155 break;
1156 }
1157 } else {
1158 QFile::remove( list[0] );
1159 }
1160 m_View->takeItem( sel );
1161 delete sel;
1162}
1163void OFileSelector::cdUP()
1164{
1165 QDir dir( m_currentDir );
1166 dir.cdUp();
1167 if(dir.exists() ){
1168 m_currentDir = dir.absPath();
1169 reparse();
1170 int count = m_location->count();
1171 slotInsertLocationPath( m_currentDir, count);
1172 m_location->setCurrentItem( indexByString( m_location, m_currentDir));
1173 //this wont work in all instances
1174 // FIXME
1175 }
1176}
1177void OFileSelector::slotHome()
1178{
1179 cd(QDir::homeDirPath() );
1180}
1181void OFileSelector::slotDoc()
1182{
1183 cd(QPEApplication::documentDir() );
1184}
1185void OFileSelector::slotNavigate( )
1186{
1187
1188}
1189// fill the View with life
1190void OFileSelector::reparse()
1191{
1192 if( m_selector == NORMAL )
1193 return;
1194 if( m_selector == EXTENDED || m_selector == EXTENDED_ALL )
1195 m_View->clear();
1196 else // custom view
1197 ; // currentView()->clear();
1198 if( m_shChooser)
1199 qWarning("reparse %s", m_mimeCheck->currentText().latin1() );
1200
1201 QString currentMimeType;
1202 // let's update the mimetype
1203 if( m_autoMime ){
1204 m_mimetypes.clear();
1205 // ok we can change mimetype so we need to be able to give a selection
1206 if( m_shChooser ) {
1207 currentMimeType = m_mimeCheck->currentText();
1208 m_mimeCheck->clear();
1209
1210 // let's find possible mimetypes
1211 QDir dir( m_currentDir );
1212 if( dir.exists() ){
1213 dir.setFilter( QDir::Files | QDir::Readable );
1214 dir.setSorting( QDir::Size );
1215 const QFileInfoList *list = dir.entryInfoList();
1216 QFileInfoListIterator it( *list );
1217 QFileInfo *fi;
1218 while( (fi=it.current() ) ) {
1219 if( fi->extension() == QString::fromLatin1("desktop") ){
1220 ++it;
1221 continue;
1222 }
1223 MimeType type( fi->absFilePath() );
1224 if( !m_mimetypes.contains( type.id() ) ){
1225 //qWarning("Type %s", type.id().latin1() );
1226 m_mimetypes.insert( type.id(), type.id() );
1227 }
1228
1229 ++it;
1230 }
1231 // add them to the chooser
1232 updateMimeCheck();
1233 m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currentMimeType ) );
1234 currentMimeType = m_mimeCheck->currentText();
1235 }
1236 }
1237 }else { // no autoMime
1238 // let the mimetype be set from out side the m_mimeCheck FEATURE
1239
1240 if( m_shChooser ){
1241 currentMimeType = m_mimeCheck->currentText();
1242// updateMimeCheck();
1243 }
1244 }
1245 // now we got our mimetypes we can add the files
1246
1247 QDir dir( m_currentDir );
1248
1249 if( dir.exists() ){
1250 int sort;
1251 if ( m_case )
1252 sort = (QDir::IgnoreCase | QDir::Name | QDir::DirsFirst | QDir::Reversed);
1253 else
1254 sort = (QDir::Name | QDir::DirsFirst | QDir::Reversed);
1255 dir.setSorting( sort );
1256
1257 int filter;
1258 if( m_selector == EXTENDED_ALL /*|| m_selector ==CUSTOM_ALL */ ){
1259 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All;
1260 }else
1261 filter = QDir::Files | QDir::Dirs | QDir::All;
1262 dir.setFilter( filter );
1263
1264 // now go through all files
1265 const QFileInfoList *list = dir.entryInfoList();
1266 QFileInfoListIterator it( *list );
1267 QFileInfo *fi;
1268 while( (fi=it.current() ) ){
1269 //qWarning("True and only" );
1270 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){
1271 //qWarning(".. or ." );
1272 ++it;
1273 continue;
1274 }
1275 if( fi->isSymLink() ){
1276 QString file = fi->dirPath( true ) + "/" + fi->readLink();
1277 for( int i = 0; i<=4; i++) { // 5 tries to prevent dos
1278 QFileInfo info( file );
1279 if( !info.exists() ){
1280 addSymlink( currentMimeType, fi, TRUE );
1281 break;
1282 }else if( info.isDir() ){
1283 addDir( currentMimeType, fi, TRUE );
1284 break;
1285 }else if( info.isFile() ){
1286 addFile( currentMimeType, fi, TRUE );
1287 break;
1288 }else if( info.isSymLink() ){
1289 file = info.dirPath(true ) + "/" + info.readLink() ;
1290 break;
1291 }else if( i == 4){
1292 addSymlink( currentMimeType, fi );
1293 }
1294 } // off for loop
1295 }else if( fi->isDir() ){
1296 addDir( currentMimeType, fi );
1297 }else if( fi->isFile() ){
1298 addFile( currentMimeType, fi );
1299 }
1300 //qWarning( "%s", fi->fileName().latin1() );
1301 ++it;
1302 } // of while loop
1303 } // if ( dir.exists() )
1304 m_View->sort();
1305 if( m_shTool ){
1306 m_location->insertItem( m_currentDir );
1307
1308 }
1309 // reenable painting and updates
1310}
diff --git a/libopie/ofileselector.cpp b/libopie/ofileselector.cpp
new file mode 100644
index 0000000..577e916
--- a/dev/null
+++ b/libopie/ofileselector.cpp
@@ -0,0 +1,856 @@
1#include <qcombobox.h>
2#include <qdir.h>
3#include <qhbox.h>
4#include <qheader.h>
5#include <qlabel.h>
6#include <qlayout.h>
7#include <qlineedit.h>
8#include <qlistview.h>
9#include <qpopupmenu.h>
10#include <qwidgetstack.h>
11#include <qregexp.h>
12#include <qobjectlist.h>
13
14/* hacky but we need to get FileSelector::filter */
15#define private public
16#include <qpe/fileselector.h>
17#undef private
18
19#include <qpe/qpeapplication.h>
20#include <qpe/mimetype.h>
21#include <qpe/resource.h>
22#include <qpe/storage.h>
23
24#include "ofileselector_p.h"
25#include "ofileselector.h"
26
27
28
29OFileViewInterface::OFileViewInterface( OFileSelector* selector )
30 : m_selector( selector ) {
31}
32OFileViewInterface::~OFileViewInterface() {
33}
34QString OFileViewInterface::name()const{
35 return m_name;
36}
37void OFileViewInterface::setName( const QString& name ) {
38 m_name = name;
39}
40OFileSelector* OFileViewInterface::selector()const {
41 return m_selector;
42}
43DocLnk OFileViewInterface::selectedDocument()const {
44 return DocLnk( selectedName() );
45}
46bool OFileViewInterface::showNew()const {
47 return selector()->showNew();
48}
49bool OFileViewInterface::showClose()const {
50 return selector()->showClose();
51}
52MimeTypes OFileViewInterface::mimeTypes()const {
53 return selector()->mimeTypes();
54}
55QStringList OFileViewInterface::currentMimeType()const {
56 return selector()->currentMimeType();
57}
58void OFileViewInterface::activate( const QString& ) {
59 // not implemented here
60}
61void OFileViewInterface::ok() {
62 emit selector()->ok();
63}
64void OFileViewInterface::cancel() {
65 emit selector()->cancel();
66}
67void OFileViewInterface::closeMe() {
68 emit selector()->closeMe();
69}
70void OFileViewInterface::fileSelected( const QString& str) {
71 emit selector()->fileSelected( str);
72}
73void OFileViewInterface::fileSelected( const DocLnk& lnk) {
74 emit selector()->fileSelected( lnk );
75}
76void OFileViewInterface::setCurrentFileName( const QString& str ) {
77 selector()->m_lneEdit->setText( str );
78}
79QString OFileViewInterface::currentFileName()const{
80 return selector()->m_lneEdit->text();
81}
82QString OFileViewInterface::startDirectory()const{
83 return selector()->m_startDir;
84}
85
86
87ODocumentFileView::ODocumentFileView( OFileSelector* selector )
88 : OFileViewInterface( selector ) {
89 m_selector = 0;
90 setName( QObject::tr("Documents") );
91}
92ODocumentFileView::~ODocumentFileView() {
93
94}
95QString ODocumentFileView::selectedName()const {
96 if (!m_selector)
97 return QString::null;
98
99 return m_selector->selectedDocument().file();
100}
101QString ODocumentFileView::selectedPath()const {
102 return QPEApplication::documentDir();
103}
104QString ODocumentFileView::directory()const {
105 return selectedPath();
106}
107void ODocumentFileView::reread() {
108 if (!m_selector)
109 return;
110
111 m_selector->setNewVisible( showNew() );
112 m_selector->setCloseVisible( showClose() );
113 m_selector->filter = currentMimeType().join(";");
114 m_selector->reread();
115}
116int ODocumentFileView::fileCount()const {
117 if (!m_selector)
118 return -1;
119
120 return m_selector->fileCount();
121}
122DocLnk ODocumentFileView::selectedDocument()const {
123 if (!m_selector)
124 return DocLnk();
125
126 return m_selector->selectedDocument();
127}
128QWidget* ODocumentFileView::widget( QWidget* parent ) {
129 if (!m_selector ) {
130 m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() );
131 QObject::connect(m_selector, SIGNAL(fileSelected( const DocLnk& ) ),
132 selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) );
133 QObject::connect(m_selector, SIGNAL(closeMe() ),
134 selector(), SIGNAL(closeMe() ) );
135 QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk& ) ),
136 selector(), SIGNAL(newSelected(const DocLnk& ) ) );
137 }
138
139 return m_selector;
140}
141
142/*
143 * This is the file system view used
144 * we use a QListView + QListViewItems for it
145 */
146
147OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap,
148 const QString& path, const QString& date,
149 const QString& size, const QString& dir,
150 bool isLocked, bool isDir )
151 : QListViewItem( view )
152{
153 setPixmap(0, pixmap );
154 setText(1, path );
155 setText(2, size );
156 setText(3, date );
157 m_isDir = isDir;
158 m_dir = dir;
159 m_locked = isLocked;
160}
161OFileSelectorItem::~OFileSelectorItem() {
162
163}
164bool OFileSelectorItem::isLocked()const {
165 return m_locked;
166}
167QString OFileSelectorItem::directory()const {
168 return m_dir;
169}
170bool OFileSelectorItem::isDir()const {
171 return m_isDir;
172}
173QString OFileSelectorItem::path()const {
174 return text( 1 );
175}
176QString OFileSelectorItem::key( int id, bool )const {
177 QString ke;
178 if( id == 0 || id == 1 ){ // name
179 if( m_isDir ){
180 ke.append("0" );
181 ke.append( text(1) );
182 }else{
183 ke.append("1" );
184 ke.append( text(1) );
185 }
186 return ke;
187 }else
188 return text( id );
189
190}
191
192OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir,
193 OFileSelector* sel)
194 : QWidget( parent ), m_sel( sel ) {
195 m_all = false;
196 QVBoxLayout* lay = new QVBoxLayout( this );
197 m_currentDir = startDir;
198
199 /*
200 * now we add a special bar
201 * One Button For Up
202 * Home
203 * Doc
204 * And a dropdown menu with FileSystems
205 * FUTURE: one to change dir with lineedit
206 * Bookmarks
207 * Create Dir
208 */
209 QHBox* box = new QHBox(this );
210 box->setBackgroundMode( PaletteButton );
211 box->setSpacing( 0 );
212
213 QToolButton *btn = new QToolButton( box );
214 btn->setIconSet( Resource::loadIconSet("up") );
215 connect(btn, SIGNAL(clicked() ),
216 this, SLOT( cdUP() ) );
217
218 btn = new QToolButton( box );
219 btn->setIconSet( Resource::loadIconSet("home") );
220 connect(btn, SIGNAL(clicked() ),
221 this, SLOT( cdHome() ) );
222
223 btn = new QToolButton( box );
224 btn->setIconSet( Resource::loadIconSet("DocsIcon") );
225 connect(btn, SIGNAL(clicked() ),
226 this, SLOT(cdDoc() ) );
227
228 m_btnNew = new QToolButton( box );
229 m_btnNew->setIconSet( Resource::loadIconSet("new") );
230 connect(m_btnNew, SIGNAL(clicked() ),
231 this, SLOT(slotNew() ) );
232
233
234 m_btnClose = new QToolButton( box );
235 m_btnClose->setIconSet( Resource::loadIconSet("close") );
236 connect(m_btnClose, SIGNAL(clicked() ),
237 selector(), SIGNAL(closeMe() ) );
238
239 btn = new QToolButton( box );
240 btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") );
241
242 /* let's fill device parts */
243 QPopupMenu* pop = new QPopupMenu(this);
244 connect(pop, SIGNAL( activated(int) ),
245 this, SLOT(slotFSActivated(int) ) );
246
247 StorageInfo storage;
248 const QList<FileSystem> &fs = storage.fileSystems();
249 QListIterator<FileSystem> it(fs);
250 for ( ; it.current(); ++it ) {
251 const QString disk = (*it)->name();
252 const QString path = (*it)->path();
253 m_dev.insert( disk, path );
254 pop->insertItem( disk );
255 }
256 m_fsPop = pop;
257
258
259 btn->setPopup( pop );
260
261 lay->addWidget( box );
262
263 m_view = new QListView( this );
264
265 m_view->installEventFilter(this);
266
267 QPEApplication::setStylusOperation( m_view->viewport(),
268 QPEApplication::RightOnHold);
269 m_view->addColumn(" " );
270 m_view->addColumn(tr("Name"), 135 );
271 m_view->addColumn(tr("Size"), -1 );
272 m_view->addColumn(tr("Date"), 60 );
273 m_view->addColumn(tr("Mime Type"), -1 );
274
275
276 m_view->setSorting( 1 );
277 m_view->setAllColumnsShowFocus( TRUE );
278
279 lay->addWidget( m_view, 1000 );
280 connectSlots();
281}
282OFileViewFileListView::~OFileViewFileListView() {
283}
284void OFileViewFileListView::slotNew() {
285 DocLnk lnk;
286 emit selector()->newSelected( lnk );
287}
288OFileSelectorItem* OFileViewFileListView::currentItem()const{
289 QListViewItem* item = m_view->currentItem();
290 if (!item )
291 return 0l;
292
293 return static_cast<OFileSelectorItem*>(item);
294}
295void OFileViewFileListView::reread( bool all ) {
296 m_view->clear();
297
298 if (selector()->showClose() )
299 m_btnClose->show();
300 else
301 m_btnClose->hide();
302
303 if (selector()->showNew() )
304 m_btnNew->show();
305 else
306 m_btnNew->hide();
307
308 m_mimes = selector()->currentMimeType();
309 m_all = all;
310
311 QDir dir( m_currentDir );
312 if (!dir.exists() )
313 return;
314
315 dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed );
316 int filter;
317 if (m_all )
318 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All;
319 else
320 filter = QDir::Files | QDir::Dirs | QDir::All;
321 dir.setFilter( filter );
322
323 // now go through all files
324 const QFileInfoList *list = dir.entryInfoList();
325 if (!list) {
326 cdUP();
327 return;
328 }
329 QFileInfoListIterator it( *list );
330 QFileInfo *fi;
331 while( (fi=it.current() ) ){
332 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){
333 ++it;
334 continue;
335 }
336
337 /*
338 * It is a symlink we try to resolve it now but don't let us attack by DOS
339 *
340 */
341 if( fi->isSymLink() ){
342 QString file = fi->dirPath( true ) + "/" + fi->readLink();
343 for( int i = 0; i<=4; i++) { // 5 tries to prevent dos
344 QFileInfo info( file );
345 if( !info.exists() ){
346 addSymlink( fi, TRUE );
347 break;
348 }else if( info.isDir() ){
349 addDir( fi, TRUE );
350 break;
351 }else if( info.isFile() ){
352 addFile( fi, TRUE );
353 break;
354 }else if( info.isSymLink() ){
355 file = info.dirPath(true ) + "/" + info.readLink() ;
356 break;
357 }else if( i == 4){ // couldn't resolve symlink add it as symlink
358 addSymlink( fi );
359 }
360 } // off for loop for symlink resolving
361 }else if( fi->isDir() )
362 addDir( fi );
363 else if( fi->isFile() )
364 addFile( fi );
365
366 ++it;
367 } // of while loop
368 m_view->sort();
369
370}
371int OFileViewFileListView::fileCount()const{
372 return m_view->childCount();
373}
374QString OFileViewFileListView::currentDir()const{
375 return m_currentDir;
376}
377OFileSelector* OFileViewFileListView::selector() {
378 return m_sel;
379}
380
381bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) {
382 if ( e->type() == QEvent::KeyPress ) {
383 QKeyEvent *k = (QKeyEvent *)e;
384 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) {
385 slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0);
386 return true;
387 }
388 }
389 return false;
390}
391
392
393void OFileViewFileListView::connectSlots() {
394 connect(m_view, SIGNAL(clicked(QListViewItem*) ),
395 this, SLOT(slotCurrentChanged(QListViewItem*) ) );
396 connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ),
397 this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) );
398}
399void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) {
400 if (!item)
401 return;
402#if 0
403
404 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
405
406 if (!sel->isDir() ) {
407 selector()->m_lneEdit->setText( sel->text(1) );
408 // if in fileselector mode we will emit selected
409 if ( selector()->mode() == OFileSelector::FileSelector ) {
410 qWarning("slot Current Changed");
411 QStringList str = QStringList::split("->", sel->text(1) );
412 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
413 emit selector()->fileSelected( path );
414 DocLnk lnk( path );
415 emit selector()->fileSelected( lnk );
416 }
417 }
418#endif
419}
420void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) {
421 if (!item || ( button != Qt::LeftButton) )
422 return;
423
424 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
425 if (!sel->isLocked() ) {
426 QStringList str = QStringList::split("->", sel->text(1) );
427 if (sel->isDir() ) {
428 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace();
429 emit selector()->dirSelected( m_currentDir );
430 reread( m_all );
431 }else { // file
432 qWarning("slot Clicked");
433 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() );
434 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
435 emit selector()->fileSelected( path );
436 DocLnk lnk( path );
437 emit selector()->fileSelected( lnk );
438 }
439 } // not locked
440}
441void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) {
442 MimeType type( info->absFilePath() );
443 if (!compliesMime( type.id() ) )
444 return;
445
446 QPixmap pix = type.pixmap();
447 QString dir, name; bool locked;
448 if ( pix.isNull() ) {
449 QWMatrix matrix;
450 QPixmap pixer(Resource::loadPixmap("UnknownDocument") );
451 matrix.scale( .4, .4 );
452 pix = pixer.xForm( matrix );
453 }
454 dir = info->dirPath( true );
455 locked = false;
456 if ( symlink )
457 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink();
458 else{
459 name = info->fileName();
460 if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) ||
461 ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) {
462 locked = true; pix = Resource::loadPixmap("locked");
463 }
464 }
465 (void)new OFileSelectorItem( m_view, pix, name,
466 info->lastModified().toString(), QString::number( info->size() ),
467 dir, locked );
468}
469void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) {
470 bool locked = false; QString name; QPixmap pix;
471
472 if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) ||
473 ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) {
474 locked = true;
475 if ( symlink )
476 pix = Resource::loadPixmap( "opie/symlink" );
477 else
478 pix = Resource::loadPixmap( "lockedfolder" );
479 }else
480 pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder");
481
482 name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() :
483 info->fileName();
484
485 (void)new OFileSelectorItem( m_view, pix, name,
486 info->lastModified().toString(),
487 QString::number( info->size() ),
488 info->dirPath( true ), locked, true );
489
490
491}
492void OFileViewFileListView::addSymlink( QFileInfo* , bool ) {
493
494}
495void OFileViewFileListView::cdUP() {
496 QDir dir( m_currentDir );
497 dir.cdUp();
498
499 if (!dir.exists() )
500 m_currentDir = "/";
501 else
502 m_currentDir = dir.absPath();
503
504 emit selector()->dirSelected( m_currentDir );
505 reread( m_all );
506}
507void OFileViewFileListView::cdHome() {
508 m_currentDir = QDir::homeDirPath();
509 emit selector()->dirSelected( m_currentDir );
510 reread( m_all );
511}
512void OFileViewFileListView::cdDoc() {
513 m_currentDir = QPEApplication::documentDir();
514 emit selector()->dirSelected( m_currentDir );
515 reread( m_all );
516}
517void OFileViewFileListView::changeDir( const QString& dir ) {
518 m_currentDir = dir;
519 emit selector()->dirSelected( m_currentDir );
520 reread( m_all );
521}
522void OFileViewFileListView::slotFSActivated( int id ) {
523 changeDir ( m_dev[m_fsPop->text(id)] );
524}
525
526/* check if the mimetype in mime
527 * complies with the one which is current
528 */
529/*
530 * We've the mimetype of the file
531 * We need to get the stringlist of the current mimetype
532 *
533 * mime = image@slashjpeg
534 * QStringList = 'image@slash*'
535 * or QStringList = image/jpeg;image/png;application/x-ogg
536 * or QStringList = application/x-ogg;image@slash*;
537 * with all these mime filters it should get acceptes
538 * to do so we need to look if mime is contained inside
539 * the stringlist
540 * if it's contained return true
541 * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*'
542 * is contained in the mimefilter and then we will
543 * look if both are equal until the '/'
544 */
545bool OFileViewFileListView::compliesMime( const QString& str) {
546 if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() )
547 return true;
548
549 for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) {
550 QRegExp reg( (*it) );
551 reg.setWildcard( true );
552 if ( str.find( reg ) != -1 )
553 return true;
554
555 }
556 return false;
557}
558/*
559 * The listView giving access to the file system!
560 */
561class OFileViewFileSystem : public OFileViewInterface {
562public:
563 OFileViewFileSystem( OFileSelector* );
564 ~OFileViewFileSystem();
565
566 QString selectedName() const;
567 QString selectedPath() const;
568
569 QString directory()const;
570 void reread();
571 int fileCount()const;
572
573 QWidget* widget( QWidget* parent );
574 void activate( const QString& );
575private:
576 OFileViewFileListView* m_view;
577 bool m_all : 1;
578};
579OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel)
580 : OFileViewInterface( sel ) {
581 m_view = 0;
582 m_all = false;
583}
584OFileViewFileSystem::~OFileViewFileSystem() {
585}
586QString OFileViewFileSystem::selectedName()const{
587 if (!m_view )
588 return QString::null;
589
590 QString cFN=currentFileName();
591 if (cFN.startsWith("/")) return cFN;
592 return m_view->currentDir() + "/" + cFN;
593}
594QString OFileViewFileSystem::selectedPath()const{
595 return QString::null;
596}
597QString OFileViewFileSystem::directory()const{
598 if (!m_view)
599 return QString::null;
600
601 OFileSelectorItem* item = m_view->currentItem();
602 if (!item )
603 return QString::null;
604
605 return QDir(item->directory() ).absPath();
606}
607void OFileViewFileSystem::reread() {
608 if (!m_view)
609 return;
610
611 m_view->reread( m_all );
612}
613int OFileViewFileSystem::fileCount()const{
614 if (!m_view )
615 return -1;
616 return m_view->fileCount();
617}
618QWidget* OFileViewFileSystem::widget( QWidget* parent ) {
619 if (!m_view ) {
620 m_view = new OFileViewFileListView( parent, startDirectory(), selector() );
621 }
622 return m_view;
623}
624void OFileViewFileSystem::activate( const QString& str) {
625 m_all = (str != QObject::tr("Files") );
626
627
628}
629
630/* Selector */
631OFileSelector::OFileSelector( QWidget* parent, int mode, int sel,
632 const QString& dirName, const QString& fileName,
633 const MimeTypes& mimetypes,
634 bool showNew, bool showClose)
635 : QWidget( parent, "OFileSelector" )
636{
637 m_current = 0;
638 m_shNew = showNew;
639 m_shClose = showClose;
640 m_mimeType = mimetypes;
641 m_startDir = dirName;
642
643 m_mode = mode;
644 m_selector = sel;
645
646 initUI();
647 m_lneEdit->setText( fileName );
648 initMime();
649 initViews();
650
651 QString str;
652 switch ( m_selector ) {
653 default:
654 case Normal:
655 str = QObject::tr("Documents");
656 m_cmbView->setCurrentItem( 0 );
657 break;
658 case Extended:
659 str = QObject::tr("Files");
660 m_cmbView->setCurrentItem( 1 );
661 break;
662 case ExtendedAll:
663 str = QObject::tr("All Files");
664 m_cmbView->setCurrentItem( 2 );
665 break;
666 }
667 slotViewChange( str );
668
669}
670OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name,
671 bool showNew, bool showClose )
672 : QWidget( parent, name )
673{
674 m_current = 0;
675 m_shNew = showNew;
676 m_shClose = showClose;
677 m_startDir = QPEApplication::documentDir();
678
679 if (!mimeFilter.isEmpty() )
680 m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) );
681
682 m_mode = OFileSelector::FileSelector;
683 m_selector = OFileSelector::Normal;
684
685 initUI();
686 initMime();
687 initViews();
688 m_cmbView->setCurrentItem( 0 );
689 slotViewChange( QObject::tr("Documents") );
690}
691/*
692 * INIT UI will set up the basic GUI
693 * Layout: Simple VBoxLayout
694 * On top a WidgetStack containing the Views...
695 * - List View
696 * - Document View
697 * Below we will have a Label + LineEdit
698 * Below we will have two ComoBoxes one for choosing the view one for
699 * choosing the mimetype
700 */
701void OFileSelector::initUI() {
702 QVBoxLayout* lay = new QVBoxLayout( this );
703
704 m_stack = new QWidgetStack( this );
705 lay->addWidget( m_stack, 1000 );
706
707 m_nameBox = new QHBox( this );
708 (void)new QLabel( tr("Name:"), m_nameBox );
709 m_lneEdit = new QLineEdit( m_nameBox );
710 m_lneEdit ->installEventFilter(this);
711 lay->addWidget( m_nameBox );
712
713 m_cmbBox = new QHBox( this );
714 m_cmbView = new QComboBox( m_cmbBox );
715 m_cmbMime = new QComboBox( m_cmbBox );
716 lay->addWidget( m_cmbBox );
717}
718
719/*
720 * This will make sure that the return key in the name edit causes dialogs to close
721 */
722
723bool OFileSelector::eventFilter (QObject *o, QEvent *e) {
724 if ( e->type() == QEvent::KeyPress ) {
725 QKeyEvent *k = (QKeyEvent *)e;
726 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) {
727 emit ok();
728 return true;
729 }
730 }
731 return false;
732}
733
734/*
735 * This will insert the MimeTypes into the Combo Box
736 * And also connect the changed signal
737 *
738 * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes
739 */
740void OFileSelector::initMime() {
741 MimeTypes::Iterator it;
742 for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) {
743 m_cmbMime->insertItem( it.key() );
744 }
745 m_cmbMime->setCurrentItem( 0 );
746
747 connect( m_cmbMime, SIGNAL(activated(int) ),
748 this, SLOT(slotMimeTypeChanged() ) );
749
750}
751void OFileSelector::initViews() {
752 m_cmbView->insertItem( QObject::tr("Documents") );
753 m_cmbView->insertItem( QObject::tr("Files") );
754 m_cmbView->insertItem( QObject::tr("All Files") );
755 connect(m_cmbView, SIGNAL(activated( const QString& ) ),
756 this, SLOT(slotViewChange( const QString& ) ) );
757
758
759 m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
760
761 /* see above why add both */
762 OFileViewInterface* in = new OFileViewFileSystem( this );
763 m_views.insert( QObject::tr("Files"), in );
764 m_views.insert( QObject::tr("All Files"), in );
765}
766OFileSelector::~OFileSelector() {
767
768}
769const DocLnk* OFileSelector::selected() {
770 DocLnk* lnk = new DocLnk( currentView()->selectedDocument() );
771 return lnk;
772}
773QString OFileSelector::selectedName()const{
774 return currentView()->selectedName();
775}
776QString OFileSelector::selectedPath()const {
777 return currentView()->selectedPath();
778}
779QString OFileSelector::directory()const {
780 return currentView()->directory();
781}
782DocLnk OFileSelector::selectedDocument()const {
783 return currentView()->selectedDocument();
784}
785int OFileSelector::fileCount()const {
786 return currentView()->fileCount();
787}
788void OFileSelector::reread() {
789 return currentView()->reread();
790}
791OFileViewInterface* OFileSelector::currentView()const{
792 return m_current;
793}
794bool OFileSelector::showNew()const {
795 return m_shNew;
796}
797bool OFileSelector::showClose()const {
798 return m_shClose;
799}
800MimeTypes OFileSelector::mimeTypes()const {
801 return m_mimeType;
802}
803int OFileSelector::mode()const{
804 return m_mode;
805}
806int OFileSelector::selector()const{
807 return m_selector;
808}
809QStringList OFileSelector::currentMimeType()const {
810 return m_mimeType[m_cmbMime->currentText()];
811}
812void OFileSelector::slotMimeTypeChanged() {
813 reread();
814}
815void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) {
816 m_lneEdit->setText( lnk.name() );
817 emit fileSelected( lnk );
818 emit fileSelected( lnk.name() );
819}
820void OFileSelector::slotFileBridge( const QString& str) {
821 DocLnk lnk( str );
822 emit fileSelected( lnk );
823}
824void OFileSelector::slotViewChange( const QString& view ) {
825 OFileViewInterface* interface = m_views[view];
826 if (!interface)
827 return;
828
829 interface->activate( view );
830 if (m_current)
831 m_stack->removeWidget( m_current->widget( m_stack ) );
832
833 static int id = 1;
834
835 m_stack->addWidget( interface->widget(m_stack), id );
836 m_stack->raiseWidget( id );
837
838 interface->reread();
839 m_current = interface;
840
841 id++;
842}
843void OFileSelector::setNewVisible( bool b ) {
844 m_shNew = b;
845 currentView()->reread();
846}
847void OFileSelector::setCloseVisible( bool b ) {
848 m_shClose = b;
849 currentView()->reread();
850}
851void OFileSelector::setNameVisible( bool b ) {
852 if ( b )
853 m_nameBox->show();
854 else
855 m_nameBox->hide();
856}
diff --git a/libopie/ofileselector.h b/libopie/ofileselector.h
index d06aa0a..bdb3e56 100644
--- a/libopie/ofileselector.h
+++ b/libopie/ofileselector.h
@@ -6,5 +6,5 @@
6 6
7               =. This file is part of the OPIE Project 7               =. This file is part of the OPIE Project
8             .=l. Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> 8             .=l. Copyright (c) 2002,2003 Holger Freyther <zecke@handhelds.org>
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This library is free software; you can 10 _;:,     .>    :=|. This library is free software; you can
@@ -32,283 +32,119 @@
32*/ 32*/
33 33
34#ifndef opiefileselector_h
35#define opiefileselector_h
36 34
35#ifndef OPIE_OFILESELECTOR_FOO_H
36#define OPIE_OFILESELECTOR_FOO_H
37
38#include <qlist.h>
37#include <qwidget.h> 39#include <qwidget.h>
38#include <qstring.h>
39#include <qpixmap.h>
40#include <qstringlist.h>
41#include <qmap.h> 40#include <qmap.h>
42#include <qvaluelist.h> 41#include <qvaluelist.h>
42#include <qstringlist.h>
43 43
44#include <qpe/applnk.h> 44#include <qpe/applnk.h>
45#include <qlistview.h>
46 45
46typedef QMap<QString, QStringList> MimeTypes;
47 47
48class DocLnk; 48class OFileViewInterface;
49class QCheckBox; 49class OFileViewFileListView;
50class QComboBox;
51class QPushButton;
52class FileSelector;
53class QGridLayout;
54class QLineEdit; 50class QLineEdit;
55class QLabel; 51class QComboBox;
56class QWidgetStack; 52class QWidgetStack;
57class QHBoxLayout;
58class QVBoxLayout;
59class QPopupMenu;
60class QFileInfo;
61class QHBox; 53class QHBox;
62//
63
64typedef QMap< QString, QStringList> MimeTypes;
65
66/**
67 * This is OPIEs FileDialog Widget. You can use it
68 * as a dropin replacement of the fileselector and
69 * or use any of the new features.
70 * This is also a complete FileSave and FileLoad widget
71 * If you look for a Dialog check OFileDialog
72 *
73 * NOTE THAT the API will change to be more extendable!
74 */
75class OFileSelector : public QWidget { 54class OFileSelector : public QWidget {
76 Q_OBJECT 55 Q_OBJECT
77 public: 56 friend class OFileViewInterface;
78 /** 57 friend class OFileViewFileListView;
79 * The mode of the file selector 58public:
80 * Either open, save, fileselector or dir browsing mode 59 enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 };
81 * 60// enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 };
82 */ 61 enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 };
83 enum Mode {OPEN=1, SAVE=2, FILESELECTOR=4, DIR=8 }; 62// enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2};
84 63
85 /** 64 OFileSelector(QWidget* parent, int mode, int selector,
86 * Selector. Either NORMAL for the one shipped with 65 const QString& dirName,
87 * libqpe or EXTENDED. for the EXTENDED 66 const QString& fileName,
88 * EXTENDED_ALL also shows 'hidden' files 67 const MimeTypes& mimetypes = MimeTypes(),
89 */ 68 bool newVisible = FALSE, bool closeVisible = FALSE );
90 enum Selector{NORMAL=0, EXTENDED = 1, EXTENDED_ALL =2 }; 69
91 70 OFileSelector(const QString& mimeFilter, QWidget* parent,
92 /** 71 const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE );
93 * This is reserved for futrue views 72 ~OFileSelector();
94 */ 73
95 enum View { DIRS = 1, FILES = 2, TREE = 4, ICON = 8 }; 74 const DocLnk* selected();
96 75
97 /** 76 QString selectedName()const;
98 * A c'tor which should be used for advanced mode 77 QString selectedPath()const;
99 * @param wid the parent 78 QString directory()const;
100 * @param mode the Mode of the Selector 79
101 * @param selector the current View of the Selector 80 DocLnk selectedDocument()const;
102 * @param dirName in which dir to start 81
103 * @param fileName a proposed filename 82 int fileCount()const;
104 * @param mimetypes A list of mimetypes \ 83 void reread();
105 * QString is for a identifier name like "Text files" 84
106 * the coresponding QStringList is used for the mimetypes 85 int mode()const;
107 * if empty it'll fill the list of mimetypes depending 86 int selector()const;
108 * on the content of the current directory 87
109 */ 88
110 89 void setNewVisible( bool b );
111 OFileSelector(QWidget *wid, int mode, int selector, 90 void setCloseVisible( bool b );
112 const QString &dirName, 91 void setNameVisible( bool b );
113 const QString &fileName = QString::null, 92
114 const MimeTypes &mimetypes = MimeTypes() ); 93signals:
115 94 void dirSelected( const QString& );
116 95 void fileSelected( const DocLnk& );
117 /** 96 void fileSelected( const QString& );
118 * This is a QPE compatible c'tor 97 void newSelected( const DocLnk& );
119 */ 98 void closeMe();
120 OFileSelector(const QString &mimeFilter, QWidget *parent, 99 void ok();
121 const char *name, bool newVisible = TRUE, 100 void cancel();
122 bool closeVisible = FALSE ); 101
123 102/* used by the ViewInterface */
124 ~OFileSelector(); 103private:
125 104 bool showNew()const;
126 // currently only for the FILESELECTOR Mode 105 bool showClose()const;
127 /** 106 MimeTypes mimeTypes()const;
128 */ 107 QStringList currentMimeType()const;
129 void setNewVisible( bool /*b*/ ); 108
130 void setCloseVisible(bool /*b*/ ); 109private:
131 110 /* inits the Widgets */
132 // end file selector mode 111 void initUI();
133 // deprecated 112 /* inits the MimeType ComboBox content + connects signals and slots */
134 void reread(); 113 void initMime();
135 // make sure not to leak please 114 /* init the Views :) */
136 const DocLnk *selected(); 115 void initViews();
137 // end deprecated 116
138 117private:
139 bool isToolbarVisible() const { return m_shTool; }; 118 QLineEdit* m_lneEdit; // the LineEdit for the Name
140 bool isPermissionBarVisible() const { return m_shPerm; }; 119 QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType
141 bool isLineEditVisible()const { return m_shLne; }; 120 QWidgetStack* m_stack; // our widget stack which will contain the views
142 bool isChooserVisible( )const { return m_shChooser; }; 121 OFileViewInterface* currentView()const; // returns the currentView
143 bool isYesCancelVisible()const { return m_shYesNo; }; 122 OFileViewInterface* m_current; // here is the view saved
144 void setYesCancelVisible( bool show ); 123 bool m_shNew : 1; // should we show New?
145 void setToolbarVisible( bool show ); 124 bool m_shClose : 1; // should we show Close?
146 void setPermissionBarVisible( bool show ); 125 MimeTypes m_mimeType; // list of mimetypes
147 void setLineEditVisible(bool show) ; 126
148 void setChooserVisible( bool chooser ); 127 QMap<QString, OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr
149 128 QHBox* m_nameBox; // the LineEdit + Label is hold here
150 QCheckBox* permissionCheckbox(); 129 QHBox* m_cmbBox; // this holds the two combo boxes
151 bool setPermission() const; 130
152 void setPermissionChecked( bool check ); 131 QString m_startDir;
153 132 int m_mode;
154 void setMode( int ); 133 int m_selector;
155 134
156 bool showDirs()const { return m_dir; } 135 struct Data; // used for future versions
157 void setShowDirs(bool ); 136 Data *d;
158
159 const QListView* listView() { return m_View; };
160
161 bool isCaseSensetive()const { return m_case; }
162 void setCaseSensetive(bool caSe );
163
164 bool showFiles()const { return m_files; };
165 void setShowFiles(bool );
166 bool cd(const QString &path );
167 137
138private slots:
139 void slotMimeTypeChanged();
168 140
169 int mode()const { return m_mode; }; 141 /* will set the text of the lineedit and emit a fileChanged signal */
170 int selector()const { return m_selector; }; 142 void slotDocLnkBridge( const DocLnk& );
171 void setSelector( int ); 143 void slotFileBridge( const QString& );
172 144 void slotViewChange( const QString& );
173 bool showPopup()const { return m_showPopup; };
174 void setShowPopup( bool pop ) { m_showPopup = pop; };
175 void setPopupMenu( QPopupMenu * );
176
177 // void updateLay();
178
179 void reparse(); // re reads the dir
180
181 QString selectedName( )const;
182 QStringList selectedNames()const;
183
184 QString selectedPath() const;
185 QStringList selectedPaths() const;
186
187 QString directory()const;
188 int fileCount() const;
189
190 /* the user needs to delete it */
191 DocLnk selectedDocument()const;
192 /* the user needs to delete it */
193 QValueList<DocLnk> selectedDocuments()const;
194
195 signals:
196 void fileSelected( const DocLnk & );
197 void fileSelected( const QString & );
198 void dirSelected(const QString &dir );
199 void closeMe();
200 void ok();
201 void cancel();
202 void contextMenu();
203
204 private slots:
205 void slotTest() { qWarning("slotTest" ); setLineEditVisible(false ); };
206 void slotOk();
207 void slotCancel();
208 void slotViewCheck(const QString & );
209 void slotMimeCheck(const QString & );
210 void slotLocationActivated(const QString & );
211 void slotInsertLocationPath(const QString &, int);
212 void locationComboChanged();
213
214 private:
215 void init();
216 void updateMimes();
217
218 protected:
219
220 private:
221 int m_mode, m_selector;
222 QComboBox *m_location, *m_mimeCheck, *m_viewCheck;
223 QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel;
224 QPushButton *m_reread, *m_up, *m_new, *m_close;
225 QListView *m_View;
226 QCheckBox *m_checkPerm;
227 QWidget *m_pseudo;
228 QVBoxLayout *m_pseudoLayout;
229
230 QString m_currentDir;
231 QString m_name;
232// QStringList m_mimetypes;
233 QMap<QString, QStringList> m_mimetypes;
234
235 FileSelector *m_select;
236 QWidgetStack *m_stack;
237 QVBoxLayout *m_lay;
238 QGridLayout *m_Oselector;
239
240 QHBox *m_boxToolbar;
241 QHBox *m_boxOk; // (no layout anymore) wait
242 QHBox *m_boxName; // (no Layout anymore) wait
243 QHBox *m_boxView;
244
245 QPopupMenu *m_custom;
246
247 QLineEdit *m_edit;
248 QLabel *m_fnLabel;
249
250 bool m_shClose : 1;
251 bool m_shNew : 1;
252 bool m_shTool : 1;
253 bool m_shPerm : 1;
254 bool m_shLne : 1;
255 bool m_shChooser : 1;
256 bool m_shYesNo : 1;
257 bool m_boCheckPerm : 1;
258 bool m_autoMime : 1;
259 bool m_case : 1;
260 bool m_dir : 1;
261 bool m_files : 1;
262 bool m_showPopup : 1;
263
264 void initVars();
265 virtual void addFile(const QString &mime, QFileInfo *info, bool symlink = FALSE );
266 virtual void addDir( const QString &mime, QFileInfo *info , bool symlink = FALSE );
267 virtual void addSymlink(const QString &, QFileInfo *, bool = FALSE ){};
268 void delItems();
269 void initializeName();
270 void initializeYes();
271 void initializeChooser();
272 void initializeListView();
273 void initializePerm();
274 void initPics();
275 bool compliesMime(const QString &path,
276 const QString &mime);
277 bool compliesMime(const QString& mime );
278 /**
279 * Updates the QComboBox with the current mimetypes
280 */
281 void updateMimeCheck();
282 145
283 /** 146 bool eventFilter (QObject *o, QEvent *e);
284 * Returns the current mimetype
285 */
286 QString currentMimeType()const;
287 class OFileSelectorPrivate;
288 OFileSelectorPrivate *d;
289 static QMap<QString,QPixmap> *m_pixmaps;
290 147
291private slots:
292 void slotFileSelected(const QString & ); // not really meant to be a slot
293 void slotFileBridgeSelected( const DocLnk & );
294 virtual void slotSelectionChanged();
295 virtual void slotCurrentChanged(QListViewItem* );
296 virtual void slotClicked( int, QListViewItem *item, const QPoint &, int);
297 virtual void slotRightButton(int, QListViewItem *, const QPoint &, int );
298 virtual void slotContextMenu( QListViewItem *item);
299 // listview above
300 // popup below
301 virtual void slotChangedDir();
302 virtual void slotOpen();
303 virtual void slotRescan();
304 virtual void slotRename();
305 virtual void slotDelete();
306 virtual void cdUP();
307 virtual void slotHome();
308 virtual void slotDoc();
309 virtual void slotNavigate( );
310}; 148};
311 149
312
313#endif 150#endif
314
diff --git a/libopie/ofileselector_p.h b/libopie/ofileselector_p.h
new file mode 100644
index 0000000..7fd0c50
--- a/dev/null
+++ b/libopie/ofileselector_p.h
@@ -0,0 +1,151 @@
1#ifndef OPIE_OFILE_SELECTOR_PRIVATE_H
2#define OPIE_OFILE_SELECTOR_PRIVATE_H
3
4#include <qmap.h>
5#include <qstringlist.h>
6#include <qwidget.h>
7#include <qlistview.h>
8
9#include <qpe/applnk.h>
10#include <qpe/fileselector.h>
11
12
13/*
14 * How to avoid having really two different objects
15 * for Extended and ExtendedAll
16 * The only difference is the Lister...
17 * a) static object?
18 * b) leave some object inside the OFileSelector which can be used?
19 * c) when switching views tell which view we want o have.. internally we can switch then
20 *
21 * I'll take c) -zecke
22 */
23
24
25/* the View Interface */
26class OFileSelector;
27typedef QMap<QString, QStringList> MimeTypes;
28class QFileInfo;
29class QToolButton;
30class OFileViewInterface {
31public:
32 OFileViewInterface( OFileSelector* selector );
33 virtual ~OFileViewInterface();
34 virtual QString selectedName()const = 0;
35 virtual QString selectedPath()const = 0;
36 virtual QString directory()const = 0;
37 virtual void reread() = 0;
38 virtual int fileCount()const = 0;
39 virtual DocLnk selectedDocument()const;
40 virtual QWidget* widget( QWidget* parent) = 0;
41 virtual void activate( const QString& );
42 QString name()const;
43protected:
44 OFileSelector* selector()const;
45 void setName( const QString& );
46 bool showNew()const;
47 bool showClose()const;
48 MimeTypes mimeTypes()const;
49 QStringList currentMimeType()const;
50 QString startDirectory()const;
51protected:
52 void ok();
53 void cancel();
54 void closeMe();
55 void fileSelected( const QString& );
56 void fileSelected( const DocLnk& );
57 void setCurrentFileName( const QString& );
58 QString currentFileName()const;
59
60private:
61 QString m_name;
62 OFileSelector* m_selector;
63};
64
65
66/* THE Document View hosting a FileSelector*/
67class ODocumentFileView : public OFileViewInterface {
68public:
69 ODocumentFileView( OFileSelector* selector );
70 ~ODocumentFileView();
71
72 QString selectedName() const;
73 QString selectedPath() const;
74
75 QString directory() const;
76 void reread();
77 int fileCount()const;
78 DocLnk selectedDocument()const;
79
80 QWidget* widget( QWidget* parent );
81
82private:
83 mutable FileSelector* m_selector;
84
85};
86
87class OFileSelectorItem : public QListViewItem {
88public:
89 OFileSelectorItem( QListView* view, const QPixmap& pixmap,
90 const QString& path, const QString& date,
91 const QString& size, const QString& mDir,
92 bool isLocked = false, bool isDir = false );
93 ~OFileSelectorItem();
94 bool isLocked()const;
95 bool isDir()const;
96 QString directory()const;
97 QString path()const;
98 QString key(int id, bool )const;
99
100private:
101 bool m_locked : 1;
102 bool m_isDir : 1;
103 QString m_dir;
104};
105
106class OFileViewFileListView : public QWidget {
107 Q_OBJECT
108public:
109 OFileViewFileListView( QWidget* parent, const QString& dir, OFileSelector* selector );
110 ~OFileViewFileListView();
111
112 OFileSelectorItem* currentItem()const;
113 void reread( bool all = false );
114 int fileCount()const;
115 QString currentDir()const;
116protected:
117 bool eventFilter (QObject *o, QEvent *e);
118private slots:
119 void slotNew(); // will emit newSelected
120 void cdUP();
121 void cdHome();
122 void cdDoc();
123 void changeDir( const QString& );
124 void slotCurrentChanged( QListViewItem* );
125 void slotClicked(int, QListViewItem*, const QPoint&, int );
126 void slotFSActivated(int);
127
128protected:
129
130 OFileSelector* selector();
131
132private:
133 QMap<QString, QString> m_dev;
134 bool m_all : 1;
135 OFileSelector* m_sel;
136 QPopupMenu* m_fsPop;
137 bool compliesMime( const QString& );
138 QStringList m_mimes; // used in compy mime
139 QString m_currentDir;
140 QToolButton *m_btnNew, *m_btnClose;
141 void connectSlots();
142 void addFile( QFileInfo* info, bool symlink = FALSE );
143 void addDir ( QFileInfo* info, bool symlink = FALSE );
144 void addSymlink( QFileInfo* info, bool = FALSE );
145
146
147private:
148 QListView* m_view;
149};
150
151#endif
diff --git a/libopie/orecurrancewidget.cpp b/libopie/orecurrancewidget.cpp
index 471249d..be8ec30 100644
--- a/libopie/orecurrancewidget.cpp
+++ b/libopie/orecurrancewidget.cpp
@@ -9,17 +9,34 @@
9 9
10// Global Templates for use in setting up the repeat label... 10// Global Templates for use in setting up the repeat label...
11const QString strDayTemplate = QObject::tr("Every"); 11// the problem is these strings get initialized before QPEApplication can install the translator -zecke
12const QString strYearTemplate = QObject::tr("%1 %2 every "); 12namespace {
13const QString strMonthDateTemplate = QObject::tr("The %1 every "); 13QString strDayTemplate;
14const QString strMonthDayTemplate = QObject::tr("The %1 %1 of every"); 14QString strYearTemplate;
15const QString strWeekTemplate = QObject::tr("Every "); 15QString strMonthDateTemplate;
16const QString dayLabel[] = { QObject::tr("Monday"), 16QString strMonthDayTemplate;
17 QObject::tr("Tuesday"), 17QString strWeekTemplate;
18 QObject::tr("Wednesday"), 18QString dayLabel[7];
19 QObject::tr("Thursday"), 19}
20 QObject::tr("Friday"),
21 QObject::tr("Saturday"),
22 QObject::tr("Sunday") };
23 20
21/*
22 * static linkage to not polute the symbol table...
23 * The problem is that const and static linkage are resolved prior to installing a translator
24 * leading to that the above strings are translted but to the original we delay the init of these strings...
25 * -zecke
26 */
27static void fillStrings() {
28 strDayTemplate = QObject::tr("Every");
29 strYearTemplate = QObject::tr("%1 %2 every ");
30 strMonthDateTemplate = QObject::tr("The %1 every ");
31 strMonthDayTemplate = QObject::tr("The %1 %2 of every");
32 strWeekTemplate = QObject::tr("Every ");
33 dayLabel[0] = QObject::tr("Monday");
34 dayLabel[1] = QObject::tr("Tuesday");
35 dayLabel[2] = QObject::tr("Wednesday");
36 dayLabel[3] = QObject::tr("Thursday");
37 dayLabel[4] = QObject::tr("Friday");
38 dayLabel[5] = QObject::tr("Saturday");
39 dayLabel[6] = QObject::tr("Sunday");
40}
24 41
25 static QString numberPlacing( int x );// return the proper word format for 42 static QString numberPlacing( int x );// return the proper word format for
@@ -47,4 +64,7 @@ ORecurranceWidget::ORecurranceWidget( bool startOnMonday,
47 startWeekOnMonday( startOnMonday ) 64 startWeekOnMonday( startOnMonday )
48{ 65{
66 if (strDayTemplate.isEmpty() )
67 fillStrings();
68
49 init(); 69 init();
50 fraType->setButton( currInterval ); 70 fraType->setButton( currInterval );
@@ -72,4 +92,6 @@ ORecurranceWidget::ORecurranceWidget( bool startOnMonday,
72 startWeekOnMonday( startOnMonday ) 92 startWeekOnMonday( startOnMonday )
73{ 93{
94 if (strDayTemplate.isEmpty() )
95 fillStrings();
74 // do some stuff with the repeat pattern 96 // do some stuff with the repeat pattern
75 init(); 97 init();
@@ -85,5 +107,4 @@ ORecurranceWidget::~ORecurranceWidget() {
85 */ 107 */
86void ORecurranceWidget::setStartDate( const QDate& date ) { 108void ORecurranceWidget::setStartDate( const QDate& date ) {
87 qWarning("ORecurranceWidget::setStartDate");
88 setRecurrence( recurrence(), date ); 109 setRecurrence( recurrence(), date );
89} 110}
@@ -368,5 +389,6 @@ void ORecurranceWidget::slotWeekLabel() {
368 } 389 }
369 } 390 }
370 str = str.prepend( "on " ); 391 str = str.prepend( tr("on ") );
392
371 lblWeekVar->setText( str ); 393 lblWeekVar->setText( str );
372} 394}
@@ -376,8 +398,8 @@ void ORecurranceWidget::slotMonthLabel(int type) {
376 return; 398 return;
377 if ( type == 1 ) 399 if ( type == 1 )
378 str = strMonthDateTemplate.arg( numberPlacing(start.day()) ); 400 str = strMonthDateTemplate.arg( numberPlacing(start.day()) );
379 else 401 else
380 str = strMonthDayTemplate.arg( numberPlacing(week(start))) 402 str = strMonthDayTemplate.arg( numberPlacing(week(start)))
381 .arg( dayLabel[start.dayOfWeek() - 1] ); 403 .arg( dayLabel[start.dayOfWeek() - 1] );
382 lblRepeat->setText( str ); 404 lblRepeat->setText( str );
383} 405}
diff --git a/libopie/oticker.h b/libopie/oticker.h
index 0b88919..4026eb5 100644
--- a/libopie/oticker.h
+++ b/libopie/oticker.h
@@ -74,5 +74,5 @@ public:
74 void setText( const QString& text ) ; 74 void setText( const QString& text ) ;
75/*! 75/*!
76 * @fn setBackgroundColor(QColor color) 76 * @fn setBackgroundColor(const QColor& color)
77 * @brief sets color of the ticker's background 77 * @brief sets color of the ticker's background
78 * @param color QColor color to be set. 78 * @param color QColor color to be set.
@@ -81,5 +81,5 @@ public:
81 void setBackgroundColor(const QColor& color); 81 void setBackgroundColor(const QColor& color);
82/*! 82/*!
83 * @fn setForegroundColor(QColor color) 83 * @fn setForegroundColor(const QColor& color)
84 * @brief sets color of text 84 * @brief sets color of text
85 * @param color QColor color of text 85 * @param color QColor color of text
diff --git a/libopie/todayplugininterface.h b/libopie/todayplugininterface.h
index 532f492..5dfeaa8 100644
--- a/libopie/todayplugininterface.h
+++ b/libopie/todayplugininterface.h
@@ -1,2 +1,32 @@
1/*
2                This file is part of the Opie Project
3 Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4 =.
5 .=l.
6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU General Public
10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details.
21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28
29*/
30
1 31
2#ifndef TODAY_PLUGIN_INTERFACE 32#ifndef TODAY_PLUGIN_INTERFACE
@@ -81,18 +111,12 @@ public:
81 /** 111 /**
82 * Refresh that plugins view. For updating the plugins 112 * Refresh that plugins view. For updating the plugins
83 *
84 */ 113 */
85 virtual void refresh() {}; 114 virtual void refresh() {};
86 115
87 /** 116 /**
88 * minimum height the plugin at least should have 117 * reread the plugins config and act apropiate
118 * This is for example used when returning from the config dialog
89 */ 119 */
90 // virtual int minHeight() const = 0; 120 virtual void reinitialize() {};
91
92 /**
93 * maximum height that should be used before starting scrolling
94 */
95 // virtual int maxHeight() const = 0;
96
97}; 121};
98 122