summaryrefslogtreecommitdiff
path: root/libopie2/opieui
Side-by-side diff
Diffstat (limited to 'libopie2/opieui') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/fileselector/ofileselector.cpp19
-rw-r--r--libopie2/opieui/fileselector/ofileselector.h10
2 files changed, 24 insertions, 5 deletions
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp
index 5528aed..b06defd 100644
--- a/libopie2/opieui/fileselector/ofileselector.cpp
+++ b/libopie2/opieui/fileselector/ofileselector.cpp
@@ -41,51 +41,53 @@
#include <qpe/qpeapplication.h>
#include <qpe/mimetype.h>
#include <qpe/resource.h>
#include <qpe/storage.h>
/* QT */
#include <qcombobox.h>
#include <qdir.h>
#include <qhbox.h>
#include <qheader.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qlistview.h>
#include <qpopupmenu.h>
#include <qwidgetstack.h>
#include <qregexp.h>
#include <qobjectlist.h>
using namespace Opie::Ui::Internal;
namespace Opie {
namespace Ui {
namespace Internal {
-OFileViewInterface::OFileViewInterface( OFileSelector* selector )
- : m_selector( selector )
-{}
+OFileViewInterface::OFileViewInterface( OFileSelector* _selector )
+ : m_selector( _selector )
+{
+ selector()->registerView( this );
+}
OFileViewInterface::~OFileViewInterface()
{}
QString OFileViewInterface::name()const
{
return m_name;
}
void OFileViewInterface::setName( const QString& name )
{
m_name = name;
}
OFileSelector* OFileViewInterface::selector()const
{
return m_selector;
}
DocLnk OFileViewInterface::selectedDocument()const
{
return DocLnk( selectedName() );
}
@@ -490,49 +492,49 @@ void OFileViewFileListView::reread( bool all )
addDir( fi );
else if( fi->isFile() )
addFile( fi );
++it;
} // of while loop
m_view->sort();
}
int OFileViewFileListView::fileCount()const
{
return m_view->childCount();
}
QString OFileViewFileListView::currentDir()const
{
return m_currentDir;
}
OFileSelector* OFileViewFileListView::selector()
{
return m_sel;
}
-bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e)
+bool OFileViewFileListView::eventFilter (QObject *, QEvent *e)
{
if ( e->type() == QEvent::KeyPress )
{
QKeyEvent *k = (QKeyEvent *)e;
if ( (k->key()==Key_Enter) || (k->key()==Key_Return))
{
slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0);
return true;
}
}
return false;
}
void OFileViewFileListView::connectSlots()
{
connect(m_view, SIGNAL(clicked(QListViewItem*) ),
this, SLOT(slotCurrentChanged(QListViewItem*) ) );
connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ),
this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) );
}
void OFileViewFileListView::slotCurrentChanged( QListViewItem* item)
{
if (!item)
@@ -926,49 +928,49 @@ OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const
*/
void OFileSelector::initUI()
{
QVBoxLayout* lay = new QVBoxLayout( this );
m_stack = new QWidgetStack( this );
lay->addWidget( m_stack, 1000 );
m_nameBox = new QHBox( this );
(void)new QLabel( tr("Name:"), m_nameBox );
m_lneEdit = new QLineEdit( m_nameBox );
m_lneEdit ->installEventFilter(this);
lay->addWidget( m_nameBox );
m_cmbBox = new QHBox( this );
m_cmbView = new QComboBox( m_cmbBox );
m_cmbMime = new QComboBox( m_cmbBox );
lay->addWidget( m_cmbBox );
}
/*
* This will make sure that the return key in the name edit causes dialogs to close
*/
-bool OFileSelector::eventFilter (QObject *o, QEvent *e)
+bool OFileSelector::eventFilter (QObject *, QEvent *e)
{
if ( e->type() == QEvent::KeyPress )
{
QKeyEvent *k = (QKeyEvent *)e;
if ( (k->key()==Key_Enter) || (k->key()==Key_Return))
{
emit ok();
return true;
}
}
return false;
}
/*
* This will insert the MimeTypes into the Combo Box
* And also connect the changed signal
*
* AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes
*/
void OFileSelector::initMime()
{
MimeTypes::Iterator it;
for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it )
{
@@ -977,53 +979,60 @@ void OFileSelector::initMime()
m_cmbMime->setCurrentItem( 0 );
connect( m_cmbMime, SIGNAL(activated(int) ),
this, SLOT(slotMimeTypeChanged() ) );
}
void OFileSelector::initViews()
{
m_cmbView->insertItem( QObject::tr("Documents") );
m_cmbView->insertItem( QObject::tr("Files") );
m_cmbView->insertItem( QObject::tr("All Files") );
connect(m_cmbView, SIGNAL(activated(const QString&) ),
this, SLOT(slotViewChange(const QString&) ) );
m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
/* see above why add both */
OFileViewInterface* in = new OFileViewFileSystem( this );
m_views.insert( QObject::tr("Files"), in );
m_views.insert( QObject::tr("All Files"), in );
}
+void OFileSelector::registerView( const Internal::OFileViewInterface* iface ) {
+ m_viewsPtr.append( iface );
+}
+
+
/**
* d'tor
*/
OFileSelector::~OFileSelector()
{
+ m_viewsPtr.setAutoDelete( true );
+ m_viewsPtr.clear();
}
/**
* Convience function for the fileselector
* make sure to delete the DocLnk
*
* @see DocLnk
* @todo remove in ODP
*/
const DocLnk* OFileSelector::selected()
{
DocLnk* lnk = new DocLnk( currentView()->selectedDocument() );
return lnk;
}
/**
*
* @return the name of the selected file
*/
QString OFileSelector::selectedName()const
{
return currentView()->selectedName();
diff --git a/libopie2/opieui/fileselector/ofileselector.h b/libopie2/opieui/fileselector/ofileselector.h
index 8bcd9ee..de2b98a 100644
--- a/libopie2/opieui/fileselector/ofileselector.h
+++ b/libopie2/opieui/fileselector/ofileselector.h
@@ -23,48 +23,49 @@
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/*
This is based on code and ideas of
L. J. Potter ljp@llornkcor.com
Thanks a lot
*/
#ifndef OFILESELECTOR_H
#define OFILESELECTOR_H
/* OPIE */
#include <qpe/applnk.h>
/* QT */
#include <qlist.h>
#include <qwidget.h>
#include <qmap.h>
#include <qvaluelist.h>
#include <qstringlist.h>
+#include <qlist.h>
class QLineEdit;
class QComboBox;
class QWidgetStack;
class QHBox;
typedef QMap<QString, QStringList> MimeTypes;
namespace Opie {
namespace Ui {
namespace Internal {
class OFileViewInterface;
class OFileViewFileListView;
}
/**
* @short a dropin replacement for the FileSelector
*
* This class is first used insert the OFileDialog.
* It supports multiple view and mimetype filtering for now.
*
* @see OFileDialog
@@ -162,59 +163,68 @@ signals:
void closeMe();
/**
* Ok is emitted on a Qt::Key_Return or Q::Key_Enter
* in the line edit
*/
void ok();
void cancel();
/* used by the ViewInterface */
private:
bool showNew()const;
bool showClose()const;
MimeTypes mimeTypes()const;
QStringList currentMimeType()const;
private:
/* inits the Widgets */
void initUI();
/* inits the MimeType ComboBox content + connects signals and slots */
void initMime();
/* init the Views :) */
void initViews();
+
+ /*
+ * register a view for deletion.
+ * This happens on creation of a OFileViewInterface
+ */
+ void registerView( const Internal::OFileViewInterface* );
+
private:
QLineEdit* m_lneEdit; // the LineEdit for the Name
QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType
QWidgetStack* m_stack; // our widget stack which will contain the views
Internal::OFileViewInterface* currentView() const; // returns the currentView
Internal::OFileViewInterface* m_current; // here is the view saved
bool m_shNew : 1; // should we show New?
bool m_shClose : 1; // should we show Close?
MimeTypes m_mimeType; // list of mimetypes
QMap<QString, Internal::OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr
+ /* views register themselves automatically */
+ QList<Internal::OFileViewInterface> m_viewsPtr;
QHBox* m_nameBox; // the LineEdit + Label is hold here
QHBox* m_cmbBox; // this holds the two combo boxes
QString m_startDir;
int m_mode;
int m_selector;
struct Data; // used for future versions
Data *d;
private slots:
void slotMimeTypeChanged();
/* will set the text of the lineedit and emit a fileChanged signal */
void slotDocLnkBridge( const DocLnk& );
void slotFileBridge( const QString& );
void slotViewChange( const QString& );
bool eventFilter (QObject *o, QEvent *e);
};
}
}