From ea9e5d0f1e02ca8c8859bbf59f2081b819f1d329 Mon Sep 17 00:00:00 2001 From: am Date: Mon, 6 Jul 2009 08:44:14 +0000 Subject: -added some artwork -started implementing FilesystemView git-svn-id: file:///var/svn/repos2/shemov/trunk@377 f440f766-f032-0410-8965-dc7d17de2ca0 --- dildo.png | Bin 0 -> 874 bytes filesystemdirproxy.cpp | 1 + filesystemdirproxy.h | 2 + filesystemfileproxy.cpp | 14 +++++ filesystemfileproxy.h | 24 ++++++++ filesystemwidget.cpp | 53 +++++++++++++++++ filesystemwidget.h | 6 ++ fileview.cpp | 30 ++++++++++ fileview.h | 26 +++++++++ helper.cpp | 39 +++++++++++++ helper.h | 20 +++++++ main.cpp | 3 + movie.svg | 148 ++++++++++++++++++++++++++++++++++++++++++++++++ picture.svg | 131 ++++++++++++++++++++++++++++++++++++++++++ shemov.cpp | 30 ++++++++++ shemov.h | 29 ++++++++++ shemov.pro | 16 +++++- shemov.qrc | 9 +++ shemoviconprovider.cpp | 29 ++++++++++ shemoviconprovider.h | 24 ++++++++ 20 files changed, 632 insertions(+), 2 deletions(-) create mode 100755 dildo.png create mode 100644 filesystemfileproxy.cpp create mode 100644 filesystemfileproxy.h create mode 100644 fileview.cpp create mode 100644 fileview.h create mode 100644 helper.cpp create mode 100644 helper.h create mode 100644 movie.svg create mode 100644 picture.svg create mode 100644 shemov.cpp create mode 100644 shemov.h create mode 100644 shemov.qrc create mode 100644 shemoviconprovider.cpp create mode 100644 shemoviconprovider.h diff --git a/dildo.png b/dildo.png new file mode 100755 index 0000000..8a167cb Binary files /dev/null and b/dildo.png differ diff --git a/filesystemdirproxy.cpp b/filesystemdirproxy.cpp index ff97309..6e9a714 100644 --- a/filesystemdirproxy.cpp +++ b/filesystemdirproxy.cpp @@ -20,3 +20,4 @@ bool FilesystemDirProxy::filterAcceptsRow(int sourcerow, const QModelIndex &sour } return m->isDir(idx); } + diff --git a/filesystemdirproxy.h b/filesystemdirproxy.h index e86773f..67c30de 100644 --- a/filesystemdirproxy.h +++ b/filesystemdirproxy.h @@ -10,6 +10,8 @@ #include +class QModelIndex; + class FilesystemDirProxy : public QSortFilterProxyModel { Q_OBJECT public: diff --git a/filesystemfileproxy.cpp b/filesystemfileproxy.cpp new file mode 100644 index 0000000..22f8868 --- /dev/null +++ b/filesystemfileproxy.cpp @@ -0,0 +1,14 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include +#include + +#include "filesystemfileproxy.h" + +FilesystemFileProxy::FilesystemFileProxy(QObject *parent) : QSortFilterProxyModel(parent) {} + diff --git a/filesystemfileproxy.h b/filesystemfileproxy.h new file mode 100644 index 0000000..cb32a77 --- /dev/null +++ b/filesystemfileproxy.h @@ -0,0 +1,24 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#ifndef FILESYSTEMFILEPROXY_H +#define FILESYSTEMFILEPROXY_H + +#include + +class QModelIndex; +class QVariant; + +class FilesystemFileProxy : public QSortFilterProxyModel { + Q_OBJECT + public: + FilesystemFileProxy(QObject *parent = 0); + ~FilesystemFileProxy() {}; +}; + +#endif + diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index 5e30b66..3798dcc 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -7,16 +7,69 @@ #include #include +#include +#include +#include +#include #include "filesystemwidget.h" #include "filesystemdirproxy.h" +#include "fileview.h" +#include "shemoviconprovider.h" FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) { mModel = new QDirModel; mModel->setFilter(QDir::AllEntries | QDir::NoDotAndDotDot); + mModel->setSorting(QDir::DirsFirst | QDir::IgnoreCase); + SheMovIconProvider *p = new SheMovIconProvider; + mModel->setIconProvider(p); + mDirProxy = new FilesystemDirProxy; mDirProxy->setSourceModel(mModel); mDirView = new QTreeView; mDirView->setModel(mDirProxy); + mDirView->setColumnHidden(1, true); + mDirView->setColumnHidden(2, true); + mDirView->setColumnHidden(3, true); + mDirView->setRootIsDecorated(false); + + mFileView = new FileView; + mFileView->setModel(mModel); + connect(mDirView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(directoryChanged(const QModelIndex &))); + + QSettings s; + QString startDir = s.value("paths/start", QDir::homePath()).toString(); + QModelIndex startIndex = mModel->index(startDir); + if(startIndex.isValid()){ + QModelIndex proxyIndex = mDirProxy->mapFromSource(startIndex); + mDirView->setCurrentIndex(proxyIndex); + mDirView->setExpanded(proxyIndex, true); + QModelIndex parent = proxyIndex.parent(); + mFileView->setRootIndex(startIndex); + do { + mDirView->setExpanded(parent, true); + parent = parent.parent(); + }while(parent.isValid()); + } + + mFileView->resizeColumnToContents(0); + QVBoxLayout *mainLayout = new QVBoxLayout; + QSplitter *splitter = new QSplitter; + splitter->addWidget(mDirView); + splitter->addWidget(mFileView); + splitter->setStretchFactor(0, 1); + splitter->setStretchFactor(1, 2); + mainLayout->addWidget(splitter); + + setLayout(mainLayout); +} + +void FilesystemWidget::directoryChanged(const QModelIndex &index){ + QModelIndex real = mDirProxy->mapToSource(index); + if(!index.isValid()){ + return; + } + mFileView->setRootIndex(real); } + diff --git a/filesystemwidget.h b/filesystemwidget.h index 63707da..380fa22 100644 --- a/filesystemwidget.h +++ b/filesystemwidget.h @@ -13,6 +13,8 @@ class QDirModel; class QTreeView; class FilesystemDirProxy; +class FileView; +class QModelIndex; class FilesystemWidget : public QWidget { Q_OBJECT @@ -20,9 +22,13 @@ class FilesystemWidget : public QWidget { FilesystemWidget(QWidget *parent = 0); ~FilesystemWidget() {}; + public slots: + void directoryChanged(const QModelIndex &index); + private: QDirModel *mModel; QTreeView *mDirView; + FileView *mFileView; FilesystemDirProxy *mDirProxy; }; diff --git a/fileview.cpp b/fileview.cpp new file mode 100644 index 0000000..b402bd1 --- /dev/null +++ b/fileview.cpp @@ -0,0 +1,30 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include +#include +#include + +#include "fileview.h" + +FileView::FileView(QWidget *parent) : QTreeView(parent) { + setRootIsDecorated(false); +} + +void FileView::contextMenuEvent(QContextMenuEvent *e){ + QMenu contextMenu(this); + int ctr(0); + foreach(QAction *a, actions()){ + contextMenu.addAction(a); + if(false){ + contextMenu.addSeparator(); + } + ++ctr; + } + contextMenu.exec(e->globalPos()); +} + diff --git a/fileview.h b/fileview.h new file mode 100644 index 0000000..3382132 --- /dev/null +++ b/fileview.h @@ -0,0 +1,26 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#ifndef FILEVIEW_H +#define FILEVIEW_H + +#include + +class QContextMenuEvent; + +class FileView : public QTreeView { + Q_OBJECT + public: + FileView(QWidget *parent = 0); + ~FileView() {}; + + protected: + virtual void contextMenuEvent(QContextMenuEvent *e); +}; + +#endif + diff --git a/helper.cpp b/helper.cpp new file mode 100644 index 0000000..116efa5 --- /dev/null +++ b/helper.cpp @@ -0,0 +1,39 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include +#include + +#include "helper.h" + +namespace Helper { + const QString mimeType(const QString &path){ + QString retval; + magic_t mc = magic_open(MAGIC_MIME_TYPE); + QByteArray name = path.toUtf8(); + if(mc){ + magic_load(mc, 0); + const char* magic_c = magic_file(mc, name.constData()); + retval = QString(magic_c); + magic_close(mc); + } + if(retval.toLower().startsWith("application/octet-stream")){ + magic_t mc = magic_open(MAGIC_NONE); + if(mc){ + magic_load(mc, 0); + const char* magic_c = magic_file(mc, name.constData()); + QString desc(magic_c); + magic_close(mc); + if(desc.toLower().contains("mpeg sequence") || desc.toLower().contains("microsoft asf")){ + retval = "video/"; + } + } + return retval; + } + } +} + diff --git a/helper.h b/helper.h new file mode 100644 index 0000000..033f7d6 --- /dev/null +++ b/helper.h @@ -0,0 +1,20 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#ifndef HELPER_H +#define HELPER_H + +#include + +class QString; + +namespace Helper { + const QString mimeType(const QString &path); +} + +#endif + diff --git a/main.cpp b/main.cpp index 34f2917..58fea7a 100644 --- a/main.cpp +++ b/main.cpp @@ -7,11 +7,14 @@ #include +#include "shemov.h" + int main(int argc, char **argv){ QApplication app(argc, argv); QCoreApplication::setOrganizationName("Sissie's, Inc."); QCoreApplication::setOrganizationDomain("hadante.servebeer.com"); QCoreApplication::setApplicationName("SheMov"); QCoreApplication::setApplicationVersion("0.1"); + (void) new SheMov; return app.exec(); } diff --git a/movie.svg b/movie.svg new file mode 100644 index 0000000..4c85bb6 --- /dev/null +++ b/movie.svg @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + M + + diff --git a/picture.svg b/picture.svg new file mode 100644 index 0000000..119879f --- /dev/null +++ b/picture.svg @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + P + + diff --git a/shemov.cpp b/shemov.cpp new file mode 100644 index 0000000..ea84a7e --- /dev/null +++ b/shemov.cpp @@ -0,0 +1,30 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include +#include + +#include "shemov.h" +#include "filesystemwidget.h" + +SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) { + mFSWidget = new FilesystemWidget; + + mTab = new QTabWidget; + mTab->addTab(mFSWidget, tr("Filemanager")); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(mTab); + + QWidget *centralWidget = new QWidget; + centralWidget->setLayout(mainLayout); + setCentralWidget(centralWidget); + show(); + +} + + diff --git a/shemov.h b/shemov.h new file mode 100644 index 0000000..2de2adc --- /dev/null +++ b/shemov.h @@ -0,0 +1,29 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#ifndef SHEMOV_H +#define SHEMOV_H + +#include + +class QTabWidget; +class FilesystemWidget; + +class SheMov : public QMainWindow { + Q_OBJECT + public: + SheMov(QWidget *parent = 0, Qt::WindowFlags flags = 0); + ~SheMov() {}; + + private: + QTabWidget *mTab; + FilesystemWidget *mFSWidget; + +}; + +#endif + diff --git a/shemov.pro b/shemov.pro index d869881..4b4d3d9 100644 --- a/shemov.pro +++ b/shemov.pro @@ -8,11 +8,23 @@ movieitem.cpp \ moviemodel.cpp \ coveritem.cpp \ filesystemdirproxy.cpp \ -filesystemwidget.cpp +filesystemwidget.cpp \ +fileview.cpp \ +shemov.cpp \ +filesystemfileproxy.cpp \ +helper.cpp \ +shemoviconprovider.cpp HEADERS = listitem.h \ listmodel.h \ movieitem.h \ moviemodel.h \ coveritem.h \ filesystemdirproxy.h \ -filesystemwidget.h +filesystemwidget.h \ +fileview.h \ +shemov.h \ +filesystemfileproxy.h \ +helper.h \ +shemoviconprovider.h +LIBS += -lmagic +RESOURCES = shemov.qrc diff --git a/shemov.qrc b/shemov.qrc new file mode 100644 index 0000000..9763baf --- /dev/null +++ b/shemov.qrc @@ -0,0 +1,9 @@ + + + + movie.svg + dildo.png + picture.svg + + + diff --git a/shemoviconprovider.cpp b/shemoviconprovider.cpp new file mode 100644 index 0000000..f0ea01e --- /dev/null +++ b/shemoviconprovider.cpp @@ -0,0 +1,29 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include +#include + +#include "shemoviconprovider.h" +#include "helper.h" + +SheMovIconProvider::SheMovIconProvider() {}; + +QIcon SheMovIconProvider::icon(const QFileInfo &info) const { + if(info.isDir()){ + return QIcon(":/dildo.png"); + } + QString type = Helper::mimeType(info.absoluteFilePath()); + if(type.toLower().startsWith("video")){ + return QIcon(":/movie.svg"); + } + if(type.toLower().startsWith("image")){ + return QIcon(":/picture.svg"); + } + return QFileIconProvider::icon(info); +} + diff --git a/shemoviconprovider.h b/shemoviconprovider.h new file mode 100644 index 0000000..04af45b --- /dev/null +++ b/shemoviconprovider.h @@ -0,0 +1,24 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#ifndef SHEMOVICONPROVIDER_H +#define SHEMOVICONPROVIDER_H + +#include + +class QIcon; +class QFileInfo; + +class SheMovIconProvider : public QFileIconProvider { + public: + SheMovIconProvider(); + ~SheMovIconProvider() {}; + virtual QIcon icon(const QFileInfo &info) const; +}; + +#endif + -- cgit v1.2.3-70-g09d2