author | zautrix <zautrix> | 2005-02-05 12:03:42 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-05 12:03:42 (UTC) |
commit | f5902d0e08e0b10321c555e8846a8a8ce2087d30 (patch) (unidiff) | |
tree | 5aeaa9689b3161867fb0c8707adc5908b5072f06 /microkde | |
parent | 86c0d35262454a31ed7d50d3e20cbdace954ebdf (diff) | |
download | kdepimpi-f5902d0e08e0b10321c555e8846a8a8ce2087d30.zip kdepimpi-f5902d0e08e0b10321c555e8846a8a8ce2087d30.tar.gz kdepimpi-f5902d0e08e0b10321c555e8846a8a8ce2087d30.tar.bz2 |
file selector fix
-rw-r--r-- | microkde/kfiledialog.cpp | 2 | ||||
-rw-r--r-- | microkde/ofileselector_p.cpp | 28 | ||||
-rw-r--r-- | microkde/ofileselector_p.h | 1 |
3 files changed, 30 insertions, 1 deletions
diff --git a/microkde/kfiledialog.cpp b/microkde/kfiledialog.cpp index 977499e..309f8dc 100644 --- a/microkde/kfiledialog.cpp +++ b/microkde/kfiledialog.cpp | |||
@@ -1,74 +1,76 @@ | |||
1 | #include <kfiledialog.h> | 1 | #include <kfiledialog.h> |
2 | #include <qdialog.h> | 2 | #include <qdialog.h> |
3 | #include <qlayout.h> | 3 | #include <qlayout.h> |
4 | #include <qdir.h> | 4 | #include <qdir.h> |
5 | #include <qfileinfo.h> | 5 | #include <qfileinfo.h> |
6 | #include <qapplication.h> | 6 | #include <qapplication.h> |
7 | 7 | ||
8 | #ifndef DESKTOP_VERSION | 8 | #ifndef DESKTOP_VERSION |
9 | //US orig#include <ofileselector.h> | 9 | //US orig#include <ofileselector.h> |
10 | #include <ofileselector_p.h> | 10 | #include <ofileselector_p.h> |
11 | QString KFileDialog::getSaveFileName( const QString & fn, | 11 | QString KFileDialog::getSaveFileName( const QString & fn, |
12 | const QString & cap , QWidget * par ) | 12 | const QString & cap , QWidget * par ) |
13 | { | 13 | { |
14 | QString retfile = ""; | 14 | QString retfile = ""; |
15 | QDialog dia ( par, "input-dialog", true ); | 15 | QDialog dia ( par, "input-dialog", true ); |
16 | QVBoxLayout lay( &dia ); | 16 | QVBoxLayout lay( &dia ); |
17 | lay.setMargin(7); | 17 | lay.setMargin(7); |
18 | lay.setSpacing(7); | 18 | lay.setSpacing(7); |
19 | dia.setCaption( cap ); | 19 | dia.setCaption( cap ); |
20 | QString file = fn; | 20 | QString file = fn; |
21 | if ( file.isEmpty() ) | 21 | if ( file.isEmpty() ) |
22 | file = QDir::homeDirPath()+"/*"; | 22 | file = QDir::homeDirPath()+"/*"; |
23 | QFileInfo fi ( file ); | 23 | QFileInfo fi ( file ); |
24 | OFileSelector o ( &dia,OFileSelector::FileSelector, OFileSelector::Save, fi.dirPath(true), fi.fileName() ); | 24 | OFileSelector o ( &dia,OFileSelector::FileSelector, OFileSelector::Save, fi.dirPath(true), fi.fileName() ); |
25 | QObject::connect ( &o, SIGNAL( ok() ), &dia, SLOT ( accept () ) ); | ||
25 | lay.addWidget( &o); | 26 | lay.addWidget( &o); |
26 | // o.setNewVisible( true ); | 27 | // o.setNewVisible( true ); |
27 | // o.setNameVisible( true ); | 28 | // o.setNameVisible( true ); |
28 | dia.showMaximized(); | 29 | dia.showMaximized(); |
29 | int res = dia.exec(); | 30 | int res = dia.exec(); |
30 | if ( res ) | 31 | if ( res ) |
31 | retfile = o.selectedName(); | 32 | retfile = o.selectedName(); |
32 | return retfile; | 33 | return retfile; |
33 | } | 34 | } |
34 | 35 | ||
35 | QString KFileDialog::getOpenFileName( const QString & fn, | 36 | QString KFileDialog::getOpenFileName( const QString & fn, |
36 | const QString & cap, QWidget * par ) | 37 | const QString & cap, QWidget * par ) |
37 | { | 38 | { |
38 | QString retfile = ""; | 39 | QString retfile = ""; |
39 | QDialog dia ( par, "input-dialog", true ); | 40 | QDialog dia ( par, "input-dialog", true ); |
40 | // QLineEdit lab ( &dia ); | 41 | // QLineEdit lab ( &dia ); |
41 | QVBoxLayout lay( &dia ); | 42 | QVBoxLayout lay( &dia ); |
42 | lay.setMargin(7); | 43 | lay.setMargin(7); |
43 | lay.setSpacing(7); | 44 | lay.setSpacing(7); |
44 | dia.setCaption( cap ); | 45 | dia.setCaption( cap ); |
45 | QString file = fn; | 46 | QString file = fn; |
46 | if ( file.isEmpty() ) | 47 | if ( file.isEmpty() ) |
47 | file = QDir::homeDirPath()+"/*";; | 48 | file = QDir::homeDirPath()+"/*";; |
48 | QFileInfo fi ( file ); | 49 | QFileInfo fi ( file ); |
49 | OFileSelector o ( &dia,OFileSelector::FileSelector, OFileSelector::Open, fi.dirPath(true), fi.fileName() ); | 50 | OFileSelector o ( &dia,OFileSelector::FileSelector, OFileSelector::Open, fi.dirPath(true), fi.fileName() ); |
51 | QObject::connect ( &o, SIGNAL( ok() ), &dia, SLOT ( accept () ) ); | ||
50 | lay.addWidget( &o); | 52 | lay.addWidget( &o); |
51 | dia.showMaximized(); | 53 | dia.showMaximized(); |
52 | int res = dia.exec(); | 54 | int res = dia.exec(); |
53 | if ( res ) | 55 | if ( res ) |
54 | retfile = o.selectedName(); | 56 | retfile = o.selectedName(); |
55 | return retfile; | 57 | return retfile; |
56 | } | 58 | } |
57 | 59 | ||
58 | #else | 60 | #else |
59 | 61 | ||
60 | #include <qfiledialog.h> | 62 | #include <qfiledialog.h> |
61 | 63 | ||
62 | QString KFileDialog::getSaveFileName( const QString & fn, | 64 | QString KFileDialog::getSaveFileName( const QString & fn, |
63 | const QString & cap , QWidget * par ) | 65 | const QString & cap , QWidget * par ) |
64 | { | 66 | { |
65 | return QFileDialog::getSaveFileName( fn, QString::null, par, "openfile", cap ); | 67 | return QFileDialog::getSaveFileName( fn, QString::null, par, "openfile", cap ); |
66 | } | 68 | } |
67 | QString KFileDialog::getOpenFileName( const QString & fn, | 69 | QString KFileDialog::getOpenFileName( const QString & fn, |
68 | const QString & cap, QWidget * par ) | 70 | const QString & cap, QWidget * par ) |
69 | { | 71 | { |
70 | 72 | ||
71 | return QFileDialog::getOpenFileName( fn, QString::null, par, "openfile", cap ); | 73 | return QFileDialog::getOpenFileName( fn, QString::null, par, "openfile", cap ); |
72 | } | 74 | } |
73 | #endif | 75 | #endif |
74 | 76 | ||
diff --git a/microkde/ofileselector_p.cpp b/microkde/ofileselector_p.cpp index fd5f965..f85f8f4 100644 --- a/microkde/ofileselector_p.cpp +++ b/microkde/ofileselector_p.cpp | |||
@@ -1,866 +1,892 @@ | |||
1 | #include <qcombobox.h> | 1 | #include <qcombobox.h> |
2 | #include <qdir.h> | 2 | #include <qdir.h> |
3 | #include <qhbox.h> | 3 | #include <qhbox.h> |
4 | #include <qheader.h> | 4 | #include <qheader.h> |
5 | #include <qlabel.h> | 5 | #include <qlabel.h> |
6 | #include <qlayout.h> | 6 | #include <qlayout.h> |
7 | #include <qlineedit.h> | 7 | #include <qlineedit.h> |
8 | #include <qlistview.h> | 8 | #include <qlistview.h> |
9 | #include <qpopupmenu.h> | 9 | #include <qpopupmenu.h> |
10 | #include <qwidgetstack.h> | 10 | #include <qwidgetstack.h> |
11 | #include <qregexp.h> | 11 | #include <qregexp.h> |
12 | #include <qobjectlist.h> | 12 | #include <qobjectlist.h> |
13 | 13 | ||
14 | /* hacky but we need to get FileSelector::filter */ | 14 | /* hacky but we need to get FileSelector::filter */ |
15 | #define private public | 15 | #define private public |
16 | #include <qpe/fileselector.h> | 16 | #include <qpe/fileselector.h> |
17 | #undef private | 17 | #undef private |
18 | 18 | ||
19 | #include <qpe/qpeapplication.h> | 19 | #include <qpe/qpeapplication.h> |
20 | #include <qpe/mimetype.h> | 20 | #include <qpe/mimetype.h> |
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include <qpe/storage.h> | 22 | #include <qpe/storage.h> |
23 | #include <kglobal.h> | 23 | #include <kglobal.h> |
24 | #include <klocale.h> | 24 | #include <klocale.h> |
25 | 25 | ||
26 | #include "ofileselector_p.h" | 26 | #include "ofileselector_p.h" |
27 | //US#include "ofileselector.h" | 27 | //US#include "ofileselector.h" |
28 | 28 | ||
29 | #include "klocale.h" | 29 | #include "klocale.h" |
30 | 30 | ||
31 | OFileViewInterface::OFileViewInterface( OFileSelector* selector ) | 31 | OFileViewInterface::OFileViewInterface( OFileSelector* selector ) |
32 | : m_selector( selector ) { | 32 | : m_selector( selector ) { |
33 | } | 33 | } |
34 | OFileViewInterface::~OFileViewInterface() { | 34 | OFileViewInterface::~OFileViewInterface() { |
35 | } | 35 | } |
36 | QString OFileViewInterface::name()const{ | 36 | QString OFileViewInterface::name()const{ |
37 | return m_name; | 37 | return m_name; |
38 | } | 38 | } |
39 | void OFileViewInterface::setName( const QString& name ) { | 39 | void OFileViewInterface::setName( const QString& name ) { |
40 | m_name = name; | 40 | m_name = name; |
41 | } | 41 | } |
42 | OFileSelector* OFileViewInterface::selector()const { | 42 | OFileSelector* OFileViewInterface::selector()const { |
43 | return m_selector; | 43 | return m_selector; |
44 | } | 44 | } |
45 | 45 | ||
46 | DocLnk OFileViewInterface::selectedDocument()const { | 46 | DocLnk OFileViewInterface::selectedDocument()const { |
47 | return DocLnk( selectedName() ); | 47 | return DocLnk( selectedName() ); |
48 | } | 48 | } |
49 | 49 | ||
50 | bool OFileViewInterface::showNew()const { | 50 | bool OFileViewInterface::showNew()const { |
51 | return selector()->showNew(); | 51 | return selector()->showNew(); |
52 | } | 52 | } |
53 | bool OFileViewInterface::showClose()const { | 53 | bool OFileViewInterface::showClose()const { |
54 | return selector()->showClose(); | 54 | return selector()->showClose(); |
55 | } | 55 | } |
56 | MimeTypes OFileViewInterface::mimeTypes()const { | 56 | MimeTypes OFileViewInterface::mimeTypes()const { |
57 | return selector()->mimeTypes(); | 57 | return selector()->mimeTypes(); |
58 | } | 58 | } |
59 | QStringList OFileViewInterface::currentMimeType()const { | 59 | QStringList OFileViewInterface::currentMimeType()const { |
60 | return selector()->currentMimeType(); | 60 | return selector()->currentMimeType(); |
61 | } | 61 | } |
62 | void OFileViewInterface::activate( const QString& ) { | 62 | void OFileViewInterface::activate( const QString& ) { |
63 | // not implemented here | 63 | // not implemented here |
64 | } | 64 | } |
65 | void OFileViewInterface::ok() { | 65 | void OFileViewInterface::ok() { |
66 | emit selector()->ok(); | 66 | emit selector()->ok(); |
67 | } | 67 | } |
68 | void OFileViewInterface::cancel() { | 68 | void OFileViewInterface::cancel() { |
69 | emit selector()->cancel(); | 69 | emit selector()->cancel(); |
70 | } | 70 | } |
71 | void OFileViewInterface::closeMe() { | 71 | void OFileViewInterface::closeMe() { |
72 | emit selector()->closeMe(); | 72 | emit selector()->closeMe(); |
73 | } | 73 | } |
74 | void OFileViewInterface::fileSelected( const QString& str) { | 74 | void OFileViewInterface::fileSelected( const QString& str) { |
75 | emit selector()->fileSelected( str); | 75 | emit selector()->fileSelected( str); |
76 | } | 76 | } |
77 | void OFileViewInterface::fileSelected( const DocLnk& lnk) { | 77 | void OFileViewInterface::fileSelected( const DocLnk& lnk) { |
78 | emit selector()->fileSelected( lnk ); | 78 | emit selector()->fileSelected( lnk ); |
79 | } | 79 | } |
80 | void OFileViewInterface::setCurrentFileName( const QString& str ) { | 80 | void OFileViewInterface::setCurrentFileName( const QString& str ) { |
81 | selector()->m_lneEdit->setText( str ); | 81 | selector()->m_lneEdit->setText( str ); |
82 | } | 82 | } |
83 | QString OFileViewInterface::currentFileName()const{ | 83 | QString OFileViewInterface::currentFileName()const{ |
84 | return selector()->m_lneEdit->text(); | 84 | return selector()->m_lneEdit->text(); |
85 | } | 85 | } |
86 | QString OFileViewInterface::startDirectory()const{ | 86 | QString OFileViewInterface::startDirectory()const{ |
87 | return selector()->m_startDir; | 87 | return selector()->m_startDir; |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
91 | ODocumentFileView::ODocumentFileView( OFileSelector* selector ) | 91 | ODocumentFileView::ODocumentFileView( OFileSelector* selector ) |
92 | : OFileViewInterface( selector ) { | 92 | : OFileViewInterface( selector ) { |
93 | m_selector = 0; | 93 | m_selector = 0; |
94 | setName( i18n("Documents") ); | 94 | setName( i18n("Documents") ); |
95 | } | 95 | } |
96 | ODocumentFileView::~ODocumentFileView() { | 96 | ODocumentFileView::~ODocumentFileView() { |
97 | 97 | ||
98 | } | 98 | } |
99 | QString ODocumentFileView::selectedName()const { | 99 | QString ODocumentFileView::selectedName()const { |
100 | if (!m_selector) | 100 | if (!m_selector) |
101 | return QString::null; | 101 | return QString::null; |
102 | 102 | ||
103 | return m_selector->selected()->file(); | 103 | return m_selector->selected()->file(); |
104 | } | 104 | } |
105 | QString ODocumentFileView::selectedPath()const { | 105 | QString ODocumentFileView::selectedPath()const { |
106 | return QPEApplication::documentDir(); | 106 | return QPEApplication::documentDir(); |
107 | } | 107 | } |
108 | QString ODocumentFileView::directory()const { | 108 | QString ODocumentFileView::directory()const { |
109 | return selectedPath(); | 109 | return selectedPath(); |
110 | } | 110 | } |
111 | void ODocumentFileView::reread() { | 111 | void ODocumentFileView::reread() { |
112 | if (!m_selector) | 112 | if (!m_selector) |
113 | return; | 113 | return; |
114 | 114 | ||
115 | m_selector->setNewVisible( showNew() ); | 115 | m_selector->setNewVisible( showNew() ); |
116 | m_selector->setCloseVisible( showClose() ); | 116 | m_selector->setCloseVisible( showClose() ); |
117 | m_selector->filter = currentMimeType().join(";"); | 117 | m_selector->filter = currentMimeType().join(";"); |
118 | m_selector->reread(); | 118 | m_selector->reread(); |
119 | } | 119 | } |
120 | int ODocumentFileView::fileCount()const { | 120 | int ODocumentFileView::fileCount()const { |
121 | if (!m_selector) | 121 | if (!m_selector) |
122 | return -1; | 122 | return -1; |
123 | 123 | ||
124 | return m_selector->fileCount(); | 124 | return m_selector->fileCount(); |
125 | } | 125 | } |
126 | 126 | ||
127 | DocLnk ODocumentFileView::selectedDocument()const { | 127 | DocLnk ODocumentFileView::selectedDocument()const { |
128 | if (!m_selector) | 128 | if (!m_selector) |
129 | return DocLnk(); | 129 | return DocLnk(); |
130 | DocLnk lnk = *m_selector->selected(); | 130 | DocLnk lnk = *m_selector->selected(); |
131 | return lnk; | 131 | return lnk; |
132 | } | 132 | } |
133 | 133 | ||
134 | QWidget* ODocumentFileView::widget( QWidget* parent ) { | 134 | QWidget* ODocumentFileView::widget( QWidget* parent ) { |
135 | if (!m_selector ) { | 135 | if (!m_selector ) { |
136 | m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); | 136 | m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); |
137 | QObject::connect(m_selector, SIGNAL(fileSelected( const DocLnk& ) ), | 137 | QObject::connect(m_selector, SIGNAL(fileSelected( const DocLnk& ) ), |
138 | selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); | 138 | selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); |
139 | QObject::connect(m_selector, SIGNAL(closeMe() ), | 139 | QObject::connect(m_selector, SIGNAL(closeMe() ), |
140 | selector(), SIGNAL(closeMe() ) ); | 140 | selector(), SIGNAL(closeMe() ) ); |
141 | QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk& ) ), | 141 | QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk& ) ), |
142 | selector(), SIGNAL(newSelected(const DocLnk& ) ) ); | 142 | selector(), SIGNAL(newSelected(const DocLnk& ) ) ); |
143 | } | 143 | } |
144 | 144 | ||
145 | return m_selector; | 145 | return m_selector; |
146 | } | 146 | } |
147 | 147 | ||
148 | /* | 148 | /* |
149 | * This is the file system view used | 149 | * This is the file system view used |
150 | * we use a QListView + QListViewItems for it | 150 | * we use a QListView + QListViewItems for it |
151 | */ | 151 | */ |
152 | 152 | ||
153 | OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, | 153 | OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, |
154 | const QString& path, const QString& date, | 154 | const QString& path, const QString& date, |
155 | const QString& size, const QString& dir, | 155 | const QString& size, const QString& dir, |
156 | bool isLocked, bool isDir ) | 156 | bool isLocked, bool isDir ) |
157 | : QListViewItem( view ) | 157 | : QListViewItem( view ) |
158 | { | 158 | { |
159 | setPixmap(0, pixmap ); | 159 | setPixmap(0, pixmap ); |
160 | setText(1, path ); | 160 | setText(1, path ); |
161 | setText(2, size ); | 161 | setText(2, size ); |
162 | setText(3, date ); | 162 | setText(3, date ); |
163 | m_isDir = isDir; | 163 | m_isDir = isDir; |
164 | m_dir = dir; | 164 | m_dir = dir; |
165 | m_locked = isLocked; | 165 | m_locked = isLocked; |
166 | } | 166 | } |
167 | OFileSelectorItem::~OFileSelectorItem() { | 167 | OFileSelectorItem::~OFileSelectorItem() { |
168 | 168 | ||
169 | } | 169 | } |
170 | bool OFileSelectorItem::isLocked()const { | 170 | bool OFileSelectorItem::isLocked()const { |
171 | return m_locked; | 171 | return m_locked; |
172 | } | 172 | } |
173 | QString OFileSelectorItem::directory()const { | 173 | QString OFileSelectorItem::directory()const { |
174 | return m_dir; | 174 | return m_dir; |
175 | } | 175 | } |
176 | bool OFileSelectorItem::isDir()const { | 176 | bool OFileSelectorItem::isDir()const { |
177 | return m_isDir; | 177 | return m_isDir; |
178 | } | 178 | } |
179 | QString OFileSelectorItem::path()const { | 179 | QString OFileSelectorItem::path()const { |
180 | return text( 1 ); | 180 | return text( 1 ); |
181 | } | 181 | } |
182 | QString OFileSelectorItem::key( int id, bool )const { | 182 | QString OFileSelectorItem::key( int id, bool )const { |
183 | QString ke; | 183 | QString ke; |
184 | if( id == 0 || id == 1 ){ // name | 184 | if( id == 0 || id == 1 ){ // name |
185 | if( m_isDir ){ | 185 | if( m_isDir ){ |
186 | ke.append("0" ); | 186 | ke.append("0" ); |
187 | ke.append( text(1) ); | 187 | ke.append( text(1) ); |
188 | }else{ | 188 | }else{ |
189 | ke.append("1" ); | 189 | ke.append("1" ); |
190 | ke.append( text(1) ); | 190 | ke.append( text(1) ); |
191 | } | 191 | } |
192 | return ke; | 192 | return ke; |
193 | }else | 193 | }else |
194 | return text( id ); | 194 | return text( id ); |
195 | 195 | ||
196 | } | 196 | } |
197 | 197 | ||
198 | OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, | 198 | OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, |
199 | OFileSelector* sel) | 199 | OFileSelector* sel) |
200 | : QWidget( parent ), m_sel( sel ) { | 200 | : QWidget( parent ), m_sel( sel ) { |
201 | m_all = false; | 201 | m_all = false; |
202 | QVBoxLayout* lay = new QVBoxLayout( this ); | 202 | QVBoxLayout* lay = new QVBoxLayout( this ); |
203 | m_currentDir = startDir; | 203 | m_currentDir = startDir; |
204 | 204 | ||
205 | /* | 205 | /* |
206 | * now we add a special bar | 206 | * now we add a special bar |
207 | * One Button For Up | 207 | * One Button For Up |
208 | * Home | 208 | * Home |
209 | * Doc | 209 | * Doc |
210 | * And a dropdown menu with FileSystems | 210 | * And a dropdown menu with FileSystems |
211 | * FUTURE: one to change dir with lineedit | 211 | * FUTURE: one to change dir with lineedit |
212 | * Bookmarks | 212 | * Bookmarks |
213 | * Create Dir | 213 | * Create Dir |
214 | */ | 214 | */ |
215 | QHBox* box = new QHBox(this ); | 215 | QHBox* box = new QHBox(this ); |
216 | box->setBackgroundMode( PaletteButton ); | 216 | box->setBackgroundMode( PaletteButton ); |
217 | box->setSpacing( 0 ); | 217 | box->setSpacing( 0 ); |
218 | 218 | ||
219 | QToolButton *btn = new QToolButton( box ); | 219 | QToolButton *btn = new QToolButton( box ); |
220 | btn->setIconSet( Resource::loadPixmap("up") ); | 220 | btn->setIconSet( Resource::loadPixmap("up") ); |
221 | connect(btn, SIGNAL(clicked() ), | 221 | connect(btn, SIGNAL(clicked() ), |
222 | this, SLOT( cdUP() ) ); | 222 | this, SLOT( cdUP() ) ); |
223 | 223 | ||
224 | btn = new QToolButton( box ); | 224 | btn = new QToolButton( box ); |
225 | btn->setIconSet( Resource::loadPixmap("home") ); | 225 | btn->setIconSet( Resource::loadPixmap("home") ); |
226 | connect(btn, SIGNAL(clicked() ), | 226 | connect(btn, SIGNAL(clicked() ), |
227 | this, SLOT( cdHome() ) ); | 227 | this, SLOT( cdHome() ) ); |
228 | 228 | ||
229 | btn = new QToolButton( box ); | 229 | btn = new QToolButton( box ); |
230 | btn->setIconSet( Resource::loadPixmap("DocsIcon") ); | 230 | btn->setIconSet( Resource::loadPixmap("DocsIcon") ); |
231 | connect(btn, SIGNAL(clicked() ), | 231 | connect(btn, SIGNAL(clicked() ), |
232 | this, SLOT(cdDoc() ) ); | 232 | this, SLOT(cdDoc() ) ); |
233 | 233 | ||
234 | m_btnNew = new QToolButton( box ); | 234 | m_btnNew = new QToolButton( box ); |
235 | m_btnNew->setIconSet( Resource::loadPixmap("new") ); | 235 | m_btnNew->setIconSet( Resource::loadPixmap("new") ); |
236 | connect(m_btnNew, SIGNAL(clicked() ), | 236 | connect(m_btnNew, SIGNAL(clicked() ), |
237 | this, SLOT(slotNew() ) ); | 237 | this, SLOT(slotNew() ) ); |
238 | 238 | ||
239 | 239 | ||
240 | m_btnClose = new QToolButton( box ); | 240 | m_btnClose = new QToolButton( box ); |
241 | m_btnClose->setIconSet( Resource::loadPixmap("close") ); | 241 | m_btnClose->setIconSet( Resource::loadPixmap("close") ); |
242 | connect(m_btnClose, SIGNAL(clicked() ), | 242 | connect(m_btnClose, SIGNAL(clicked() ), |
243 | selector(), SIGNAL(closeMe() ) ); | 243 | selector(), SIGNAL(closeMe() ) ); |
244 | 244 | ||
245 | btn = new QToolButton( box ); | 245 | btn = new QToolButton( box ); |
246 | btn->setIconSet( Resource::loadPixmap("cardmon/pcmcia") ); | 246 | btn->setIconSet( Resource::loadPixmap("cardmon/pcmcia") ); |
247 | 247 | ||
248 | /* let's fill device parts */ | 248 | /* let's fill device parts */ |
249 | QPopupMenu* pop = new QPopupMenu(this); | 249 | QPopupMenu* pop = new QPopupMenu(this); |
250 | connect(pop, SIGNAL( activated(int) ), | 250 | connect(pop, SIGNAL( activated(int) ), |
251 | this, SLOT(slotFSActivated(int) ) ); | 251 | this, SLOT(slotFSActivated(int) ) ); |
252 | 252 | ||
253 | StorageInfo storage; | 253 | StorageInfo storage; |
254 | const QList<FileSystem> &fs = storage.fileSystems(); | 254 | const QList<FileSystem> &fs = storage.fileSystems(); |
255 | QListIterator<FileSystem> it(fs); | 255 | QListIterator<FileSystem> it(fs); |
256 | for ( ; it.current(); ++it ) { | 256 | for ( ; it.current(); ++it ) { |
257 | const QString disk = (*it)->name(); | 257 | const QString disk = (*it)->name(); |
258 | const QString path = (*it)->path(); | 258 | const QString path = (*it)->path(); |
259 | m_dev.insert( disk, path ); | 259 | m_dev.insert( disk, path ); |
260 | pop->insertItem( disk ); | 260 | pop->insertItem( disk ); |
261 | } | 261 | } |
262 | m_fsPop = pop; | 262 | m_fsPop = pop; |
263 | 263 | ||
264 | 264 | ||
265 | btn->setPopup( pop ); | 265 | btn->setPopup( pop ); |
266 | btn->setPopupDelay ( 0 ); | 266 | btn->setPopupDelay ( 0 ); |
267 | lay->addWidget( box ); | 267 | lay->addWidget( box ); |
268 | 268 | ||
269 | m_view = new QListView( this ); | 269 | m_view = new QListView( this ); |
270 | 270 | ||
271 | m_view->installEventFilter(this); | 271 | m_view->installEventFilter(this); |
272 | 272 | ||
273 | QPEApplication::setStylusOperation( m_view->viewport(), | 273 | QPEApplication::setStylusOperation( m_view->viewport(), |
274 | QPEApplication::RightOnHold); | 274 | QPEApplication::RightOnHold); |
275 | m_view->addColumn(" " ); | 275 | m_view->addColumn(" " ); |
276 | m_view->addColumn(i18n("Name"), 135 ); | 276 | m_view->addColumn(i18n("Name"), 135 ); |
277 | m_view->addColumn(i18n("Size"), -1 ); | 277 | m_view->addColumn(i18n("Size"), -1 ); |
278 | m_view->addColumn(i18n("Date"), 60 ); | 278 | m_view->addColumn(i18n("Date"), 60 ); |
279 | m_view->addColumn(i18n("Mime Type"), -1 ); | 279 | m_view->addColumn(i18n("Mime Type"), -1 ); |
280 | 280 | ||
281 | 281 | ||
282 | m_view->setSorting( 1 ); | 282 | m_view->setSorting( 1 ); |
283 | m_view->setAllColumnsShowFocus( TRUE ); | 283 | m_view->setAllColumnsShowFocus( TRUE ); |
284 | 284 | ||
285 | lay->addWidget( m_view, 1000 ); | 285 | lay->addWidget( m_view, 1000 ); |
286 | connectSlots(); | 286 | connectSlots(); |
287 | } | 287 | } |
288 | OFileViewFileListView::~OFileViewFileListView() { | 288 | OFileViewFileListView::~OFileViewFileListView() { |
289 | } | 289 | } |
290 | void OFileViewFileListView::slotNew() { | 290 | void OFileViewFileListView::slotNew() { |
291 | DocLnk lnk; | 291 | DocLnk lnk; |
292 | emit selector()->newSelected( lnk ); | 292 | emit selector()->newSelected( lnk ); |
293 | } | 293 | } |
294 | OFileSelectorItem* OFileViewFileListView::currentItem()const{ | 294 | OFileSelectorItem* OFileViewFileListView::currentItem()const{ |
295 | QListViewItem* item = m_view->currentItem(); | 295 | QListViewItem* item = m_view->currentItem(); |
296 | if (!item ) | 296 | if (!item ) |
297 | return 0l; | 297 | return 0l; |
298 | 298 | ||
299 | return static_cast<OFileSelectorItem*>(item); | 299 | return static_cast<OFileSelectorItem*>(item); |
300 | } | 300 | } |
301 | void OFileViewFileListView::reread( bool all ) { | 301 | void OFileViewFileListView::reread( bool all ) { |
302 | m_view->clear(); | 302 | m_view->clear(); |
303 | 303 | ||
304 | if (selector()->showClose() ) | 304 | if (selector()->showClose() ) |
305 | m_btnClose->show(); | 305 | m_btnClose->show(); |
306 | else | 306 | else |
307 | m_btnClose->hide(); | 307 | m_btnClose->hide(); |
308 | 308 | ||
309 | if (selector()->showNew() ) | 309 | if (selector()->showNew() ) |
310 | m_btnNew->show(); | 310 | m_btnNew->show(); |
311 | else | 311 | else |
312 | m_btnNew->hide(); | 312 | m_btnNew->hide(); |
313 | 313 | ||
314 | m_mimes = selector()->currentMimeType(); | 314 | m_mimes = selector()->currentMimeType(); |
315 | m_all = all; | 315 | m_all = all; |
316 | 316 | ||
317 | QDir dir( m_currentDir ); | 317 | QDir dir( m_currentDir ); |
318 | if (!dir.exists() ) | 318 | if (!dir.exists() ) |
319 | return; | 319 | return; |
320 | topLevelWidget()->setCaption( dir.path() ); | 320 | topLevelWidget()->setCaption( dir.path() ); |
321 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); | 321 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); |
322 | int filter; | 322 | int filter; |
323 | if (m_all ) | 323 | if (m_all ) |
324 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; | 324 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; |
325 | else | 325 | else |
326 | filter = QDir::Files | QDir::Dirs | QDir::All; | 326 | filter = QDir::Files | QDir::Dirs | QDir::All; |
327 | dir.setFilter( filter ); | 327 | dir.setFilter( filter ); |
328 | 328 | ||
329 | // now go through all files | 329 | // now go through all files |
330 | const QFileInfoList *list = dir.entryInfoList(); | 330 | const QFileInfoList *list = dir.entryInfoList(); |
331 | if (!list) { | 331 | if (!list) { |
332 | cdUP(); | 332 | cdUP(); |
333 | return; | 333 | return; |
334 | } | 334 | } |
335 | QFileInfoListIterator it( *list ); | 335 | QFileInfoListIterator it( *list ); |
336 | QFileInfo *fi; | 336 | QFileInfo *fi; |
337 | while( (fi=it.current() ) ){ | 337 | while( (fi=it.current() ) ){ |
338 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){ | 338 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){ |
339 | ++it; | 339 | ++it; |
340 | continue; | 340 | continue; |
341 | } | 341 | } |
342 | 342 | ||
343 | /* | 343 | /* |
344 | * It is a symlink we try to resolve it now but don't let us attack by DOS | 344 | * It is a symlink we try to resolve it now but don't let us attack by DOS |
345 | * | 345 | * |
346 | */ | 346 | */ |
347 | if( fi->isSymLink() ){ | 347 | if( fi->isSymLink() ){ |
348 | QString file = fi->dirPath( true ) + "/" + fi->readLink(); | 348 | QString file = fi->dirPath( true ) + "/" + fi->readLink(); |
349 | for( int i = 0; i<=4; i++) { // 5 tries to prevent dos | 349 | for( int i = 0; i<=4; i++) { // 5 tries to prevent dos |
350 | QFileInfo info( file ); | 350 | QFileInfo info( file ); |
351 | if( !info.exists() ){ | 351 | if( !info.exists() ){ |
352 | addSymlink( fi, TRUE ); | 352 | addSymlink( fi, TRUE ); |
353 | break; | 353 | break; |
354 | }else if( info.isDir() ){ | 354 | }else if( info.isDir() ){ |
355 | addDir( fi, TRUE ); | 355 | addDir( fi, TRUE ); |
356 | break; | 356 | break; |
357 | }else if( info.isFile() ){ | 357 | }else if( info.isFile() ){ |
358 | addFile( fi, TRUE ); | 358 | addFile( fi, TRUE ); |
359 | break; | 359 | break; |
360 | }else if( info.isSymLink() ){ | 360 | }else if( info.isSymLink() ){ |
361 | file = info.dirPath(true ) + "/" + info.readLink() ; | 361 | file = info.dirPath(true ) + "/" + info.readLink() ; |
362 | break; | 362 | break; |
363 | }else if( i == 4){ // couldn't resolve symlink add it as symlink | 363 | }else if( i == 4){ // couldn't resolve symlink add it as symlink |
364 | addSymlink( fi ); | 364 | addSymlink( fi ); |
365 | } | 365 | } |
366 | } // off for loop for symlink resolving | 366 | } // off for loop for symlink resolving |
367 | }else if( fi->isDir() ) | 367 | }else if( fi->isDir() ) |
368 | addDir( fi ); | 368 | addDir( fi ); |
369 | else if( fi->isFile() ) | 369 | else if( fi->isFile() ) |
370 | addFile( fi ); | 370 | addFile( fi ); |
371 | 371 | ||
372 | ++it; | 372 | ++it; |
373 | } // of while loop | 373 | } // of while loop |
374 | m_view->sort(); | 374 | m_view->sort(); |
375 | 375 | ||
376 | } | 376 | } |
377 | int OFileViewFileListView::fileCount()const{ | 377 | int OFileViewFileListView::fileCount()const{ |
378 | return m_view->childCount(); | 378 | return m_view->childCount(); |
379 | } | 379 | } |
380 | QString OFileViewFileListView::currentDir()const{ | 380 | QString OFileViewFileListView::currentDir()const{ |
381 | return m_currentDir; | 381 | return m_currentDir; |
382 | } | 382 | } |
383 | OFileSelector* OFileViewFileListView::selector() { | 383 | OFileSelector* OFileViewFileListView::selector() { |
384 | return m_sel; | 384 | return m_sel; |
385 | } | 385 | } |
386 | 386 | ||
387 | bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) { | 387 | bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) { |
388 | #if 0 | ||
388 | if ( e->type() == QEvent::KeyPress ) { | 389 | if ( e->type() == QEvent::KeyPress ) { |
389 | QKeyEvent *k = (QKeyEvent *)e; | 390 | QKeyEvent *k = (QKeyEvent *)e; |
390 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { | 391 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { |
391 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); | 392 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); |
392 | return true; | 393 | return true; |
393 | } | 394 | } |
394 | } | 395 | } |
396 | #endif | ||
395 | return false; | 397 | return false; |
396 | } | 398 | } |
397 | 399 | ||
398 | 400 | ||
399 | void OFileViewFileListView::connectSlots() { | 401 | void OFileViewFileListView::connectSlots() { |
400 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), | 402 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), |
401 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); | 403 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); |
402 | connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ), | 404 | connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ), |
403 | this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) ); | 405 | this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) ); |
406 | connect(m_view, SIGNAL(doubleClicked( QListViewItem* )), | ||
407 | this, SLOT(slotDoubleClicked(QListViewItem* ) ) ); | ||
408 | connect(m_view, SIGNAL(returnPressed( QListViewItem* )), | ||
409 | this, SLOT(slotDoubleClicked(QListViewItem* ) ) ); | ||
404 | } | 410 | } |
405 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) { | 411 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) { |
406 | if (!item) | 412 | if (!item) |
407 | return; | 413 | return; |
408 | #if 0 | 414 | #if 0 |
409 | 415 | ||
410 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 416 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
411 | 417 | ||
412 | if (!sel->isDir() ) { | 418 | if (!sel->isDir() ) { |
413 | selector()->m_lneEdit->setText( sel->text(1) ); | 419 | selector()->m_lneEdit->setText( sel->text(1) ); |
414 | // if in fileselector mode we will emit selected | 420 | // if in fileselector mode we will emit selected |
415 | if ( selector()->mode() == OFileSelector::FileSelector ) { | 421 | if ( selector()->mode() == OFileSelector::FileSelector ) { |
416 | qWarning("slot Current Changed"); | 422 | qWarning("slot Current Changed"); |
417 | QStringList str = QStringList::split("->", sel->text(1) ); | 423 | QStringList str = QStringList::split("->", sel->text(1) ); |
418 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); | 424 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); |
419 | emit selector()->fileSelected( path ); | 425 | emit selector()->fileSelected( path ); |
420 | DocLnk lnk( path ); | 426 | DocLnk lnk( path ); |
421 | emit selector()->fileSelected( lnk ); | 427 | emit selector()->fileSelected( lnk ); |
422 | } | 428 | } |
423 | } | 429 | } |
424 | #endif | 430 | #endif |
425 | } | 431 | } |
432 | void OFileViewFileListView::slotDoubleClicked(QListViewItem* item ) { | ||
433 | if (!item ) return; | ||
434 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | ||
435 | if (!sel->isLocked() ) { | ||
436 | QStringList str = QStringList::split("->", sel->text(1) ); | ||
437 | if (sel->isDir() ) { | ||
438 | m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); | ||
439 | emit selector()->dirSelected( m_currentDir ); | ||
440 | reread( m_all ); | ||
441 | }else { // file | ||
442 | //qWarning("slot Clicked"); | ||
443 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); | ||
444 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); | ||
445 | emit selector()->fileSelected( path ); | ||
446 | DocLnk lnk( path ); | ||
447 | emit selector()->fileSelected( lnk ); | ||
448 | emit selector()->ok(); | ||
449 | } | ||
450 | } // not locked | ||
451 | } | ||
426 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) { | 452 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) { |
427 | if (!item || ( button != Qt::LeftButton) ) | 453 | if (!item || ( button != Qt::LeftButton) ) |
428 | return; | 454 | return; |
429 | 455 | ||
430 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 456 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
431 | if (!sel->isLocked() ) { | 457 | if (!sel->isLocked() ) { |
432 | QStringList str = QStringList::split("->", sel->text(1) ); | 458 | QStringList str = QStringList::split("->", sel->text(1) ); |
433 | if (sel->isDir() ) { | 459 | if (sel->isDir() ) { |
434 | m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); | 460 | m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); |
435 | emit selector()->dirSelected( m_currentDir ); | 461 | emit selector()->dirSelected( m_currentDir ); |
436 | reread( m_all ); | 462 | reread( m_all ); |
437 | }else { // file | 463 | }else { // file |
438 | qWarning("slot Clicked"); | 464 | //qWarning("slot Clicked"); |
439 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); | 465 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); |
440 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); | 466 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); |
441 | emit selector()->fileSelected( path ); | 467 | emit selector()->fileSelected( path ); |
442 | DocLnk lnk( path ); | 468 | DocLnk lnk( path ); |
443 | emit selector()->fileSelected( lnk ); | 469 | emit selector()->fileSelected( lnk ); |
444 | } | 470 | } |
445 | } // not locked | 471 | } // not locked |
446 | } | 472 | } |
447 | void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) { | 473 | void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) { |
448 | MimeType type( info->absFilePath() ); | 474 | MimeType type( info->absFilePath() ); |
449 | if (!compliesMime( type.id() ) ) | 475 | if (!compliesMime( type.id() ) ) |
450 | return; | 476 | return; |
451 | 477 | ||
452 | QPixmap pix = type.pixmap(); | 478 | QPixmap pix = type.pixmap(); |
453 | QString dir, name; bool locked; | 479 | QString dir, name; bool locked; |
454 | if ( pix.isNull() ) { | 480 | if ( pix.isNull() ) { |
455 | QWMatrix matrix; | 481 | QWMatrix matrix; |
456 | QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); | 482 | QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); |
457 | matrix.scale( .4, .4 ); | 483 | matrix.scale( .4, .4 ); |
458 | pix = pixer.xForm( matrix ); | 484 | pix = pixer.xForm( matrix ); |
459 | } | 485 | } |
460 | dir = info->dirPath( true ); | 486 | dir = info->dirPath( true ); |
461 | locked = false; | 487 | locked = false; |
462 | if ( symlink ) | 488 | if ( symlink ) |
463 | name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); | 489 | name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); |
464 | else{ | 490 | else{ |
465 | name = info->fileName(); | 491 | name = info->fileName(); |
466 | if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || | 492 | if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || |
467 | ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) { | 493 | ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) { |
468 | locked = true; pix = Resource::loadPixmap("locked"); | 494 | locked = true; pix = Resource::loadPixmap("locked"); |
469 | } | 495 | } |
470 | } | 496 | } |
471 | (void)new OFileSelectorItem( m_view, pix, name, | 497 | (void)new OFileSelectorItem( m_view, pix, name, |
472 | KGlobal::locale()->formatDateTime(info->lastModified(),true, true, KLocale::ISODate), | 498 | KGlobal::locale()->formatDateTime(info->lastModified(),true, true, KLocale::ISODate), |
473 | QString::number( info->size() ), | 499 | QString::number( info->size() ), |
474 | dir, locked ); | 500 | dir, locked ); |
475 | } | 501 | } |
476 | void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) { | 502 | void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) { |
477 | bool locked = false; QString name; QPixmap pix; | 503 | bool locked = false; QString name; QPixmap pix; |
478 | 504 | ||
479 | if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || | 505 | if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || |
480 | ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) { | 506 | ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) { |
481 | locked = true; | 507 | locked = true; |
482 | if ( symlink ) | 508 | if ( symlink ) |
483 | pix = Resource::loadPixmap( "symlink" ); | 509 | pix = Resource::loadPixmap( "symlink" ); |
484 | else | 510 | else |
485 | pix = Resource::loadPixmap( "lockedfolder" ); | 511 | pix = Resource::loadPixmap( "lockedfolder" ); |
486 | }else | 512 | }else |
487 | pix = symlink ? Resource::loadPixmap( "symlink") : Resource::loadPixmap("folder"); | 513 | pix = symlink ? Resource::loadPixmap( "symlink") : Resource::loadPixmap("folder"); |
488 | 514 | ||
489 | name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() : | 515 | name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() : |
490 | info->fileName(); | 516 | info->fileName(); |
491 | 517 | ||
492 | (void)new OFileSelectorItem( m_view, pix, name, | 518 | (void)new OFileSelectorItem( m_view, pix, name, |
493 | KGlobal::locale()->formatDateTime(info->lastModified(),true, true, KLocale::ISODate), | 519 | KGlobal::locale()->formatDateTime(info->lastModified(),true, true, KLocale::ISODate), |
494 | QString::number( info->size() ), | 520 | QString::number( info->size() ), |
495 | info->dirPath( true ), locked, true ); | 521 | info->dirPath( true ), locked, true ); |
496 | 522 | ||
497 | 523 | ||
498 | } | 524 | } |
499 | void OFileViewFileListView::addSymlink( QFileInfo* , bool ) { | 525 | void OFileViewFileListView::addSymlink( QFileInfo* , bool ) { |
500 | 526 | ||
501 | } | 527 | } |
502 | void OFileViewFileListView::cdUP() { | 528 | void OFileViewFileListView::cdUP() { |
503 | QDir dir( m_currentDir ); | 529 | QDir dir( m_currentDir ); |
504 | dir.cdUp(); | 530 | dir.cdUp(); |
505 | 531 | ||
506 | if (!dir.exists() ) | 532 | if (!dir.exists() ) |
507 | m_currentDir = "/"; | 533 | m_currentDir = "/"; |
508 | else | 534 | else |
509 | m_currentDir = dir.absPath(); | 535 | m_currentDir = dir.absPath(); |
510 | 536 | ||
511 | emit selector()->dirSelected( m_currentDir ); | 537 | emit selector()->dirSelected( m_currentDir ); |
512 | reread( m_all ); | 538 | reread( m_all ); |
513 | } | 539 | } |
514 | void OFileViewFileListView::cdHome() { | 540 | void OFileViewFileListView::cdHome() { |
515 | m_currentDir = QDir::homeDirPath(); | 541 | m_currentDir = QDir::homeDirPath(); |
516 | emit selector()->dirSelected( m_currentDir ); | 542 | emit selector()->dirSelected( m_currentDir ); |
517 | reread( m_all ); | 543 | reread( m_all ); |
518 | } | 544 | } |
519 | void OFileViewFileListView::cdDoc() { | 545 | void OFileViewFileListView::cdDoc() { |
520 | m_currentDir = QPEApplication::documentDir(); | 546 | m_currentDir = QPEApplication::documentDir(); |
521 | emit selector()->dirSelected( m_currentDir ); | 547 | emit selector()->dirSelected( m_currentDir ); |
522 | reread( m_all ); | 548 | reread( m_all ); |
523 | } | 549 | } |
524 | void OFileViewFileListView::changeDir( const QString& dir ) { | 550 | void OFileViewFileListView::changeDir( const QString& dir ) { |
525 | m_currentDir = dir; | 551 | m_currentDir = dir; |
526 | emit selector()->dirSelected( m_currentDir ); | 552 | emit selector()->dirSelected( m_currentDir ); |
527 | reread( m_all ); | 553 | reread( m_all ); |
528 | } | 554 | } |
529 | void OFileViewFileListView::slotFSActivated( int id ) { | 555 | void OFileViewFileListView::slotFSActivated( int id ) { |
530 | changeDir ( m_dev[m_fsPop->text(id)] ); | 556 | changeDir ( m_dev[m_fsPop->text(id)] ); |
531 | } | 557 | } |
532 | 558 | ||
533 | /* check if the mimetype in mime | 559 | /* check if the mimetype in mime |
534 | * complies with the one which is current | 560 | * complies with the one which is current |
535 | */ | 561 | */ |
536 | /* | 562 | /* |
537 | * We've the mimetype of the file | 563 | * We've the mimetype of the file |
538 | * We need to get the stringlist of the current mimetype | 564 | * We need to get the stringlist of the current mimetype |
539 | * | 565 | * |
540 | * mime = image@slashjpeg | 566 | * mime = image@slashjpeg |
541 | * QStringList = 'image@slash*' | 567 | * QStringList = 'image@slash*' |
542 | * or QStringList = image/jpeg;image/png;application/x-ogg | 568 | * or QStringList = image/jpeg;image/png;application/x-ogg |
543 | * or QStringList = application/x-ogg;image@slash*; | 569 | * or QStringList = application/x-ogg;image@slash*; |
544 | * with all these mime filters it should get acceptes | 570 | * with all these mime filters it should get acceptes |
545 | * to do so we need to look if mime is contained inside | 571 | * to do so we need to look if mime is contained inside |
546 | * the stringlist | 572 | * the stringlist |
547 | * if it's contained return true | 573 | * if it's contained return true |
548 | * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' | 574 | * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' |
549 | * is contained in the mimefilter and then we will | 575 | * is contained in the mimefilter and then we will |
550 | * look if both are equal until the '/' | 576 | * look if both are equal until the '/' |
551 | */ | 577 | */ |
552 | bool OFileViewFileListView::compliesMime( const QString& str) { | 578 | bool OFileViewFileListView::compliesMime( const QString& str) { |
553 | if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) | 579 | if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) |
554 | return true; | 580 | return true; |
555 | 581 | ||
556 | for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) { | 582 | for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) { |
557 | QRegExp reg( (*it) ); | 583 | QRegExp reg( (*it) ); |
558 | reg.setWildcard( true ); | 584 | reg.setWildcard( true ); |
559 | if ( str.find( reg ) != -1 ) | 585 | if ( str.find( reg ) != -1 ) |
560 | return true; | 586 | return true; |
561 | 587 | ||
562 | } | 588 | } |
563 | return false; | 589 | return false; |
564 | } | 590 | } |
565 | /* | 591 | /* |
566 | * The listView giving access to the file system! | 592 | * The listView giving access to the file system! |
567 | */ | 593 | */ |
568 | class OFileViewFileSystem : public OFileViewInterface { | 594 | class OFileViewFileSystem : public OFileViewInterface { |
569 | public: | 595 | public: |
570 | OFileViewFileSystem( OFileSelector* ); | 596 | OFileViewFileSystem( OFileSelector* ); |
571 | ~OFileViewFileSystem(); | 597 | ~OFileViewFileSystem(); |
572 | 598 | ||
573 | QString selectedName() const; | 599 | QString selectedName() const; |
574 | QString selectedPath() const; | 600 | QString selectedPath() const; |
575 | 601 | ||
576 | QString directory()const; | 602 | QString directory()const; |
577 | void reread(); | 603 | void reread(); |
578 | int fileCount()const; | 604 | int fileCount()const; |
579 | 605 | ||
580 | QWidget* widget( QWidget* parent ); | 606 | QWidget* widget( QWidget* parent ); |
581 | void activate( const QString& ); | 607 | void activate( const QString& ); |
582 | private: | 608 | private: |
583 | OFileViewFileListView* m_view; | 609 | OFileViewFileListView* m_view; |
584 | bool m_all : 1; | 610 | bool m_all : 1; |
585 | }; | 611 | }; |
586 | OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) | 612 | OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) |
587 | : OFileViewInterface( sel ) { | 613 | : OFileViewInterface( sel ) { |
588 | m_view = 0; | 614 | m_view = 0; |
589 | m_all = false; | 615 | m_all = false; |
590 | } | 616 | } |
591 | OFileViewFileSystem::~OFileViewFileSystem() { | 617 | OFileViewFileSystem::~OFileViewFileSystem() { |
592 | } | 618 | } |
593 | QString OFileViewFileSystem::selectedName()const{ | 619 | QString OFileViewFileSystem::selectedName()const{ |
594 | if (!m_view ) | 620 | if (!m_view ) |
595 | return QString::null; | 621 | return QString::null; |
596 | 622 | ||
597 | QString cFN=currentFileName(); | 623 | QString cFN=currentFileName(); |
598 | if (cFN.startsWith("/")) return cFN; | 624 | if (cFN.startsWith("/")) return cFN; |
599 | return m_view->currentDir() + "/" + cFN; | 625 | return m_view->currentDir() + "/" + cFN; |
600 | } | 626 | } |
601 | QString OFileViewFileSystem::selectedPath()const{ | 627 | QString OFileViewFileSystem::selectedPath()const{ |
602 | return QString::null; | 628 | return QString::null; |
603 | } | 629 | } |
604 | QString OFileViewFileSystem::directory()const{ | 630 | QString OFileViewFileSystem::directory()const{ |
605 | if (!m_view) | 631 | if (!m_view) |
606 | return QString::null; | 632 | return QString::null; |
607 | 633 | ||
608 | OFileSelectorItem* item = m_view->currentItem(); | 634 | OFileSelectorItem* item = m_view->currentItem(); |
609 | if (!item ) | 635 | if (!item ) |
610 | return QString::null; | 636 | return QString::null; |
611 | 637 | ||
612 | return QDir(item->directory() ).absPath(); | 638 | return QDir(item->directory() ).absPath(); |
613 | } | 639 | } |
614 | void OFileViewFileSystem::reread() { | 640 | void OFileViewFileSystem::reread() { |
615 | if (!m_view) | 641 | if (!m_view) |
616 | return; | 642 | return; |
617 | 643 | ||
618 | m_view->reread( m_all ); | 644 | m_view->reread( m_all ); |
619 | } | 645 | } |
620 | int OFileViewFileSystem::fileCount()const{ | 646 | int OFileViewFileSystem::fileCount()const{ |
621 | if (!m_view ) | 647 | if (!m_view ) |
622 | return -1; | 648 | return -1; |
623 | return m_view->fileCount(); | 649 | return m_view->fileCount(); |
624 | } | 650 | } |
625 | QWidget* OFileViewFileSystem::widget( QWidget* parent ) { | 651 | QWidget* OFileViewFileSystem::widget( QWidget* parent ) { |
626 | if (!m_view ) { | 652 | if (!m_view ) { |
627 | m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); | 653 | m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); |
628 | } | 654 | } |
629 | return m_view; | 655 | return m_view; |
630 | } | 656 | } |
631 | void OFileViewFileSystem::activate( const QString& str) { | 657 | void OFileViewFileSystem::activate( const QString& str) { |
632 | m_all = (str !=i18n("Files") ); | 658 | m_all = (str !=i18n("Files") ); |
633 | 659 | ||
634 | 660 | ||
635 | } | 661 | } |
636 | 662 | ||
637 | /* Selector */ | 663 | /* Selector */ |
638 | OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, | 664 | OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, |
639 | const QString& dirName, const QString& fileName, | 665 | const QString& dirName, const QString& fileName, |
640 | const MimeTypes& mimetypes, | 666 | const MimeTypes& mimetypes, |
641 | bool showNew, bool showClose) | 667 | bool showNew, bool showClose) |
642 | : QWidget( parent, "OFileSelector" ) | 668 | : QWidget( parent, "OFileSelector" ) |
643 | { | 669 | { |
644 | m_current = 0; | 670 | m_current = 0; |
645 | m_shNew = showNew; | 671 | m_shNew = showNew; |
646 | m_shClose = showClose; | 672 | m_shClose = showClose; |
647 | m_mimeType = mimetypes; | 673 | m_mimeType = mimetypes; |
648 | m_startDir = dirName; | 674 | m_startDir = dirName; |
649 | m_mode = mode; | 675 | m_mode = mode; |
650 | m_selector = sel; | 676 | m_selector = sel; |
651 | 677 | ||
652 | initUI(); | 678 | initUI(); |
653 | m_lneEdit->setText( fileName ); | 679 | m_lneEdit->setText( fileName ); |
654 | initMime(); | 680 | initMime(); |
655 | initViews(); | 681 | initViews(); |
656 | 682 | ||
657 | QString str; | 683 | QString str; |
658 | switch ( m_selector ) { | 684 | switch ( m_selector ) { |
659 | default: | 685 | default: |
660 | case Normal: | 686 | case Normal: |
661 | str = i18n("Documents"); | 687 | str = i18n("Documents"); |
662 | m_cmbView->setCurrentItem( 0 ); | 688 | m_cmbView->setCurrentItem( 0 ); |
663 | break; | 689 | break; |
664 | case Extended: | 690 | case Extended: |
665 | str = i18n("Files"); | 691 | str = i18n("Files"); |
666 | m_cmbView->setCurrentItem( 1 ); | 692 | m_cmbView->setCurrentItem( 1 ); |
667 | break; | 693 | break; |
668 | case ExtendedAll: | 694 | case ExtendedAll: |
669 | str = i18n("All Files"); | 695 | str = i18n("All Files"); |
670 | m_cmbView->setCurrentItem( 2 ); | 696 | m_cmbView->setCurrentItem( 2 ); |
671 | break; | 697 | break; |
672 | } | 698 | } |
673 | slotViewChange( str ); | 699 | slotViewChange( str ); |
674 | 700 | ||
675 | } | 701 | } |
676 | OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, | 702 | OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, |
677 | bool showNew, bool showClose ) | 703 | bool showNew, bool showClose ) |
678 | : QWidget( parent, name ) | 704 | : QWidget( parent, name ) |
679 | { | 705 | { |
680 | m_current = 0; | 706 | m_current = 0; |
681 | m_shNew = showNew; | 707 | m_shNew = showNew; |
682 | m_shClose = showClose; | 708 | m_shClose = showClose; |
683 | m_startDir = QPEApplication::documentDir(); | 709 | m_startDir = QPEApplication::documentDir(); |
684 | 710 | ||
685 | if (!mimeFilter.isEmpty() ) | 711 | if (!mimeFilter.isEmpty() ) |
686 | m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); | 712 | m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); |
687 | 713 | ||
688 | m_mode = OFileSelector::FileSelector; | 714 | m_mode = OFileSelector::FileSelector; |
689 | m_selector = OFileSelector::Normal; | 715 | m_selector = OFileSelector::Normal; |
690 | 716 | ||
691 | initUI(); | 717 | initUI(); |
692 | initMime(); | 718 | initMime(); |
693 | initViews(); | 719 | initViews(); |
694 | m_cmbView->setCurrentItem( 0 ); | 720 | m_cmbView->setCurrentItem( 0 ); |
695 | slotViewChange( i18n("Documents") ); | 721 | slotViewChange( i18n("Documents") ); |
696 | } | 722 | } |
697 | /* | 723 | /* |
698 | * INIT UI will set up the basic GUI | 724 | * INIT UI will set up the basic GUI |
699 | * Layout: Simple VBoxLayout | 725 | * Layout: Simple VBoxLayout |
700 | * On top a WidgetStack containing the Views... | 726 | * On top a WidgetStack containing the Views... |
701 | * - List View | 727 | * - List View |
702 | * - Document View | 728 | * - Document View |
703 | * Below we will have a Label + LineEdit | 729 | * Below we will have a Label + LineEdit |
704 | * Below we will have two ComoBoxes one for choosing the view one for | 730 | * Below we will have two ComoBoxes one for choosing the view one for |
705 | * choosing the mimetype | 731 | * choosing the mimetype |
706 | */ | 732 | */ |
707 | void OFileSelector::initUI() { | 733 | void OFileSelector::initUI() { |
708 | QVBoxLayout* lay = new QVBoxLayout( this ); | 734 | QVBoxLayout* lay = new QVBoxLayout( this ); |
709 | 735 | ||
710 | m_stack = new QWidgetStack( this ); | 736 | m_stack = new QWidgetStack( this ); |
711 | lay->addWidget( m_stack, 1000 ); | 737 | lay->addWidget( m_stack, 1000 ); |
712 | 738 | ||
713 | m_nameBox = new QHBox( this ); | 739 | m_nameBox = new QHBox( this ); |
714 | (void)new QLabel( i18n("Name:"), m_nameBox ); | 740 | (void)new QLabel( i18n("Name:"), m_nameBox ); |
715 | m_lneEdit = new QLineEdit( m_nameBox ); | 741 | m_lneEdit = new QLineEdit( m_nameBox ); |
716 | m_lneEdit ->installEventFilter(this); | 742 | m_lneEdit ->installEventFilter(this); |
717 | lay->addWidget( m_nameBox ); | 743 | lay->addWidget( m_nameBox ); |
718 | 744 | ||
719 | m_cmbBox = new QHBox( this ); | 745 | m_cmbBox = new QHBox( this ); |
720 | m_cmbView = new QComboBox( m_cmbBox ); | 746 | m_cmbView = new QComboBox( m_cmbBox ); |
721 | m_cmbMime = new QComboBox( m_cmbBox ); | 747 | m_cmbMime = new QComboBox( m_cmbBox ); |
722 | lay->addWidget( m_cmbBox ); | 748 | lay->addWidget( m_cmbBox ); |
723 | } | 749 | } |
724 | 750 | ||
725 | /* | 751 | /* |
726 | * This will make sure that the return key in the name edit causes dialogs to close | 752 | * This will make sure that the return key in the name edit causes dialogs to close |
727 | */ | 753 | */ |
728 | 754 | ||
729 | bool OFileSelector::eventFilter (QObject *o, QEvent *e) { | 755 | bool OFileSelector::eventFilter (QObject *o, QEvent *e) { |
730 | if ( e->type() == QEvent::KeyPress ) { | 756 | if ( e->type() == QEvent::KeyPress ) { |
731 | QKeyEvent *k = (QKeyEvent *)e; | 757 | QKeyEvent *k = (QKeyEvent *)e; |
732 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { | 758 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { |
733 | emit ok(); | 759 | emit ok(); |
734 | return true; | 760 | return true; |
735 | } | 761 | } |
736 | } | 762 | } |
737 | return false; | 763 | return false; |
738 | } | 764 | } |
739 | 765 | ||
740 | /* | 766 | /* |
741 | * This will insert the MimeTypes into the Combo Box | 767 | * This will insert the MimeTypes into the Combo Box |
742 | * And also connect the changed signal | 768 | * And also connect the changed signal |
743 | * | 769 | * |
744 | * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes | 770 | * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes |
745 | */ | 771 | */ |
746 | void OFileSelector::initMime() { | 772 | void OFileSelector::initMime() { |
747 | MimeTypes::Iterator it; | 773 | MimeTypes::Iterator it; |
748 | for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) { | 774 | for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) { |
749 | m_cmbMime->insertItem( it.key() ); | 775 | m_cmbMime->insertItem( it.key() ); |
750 | } | 776 | } |
751 | m_cmbMime->setCurrentItem( 0 ); | 777 | m_cmbMime->setCurrentItem( 0 ); |
752 | 778 | ||
753 | connect( m_cmbMime, SIGNAL(activated(int) ), | 779 | connect( m_cmbMime, SIGNAL(activated(int) ), |
754 | this, SLOT(slotMimeTypeChanged() ) ); | 780 | this, SLOT(slotMimeTypeChanged() ) ); |
755 | 781 | ||
756 | } | 782 | } |
757 | void OFileSelector::initViews() { | 783 | void OFileSelector::initViews() { |
758 | m_cmbView->insertItem( i18n("Documents") ); | 784 | m_cmbView->insertItem( i18n("Documents") ); |
759 | m_cmbView->insertItem( i18n("Files") ); | 785 | m_cmbView->insertItem( i18n("Files") ); |
760 | m_cmbView->insertItem( i18n("All Files") ); | 786 | m_cmbView->insertItem( i18n("All Files") ); |
761 | connect(m_cmbView, SIGNAL(activated( const QString& ) ), | 787 | connect(m_cmbView, SIGNAL(activated( const QString& ) ), |
762 | this, SLOT(slotViewChange( const QString& ) ) ); | 788 | this, SLOT(slotViewChange( const QString& ) ) ); |
763 | 789 | ||
764 | 790 | ||
765 | m_views.insert( i18n("Documents"), new ODocumentFileView(this) ); | 791 | m_views.insert( i18n("Documents"), new ODocumentFileView(this) ); |
766 | 792 | ||
767 | /* see above why add both */ | 793 | /* see above why add both */ |
768 | OFileViewInterface* in = new OFileViewFileSystem( this ); | 794 | OFileViewInterface* in = new OFileViewFileSystem( this ); |
769 | m_views.insert( i18n("Files"), in ); | 795 | m_views.insert( i18n("Files"), in ); |
770 | m_views.insert( i18n("All Files"), in ); | 796 | m_views.insert( i18n("All Files"), in ); |
771 | } | 797 | } |
772 | OFileSelector::~OFileSelector() { | 798 | OFileSelector::~OFileSelector() { |
773 | 799 | ||
774 | } | 800 | } |
775 | 801 | ||
776 | const DocLnk* OFileSelector::selected() { | 802 | const DocLnk* OFileSelector::selected() { |
777 | DocLnk* lnk = ¤tView()->selectedDocument() ; | 803 | DocLnk* lnk = ¤tView()->selectedDocument() ; |
778 | return lnk; | 804 | return lnk; |
779 | } | 805 | } |
780 | 806 | ||
781 | QString OFileSelector::selectedName()const{ | 807 | QString OFileSelector::selectedName()const{ |
782 | return currentView()->selectedName(); | 808 | return currentView()->selectedName(); |
783 | } | 809 | } |
784 | QString OFileSelector::selectedPath()const { | 810 | QString OFileSelector::selectedPath()const { |
785 | return currentView()->selectedPath(); | 811 | return currentView()->selectedPath(); |
786 | } | 812 | } |
787 | QString OFileSelector::directory()const { | 813 | QString OFileSelector::directory()const { |
788 | return currentView()->directory(); | 814 | return currentView()->directory(); |
789 | } | 815 | } |
790 | 816 | ||
791 | DocLnk OFileSelector::selectedDocument()const { | 817 | DocLnk OFileSelector::selectedDocument()const { |
792 | return currentView()->selectedDocument(); | 818 | return currentView()->selectedDocument(); |
793 | } | 819 | } |
794 | 820 | ||
795 | int OFileSelector::fileCount()const { | 821 | int OFileSelector::fileCount()const { |
796 | return currentView()->fileCount(); | 822 | return currentView()->fileCount(); |
797 | } | 823 | } |
798 | void OFileSelector::reread() { | 824 | void OFileSelector::reread() { |
799 | return currentView()->reread(); | 825 | return currentView()->reread(); |
800 | } | 826 | } |
801 | OFileViewInterface* OFileSelector::currentView()const{ | 827 | OFileViewInterface* OFileSelector::currentView()const{ |
802 | return m_current; | 828 | return m_current; |
803 | } | 829 | } |
804 | bool OFileSelector::showNew()const { | 830 | bool OFileSelector::showNew()const { |
805 | return m_shNew; | 831 | return m_shNew; |
806 | } | 832 | } |
807 | bool OFileSelector::showClose()const { | 833 | bool OFileSelector::showClose()const { |
808 | return m_shClose; | 834 | return m_shClose; |
809 | } | 835 | } |
810 | MimeTypes OFileSelector::mimeTypes()const { | 836 | MimeTypes OFileSelector::mimeTypes()const { |
811 | return m_mimeType; | 837 | return m_mimeType; |
812 | } | 838 | } |
813 | int OFileSelector::mode()const{ | 839 | int OFileSelector::mode()const{ |
814 | return m_mode; | 840 | return m_mode; |
815 | } | 841 | } |
816 | int OFileSelector::selector()const{ | 842 | int OFileSelector::selector()const{ |
817 | return m_selector; | 843 | return m_selector; |
818 | } | 844 | } |
819 | QStringList OFileSelector::currentMimeType()const { | 845 | QStringList OFileSelector::currentMimeType()const { |
820 | return m_mimeType[m_cmbMime->currentText()]; | 846 | return m_mimeType[m_cmbMime->currentText()]; |
821 | } | 847 | } |
822 | void OFileSelector::slotMimeTypeChanged() { | 848 | void OFileSelector::slotMimeTypeChanged() { |
823 | reread(); | 849 | reread(); |
824 | } | 850 | } |
825 | void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) { | 851 | void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) { |
826 | m_lneEdit->setText( lnk.name() ); | 852 | m_lneEdit->setText( lnk.name() ); |
827 | emit fileSelected( lnk ); | 853 | emit fileSelected( lnk ); |
828 | emit fileSelected( lnk.name() ); | 854 | emit fileSelected( lnk.name() ); |
829 | } | 855 | } |
830 | void OFileSelector::slotFileBridge( const QString& str) { | 856 | void OFileSelector::slotFileBridge( const QString& str) { |
831 | DocLnk lnk( str ); | 857 | DocLnk lnk( str ); |
832 | emit fileSelected( lnk ); | 858 | emit fileSelected( lnk ); |
833 | } | 859 | } |
834 | void OFileSelector::slotViewChange( const QString& view ) { | 860 | void OFileSelector::slotViewChange( const QString& view ) { |
835 | OFileViewInterface* interface = m_views[view]; | 861 | OFileViewInterface* interface = m_views[view]; |
836 | if (!interface) | 862 | if (!interface) |
837 | return; | 863 | return; |
838 | 864 | ||
839 | interface->activate( view ); | 865 | interface->activate( view ); |
840 | if (m_current) | 866 | if (m_current) |
841 | m_stack->removeWidget( m_current->widget( m_stack ) ); | 867 | m_stack->removeWidget( m_current->widget( m_stack ) ); |
842 | 868 | ||
843 | static int id = 1; | 869 | static int id = 1; |
844 | 870 | ||
845 | m_stack->addWidget( interface->widget(m_stack), id ); | 871 | m_stack->addWidget( interface->widget(m_stack), id ); |
846 | m_stack->raiseWidget( id ); | 872 | m_stack->raiseWidget( id ); |
847 | 873 | ||
848 | interface->reread(); | 874 | interface->reread(); |
849 | m_current = interface; | 875 | m_current = interface; |
850 | 876 | ||
851 | id++; | 877 | id++; |
852 | } | 878 | } |
853 | void OFileSelector::setNewVisible( bool b ) { | 879 | void OFileSelector::setNewVisible( bool b ) { |
854 | m_shNew = b; | 880 | m_shNew = b; |
855 | currentView()->reread(); | 881 | currentView()->reread(); |
856 | } | 882 | } |
857 | void OFileSelector::setCloseVisible( bool b ) { | 883 | void OFileSelector::setCloseVisible( bool b ) { |
858 | m_shClose = b; | 884 | m_shClose = b; |
859 | currentView()->reread(); | 885 | currentView()->reread(); |
860 | } | 886 | } |
861 | void OFileSelector::setNameVisible( bool b ) { | 887 | void OFileSelector::setNameVisible( bool b ) { |
862 | if ( b ) | 888 | if ( b ) |
863 | m_nameBox->show(); | 889 | m_nameBox->show(); |
864 | else | 890 | else |
865 | m_nameBox->hide(); | 891 | m_nameBox->hide(); |
866 | } | 892 | } |
diff --git a/microkde/ofileselector_p.h b/microkde/ofileselector_p.h index b371806..834fd70 100644 --- a/microkde/ofileselector_p.h +++ b/microkde/ofileselector_p.h | |||
@@ -1,258 +1,259 @@ | |||
1 | #ifndef OPIE_OFILE_SELECTOR_PRIVATE_H | 1 | #ifndef OPIE_OFILE_SELECTOR_PRIVATE_H |
2 | #define OPIE_OFILE_SELECTOR_PRIVATE_H | 2 | #define OPIE_OFILE_SELECTOR_PRIVATE_H |
3 | 3 | ||
4 | //US | 4 | //US |
5 | #pragma message("microkde/ofileselector_p.h") | 5 | #pragma message("microkde/ofileselector_p.h") |
6 | 6 | ||
7 | #include <qmap.h> | 7 | #include <qmap.h> |
8 | #include <qstringlist.h> | 8 | #include <qstringlist.h> |
9 | #include <qwidget.h> | 9 | #include <qwidget.h> |
10 | #include <qlistview.h> | 10 | #include <qlistview.h> |
11 | 11 | ||
12 | #include <qpe/applnk.h> | 12 | #include <qpe/applnk.h> |
13 | #include <qpe/fileselector.h> | 13 | #include <qpe/fileselector.h> |
14 | 14 | ||
15 | 15 | ||
16 | /* | 16 | /* |
17 | * How to avoid having really two different objects | 17 | * How to avoid having really two different objects |
18 | * for Extended and ExtendedAll | 18 | * for Extended and ExtendedAll |
19 | * The only difference is the Lister... | 19 | * The only difference is the Lister... |
20 | * a) static object? | 20 | * a) static object? |
21 | * b) leave some object inside the OFileSelector which can be used? | 21 | * b) leave some object inside the OFileSelector which can be used? |
22 | * c) when switching views tell which view we want o have.. internally we can switch then | 22 | * c) when switching views tell which view we want o have.. internally we can switch then |
23 | * | 23 | * |
24 | * I'll take c) -zecke | 24 | * I'll take c) -zecke |
25 | */ | 25 | */ |
26 | 26 | ||
27 | 27 | ||
28 | /* the View Interface */ | 28 | /* the View Interface */ |
29 | class OFileSelector; | 29 | class OFileSelector; |
30 | typedef QMap<QString, QStringList> MimeTypes; | 30 | typedef QMap<QString, QStringList> MimeTypes; |
31 | class QFileInfo; | 31 | class QFileInfo; |
32 | class QToolButton; | 32 | class QToolButton; |
33 | class OFileViewInterface { | 33 | class OFileViewInterface { |
34 | public: | 34 | public: |
35 | OFileViewInterface( OFileSelector* selector ); | 35 | OFileViewInterface( OFileSelector* selector ); |
36 | virtual ~OFileViewInterface(); | 36 | virtual ~OFileViewInterface(); |
37 | virtual QString selectedName()const = 0; | 37 | virtual QString selectedName()const = 0; |
38 | virtual QString selectedPath()const = 0; | 38 | virtual QString selectedPath()const = 0; |
39 | virtual QString directory()const = 0; | 39 | virtual QString directory()const = 0; |
40 | virtual void reread() = 0; | 40 | virtual void reread() = 0; |
41 | virtual int fileCount()const = 0; | 41 | virtual int fileCount()const = 0; |
42 | virtual DocLnk selectedDocument()const; | 42 | virtual DocLnk selectedDocument()const; |
43 | virtual QWidget* widget( QWidget* parent) = 0; | 43 | virtual QWidget* widget( QWidget* parent) = 0; |
44 | virtual void activate( const QString& ); | 44 | virtual void activate( const QString& ); |
45 | QString name()const; | 45 | QString name()const; |
46 | protected: | 46 | protected: |
47 | OFileSelector* selector()const; | 47 | OFileSelector* selector()const; |
48 | void setName( const QString& ); | 48 | void setName( const QString& ); |
49 | bool showNew()const; | 49 | bool showNew()const; |
50 | bool showClose()const; | 50 | bool showClose()const; |
51 | MimeTypes mimeTypes()const; | 51 | MimeTypes mimeTypes()const; |
52 | QStringList currentMimeType()const; | 52 | QStringList currentMimeType()const; |
53 | QString startDirectory()const; | 53 | QString startDirectory()const; |
54 | protected: | 54 | protected: |
55 | void ok(); | 55 | void ok(); |
56 | void cancel(); | 56 | void cancel(); |
57 | void closeMe(); | 57 | void closeMe(); |
58 | void fileSelected( const QString& ); | 58 | void fileSelected( const QString& ); |
59 | void fileSelected( const DocLnk& ); | 59 | void fileSelected( const DocLnk& ); |
60 | void setCurrentFileName( const QString& ); | 60 | void setCurrentFileName( const QString& ); |
61 | QString currentFileName()const; | 61 | QString currentFileName()const; |
62 | 62 | ||
63 | private: | 63 | private: |
64 | QString m_name; | 64 | QString m_name; |
65 | OFileSelector* m_selector; | 65 | OFileSelector* m_selector; |
66 | }; | 66 | }; |
67 | 67 | ||
68 | 68 | ||
69 | /* THE Document View hosting a FileSelector*/ | 69 | /* THE Document View hosting a FileSelector*/ |
70 | class ODocumentFileView : public OFileViewInterface { | 70 | class ODocumentFileView : public OFileViewInterface { |
71 | public: | 71 | public: |
72 | ODocumentFileView( OFileSelector* selector ); | 72 | ODocumentFileView( OFileSelector* selector ); |
73 | ~ODocumentFileView(); | 73 | ~ODocumentFileView(); |
74 | 74 | ||
75 | QString selectedName() const; | 75 | QString selectedName() const; |
76 | QString selectedPath() const; | 76 | QString selectedPath() const; |
77 | 77 | ||
78 | QString directory() const; | 78 | QString directory() const; |
79 | void reread(); | 79 | void reread(); |
80 | int fileCount()const; | 80 | int fileCount()const; |
81 | DocLnk selectedDocument()const; | 81 | DocLnk selectedDocument()const; |
82 | 82 | ||
83 | QWidget* widget( QWidget* parent ); | 83 | QWidget* widget( QWidget* parent ); |
84 | 84 | ||
85 | private: | 85 | private: |
86 | mutable FileSelector* m_selector; | 86 | mutable FileSelector* m_selector; |
87 | 87 | ||
88 | }; | 88 | }; |
89 | 89 | ||
90 | class OFileSelectorItem : public QListViewItem { | 90 | class OFileSelectorItem : public QListViewItem { |
91 | public: | 91 | public: |
92 | OFileSelectorItem( QListView* view, const QPixmap& pixmap, | 92 | OFileSelectorItem( QListView* view, const QPixmap& pixmap, |
93 | const QString& path, const QString& date, | 93 | const QString& path, const QString& date, |
94 | const QString& size, const QString& mDir, | 94 | const QString& size, const QString& mDir, |
95 | bool isLocked = false, bool isDir = false ); | 95 | bool isLocked = false, bool isDir = false ); |
96 | ~OFileSelectorItem(); | 96 | ~OFileSelectorItem(); |
97 | bool isLocked()const; | 97 | bool isLocked()const; |
98 | bool isDir()const; | 98 | bool isDir()const; |
99 | QString directory()const; | 99 | QString directory()const; |
100 | QString path()const; | 100 | QString path()const; |
101 | QString key(int id, bool )const; | 101 | QString key(int id, bool )const; |
102 | 102 | ||
103 | private: | 103 | private: |
104 | bool m_locked : 1; | 104 | bool m_locked : 1; |
105 | bool m_isDir : 1; | 105 | bool m_isDir : 1; |
106 | QString m_dir; | 106 | QString m_dir; |
107 | }; | 107 | }; |
108 | 108 | ||
109 | class OFileViewFileListView : public QWidget { | 109 | class OFileViewFileListView : public QWidget { |
110 | Q_OBJECT | 110 | Q_OBJECT |
111 | public: | 111 | public: |
112 | OFileViewFileListView( QWidget* parent, const QString& dir, OFileSelector* selector ); | 112 | OFileViewFileListView( QWidget* parent, const QString& dir, OFileSelector* selector ); |
113 | ~OFileViewFileListView(); | 113 | ~OFileViewFileListView(); |
114 | 114 | ||
115 | OFileSelectorItem* currentItem()const; | 115 | OFileSelectorItem* currentItem()const; |
116 | void reread( bool all = false ); | 116 | void reread( bool all = false ); |
117 | int fileCount()const; | 117 | int fileCount()const; |
118 | QString currentDir()const; | 118 | QString currentDir()const; |
119 | protected: | 119 | protected: |
120 | bool eventFilter (QObject *o, QEvent *e); | 120 | bool eventFilter (QObject *o, QEvent *e); |
121 | private slots: | 121 | private slots: |
122 | void slotNew(); // will emit newSelected | 122 | void slotNew(); // will emit newSelected |
123 | void cdUP(); | 123 | void cdUP(); |
124 | void cdHome(); | 124 | void cdHome(); |
125 | void cdDoc(); | 125 | void cdDoc(); |
126 | void changeDir( const QString& ); | 126 | void changeDir( const QString& ); |
127 | void slotCurrentChanged( QListViewItem* ); | 127 | void slotCurrentChanged( QListViewItem* ); |
128 | void slotClicked(int, QListViewItem*, const QPoint&, int ); | 128 | void slotClicked(int, QListViewItem*, const QPoint&, int ); |
129 | void slotDoubleClicked(QListViewItem*); | ||
129 | void slotFSActivated(int); | 130 | void slotFSActivated(int); |
130 | 131 | ||
131 | protected: | 132 | protected: |
132 | 133 | ||
133 | OFileSelector* selector(); | 134 | OFileSelector* selector(); |
134 | 135 | ||
135 | private: | 136 | private: |
136 | QMap<QString, QString> m_dev; | 137 | QMap<QString, QString> m_dev; |
137 | bool m_all : 1; | 138 | bool m_all : 1; |
138 | OFileSelector* m_sel; | 139 | OFileSelector* m_sel; |
139 | QPopupMenu* m_fsPop; | 140 | QPopupMenu* m_fsPop; |
140 | bool compliesMime( const QString& ); | 141 | bool compliesMime( const QString& ); |
141 | QStringList m_mimes; // used in compy mime | 142 | QStringList m_mimes; // used in compy mime |
142 | QString m_currentDir; | 143 | QString m_currentDir; |
143 | QToolButton *m_btnNew, *m_btnClose; | 144 | QToolButton *m_btnNew, *m_btnClose; |
144 | void connectSlots(); | 145 | void connectSlots(); |
145 | void addFile( QFileInfo* info, bool symlink = FALSE ); | 146 | void addFile( QFileInfo* info, bool symlink = FALSE ); |
146 | void addDir ( QFileInfo* info, bool symlink = FALSE ); | 147 | void addDir ( QFileInfo* info, bool symlink = FALSE ); |
147 | void addSymlink( QFileInfo* info, bool = FALSE ); | 148 | void addSymlink( QFileInfo* info, bool = FALSE ); |
148 | 149 | ||
149 | 150 | ||
150 | private: | 151 | private: |
151 | QListView* m_view; | 152 | QListView* m_view; |
152 | }; | 153 | }; |
153 | 154 | ||
154 | typedef QMap<QString, QStringList> MimeTypes; | 155 | typedef QMap<QString, QStringList> MimeTypes; |
155 | 156 | ||
156 | class OFileViewInterface; | 157 | class OFileViewInterface; |
157 | class OFileViewFileListView; | 158 | class OFileViewFileListView; |
158 | class QLineEdit; | 159 | class QLineEdit; |
159 | class QComboBox; | 160 | class QComboBox; |
160 | class QWidgetStack; | 161 | class QWidgetStack; |
161 | class QHBox; | 162 | class QHBox; |
162 | class OFileSelector : public QWidget { | 163 | class OFileSelector : public QWidget { |
163 | Q_OBJECT | 164 | Q_OBJECT |
164 | friend class OFileViewInterface; | 165 | friend class OFileViewInterface; |
165 | friend class OFileViewFileListView; | 166 | friend class OFileViewFileListView; |
166 | public: | 167 | public: |
167 | enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 }; | 168 | enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 }; |
168 | // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 }; | 169 | // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 }; |
169 | enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 }; | 170 | enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 }; |
170 | // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2}; | 171 | // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2}; |
171 | 172 | ||
172 | OFileSelector(QWidget* parent, int mode, int selector, | 173 | OFileSelector(QWidget* parent, int mode, int selector, |
173 | const QString& dirName, | 174 | const QString& dirName, |
174 | const QString& fileName, | 175 | const QString& fileName, |
175 | const MimeTypes& mimetypes = MimeTypes(), | 176 | const MimeTypes& mimetypes = MimeTypes(), |
176 | bool newVisible = FALSE, bool closeVisible = FALSE ); | 177 | bool newVisible = FALSE, bool closeVisible = FALSE ); |
177 | 178 | ||
178 | OFileSelector(const QString& mimeFilter, QWidget* parent, | 179 | OFileSelector(const QString& mimeFilter, QWidget* parent, |
179 | const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE ); | 180 | const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE ); |
180 | ~OFileSelector(); | 181 | ~OFileSelector(); |
181 | 182 | ||
182 | const DocLnk* selected(); | 183 | const DocLnk* selected(); |
183 | 184 | ||
184 | QString selectedName()const; | 185 | QString selectedName()const; |
185 | QString selectedPath()const; | 186 | QString selectedPath()const; |
186 | QString directory()const; | 187 | QString directory()const; |
187 | 188 | ||
188 | DocLnk selectedDocument()const; | 189 | DocLnk selectedDocument()const; |
189 | 190 | ||
190 | int fileCount()const; | 191 | int fileCount()const; |
191 | void reread(); | 192 | void reread(); |
192 | 193 | ||
193 | int mode()const; | 194 | int mode()const; |
194 | int selector()const; | 195 | int selector()const; |
195 | 196 | ||
196 | 197 | ||
197 | void setNewVisible( bool b ); | 198 | void setNewVisible( bool b ); |
198 | void setCloseVisible( bool b ); | 199 | void setCloseVisible( bool b ); |
199 | void setNameVisible( bool b ); | 200 | void setNameVisible( bool b ); |
200 | 201 | ||
201 | signals: | 202 | signals: |
202 | void dirSelected( const QString& ); | 203 | void dirSelected( const QString& ); |
203 | void fileSelected( const DocLnk& ); | 204 | void fileSelected( const DocLnk& ); |
204 | void fileSelected( const QString& ); | 205 | void fileSelected( const QString& ); |
205 | void newSelected( const DocLnk& ); | 206 | void newSelected( const DocLnk& ); |
206 | void closeMe(); | 207 | void closeMe(); |
207 | void ok(); | 208 | void ok(); |
208 | void cancel(); | 209 | void cancel(); |
209 | 210 | ||
210 | /* used by the ViewInterface */ | 211 | /* used by the ViewInterface */ |
211 | private: | 212 | private: |
212 | bool showNew()const; | 213 | bool showNew()const; |
213 | bool showClose()const; | 214 | bool showClose()const; |
214 | MimeTypes mimeTypes()const; | 215 | MimeTypes mimeTypes()const; |
215 | QStringList currentMimeType()const; | 216 | QStringList currentMimeType()const; |
216 | 217 | ||
217 | private: | 218 | private: |
218 | /* inits the Widgets */ | 219 | /* inits the Widgets */ |
219 | void initUI(); | 220 | void initUI(); |
220 | /* inits the MimeType ComboBox content + connects signals and slots */ | 221 | /* inits the MimeType ComboBox content + connects signals and slots */ |
221 | void initMime(); | 222 | void initMime(); |
222 | /* init the Views :) */ | 223 | /* init the Views :) */ |
223 | void initViews(); | 224 | void initViews(); |
224 | 225 | ||
225 | private: | 226 | private: |
226 | QLineEdit* m_lneEdit; // the LineEdit for the Name | 227 | QLineEdit* m_lneEdit; // the LineEdit for the Name |
227 | QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType | 228 | QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType |
228 | QWidgetStack* m_stack; // our widget stack which will contain the views | 229 | QWidgetStack* m_stack; // our widget stack which will contain the views |
229 | OFileViewInterface* currentView()const; // returns the currentView | 230 | OFileViewInterface* currentView()const; // returns the currentView |
230 | OFileViewInterface* m_current; // here is the view saved | 231 | OFileViewInterface* m_current; // here is the view saved |
231 | bool m_shNew : 1; // should we show New? | 232 | bool m_shNew : 1; // should we show New? |
232 | bool m_shClose : 1; // should we show Close? | 233 | bool m_shClose : 1; // should we show Close? |
233 | MimeTypes m_mimeType; // list of mimetypes | 234 | MimeTypes m_mimeType; // list of mimetypes |
234 | 235 | ||
235 | QMap<QString, OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr | 236 | QMap<QString, OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr |
236 | QHBox* m_nameBox; // the LineEdit + Label is hold here | 237 | QHBox* m_nameBox; // the LineEdit + Label is hold here |
237 | QHBox* m_cmbBox; // this holds the two combo boxes | 238 | QHBox* m_cmbBox; // this holds the two combo boxes |
238 | 239 | ||
239 | QString m_startDir; | 240 | QString m_startDir; |
240 | int m_mode; | 241 | int m_mode; |
241 | int m_selector; | 242 | int m_selector; |
242 | 243 | ||
243 | struct Data; // used for future versions | 244 | struct Data; // used for future versions |
244 | Data *d; | 245 | Data *d; |
245 | 246 | ||
246 | private slots: | 247 | private slots: |
247 | void slotMimeTypeChanged(); | 248 | void slotMimeTypeChanged(); |
248 | 249 | ||
249 | /* will set the text of the lineedit and emit a fileChanged signal */ | 250 | /* will set the text of the lineedit and emit a fileChanged signal */ |
250 | void slotDocLnkBridge( const DocLnk& ); | 251 | void slotDocLnkBridge( const DocLnk& ); |
251 | void slotFileBridge( const QString& ); | 252 | void slotFileBridge( const QString& ); |
252 | void slotViewChange( const QString& ); | 253 | void slotViewChange( const QString& ); |
253 | 254 | ||
254 | bool eventFilter (QObject *o, QEvent *e); | 255 | bool eventFilter (QObject *o, QEvent *e); |
255 | 256 | ||
256 | }; | 257 | }; |
257 | 258 | ||
258 | #endif | 259 | #endif |