]> Some of my projects - AniAdd.git/commitdiff
Moar files!
authorAPTX <marek321@gmail.com>
Wed, 1 Dec 2010 02:22:37 +0000 (03:22 +0100)
committerAPTX <marek321@gmail.com>
Wed, 1 Dec 2010 02:22:37 +0000 (03:22 +0100)
AniAdd.pro
aniadd.cpp [new file with mode: 0644]
aniadd.h [new file with mode: 0644]
filemodel.cpp [new file with mode: 0644]
filemodel.h [new file with mode: 0644]
main.cpp
mainwindow.cpp [new file with mode: 0644]
mainwindow.h [new file with mode: 0644]
mainwindow.ui [new file with mode: 0644]
qml/AniAdd/FileDelegate.qml [new file with mode: 0644]
qml/AniAdd/main.qml

index 65bb3afaec42de06c8fad91c750ccebd05f8f599..53d4d09f3135b872414d7967c90dab81072d7721 100644 (file)
@@ -32,8 +32,21 @@ symbian:TARGET.UID3 = 0xE49443EE
 # MOBILITY +=
 
 # The .cpp file which was generated for your project. Feel free to hack it.
-SOURCES += main.cpp
+SOURCES += main.cpp \
+    mainwindow.cpp \
+    filemodel.cpp \
+    aniadd.cpp
 
 # Please do not modify the following two lines. Required for deployment.
 include(qmlapplicationviewer/qmlapplicationviewer.pri)
 qtcAddDeployment()
