1
/***************************************************************************
2
fileview.cpp - description
4
begin : Sat Sep 20 2003
5
copyright : (C) 2003 by Simone Gotti
6
email : simone.gotti@email.it
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
22
#include "mainwindow.h"
23
#include "diroperator.h"
26
#include <qdragobject.h>
32
#include <kfilefiltercombo.h>
34
#include <kfileitem.h>
35
#include <kmessagebox.h>
36
#include <kcombobox.h>
37
#include <kcompletionbox.h>
38
#include <kurlcompletion.h>
41
FileView::FileView(QWidget *parent, const char *name )
42
: QWidget(parent,name)
52
KActionCollection* FileView::actionCollection() const
54
return m_dirOp->actionCollection();
58
void FileView::setupGUI()
60
this->setMinimumHeight(200);
62
QVBoxLayout* layout = new QVBoxLayout( this );
64
KToolBar* toolbar2 = new KToolBar( this , "FileView::toolbar2", true);
66
m_comboBox = new KComboBox(TRUE, toolbar2 );
67
urlCompletion = new KURLCompletion();
68
m_comboBox->setCompletionObject(urlCompletion);
69
connect( m_comboBox, SIGNAL(returnPressed(const QString&)), this, SLOT(slotGoUrl(const QString&)) );
72
QLabel* m_comboLabel = new QLabel(i18n("Location: "), toolbar2, "kde toolbar widget"); // With this name the label is styled !!!
74
int m_comboLabel_id = toolbar2->count();
75
toolbar2->insertWidget(m_comboLabel_id,-1,m_comboLabel);
76
int m_comboBox_id = toolbar2->count();
77
toolbar2->insertWidget(m_comboBox_id,-1,m_comboBox);
78
toolbar2->setItemAutoSized(m_comboBox_id);
80
m_dirOp = new DirOperator( QDir::home().absPath(), this );
81
m_dirOp->readConfig( MainApp()->config(), "file view" );
82
m_dirOp->setMode( KFile::Files );
83
m_dirOp->setView( KFile::Default );
84
//connect( m_dirOp, SIGNAL(urlEntered(const KURL &)), this, SLOT(slotUrlEntered(const KURL &)));
85
//connect( m_dirOp, SIGNAL(completion (const QString &)), m_comboBox, SLOT(setCompletedText(const QString &)));
87
KToolBar* toolbar = new KToolBar( this , "FileView::toolbar", true);
88
toolbar->setFlat(true);
90
KActionCollection *coll = m_dirOp->actionCollection();
92
// plug nav items into the toolbar
93
coll->action( "up" )->plug( toolbar );
94
coll->action( "up" )->setWhatsThis(i18n("<qt>Click this button to enter the parent folder.<p>"
95
"For instance, if the current location is file:/home/%1 clicking this "
96
"button will take you to file:/home.</qt>").arg(getlogin()));
97
coll->action( "back" )->plug( toolbar );
98
coll->action( "back" )->setWhatsThis(i18n("Click this button to move backwards one step in the browsing history."));
99
coll->action( "forward" )->plug( toolbar );
100
coll->action( "forward" )->setWhatsThis(i18n("Click this button to move forward one step in the browsing history."));
101
coll->action( "reload" )->plug( toolbar );
102
coll->action( "reload" )->setWhatsThis(i18n("Click this button to reload the contents of the current location."));
103
coll->action( "mkdir" )->setShortcut(Key_F10);
104
coll->action( "mkdir" )->plug( toolbar );
105
coll->action( "mkdir" )->setWhatsThis(i18n("Click this button to create a new folder."));
107
KActionMenu *menu = new KActionMenu( i18n("Configure"), "configure", this, "extra menu" );
109
menu->setWhatsThis(i18n("<qt>This is the configuration menu for the file dialog. "
110
"Various options can be accessed from this menu including: <ul>"
111
"<li>how files are sorted in the list</li>"
112
"<li>types of view, including icon and list</li>"
113
"<li>showing of hidden files</li>"
114
"<li>the Quick Access navigation panel</li>"
115
"<li>file previews</li>"
116
"<li>separating folders from files</li></ul></qt>"));
117
menu->insert( coll->action( "sorting menu" ));
118
menu->insert( coll->action( "separator" ));
119
coll->action( "short view" )->setShortcut(Key_F6);
120
menu->insert( coll->action( "short view" ));
121
coll->action( "detailed view" )->setShortcut(Key_F7);
122
menu->insert( coll->action( "detailed view" ));
123
menu->insert( coll->action( "separator" ));
124
coll->action( "show hidden" )->setShortcut(Key_F8);
125
menu->insert( coll->action( "show hidden" ));
126
// menu->insert( showSidebarAction );
127
coll->action( "preview" )->setShortcut(Key_F11);
128
menu->insert( coll->action( "preview" ));
129
coll->action( "separate dirs" )->setShortcut(Key_F12);
130
menu->insert( coll->action( "separate dirs" ));
132
menu->setDelayed( false );
133
menu->plug( toolbar );
135
// create filter selection combobox
136
QLabel* filterLabel = new QLabel(i18n("Filter:"), toolbar, "kde toolbar widget"); // With this name the label is styled !!!
137
toolbar->insertWidget( toolbar->count(), 0, filterLabel );
139
m_filterWidget = new KFileFilterCombo( toolbar, "filterwidget" );
140
toolbar->insertWidget( toolbar->count(), 0, m_filterWidget );
141
m_filterWidget->setEditable( true );
142
QString filter = i18n("*|All Files");
143
filter += "\n" + i18n("image/jpeg |JPEG Image Files");
144
m_filterWidget->setFilter(filter);
145
connect( m_filterWidget, SIGNAL(filterChanged()), SLOT(slotFilterChanged()) );
147
layout->addWidget( toolbar);
148
layout->addWidget( toolbar2 );
149
layout->addWidget( m_dirOp );
151
layout->setStretchFactor( m_dirOp, 1 );
155
void FileView::slotGoUrl(const QString& text)
160
void FileView::setUrl(const KURL& url, bool forward)
162
m_dirOp->setURL( url, forward );
165
KURL FileView::Url() const
167
return m_dirOp->url();
170
void FileView::setAutoUpdate(bool b)
172
m_dirOp->dirLister()->setAutoUpdate( b );
175
void FileView::slotFilterChanged()
177
QString filter = m_filterWidget->currentFilter();
178
m_dirOp->clearFilter();
180
if( filter.find( '/' ) > -1 ) {
181
QStringList types = QStringList::split( " ", filter );
182
types.prepend( "inode/directory" );
183
m_dirOp->setMimeFilter( types );
185
m_dirOp->setNameFilter( filter );
187
m_dirOp->rereadDir();
188
// emit filterChanged( filter );
191
/*void FileView::slotUrlEntered(const KURL &url)
193
m_comboBox->setCompletedText(url.path());
196
void FileView::reload()
198
m_dirOp->actionCollection()->action("reload")->activate();
201
void FileView::saveConfig( KConfig* c )
203
m_dirOp->writeConfig( c, "file view" );
207
#include "fileview.moc"