summaryrefslogtreecommitdiff
authoralwin <alwin>2004-02-22 21:40:20 (UTC)
committer alwin <alwin>2004-02-22 21:40:20 (UTC)
commitcaa64a311d665e4d5c75cc9d45e0b3cd8ef2fdf1 (patch) (side-by-side diff)
treeef464310a07582a7179a4d136b555b806f43fe1a
parent936fc191ac5756a4de2e8b2a83c8bc910f918b95 (diff)
downloadopie-caa64a311d665e4d5c75cc9d45e0b3cd8ef2fdf1.zip
opie-caa64a311d665e4d5c75cc9d45e0b3cd8ef2fdf1.tar.gz
opie-caa64a311d665e4d5c75cc9d45e0b3cd8ef2fdf1.tar.bz2
when inserting a new media without .opiestorage.cf a dialog comes
setting up this file.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/documentlist.cpp7
-rw-r--r--core/launcher/mediadlg.cpp31
-rw-r--r--core/launcher/mediadlg.h29
-rw-r--r--core/launcher/server.pro12
4 files changed, 74 insertions, 5 deletions
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp
index 9736e65..39dc7c9 100644
--- a/core/launcher/documentlist.cpp
+++ b/core/launcher/documentlist.cpp
@@ -1,213 +1,214 @@
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "documentlist.h"
#include "serverinterface.h"
+#include "mediadlg.h"
#include <opie2/oglobal.h>
#include <qtopia/config.h>
#include <qtopia/mimetype.h>
#include <qtopia/resource.h>
#include <qtopia/private/categories.h>
#include <qtopia/qpeapplication.h>
#include <qtopia/applnk.h>
#include <qtopia/storage.h>
#ifdef Q_WS_QWS
#include <qtopia/qcopenvelope_qws.h>
#endif
#include <qtimer.h>
#include <qfileinfo.h>
#include <qtextstream.h>
#include <qfile.h>
#include <qdir.h>
#include <qpainter.h>
#include <qimage.h>
#include <qcopchannel_qws.h>
#include <qlistview.h>
#include <qlist.h>
#include <qpixmap.h>
AppLnkSet *DocumentList::appLnkSet = 0;
static const int MAX_SEARCH_DEPTH = 10;
class DocumentListPrivate : public QObject {
Q_OBJECT
public:
DocumentListPrivate( ServerInterface *gui );
~DocumentListPrivate();
void initialize();
const QString nextFile();
const DocLnk *iterate();
bool store( DocLnk* dl );
void estimatedPercentScanned();
void appendDocpath(FileSystem*);
DocLnkSet dls;
QDict<void> reference;
QDictIterator<void> *dit;
enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state;
QStringList docPaths;
unsigned int docPathsSearched;
int searchDepth;
QDir *listDirs[MAX_SEARCH_DEPTH];
const QFileInfoList *lists[MAX_SEARCH_DEPTH];
unsigned int listPositions[MAX_SEARCH_DEPTH];
StorageInfo *storage;
int tid;
ServerInterface *serverGui;
bool needToSendAllDocLinks;
bool sendAppLnks;
bool sendDocLnks;
bool scanDocs;
};
/*
* scandocs will be read from Config
*/
DocumentList::DocumentList( ServerInterface *serverGui, bool /*scanDocs*/,
QObject *parent, const char *name )
: QObject( parent, name )
{
appLnkSet = new AppLnkSet( MimeType::appsFolderName() );
d = new DocumentListPrivate( serverGui );
d->needToSendAllDocLinks = false;
Config cfg( "Launcher" );
cfg.setGroup( "DocTab" );
d->scanDocs = cfg.readBoolEntry( "Enable", true );
qDebug( "DocumentList::DocumentList() : scanDocs = %d", d->scanDocs );
QTimer::singleShot( 10, this, SLOT( startInitialScan() ) );
}
void DocumentList::startInitialScan()
{
reloadAppLnks();
reloadDocLnks();
}
DocumentList::~DocumentList()
{
delete appLnkSet;
delete d;
}
void DocumentList::add( const DocLnk& doc )
{
if ( d->serverGui && QFile::exists( doc.file() ) )
d->serverGui->documentAdded( doc );
}
void DocumentList::start()
{
resume();
}
void DocumentList::pause()
{
//qDebug("pause %i", d->tid);
killTimer( d->tid );
d->tid = 0;
}
void DocumentList::resume()
{
if ( d->tid == 0 ) {
d->tid = startTimer( 20 );
//qDebug("resumed %i", d->tid);
}
}
/*
void DocumentList::resend()
{
// Re-emits all the added items to the list (firstly letting everyone know to
// clear what they have as it is being sent again)
pause();
emit allRemoved();
QTimer::singleShot( 5, this, SLOT( resendWorker() ) );
}
void DocumentList::resendWorker()
{
const QList<DocLnk> &list = d->dls.children();
for ( QListIterator<DocLnk> it( list ); it.current(); ++it )
add( *(*it) );
resume();
}
*/
void DocumentList::rescan()
{
//qDebug("rescan");
pause();
d->initialize();
resume();
}
void DocumentList::timerEvent( QTimerEvent *te )
{
if ( te->timerId() == d->tid ) {
// Do 3 at a time
for (int i = 0; i < 3; i++ ) {
const DocLnk *lnk = d->iterate();
if ( lnk ) {
add( *lnk );
} else {
// stop when done
pause();
if ( d->serverGui )
d->serverGui->documentScanningProgress( 100 );
if ( d->needToSendAllDocLinks )
sendAllDocLinks();
break;
}
}
}
}
void DocumentList::reloadAppLnks()
{
if ( d->sendAppLnks && d->serverGui ) {
d->serverGui->applicationScanningProgress( 0 );
d->serverGui->allApplicationsRemoved();
}
@@ -245,388 +246,388 @@ void DocumentList::reloadAppLnks()
prevTypeList = types;
}
QListIterator<AppLnk> itapp( appLnkSet->children() );
AppLnk* l;
while ( (l=itapp.current()) ) {
++itapp;
if ( d->sendAppLnks && d->serverGui )
d->serverGui->applicationAdded( l->type(), *l );
}
if ( d->sendAppLnks && d->serverGui )
d->serverGui->applicationScanningProgress( 100 );
}
void DocumentList::reloadDocLnks()
{
if ( !d->scanDocs )
return;
if ( d->sendDocLnks && d->serverGui ) {
d->serverGui->documentScanningProgress( 0 );
d->serverGui->allDocumentsRemoved();
}
rescan();
}
void DocumentList::linkChanged( QString arg )
{
//qDebug( "linkchanged( %s )", arg.latin1() );
if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) {
reloadAppLnks();
} else {
const QList<DocLnk> &list = d->dls.children();
QListIterator<DocLnk> it( list );
while ( it.current() ) {
DocLnk *doc = it.current();
++it;
if ( ( doc->linkFileKnown() && doc->linkFile() == arg )
|| ( doc->fileKnown() && doc->file() == arg ) ) {
//qDebug( "found old link" );
DocLnk* dl = new DocLnk( arg );
// add new one if it exists and matches the mimetype
if ( d->store( dl ) ) {
// Existing link has been changed, send old link ref and a ref
// to the new link
//qDebug( "change case" );
if ( d->serverGui )
d->serverGui->documentChanged( *doc, *dl );
} else {
// Link has been removed or doesn't match the mimetypes any more
// so we aren't interested in it, so take it away from the list
//qDebug( "removal case" );
if ( d->serverGui )
d->serverGui->documentRemoved( *doc );
}
d->dls.remove( doc ); // remove old link from docLnkSet
delete doc;
return;
}
}
// Didn't find existing link, must be new
DocLnk* dl = new DocLnk( arg );
if ( d->store( dl ) ) {
// Add if it's a link we are interested in
//qDebug( "add case" );
add( *dl );
}
}
}
void DocumentList::restoreDone()
{
reloadAppLnks();
reloadDocLnks();
}
void DocumentList::storageChanged()
{
// ### can implement better
reloadAppLnks();
reloadDocLnks();
// ### Optimization opportunity
// Could be a bit more intelligent and somehow work out which
// mtab entry has changed and then only scan that and add and remove
// links appropriately.
// rescan();
}
void DocumentList::sendAllDocLinks()
{
if ( d->tid != 0 ) {
// We are in the middle of scanning, set a flag so
// we do this when we finish our scanning
d->needToSendAllDocLinks = true;
return;
}
QString contents;
Categories cats;
for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) {
DocLnk *doc = it.current();
QFileInfo fi( doc->file() );
if ( !fi.exists() )
continue;
bool fake = !doc->linkFileKnown();
if ( !fake ) {
QFile f( doc->linkFile() );
if ( f.open( IO_ReadOnly ) ) {
QTextStream ts( &f );
ts.setEncoding( QTextStream::UnicodeUTF8 );
contents += ts.read();
f.close();
} else
fake = TRUE;
}
if (fake) {
contents += "[Desktop Entry]\n"; // No tr
contents += "Categories = " + // No tr
cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr
contents += "Name = "+doc->name()+"\n"; // No tr
contents += "Type = "+doc->type()+"\n"; // No tr
}
contents += "File = "+doc->file()+"\n"; // No tr // (resolves path)
contents += QString("Size = %1\n").arg( fi.size() ); // No tr
}
//qDebug( "sending length %d", contents.length() );
#ifndef QT_NO_COP
QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" );
e << contents;
#endif
//qDebug( "================ \n\n%s\n\n===============", contents.latin1() );
d->needToSendAllDocLinks = false;
}
DocumentListPrivate::DocumentListPrivate( ServerInterface *gui )
{
storage = new StorageInfo( this );
serverGui = gui;
if ( serverGui ) {
sendAppLnks = serverGui->requiresApplications();
sendDocLnks = serverGui->requiresDocuments();
} else {
sendAppLnks = false;
sendDocLnks = false;
}
for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) {
listDirs[i] = 0;
lists[i] = 0;
listPositions[i] = 0;
}
initialize();
tid = 0;
}
void DocumentListPrivate::appendDocpath(FileSystem*fs)
{
QDir defPath(fs->path()+"/Documents");
QFileInfo f(fs->path()+"/.opiestorage.cf");
if (!f.exists()) {
- if (defPath.exists()) {
- docPaths+=defPath.path();
+ Mediadlg dlg(fs);
+ if (QDialog::Accepted != QPEApplication::execDialog( &dlg )) {
+ return;
}
- return;
}
Config conf(f.filePath(), Config::File );
conf.setGroup("subdirs");
bool read_all = conf.readBoolEntry("wholemedia",true);
if (read_all) {
docPaths+=fs->path();
return;
}
QStringList subDirs = conf.readListEntry("subdirs",':');
if (subDirs.isEmpty()) {
if (defPath.exists()) {
docPaths+=defPath.path();
}
return;
}
for (unsigned c = 0; c < subDirs.count();++c) {
QDir docDir(QString(fs->path()+"/"+subDirs[c]));
if (docDir.exists()) {
docPaths+=docDir.path();
}
}
}
void DocumentListPrivate::initialize()
{
// Reset
dls.clear();
docPaths.clear();
reference.clear();
QDir docDir( QPEApplication::documentDir() );
if ( docDir.exists() )
docPaths += QPEApplication::documentDir();
int i = 1;
const QList<FileSystem> &fs = storage->fileSystems();
QListIterator<FileSystem> it( fs );
for ( ; it.current(); ++it ) {
if ( (*it)->isRemovable() ) {
appendDocpath((*it));
++i;
}
}
for ( int i = 0; i < MAX_SEARCH_DEPTH; ++i ) {
if ( listDirs[i] ) {
delete listDirs[i];
listDirs[i] = 0;
}
lists[i] = 0;
listPositions[i] = 0;
}
docPathsSearched = 0;
searchDepth = -1;
state = Find;
dit = 0;
}
DocumentListPrivate::~DocumentListPrivate()
{
for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ )
if ( listDirs[i] )
delete listDirs[i];
delete dit;
}
void DocumentListPrivate::estimatedPercentScanned()
{
double overallProgress = 0.0;
double levelWeight = 75.0;
int topCount = docPaths.count();
if ( topCount > 1 ) {
levelWeight = levelWeight / topCount;
overallProgress += (docPathsSearched - 1) * levelWeight;
}
for ( int d = 0; d <= searchDepth; d++ ) {
if ( listDirs[d] ) {
int items = lists[d]->count();
if ( items > 1 ) {
levelWeight = levelWeight / items;
// Take in to account "." and ".."
overallProgress += (listPositions[d] - 3) * levelWeight;
}
} else {
break;
}
}
// qDebug( "overallProgress: %f", overallProgress );
if ( serverGui )
serverGui->documentScanningProgress( (int)overallProgress );
}
const QString DocumentListPrivate::nextFile()
{
while ( TRUE ) {
while ( searchDepth < 0 ) {
// go to next base path
if ( docPathsSearched >= docPaths.count() ) {
// end of base paths
return QString::null;
} else {
QDir dir( docPaths[docPathsSearched] );
// qDebug("now using base path: %s", docPaths[docPathsSearched].latin1() );
docPathsSearched++;
if ( !dir.exists( ".Qtopia-ignore" ) ) {
listDirs[0] = new QDir( dir );
lists[0] = listDirs[0]->entryInfoList();
listPositions[0] = 0;
searchDepth = 0;
}
}
}
const QFileInfoList *fil = lists[searchDepth];
QFileInfoList *fl = (QFileInfoList *)fil;
unsigned int pos = listPositions[searchDepth];
if ( pos >= fl->count() ) {
// go up a depth
delete listDirs[searchDepth];
listDirs[searchDepth] = 0;
lists[searchDepth] = 0;
listPositions[searchDepth] = 0;
searchDepth--;
} else {
const QFileInfo *fi = fl->at(pos);
listPositions[searchDepth]++;
QString bn = fi->fileName();
if ( bn[0] != '.' ) {
if ( fi->isDir() ) {
if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) {
// go down a depth
QDir dir( fi->filePath() );
// qDebug("now going in to path: %s", bn.latin1() );
if ( !dir.exists( ".Qtopia-ignore" ) ) {
if ( searchDepth < MAX_SEARCH_DEPTH - 1) {
searchDepth++;
listDirs[searchDepth] = new QDir( dir );
lists[searchDepth] = listDirs[searchDepth]->entryInfoList();
listPositions[searchDepth] = 0;
}
}
}
} else {
estimatedPercentScanned();
return fl->at(pos)->filePath();
}
}
}
}
return QString::null;
}
bool DocumentListPrivate::store( DocLnk* dl )
{
// if ( dl->fileKnown() && !dl->file().isEmpty() ) {
if ( dl && dl->fileKnown() ) {
dls.add( dl ); // store
return TRUE;
}
// don't store - delete
delete dl;
return FALSE;
}
#define MAGIC_NUMBER ((void*)2)
const DocLnk *DocumentListPrivate::iterate()
{
if ( state == Find ) {
//qDebug("state Find");
QString file = nextFile();
while ( !file.isNull() ) {
if ( file.right(8) == ".desktop" ) { // No tr
DocLnk* dl = new DocLnk( file );
if ( store(dl) )
return dl;
} else {
reference.insert( file, MAGIC_NUMBER );
}
file = nextFile();
diff --git a/core/launcher/mediadlg.cpp b/core/launcher/mediadlg.cpp
new file mode 100644
index 0000000..6448863
--- a/dev/null
+++ b/core/launcher/mediadlg.cpp
@@ -0,0 +1,31 @@
+#include "mediadlg.h"
+#include "mediumwidget.h"
+#include <qtopia/storage.h>
+#include <qpixmap.h>
+#include <qlayout.h>
+
+Mediadlg::Mediadlg(FileSystem*fs,QWidget *parent, const char *name, bool modal, WFlags fl)
+ : QDialog(parent,name,modal,fl)
+{
+ m_fs = fs;
+ m_widget = 0;
+ init();
+}
+
+Mediadlg::~Mediadlg()
+{
+}
+
+void Mediadlg::init()
+{
+ if (!m_fs) return;
+ m_lay = new QVBoxLayout( this );
+ m_widget = new MediumMountSetting::MediumMountWidget(m_fs->path(),QPixmap(),this);
+ m_lay->addWidget(m_widget);
+}
+
+void Mediadlg::accept()
+{
+ if (m_widget) m_widget->writeConfig();
+ QDialog::accept();
+}
diff --git a/core/launcher/mediadlg.h b/core/launcher/mediadlg.h
new file mode 100644
index 0000000..f4d552d
--- a/dev/null
+++ b/core/launcher/mediadlg.h
@@ -0,0 +1,29 @@
+#ifndef __MEDIA_DLG_H
+#define __MEDIA_DLG_H
+
+#include <qdialog.h>
+
+namespace MediumMountSetting {
+ class MediumMountWidget;
+}
+class FileSystem;
+class QVBoxLayout;
+
+class Mediadlg:public QDialog
+{
+ Q_OBJECT
+public:
+ Mediadlg(FileSystem*,QWidget *parent = 0, const char *name = 0 , bool modal = TRUE, WFlags fl = 0);
+ virtual ~Mediadlg();
+protected slots:
+ virtual void accept();
+
+protected:
+ MediumMountSetting::MediumMountWidget*m_widget;
+ FileSystem*m_fs;
+ QVBoxLayout *m_lay;
+ void init();
+};
+
+#endif
+
diff --git a/core/launcher/server.pro b/core/launcher/server.pro
index f82c741..e341e1a 100644
--- a/core/launcher/server.pro
+++ b/core/launcher/server.pro
@@ -1,124 +1,132 @@
TEMPLATE = app
CONFIG += qtopia warn_on release
DESTDIR = $$(OPIEDIR)/bin
HEADERS += server.h \
serverinterface.h \
launchertab.h \
documentlist.h \
appicons.h \
taskbar.h \
runningappbar.h \
applauncher.h \
stabmon.h \
inputmethods.h \
systray.h \
wait.h \
shutdownimpl.h \
launcher.h \
launcherview.h \
$$(OPIEDIR)/core/apps/calibrate/calibrate.h \
startmenu.h \
transferserver.h \
qcopbridge.h \
packageslave.h \
irserver.h \
firstuse.h \
$$(OPIEDIR)/rsync/buf.h \
$$(OPIEDIR)/rsync/checksum.h \
$$(OPIEDIR)/rsync/command.h \
$$(OPIEDIR)/rsync/emit.h \
$$(OPIEDIR)/rsync/job.h \
$$(OPIEDIR)/rsync/netint.h \
$$(OPIEDIR)/rsync/protocol.h \
$$(OPIEDIR)/rsync/prototab.h \
$$(OPIEDIR)/rsync/rsync.h \
$$(OPIEDIR)/rsync/search.h \
$$(OPIEDIR)/rsync/stream.h \
$$(OPIEDIR)/rsync/sumset.h \
$$(OPIEDIR)/rsync/trace.h \
$$(OPIEDIR)/rsync/types.h \
$$(OPIEDIR)/rsync/util.h \
$$(OPIEDIR)/rsync/whole.h \
$$(OPIEDIR)/rsync/config_rsync.h \
$$(OPIEDIR)/rsync/qrsync.h \
syncdialog.h \
serverapp.h \
qprocess.h \
- screensaver.h
+ screensaver.h \
+ $$(OPIEDIR)/noncore/settings/mediummount/mediumwidget.h \
+ mediadlg.h
SOURCES += server.cpp \
serverinterface.cpp \
launchertab.cpp \
documentlist.cpp \
appicons.cpp \
taskbar.cpp \
runningappbar.cpp \
applauncher.cpp \
stabmon.cpp \
inputmethods.cpp \
systray.cpp \
wait.cpp \
shutdownimpl.cpp \
launcher.cpp \
launcherview.cpp \
$$(OPIEDIR)/core/apps/calibrate/calibrate.cpp \
transferserver.cpp \
packageslave.cpp \
irserver.cpp \
qcopbridge.cpp \
startmenu.cpp \
main.cpp \
firstuse.cpp \
$$(OPIEDIR)/rsync/base64.c \
$$(OPIEDIR)/rsync/buf.c \
$$(OPIEDIR)/rsync/checksum.c \
$$(OPIEDIR)/rsync/command.c \
$$(OPIEDIR)/rsync/delta.c \
$$(OPIEDIR)/rsync/emit.c \
$$(OPIEDIR)/rsync/hex.c \
$$(OPIEDIR)/rsync/job.c \
$$(OPIEDIR)/rsync/mdfour.c \
$$(OPIEDIR)/rsync/mksum.c \
$$(OPIEDIR)/rsync/msg.c \
$$(OPIEDIR)/rsync/netint.c \
$$(OPIEDIR)/rsync/patch.c \
$$(OPIEDIR)/rsync/prototab.c \
$$(OPIEDIR)/rsync/readsums.c \
$$(OPIEDIR)/rsync/scoop.c \
$$(OPIEDIR)/rsync/search.c \
$$(OPIEDIR)/rsync/stats.c \
$$(OPIEDIR)/rsync/stream.c \
$$(OPIEDIR)/rsync/sumset.c \
$$(OPIEDIR)/rsync/trace.c \
$$(OPIEDIR)/rsync/tube.c \
$$(OPIEDIR)/rsync/util.c \
$$(OPIEDIR)/rsync/version.c \
$$(OPIEDIR)/rsync/whole.c \
$$(OPIEDIR)/rsync/qrsync.cpp \
syncdialog.cpp \
serverapp.cpp \
qprocess.cpp \
qprocess_unix.cpp \
- screensaver.cpp
+ screensaver.cpp \
+ $$(OPIEDIR)/noncore/settings/mediummount/mediumwidget.cc \
+ mediadlg.cpp
INCLUDEPATH += $(OPIEDIR)/core/apps/calibrate
DEPENDPATH += $(OPIEDIR)/core/apps/calibrate
INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/rsync
DEPENDPATH += $(OPIEDIR)/rsync
+INCLUDEPATH += $(OPIEDIR)/noncore/settings/mediummount
+DEPENDPATH += $(OPIEDIR)/noncore/settings/mediummount
+
+
TARGET = qpe
#needs OWait and ODevice
CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX )
contains( CONFTEST, y ){
LIBS += -lqpe -lopiecore2 -lopieui2
}else{
LIBS += -lcrypt -lqpe -lopiecore2 -lopieui2
}
include ( $(OPIEDIR)/include.pro )