+
+HEADERS += \
+    mainwindow.h \
+    filemodel.h \
+    aniadd.h
+
+FORMS += \
+    mainwindow.ui
+
+include(../../anidbudpclient/anidbudpclient.pri)
diff --git a/aniadd.cpp b/aniadd.cpp
new file mode 100644 (file)
index 0000000..caaa8bd
--- /dev/null
@@ -0,0 +1,119 @@
+#include "aniadd.h"
+#include "filemodel.h"
+
+#include <QFileDialog>
+#include <QDesktopServices>
+#include <QSettings>
+
+#include "mainwindow.h"
+
+AniAdd::AniAdd(int &argc, char **argv) :
+       QApplication(argc, argv), gui(0)
+{
+       m_instance = this;
+
+       model = new FileModel(this);
+
+       loadSettings();
+
+       createGui();
+}
+
+AniAdd::~AniAdd()
+{
+       if (gui)
+               gui->hide();
+
+       saveSettings();
+//     AniDBUdpClient::Client::destroy();
+
+       if (gui)
+       {
+               delete gui;
+               gui = 0;
+       }
+}
+
+QString AniAdd::lastDirectory() const
+{
+       return m_lastDirectory;
+}
+
+void AniAdd::setLastDirectory(const QString &lastDirectory)
+{
+       m_lastDirectory = lastDirectory;
+}
+
+FileModel *AniAdd::fileModel() const
+{
+       return model;
+}
+
+void AniAdd::addFiles()
+{
+       QStringList files = QFileDialog::getOpenFileNames(0, tr("Add Files.."), m_lastDirectory, QString(), 0, 0);//*/ QFileDialog::DontUseNativeDialog);
+       QFileInfoList list;
+       foreach (const QString &file, files)
+       {
+               list << file;
+       }
+
+       if (list.isEmpty())
+               return;
+
+       m_lastDirectory = list.at(0).absoluteFilePath();
+
+       model->addFiles(list);
+}
+/*
+void AniAdd::on_actionAddDirectories_triggered()
+{
+       QString dir = QFileDialog::getExistingDirectory(this, tr("Add Files.."), ".");
+
+       model->addDirectory(dir);
+       ui->tableView->resizeColumnsToContents();
+}
+*/
+void AniAdd::start()
+{
+       model->start();
+}
+
+void AniAdd::removeSelected()
+{
+//     model->removeItems(ui->tableView->selectionModel()->selectedIndexes());
+}
+
+void AniAdd::saveSettings()
+{
+       QSettings settings;
+
+       settings.beginGroup("settings");
+               settings.setValue("lastDirectory", m_lastDirectory);
+       settings.endGroup();
+
+}
+
+void AniAdd::loadSettings()
+{
+       QSettings settings;
+       settings.beginGroup("settings");
+               QString moviesDirectory = QDesktopServices::storageLocation(QDesktopServices::MoviesLocation);
+               if (!QDir(moviesDirectory).exists())
+                       moviesDirectory = ".";
+               m_lastDirectory = settings.value("lastDirectory", moviesDirectory).toString();
+       settings.endGroup();
+}
+
+void AniAdd::createGui()
+{
+       gui = new MainWindow();
+       gui->show();
+}
+
+AniAdd *AniAdd::m_instance = 0;
+
+AniAdd *AniAdd::instance()
+{
+       return m_instance;
+}
diff --git a/aniadd.h b/aniadd.h
new file mode 100644 (file)
index 0000000..31e509d
--- /dev/null
+++ b/aniadd.h
@@ -0,0 +1,56 @@
+#ifndef RENAMETOOL_H
+#define RENAMETOOL_H
+
+#include <QApplication>
+
+class FileModel;
+class MainWindow;
+
+class AniAdd : public QApplication
+{
+    Q_OBJECT
+       Q_PROPERTY(QString lastDirectory READ lastDirectory WRITE setLastDirectory);
+       Q_PROPERTY(FileModel *fileModel READ fileModel);
+
+public:
+       explicit AniAdd(int &argc, char **argv);
+       ~AniAdd();
+
+       QString lastDirectory() const;
+       void setLastDirectory(const QString &lastDirectory);
+
+       FileModel *fileModel() const;
+
+signals:
+
+public slots:
+       void addFiles();
+       void removeSelected();
+
+       void start();
+
+       //void on_actionAddDirectories_triggered();
+
+private:
+       void saveSettings();
+       void loadSettings();
+
+       void createGui();
+
+       QString m_lastDirectory;
+
+       FileModel *model;
+
+       MainWindow *gui;
+
+       static AniAdd *m_instance;
+public:
+       static AniAdd *instance();
+};
+
+#ifdef qApp
+#      undef qApp
+#endif
+#define qApp AniAdd::instance()
+
+#endif // RENAMETOOL_H
diff --git a/filemodel.cpp b/filemodel.cpp
new file mode 100644 (file)
index 0000000..6716922
--- /dev/null
@@ -0,0 +1,207 @@
+#include "filemodel.h"
+
+FileModel::FileModel(QObject *parent) : QAbstractTableModel(parent)
+{
+       QHash<int, QByteArray> roles;
+       roles[FileName]                 = "fileName";
+       roles[HashingState]             = "hashingState";
+       roles[RenamingState]    = "renamingState";
+       roles[AddingState]              = "addingState";
+       roles[MarkingState]             = "markingState";
+       setRoleNames(roles);
+}
+
+void FileModel::addFile(const QFileInfo &file)
+{
+       addFiles(QFileInfoList() << file);
+}
+
+void FileModel::addFiles(const QFileInfoList &files)
+{
+       foreach (const QFileInfo &file, files)
+       {
+               AniDBUdpClient::File *f = new AniDBUdpClient::File(file);
+
+               connect(f, SIGNAL(statusUpdate(AniDBUdpClient::File::Action,AniDBUdpClient::File::ActionState)), this, SLOT(updateState()));
+
+               this->files << f;
+       }
+       reset();
+}
+
+void FileModel::addDirectory(const QDir &directory)
+{
+       addDirectories(QList<QDir>() << directory);
+}
+
+void FileModel::addDirectories(const QList<QDir> &directories)
+{
+       foreach (const QDir &directory, directories)
+       {
+               addFiles(directory.entryInfoList(QDir::Files | QDir::NoDotAndDotDot));
+       }
+}
+
+void FileModel::removeItems(const QModelIndexList &items)
+{
+       QModelIndexList sorted = items;
+       qSort(sorted);
+
+       for (QModelIndexList::const_iterator i = sorted.constEnd()-1; i != sorted.constBegin(); --i)
+       {
+               files.removeAt(i->row());
+       }
+       files.removeAt(sorted[0].row());
+       reset();
+}
+
+void FileModel::start()
+{
+       foreach (AniDBUdpClient::File *file, files)
+       {
+               file->rename();
+               file->addToMyList();
+       }
+}
+
+int FileModel::rowCount(const QModelIndex &parent) const
+{
+       Q_UNUSED(parent);
+       return files.count();
+}
+
+int FileModel::columnCount(const QModelIndex &parent) const
+{
+       Q_UNUSED(parent);
+       return 5;
+}
+
+QVariant FileModel::data(const QModelIndex &index, int role) const
+{
+       AniDBUdpClient::File *f = files[index.row()];
+
+       switch (index.column())
+       {
+               case 0:
+                       switch (role)
+                       {
+                               case Qt::DisplayRole:
+                               case FileName:
+                                       return f->file().fileName();
+                               break;
+                               case HashingState:
+                                       return f->hashingState();
+                               break;
+                               case RenamingState:
+                                       return f->renamingState();
+                               break;
+                               case AddingState:
+                                       return f->addingState();
+                               break;
+                               case MarkingState:
+                                       return f->markingState();
+                               break;
+                               default:
+                                       return QVariant();
+                               break;
+                       }
+               break;
+               case 1:
+                       return getDescForActionState(f->hashingState(), role);
+               break;
+               case 2:
+                       return getDescForActionState(f->renamingState(), role);
+               break;
+               case 3:
+                       return getDescForActionState(f->addingState(), role);
+               break;
+               case 4:
+                       return getDescForActionState(f->markingState(), role);
+               break;
+               default:
+               break;
+       }
+       return QVariant();
+}
+
+QVariant FileModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+       if (role != Qt::DisplayRole)
+               return QVariant();
+
+       if (orientation == Qt::Vertical)
+               return section + 1;
+
+       switch (section)
+       {
+               case 0:
+                       return tr("File Name");
+               case 1:
+                       return tr("Hashing");
+               case 2:
+                       return tr("Renaming");
+               case 3:
+                       return tr("Adding");
+               case 4:
+                       return tr("Marking");
+               default:
+               break;
+       }
+       return QVariant();
+}
+
+void FileModel::updateState()
+{
+       using AniDBUdpClient::File;
+
+       File *file = qobject_cast<File *>(sender());
+       if (!file)
+               return;
+
+       int i = files.indexOf(file);
+
+       if (i == -1)
+               return;
+
+       emit dataChanged(index(i, 0), index(i, columnCount()));
+
+}
+
+QVariant FileModel::getDescForActionState(AniDBUdpClient::File::ActionState actionState, int role) const
+{
+       using AniDBUdpClient::File;
+
+       if (role == Qt::DisplayRole)
+       {
+               switch (actionState)
+               {
+                       case File::NotStarted:
+                               return tr("Not started/queued");
+                       case File::InProgress:
+                               return tr("In Progress");
+                       case File::Success:
+                               return tr("Finished");
+                       case File::Failure:
+                               return tr("Failed");
+                       default:
+                               return tr("Unknown");
+               }
+       }
+       else if (role == Qt::BackgroundColorRole)
+       {
+               switch (actionState)
+               {
+                       case File::NotStarted:
+                               return QVariant();
+                       case File::InProgress:
+                               return Qt::yellow;
+                       case File::Success:
+                               return Qt::green;
+                       case File::Failure:
+                               return Qt::red;
+                       default:
+                               return QVariant();
+               }
+       }
+       return QVariant();
+}
diff --git a/filemodel.h b/filemodel.h
new file mode 100644 (file)
index 0000000..cb76ffb
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef FILEMODEL_H
+#define FILEMODEL_H
+
+#include <QAbstractTableModel>
+#include <QFileInfoList>
+#include <QDir>
+
+#include <AniDBUdpClient/File>
+
+class FileModel : public QAbstractTableModel
+{
+       Q_OBJECT
+
+public:
+       enum Roles
+       {
+               FileName = Qt::UserRole + 1,
+               HashingState,
+               RenamingState,
+               AddingState,
+               MarkingState
+       };
+
+       FileModel(QObject *parent = 0);
+
+public slots:
+       void addFile(const QFileInfo &file);
+       void addFiles(const QFileInfoList &files);
+
+       void addDirectory(const QDir &directory);
+       void addDirectories(const QList<QDir> &directories);
+
+       void removeItems(const QModelIndexList &items);
+
+       void start();
+
+protected:
+       int rowCount(const QModelIndex &parent = QModelIndex()) const;
+       int columnCount(const QModelIndex &parent = QModelIndex()) const;
+
+       QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+
+       QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+/*
+       bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
+       bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
+*/
+private slots:
+       void updateState();
+
+private:
+       QVariant getDescForActionState(AniDBUdpClient::File::ActionState actionState, int role) const;
+       QList<AniDBUdpClient::File *> files;
+       QMap<int, QString> progressDetails;
+};
+
+#endif // FILEMODEL_H
index 046fc94648381457272152876547e26abe42b322..3847f2f829405c2c1493e1b49d017e673d01304d 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,14 +1,8 @@
-#include <QtGui/QApplication>
-#include "qmlapplicationviewer.h"
+#include "aniadd.h"
 
 int main(int argc, char *argv[])
 {
-    QApplication app(argc, argv);
+       AniAdd app(argc, argv);
 
-    QmlApplicationViewer viewer;
-    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
-    viewer.setMainQmlFile(QLatin1String("qml/AniAdd/main.qml"));
-    viewer.showExpanded();
-
-    return app.exec();
+       return app.exec();
 }
diff --git a/mainwindow.cpp b/mainwindow.cpp
new file mode 100644 (file)
index 0000000..328914f
--- /dev/null
@@ -0,0 +1,53 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+#include <QDeclarativeContext>
+
+#include "aniadd.h"
+#include "filemodel.h"
+
+MainWindow::MainWindow(QWidget *parent) :
+    QMainWindow(parent),
+    ui(new Ui::MainWindow)
+{
+    ui->setupUi(this);
+
+
+       QDeclarativeContext *ctxt = ui->declarativeView->rootContext();
+
+       ctxt->setContextProperty("renameTool", qApp);
+//     ctxt->setContextProperty("fileModel", qApp->fileModel());
+
+       //ui->declarativeView->setSource(QUrl("qrc:/qml/main.qml"));
+       ui->declarativeView->setSource(QUrl("qml/AniAdd/main.qml"));
+       ui->declarativeView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+
+
+       connect(ui->actionQuit, SIGNAL(triggered()), qApp, SLOT(quit()));
+
+}
+
+MainWindow::~MainWindow()
+{
+    delete ui;
+}
+
+void MainWindow::on_actionAddFiles_triggered()
+{
+       qApp->addFiles();
+}
+
+void MainWindow::on_actionAddDirectories_triggered()
+{
+       //
+}
+
+void MainWindow::on_actionStart_triggered()
+{
+       qApp->fileModel()->start();
+}
+
+void MainWindow::on_actionRemoveSelectedFiles_triggered()
+{
+       //model->removeItems(ui->tableView->selectionModel()->selectedIndexes());
+}
diff --git a/mainwindow.h b/mainwindow.h
new file mode 100644 (file)
index 0000000..818a6ee
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+namespace Ui {
+    class MainWindow;
+}
+
+class FileModel;
+class AniAdd;
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    explicit MainWindow(QWidget *parent = 0);
+    ~MainWindow();
+
+private slots:
+       void on_actionAddFiles_triggered();
+       void on_actionAddDirectories_triggered();
+
+       void on_actionStart_triggered();
+
+       void on_actionRemoveSelectedFiles_triggered();
+
+private:
+       void saveSettings();
+       void loadSettings();
+
+       QString lastDirectory;
+
+       FileModel *model;
+       AniAdd *aniAdd;
+
+    Ui::MainWindow *ui;
+};
+
+#endif // MAINWINDOW_H
diff --git a/mainwindow.ui b/mainwindow.ui
new file mode 100644 (file)
index 0000000..28a48b3
--- /dev/null
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>800</width>
+    <height>600</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralwidget">
+   <layout class="QVBoxLayout" name="verticalLayout">
+    <property name="spacing">
+     <number>0</number>
+    </property>
+    <property name="margin">
+     <number>0</number>
+    </property>
+    <item>
+     <widget class="QDeclarativeView" name="declarativeView"/>
+    </item>
+   </layout>
+  </widget>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>800</width>
+     <height>21</height>
+    </rect>
+   </property>
+   <widget class="QMenu" name="menuFile">
+    <property name="title">
+     <string>&amp;File</string>
+    </property>
+    <addaction name="actionAddFiles"/>
+    <addaction name="actionAddDirectories"/>
+    <addaction name="separator"/>
+    <addaction name="actionQuit"/>
+   </widget>
+   <widget class="QMenu" name="menuHelp">
+    <property name="title">
+     <string>&amp;Help</string>
+    </property>
+    <addaction name="actionAboutAniAdd"/>
+   </widget>
+   <widget class="QMenu" name="menuActions">
+    <property name="title">
+     <string>&amp;Actions</string>
+    </property>
+    <addaction name="actionStart"/>
+    <addaction name="separator"/>
+    <addaction name="actionRemoveSelectedFiles"/>
+   </widget>
+   <addaction name="menuFile"/>
+   <addaction name="menuActions"/>
+   <addaction name="menuHelp"/>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+  <action name="actionAddFiles">
+   <property name="text">
+    <string>Add &amp;Files...</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+O</string>
+   </property>
+  </action>
+  <action name="actionAddDirectories">
+   <property name="text">
+    <string>Add &amp;Directories...</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+Shift+O</string>
+   </property>
+  </action>
+  <action name="actionQuit">
+   <property name="text">
+    <string>&amp;Quit</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+Q</string>
+   </property>
+  </action>
+  <action name="actionAboutAniAdd">
+   <property name="text">
+    <string>About AniAdd</string>
+   </property>
+  </action>
+  <action name="actionStart">
+   <property name="text">
+    <string>Start</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+S</string>
+   </property>
+  </action>
+  <action name="actionRemoveSelectedFiles">
+   <property name="text">
+    <string>Remove Selected Files</string>
+   </property>
+   <property name="shortcut">
+    <string>Del</string>
+   </property>
+  </action>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>QDeclarativeView</class>
+   <extends>QGraphicsView</extends>
+   <header>QtDeclarative/QDeclarativeView</header>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/qml/AniAdd/FileDelegate.qml b/qml/AniAdd/FileDelegate.qml
new file mode 100644 (file)
index 0000000..27cf382
--- /dev/null
@@ -0,0 +1,31 @@
+import Qt 4.7
+
+Rectangle {
+       radius: 20
+
+       border.width: 0
+       border.color: "#000000"
+       opacity: 0.74
+       gradient: Gradient {
+               GradientStop {
+                       position: 0
+                       color: "#ffffff"
+               }
+               GradientStop {
+                       position: 0.85
+                       color: "#ababab"
+               }
+               GradientStop {
+                       position: 1
+                       color: "#ffffff"
+               }
+       }
+
+       Column {
+               anchors.fill: parent
+               Text {
+                       text: "Test" + fileName
+               }
+       }
+
+}
index 4ef3a885a1e1384a9fdbc856d241b6503e62a3cd..fd1d249d02b78dad2021068f0079e418ca9f3a9f 100644 (file)
@@ -1,16 +1,80 @@
 import Qt 4.7
 
 Rectangle {
-    width: 360
-    height: 360
-    Text {
-        text: "Hello World"
-        anchors.centerIn: parent
-    }
-    MouseArea {
-        anchors.fill: parent
-        onClicked: {
-            Qt.quit();
-        }
-    }
+       id: main
+
+       width: 600; height: 400
+       color: "#b7e0ff"
+
+       SystemPalette { id: activePalette }
+
+       ListModel {
+               id: testModel
+
+               ListElement
+               {
+                       fileName: "Kaichou wa Maid-sama! - 18 - Even the Maid`s a Footman - [FFFpeeps](40cef62d).mkv"
+
+                       hashProgress: 20
+                       hashingState: 1
+                       renamingState: 1
+                       addingState: 2
+               }
+
+               ListElement
+               {
+                       fileName: "K-On!! - 07 - Tea Party! - [CoalGuys](f58a5866).mkv"
+
+                       hashProgress: 0
+                       hashingState: 0
+                       renamingState: 0
+                       addingState: 0
+               }
+
+               ListElement
+               {
+                       fileName: "Mayoi Neko Overrun! - 11 - The Stray Cats Fell Apart - [Ryuumaru](62a47da4).mkv"
+
+                       hashProgress: 100
+                       hashingState: 1
+                       renamingState: 1
+                       addingState: 1
+               }
+       }
+
+       Image {
+               id: bgCharImage
+               source: "images/bgchar.png"
+
+               property variant maxHeight: 1024
+
+               function calcX()
+               {
+                       var x = parent.width - bgCharImage.width;
+                       var offset = -200;
+                       return x < offset ? offset : x
+               }
+
+               function calcY()
+               {
+                       var y = parent.height - bgCharImage.height;
+                       var offset = -200;
+                       return y < offset ? offset : y
+               }
+
+               sourceSize.width: maxHeight * 0.625521268
+               sourceSize.height: maxHeight
+
+
+               x: calcX()
+               y: calcY()
+       }
+
+       ListView {
+               id: listView
+               anchors.fill: parent
+               model: testModel
+               delegate: FileDelegate
+       }
+
 }