From: APTX Date: Sun, 26 Dec 2010 03:24:02 +0000 (+0100) Subject: Progress! X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=af24b0aa72ed60285b7ef8c2f64e13d0c66d26fc;p=AniAdd.git Progress! --- diff --git a/AniAdd.pro b/AniAdd.pro index 53d4d09..c2e8ba4 100644 --- a/AniAdd.pro +++ b/AniAdd.pro @@ -1,3 +1,5 @@ +QT += opengl + # Add more folders to ship with the application, here folder_01.source = qml/AniAdd folder_01.target = qml @@ -35,7 +37,9 @@ symbian:TARGET.UID3 = 0xE49443EE SOURCES += main.cpp \ mainwindow.cpp \ filemodel.cpp \ - aniadd.cpp + aniadd.cpp \ + anidbconfigdialog.cpp \ + renamesettingsdialog.cpp # Please do not modify the following two lines. Required for deployment. include(qmlapplicationviewer/qmlapplicationviewer.pri) @@ -44,9 +48,13 @@ qtcAddDeployment() HEADERS += \ mainwindow.h \ filemodel.h \ - aniadd.h + aniadd.h \ + anidbconfigdialog.h \ + renamesettingsdialog.h FORMS += \ - mainwindow.ui + mainwindow.ui \ + anidbconfigdialog.ui \ + renamesettingsdialog.ui include(../../anidbudpclient/anidbudpclient.pri) diff --git a/aniadd.cpp b/aniadd.cpp index caaa8bd..b30ec49 100644 --- a/aniadd.cpp +++ b/aniadd.cpp @@ -1,10 +1,13 @@ #include "aniadd.h" -#include "filemodel.h" #include #include #include +#include +#include + +#include "filemodel.h" #include "mainwindow.h" AniAdd::AniAdd(int &argc, char **argv) : @@ -12,6 +15,7 @@ AniAdd::AniAdd(int &argc, char **argv) : { m_instance = this; + AniDBUdpClient::Client::instance()->setIdlePolicy(AniDBUdpClient::LogoutIdlePolicy); model = new FileModel(this); loadSettings(); @@ -49,6 +53,27 @@ FileModel *AniAdd::fileModel() const return model; } +QString AniAdd::renameEnv() const +{ + return m_renameEnv; +} + +void AniAdd::setRenameEnv(const QString &renameEnv) +{ + m_renameEnv = renameEnv; +} + +bool AniAdd::filterResults() const +{ + return m_filterResults; +} + +void AniAdd::setFilterResults(bool filterResults) +{ + m_filterResults = filterResults; +} + + void AniAdd::addFiles() { QStringList files = QFileDialog::getOpenFileNames(0, tr("Add Files.."), m_lastDirectory, QString(), 0, 0);//*/ QFileDialog::DontUseNativeDialog); @@ -92,6 +117,20 @@ void AniAdd::saveSettings() settings.setValue("lastDirectory", m_lastDirectory); settings.endGroup(); + settings.beginGroup("anidbudpapiclient"); + settings.setValue("host", AniDBUdpClient::Client::instance()->host()); + settings.setValue("hostPort", AniDBUdpClient::Client::instance()->hostPort()); + settings.setValue("localPort", AniDBUdpClient::Client::instance()->localPort()); + settings.setValue("user", AniDBUdpClient::Client::instance()->user()); + settings.setValue("pass", AniDBUdpClient::Client::instance()->pass()); + settings.endGroup(); + + settings.beginGroup("renameparser"); + settings.setValue("renameString", fileModel()->renameEngine()->renameString()); + settings.setValue("parserType", fileModel()->renameEngine()->currentParserType()); + settings.setValue("renameEnv", m_renameEnv); + settings.setValue("filterResult", m_filterResults); + settings.endGroup(); } void AniAdd::loadSettings() @@ -103,6 +142,24 @@ void AniAdd::loadSettings() moviesDirectory = "."; m_lastDirectory = settings.value("lastDirectory", moviesDirectory).toString(); settings.endGroup(); + + settings.beginGroup("anidbudpapiclient"); + AniDBUdpClient::Client::instance()->setHost(settings.value("host", "api.anidb.info").toString()); + AniDBUdpClient::Client::instance()->setHostPort(settings.value("hostPort", 9000).toInt()); + AniDBUdpClient::Client::instance()->setLocalPort(settings.value("localPort", 9001).toInt()); + AniDBUdpClient::Client::instance()->setUser(settings.value("user").toString()); + AniDBUdpClient::Client::instance()->setPass(settings.value("pass").toString()); + settings.endGroup(); + + settings.beginGroup("renameparser"); + fileModel()->renameEngine()->setCurrentParserType( + settings.value("parserType", RenameParser::RenameEngine::AniAdd) + .value()); + + fileModel()->renameEngine()->parse(settings.value("renameString").toString()); + m_renameEnv = settings.value("renameEnv").toString(); + m_filterResults = settings.value("filterResult").toBool(); + settings.endGroup(); } void AniAdd::createGui() diff --git a/aniadd.h b/aniadd.h index 31e509d..76681e2 100644 --- a/aniadd.h +++ b/aniadd.h @@ -12,6 +12,9 @@ class AniAdd : public QApplication Q_PROPERTY(QString lastDirectory READ lastDirectory WRITE setLastDirectory); Q_PROPERTY(FileModel *fileModel READ fileModel); + Q_PROPERTY(QString renameEnv READ renameEnv WRITE setRenameEnv); + Q_PROPERTY(bool filterResults READ filterResults WRITE setFilterResults); + public: explicit AniAdd(int &argc, char **argv); ~AniAdd(); @@ -21,6 +24,12 @@ public: FileModel *fileModel() const; + QString renameEnv() const; + void setRenameEnv(const QString &renameEnv); + + bool filterResults() const; + void setFilterResults(bool filterResults); + signals: public slots: @@ -39,6 +48,9 @@ private: QString m_lastDirectory; + QString m_renameEnv; + bool m_filterResults; + FileModel *model; MainWindow *gui; diff --git a/anidbconfigdialog.cpp b/anidbconfigdialog.cpp new file mode 100644 index 0000000..dfe9172 --- /dev/null +++ b/anidbconfigdialog.cpp @@ -0,0 +1,77 @@ +#include "anidbconfigdialog.h" +#include "ui_anidbconfigdialog.h" + +#include + +AniDBConfigDialog::AniDBConfigDialog(QWidget *parent) : + QDialog(parent), + m_ui(new Ui::AniDBConfigDialog) +{ + m_ui->setupUi(this); +} + +QString AniDBConfigDialog::host() const +{ + return m_ui->host->text(); +} + +void AniDBConfigDialog::setHost(const QString &host) +{ + m_ui->host->setText(host); +} + +quint16 AniDBConfigDialog::hostPort() const +{ + return m_ui->hostPort->value(); +} + +void AniDBConfigDialog::setHostPort(quint16 port) +{ + m_ui->hostPort->setValue(port); +} + +quint16 AniDBConfigDialog::localPort() const +{ + return m_ui->localPort->value(); +} + +void AniDBConfigDialog::setLocalPort(quint16 port) +{ + m_ui->localPort->setValue(port); +} + +QString AniDBConfigDialog::user() const +{ + return m_ui->user->text(); +} + +void AniDBConfigDialog::setUser(const QString &user) +{ + m_ui->user->setText(user); +} + +QString AniDBConfigDialog::pass() const +{ + return m_ui->pass->text(); +} + +void AniDBConfigDialog::setPass(const QString &pass) +{ + m_ui->pass->setText(pass); +} + +AniDBConfigDialog::~AniDBConfigDialog() +{ + delete m_ui; +} + +void AniDBConfigDialog::changeEvent(QEvent *e) +{ + switch (e->type()) { + case QEvent::LanguageChange: + m_ui->retranslateUi(this); + break; + default: + break; + } +} diff --git a/anidbconfigdialog.h b/anidbconfigdialog.h new file mode 100644 index 0000000..a2b2cfe --- /dev/null +++ b/anidbconfigdialog.h @@ -0,0 +1,41 @@ +#ifndef ANIDBCONFIGDIALOG_H +#define ANIDBCONFIGDIALOG_H + +#include + +namespace Ui { + class AniDBConfigDialog; +} + +class AniDBConfigDialog : public QDialog { + Q_OBJECT + Q_DISABLE_COPY(AniDBConfigDialog) + +public: + explicit AniDBConfigDialog(QWidget *parent = 0); + virtual ~AniDBConfigDialog(); + + QString host() const; + void setHost(const QString &host); + + quint16 hostPort() const; + void setHostPort(quint16 port); + + quint16 localPort() const; + void setLocalPort(quint16 port); + + QString user() const; + void setUser(const QString &user); + + QString pass() const; + void setPass(const QString &pass); + +protected: + virtual void changeEvent(QEvent *e); + +private: + Ui::AniDBConfigDialog *m_ui; + +}; + +#endif // ANIDBCONFIGDIALOG_H diff --git a/anidbconfigdialog.ui b/anidbconfigdialog.ui new file mode 100644 index 0000000..bb881fc --- /dev/null +++ b/anidbconfigdialog.ui @@ -0,0 +1,165 @@ + + + AniDBConfigDialog + + + + 0 + 0 + 400 + 300 + + + + AniDB Config + + + + + + AniDB Connection Settings + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Host: + + + host + + + + + + + + + + Port: + + + hostPort + + + + + + + 1024 + + + 65536 + + + 9000 + + + + + + + Local Port: + + + localPort + + + + + + + 1024 + + + 65536 + + + 9001 + + + + + + + User: + + + user + + + + + + + + + + Password: + + + pass + + + + + + + QLineEdit::Password + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AniDBConfigDialog + accept() + + + 257 + 290 + + + 157 + 274 + + + + + buttonBox + rejected() + AniDBConfigDialog + reject() + + + 325 + 290 + + + 286 + 274 + + + + + diff --git a/filemodel.cpp b/filemodel.cpp index 6716922..d6728fd 100644 --- a/filemodel.cpp +++ b/filemodel.cpp @@ -1,14 +1,43 @@ #include "filemodel.h" -FileModel::FileModel(QObject *parent) : QAbstractTableModel(parent) +#include + +#include + +#include + +FileModel::FileModel(QObject *parent) : QAbstractTableModel(parent), renameDelegate(new AniDBUdpClient::FileRenameDelegate()) { + signalMapper = new QSignalMapper(this); + QHash roles; roles[FileName] = "fileName"; + roles[HashingProgress] = "hashingProgress"; roles[HashingState] = "hashingState"; roles[RenamingState] = "renamingState"; roles[AddingState] = "addingState"; roles[MarkingState] = "markingState"; setRoleNames(roles); + + renameDelegate->setRenameEngine(new RenameParser::RenameEngine()); + + connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(updateState(int))); +} + +FileModel::~FileModel() +{ + qDeleteAll(files); + delete renameDelegate; +} + +RenameParser::RenameEngine *FileModel::renameEngine() const +{ + return renameDelegate->renameEngine(); +} + +void FileModel::setRenameEngine(RenameParser::RenameEngine *renameEngine) +{ + renameDelegate->setRenameEngine(renameEngine); } void FileModel::addFile(const QFileInfo &file) @@ -22,9 +51,10 @@ void FileModel::addFiles(const QFileInfoList &files) { AniDBUdpClient::File *f = new AniDBUdpClient::File(file); - connect(f, SIGNAL(statusUpdate(AniDBUdpClient::File::Action,AniDBUdpClient::File::ActionState)), this, SLOT(updateState())); - this->files << f; + f->setRenameDelegate(renameDelegate); + connect(f, SIGNAL(statusUpdate(AniDBUdpClient::File::Action,AniDBUdpClient::File::ActionState,int)), signalMapper, SLOT(map())); + signalMapper->setMapping(f, this->files.size() - 1); } reset(); } @@ -42,6 +72,18 @@ void FileModel::addDirectories(const QList &directories) } } +void FileModel::removeAt(int index) +{ + if (index < 0 || index >= rowCount()) + return; + + beginRemoveRows(QModelIndex(), index, index); + signalMapper->removeMappings(files.at(index)); + files.removeAt(index); + endRemoveRows(); +} + + void FileModel::removeItems(const QModelIndexList &items) { QModelIndexList sorted = items; @@ -49,6 +91,7 @@ void FileModel::removeItems(const QModelIndexList &items) for (QModelIndexList::const_iterator i = sorted.constEnd()-1; i != sorted.constBegin(); --i) { + signalMapper->removeMappings(files.at(i->row())); files.removeAt(i->row()); } files.removeAt(sorted[0].row()); @@ -89,6 +132,8 @@ QVariant FileModel::data(const QModelIndex &index, int role) const case FileName: return f->file().fileName(); break; + case HashingProgress: + return f->hashingProgress(); case HashingState: return f->hashingState(); break; @@ -150,21 +195,12 @@ QVariant FileModel::headerData(int section, Qt::Orientation orientation, int rol return QVariant(); } -void FileModel::updateState() +void FileModel::updateState(int row) { - using AniDBUdpClient::File; - - File *file = qobject_cast(sender()); - if (!file) + if (row < 0 || row >= rowCount()) return; - int i = files.indexOf(file); - - if (i == -1) - return; - - emit dataChanged(index(i, 0), index(i, columnCount())); - + emit dataChanged(index(row, 0), index(row, columnCount() - 1)); } QVariant FileModel::getDescForActionState(AniDBUdpClient::File::ActionState actionState, int role) const diff --git a/filemodel.h b/filemodel.h index cb76ffb..aa8e110 100644 --- a/filemodel.h +++ b/filemodel.h @@ -7,6 +7,16 @@ #include +class QSignalMapper; + +namespace RenameParser { + class RenameEngine; +} +namespace AniDBUdpClient +{ + class FileRenameDelegate; +} + class FileModel : public QAbstractTableModel { Q_OBJECT @@ -15,6 +25,7 @@ public: enum Roles { FileName = Qt::UserRole + 1, + HashingProgress, HashingState, RenamingState, AddingState, @@ -22,6 +33,11 @@ public: }; FileModel(QObject *parent = 0); + ~FileModel(); + + RenameParser::RenameEngine *renameEngine() const; + void setRenameEngine(RenameParser::RenameEngine *renameEngine); + public slots: void addFile(const QFileInfo &file); @@ -30,6 +46,7 @@ public slots: void addDirectory(const QDir &directory); void addDirectories(const QList &directories); + void removeAt(int index); void removeItems(const QModelIndexList &items); void start(); @@ -46,12 +63,17 @@ protected: bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); */ private slots: - void updateState(); + void updateState(int row); private: QVariant getDescForActionState(AniDBUdpClient::File::ActionState actionState, int role) const; QList files; - QMap progressDetails; + + AniDBUdpClient::FileRenameDelegate *renameDelegate; + + QSignalMapper *signalMapper; + + int objectId; }; #endif // FILEMODEL_H diff --git a/main.cpp b/main.cpp index 3847f2f..4bb4d48 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,10 @@ int main(int argc, char *argv[]) { + AniAdd::setApplicationName(QLatin1String("AniAdd")); + AniAdd::setOrganizationName(QLatin1String("APTX")); + AniAdd::setApplicationVersion(QLatin1String("1.0.0A1")); + AniAdd app(argc, argv); return app.exec(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 328914f..f469bc2 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2,29 +2,44 @@ #include "ui_mainwindow.h" #include +#include +#include + +#include + +#include #include "aniadd.h" #include "filemodel.h" +#include "anidbconfigdialog.h" +#include "renamesettingsdialog.h" + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), - ui(new Ui::MainWindow) + ui(new Ui::MainWindow), m_selectedIndex(-1) { ui->setupUi(this); + setWindowTitle("AniAdd"); QDeclarativeContext *ctxt = ui->declarativeView->rootContext(); - ctxt->setContextProperty("renameTool", qApp); -// ctxt->setContextProperty("fileModel", qApp->fileModel()); + ctxt->setContextProperty("aniAdd", qApp); + ctxt->setContextProperty("mainWindow", this); + 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); + ui->declarativeView->setViewport(new QGLWidget()); connect(ui->actionQuit, SIGNAL(triggered()), qApp, SLOT(quit())); + + QDeclarativeProperty p( ui->declarativeView->rootObject()); + qDebug() << p.read().toString(); } MainWindow::~MainWindow() @@ -47,7 +62,65 @@ void MainWindow::on_actionStart_triggered() qApp->fileModel()->start(); } -void MainWindow::on_actionRemoveSelectedFiles_triggered() +void MainWindow::on_actionRemoveSelectedFile_triggered() +{ + qApp->fileModel()->removeAt(m_selectedIndex); + setSelectedIndex(-1); +} + +void MainWindow::on_actionSettings_triggered() { - //model->removeItems(ui->tableView->selectionModel()->selectedIndexes()); + AniDBConfigDialog dialog(this); + + dialog.setHost(AniDBUdpClient::Client::instance()->host()); + dialog.setHostPort(AniDBUdpClient::Client::instance()->hostPort()); + dialog.setLocalPort(AniDBUdpClient::Client::instance()->localPort()); + dialog.setUser(AniDBUdpClient::Client::instance()->user()); + dialog.setPass(AniDBUdpClient::Client::instance()->pass()); + + if (!dialog.exec()) + { + return; + } + + AniDBUdpClient::Client::instance()->disconnect(); + + AniDBUdpClient::Client::instance()->setHost(dialog.host()); + AniDBUdpClient::Client::instance()->setHostPort(dialog.hostPort()); + AniDBUdpClient::Client::instance()->setLocalPort(dialog.localPort()); + AniDBUdpClient::Client::instance()->setUser(dialog.user()); + AniDBUdpClient::Client::instance()->setPass(dialog.pass()); +} + +int MainWindow::selectedIndex() const +{ + return m_selectedIndex; +} + +void MainWindow::setSelectedIndex(int index) +{ + if (m_selectedIndex == index) + return; + m_selectedIndex = index; + emit selectedIndexChanged(); +} + +void MainWindow::on_actionRenameScript_triggered() +{ + RenameSettingsDialog dialog; + + dialog.setRenameEnv(qApp->renameEnv()); + dialog.setParserType(qApp->fileModel()->renameEngine()->currentParserType()); + dialog.setRenameString(qApp->fileModel()->renameEngine()->renameString()); + dialog.setFilterResults(qApp->filterResults()); + + if (!dialog.exec()) + { + return; + } + + qApp->setRenameEnv(dialog.renameEnv()); + qApp->fileModel()->renameEngine()->setCurrentParserType(dialog.parserType()); + qApp->fileModel()->renameEngine()->parse(dialog.renameString()); + qApp->setFilterResults(dialog.filterResults()); } diff --git a/mainwindow.h b/mainwindow.h index 818a6ee..ad899a4 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -12,19 +12,30 @@ class AniAdd; class MainWindow : public QMainWindow { + Q_PROPERTY(int selectedIndex READ selectedIndex WRITE setSelectedIndex NOTIFY selectedIndexChanged()); Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); + int selectedIndex() const; + void setSelectedIndex(int index); + private slots: void on_actionAddFiles_triggered(); void on_actionAddDirectories_triggered(); void on_actionStart_triggered(); - void on_actionRemoveSelectedFiles_triggered(); + void on_actionRemoveSelectedFile_triggered(); + + void on_actionSettings_triggered(); + + void on_actionRenameScript_triggered(); + +signals: + void selectedIndexChanged(); private: void saveSettings(); @@ -32,10 +43,11 @@ private: QString lastDirectory; - FileModel *model; AniAdd *aniAdd; Ui::MainWindow *ui; + + int m_selectedIndex; }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 28a48b3..875a6d2 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -11,7 +11,7 @@ - MainWindow + AniAdd @@ -42,6 +42,9 @@ + + + @@ -56,7 +59,9 @@ - + + + @@ -100,14 +105,32 @@ Ctrl+S - + - Remove Selected Files + Remove Selected File Del + + + &Settings... + + + + + &Clear all Files + + + Ctrl+Shift+Del + + + + + Rename Script... + + diff --git a/qml/AniAdd/Components/FileDelegate.qml b/qml/AniAdd/Components/FileDelegate.qml new file mode 100644 index 0000000..f554355 --- /dev/null +++ b/qml/AniAdd/Components/FileDelegate.qml @@ -0,0 +1,136 @@ +import Qt 4.7 + +Component { + Item { + id: wrapper + + property bool open: false + + height: 50 + width: wrapper.ListView.view.width - 10 + anchors.horizontalCenter: parent.horizontalCenter + + MouseArea { + anchors.fill: parent + onClicked: { + mainWindow.selectedIndex = mainWindow.selectedIndex == index ? -1 : index + } + } + + Rectangle { + id: bg + x: 2 + y: 2 + + width: parent.width - 2 * x + height: parent.height - 2 * y + + radius: 10 + + border.width: 0 + border.color: "#000000" + opacity: 0.84 + + gradient: Gradient { + GradientStop { + position: 0 + color: "#ffffff" + } + GradientStop { + position: 0.85 + color: "#ababab" + } + GradientStop { + position: 1 + color: "#ffffff" + } + } + + Item { + anchors.leftMargin: 10 + anchors.rightMargin: 10 + anchors.fill: parent + Text { + id: fileNameText + + y: parent.height / 2 - height / 2 + width: parent.width - statusIndicators.width - 5 + + elide: Text.ElideMiddle + font.pointSize: 10 + text: fileName + } + + Text { + y: fileNameText.y + fileNameText.height + 5 + id: oldFileNameText + text: renamingState == 4 ? "Old name: " + "foobar.zaz" : "Not renamed yet" + opacity: 0 + } + + Row { + id: statusIndicators + spacing: 5 + anchors.right: parent.right + y: parent.height / 2 - height / 2 + + ProgressBar { + progress: hashingProgress + } + StatusIndicator { + id: renamingStatus + idChar: "R" + state: renamingState + } + StatusIndicator { + id: addingStatus + idChar: "A" + state: addingState + } + } + } + } + states: [ + State { + when: mainWindow.selectedIndex == index + PropertyChanges { + target: wrapper + height: 100 + } + PropertyChanges { + target: fileNameText + y: 10 + width: fileNameText.parent.width + } + PropertyChanges { + target: statusIndicators + y: statusIndicators.parent.height - statusIndicators.height - 10 + } + PropertyChanges { + target: oldFileNameText + opacity: 1 + } + } + ] + + transitions: [ + Transition { + PropertyAnimation { + properties: "x,y,height,width,opacity"; easing.type: Easing.InOutQuad; duration: 300 + } + } + ] + + ListView.onAdd: SequentialAnimation { + PropertyAction { target: wrapper; property: "y"; value: wrapper.ListView.y + wrapper.ListView.height } + NumberAnimation { target: wrapper; property: "y"; to: 0; duration: 250; easing.type: Easing.InOutQuad } + } + + ListView.onRemove: SequentialAnimation { + PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: true } + NumberAnimation { target: wrapper; property: "height"; to: 0; duration: 250; easing.type: Easing.InOutQuad } + PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: false } + } + } +} + diff --git a/qml/AniAdd/Components/ProgressBar.qml b/qml/AniAdd/Components/ProgressBar.qml new file mode 100644 index 0000000..71cc38f --- /dev/null +++ b/qml/AniAdd/Components/ProgressBar.qml @@ -0,0 +1,45 @@ +import Qt 4.7 + +Item { + id: progressBar + + property variant progress: 0 + + width: 100 + height: 20 + + Rectangle { + id: bg + + radius: 5 + + color: "#000000" + opacity: 0.6 + anchors.fill: parent + } + + Rectangle { + id: bar + + property variant borderWidth: 2 + + x: bg.x + borderWidth + y: bg.y + borderWidth + width: (progress * bg.width / 100) - (progress > 1 ? borderWidth * 2 : 0) + height: bg.height - borderWidth * 2 + + radius: width < 10 ? 0 : 5 + + color: "#22AA33" + opacity: 0.6 + } + + Text { + id: progressText + text: progress + "%" + + anchors.centerIn: bg + + color: "#FFFFFF" + } +} diff --git a/qml/AniAdd/Components/StatusIndicator.qml b/qml/AniAdd/Components/StatusIndicator.qml new file mode 100644 index 0000000..d4dbf66 --- /dev/null +++ b/qml/AniAdd/Components/StatusIndicator.qml @@ -0,0 +1,80 @@ +import Qt 4.7 +Item { + id: wrapper + + property variant idChar: "" + property variant state: 1 + + width: 20 + height: 20 + + Rectangle { + + id: bg + + anchors.fill: parent + + radius: 5 + + color: "#000000" + opacity: 0.6 + } + + Rectangle { + id: statusIndicator + + x: 2 + y: 2 + width: bg.width - x * 2 + height: bg.height - y * 2 + anchors.fill: bg + anchors.margins: x + + radius: 5 + opacity: 0.6 + + color: "#ADD8E6" + + } + + Text { + id: idText + text: idChar + + anchors.centerIn: bg + + color: "#FFFFFF" + } + + states: [ + State { + when: state == 2 + PropertyChanges { + target: statusIndicator + color: "#FFFF00" + + } + }, + State { + when: state == 4 + PropertyChanges { + target: statusIndicator + color: "#22AA33" + + } + }, + State { + when: state == 8 + PropertyChanges { + target: statusIndicator + color: "#FF0000" + + } + } + ] + transitions: [ + Transition { + ColorAnimation { duration: 200 } + } + ] +} diff --git a/qml/AniAdd/Components/qmldir b/qml/AniAdd/Components/qmldir new file mode 100644 index 0000000..ecdf5fe --- /dev/null +++ b/qml/AniAdd/Components/qmldir @@ -0,0 +1 @@ +FileDelegate 1.0 FileDelegate.qml \ No newline at end of file diff --git a/qml/AniAdd/FileDelegate.qml b/qml/AniAdd/FileDelegate.qml deleted file mode 100644 index 27cf382..0000000 --- a/qml/AniAdd/FileDelegate.qml +++ /dev/null @@ -1,31 +0,0 @@ -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 - } - } - -} diff --git a/qml/AniAdd/images/bgchar.svg b/qml/AniAdd/images/bgchar.svg new file mode 100644 index 0000000..8907588 --- /dev/null +++ b/qml/AniAdd/images/bgchar.svg @@ -0,0 +1,2563 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/qml/AniAdd/main.qml b/qml/AniAdd/main.qml index fd1d249..70d1e0c 100644 --- a/qml/AniAdd/main.qml +++ b/qml/AniAdd/main.qml @@ -1,8 +1,11 @@ import Qt 4.7 +import "Components" 1.0 as Components Rectangle { id: main + property variant foo: "I has a value"; + width: 600; height: 400 color: "#b7e0ff" @@ -15,7 +18,7 @@ Rectangle { { fileName: "Kaichou wa Maid-sama! - 18 - Even the Maid`s a Footman - [FFFpeeps](40cef62d).mkv" - hashProgress: 20 + hashingProgress: 20 hashingState: 1 renamingState: 1 addingState: 2 @@ -25,7 +28,7 @@ Rectangle { { fileName: "K-On!! - 07 - Tea Party! - [CoalGuys](f58a5866).mkv" - hashProgress: 0 + hashingProgress: 0 hashingState: 0 renamingState: 0 addingState: 0 @@ -35,13 +38,146 @@ Rectangle { { fileName: "Mayoi Neko Overrun! - 11 - The Stray Cats Fell Apart - [Ryuumaru](62a47da4).mkv" - hashProgress: 100 + hashingProgress: 100 + hashingState: 1 + renamingState: 1 + addingState: 1 + } + + ListElement + { + fileName: "Kaichou wa Maid-sama! - 18 - Even the Maid`s a Footman - [FFFpeeps](40cef62d).mkv" + + hashingProgress: 20 + hashingState: 1 + renamingState: 1 + addingState: 2 + } + + ListElement + { + fileName: "K-On!! - 07 - Tea Party! - [CoalGuys](f58a5866).mkv" + + hashingProgress: 0 + hashingState: 0 + renamingState: 0 + addingState: 0 + } + + ListElement + { + fileName: "Mayoi Neko Overrun! - 11 - The Stray Cats Fell Apart - [Ryuumaru](62a47da4).mkv" + + hashingProgress: 100 + hashingState: 1 + renamingState: 1 + addingState: 1 + } + ListElement + { + fileName: "Kaichou wa Maid-sama! - 18 - Even the Maid`s a Footman - [FFFpeeps](40cef62d).mkv" + + hashingProgress: 20 + hashingState: 1 + renamingState: 1 + addingState: 2 + } + + ListElement + { + fileName: "K-On!! - 07 - Tea Party! - [CoalGuys](f58a5866).mkv" + + hashingProgress: 0 + hashingState: 0 + renamingState: 8 + addingState: 0 + } + + ListElement + { + fileName: "Mayoi Neko Overrun! - 11 - The Stray Cats Fell Apart - [Ryuumaru](62a47da4).mkv" + + hashingProgress: 100 hashingState: 1 renamingState: 1 addingState: 1 } + ListElement + { + fileName: "Kaichou wa Maid-sama! - 18 - Even the Maid`s a Footman - [FFFpeeps](40cef62d).mkv" + + hashingProgress: 20 + hashingState: 1 + renamingState: 1 + addingState: 2 + } + + ListElement + { + fileName: "K-On!! - 07 - Tea Party! - [CoalGuys](f58a5866).mkv" + + hashingProgress: 0 + hashingState: 0 + renamingState: 4 + addingState: 8 + } + + ListElement + { + fileName: "Mayoi Neko Overrun! - 11 - The Stray Cats Fell Apart - [Ryuumaru](62a47da4).mkv" + + hashingProgress: 100 + hashingState: 1 + renamingState: 1 + addingState: 1 + } + ListElement + { + fileName: "Kaichou wa Maid-sama! - 18 - Even the Maid`s a Footman - [FFFpeeps](40cef62d).mkv" + + hashingProgress: 20 + hashingState: 1 + renamingState: 1 + addingState: 2 + } + + ListElement + { + fileName: "K-On!! - 07 - Tea Party! - [CoalGuys](f58a5866).mkv" + + hashingProgress: 0 + hashingState: 0 + renamingState: 0 + addingState: 0 + } + + ListElement + { + fileName: "Mayoi Neko Overrun! - 11 - The Stray Cats Fell Apart - [Ryuumaru](62a47da4).mkv" + + hashingProgress: 100 + hashingState: 1 + renamingState: 1 + addingState: 1 + } + + } + + Image { + id: bgCharImage + source: "images/bgchar.svg" + + property variant aspectRatio: 0.56839 + + fillMode: Image.Stretch + smooth: true + + y: height < parent.height ? parent.height - height : 0 + width: parent.width + height: width / aspectRatio } +/* Image { id: bgCharImage source: "images/bgchar.png" @@ -69,12 +205,16 @@ Rectangle { x: calcX() y: calcY() } - +*/ ListView { id: listView + anchors.fill: parent - model: testModel - delegate: FileDelegate + model: fileModel + delegate: Components.FileDelegate {} + footer: Item { + width: listView.width + height: listView.height / 2 + } } - } diff --git a/renamesettingsdialog.cpp b/renamesettingsdialog.cpp new file mode 100644 index 0000000..b6bc957 --- /dev/null +++ b/renamesettingsdialog.cpp @@ -0,0 +1,205 @@ +#include "renamesettingsdialog.h" +#include "ui_renamesettingsdialog.h" + +static const char *rulesStrAniAdd = + "AT := [%ATr%, %ATe%, %ATk%]\n" + "ET := [%ETe%, %ETr%, %ETk%]\n" + "GT := \"[\" [%GTs%, %GTl%] \"]\"\n" + "EpNoPad := $pad(%EpNo%, $max($len(%EpHiNo%), $len(%EpCount%)), \"0\")\n" + "SrcStyled := \"[\" %Source% \"]\"\n" + "isMovieType := {(%Type% = \"Movie\") ? \"True\" : \"False\"}\n" + "isDepr := {%Depr% ? \"[Depr]\" : \"\"}\n" + "isCen := {%Cen% ? \"[Cen]\" : \"\"}\n" + "VerStyled := %Ver% = \"1\" ? \"\" : \"v\" %Ver%\n" + "\n" + "FileName := %AT% \" \" %EpNoPad% %VerStyled% \" - \" %ET% \" \" %GT% %isDepr% %isCen% %SrcStyled%\n" + "PathName := \"E:\\Anime\\!Processed\\\" %AT%"; + +static const char *rulesStrAniAddNoCompat = + "AT := [ATr, ATe, ATk]\n" + "ET := [ETe, ETr, ETk]\n" + "GT := \"[\" [GTs, GTl] \"]\"\n" + "EpNoPad := $pad(EpNo, $max($len(EpHiNo), $len(EpCount)), 0)\n" + "SrcStyled := \"[\" Source \"]\"\n" + "isMovieType := Type = \"Movie\" ? \"True\" : \"False\"\n" + "isDepr := Depr ? \"[Depr]\" : \"\"\n" + "isCen := Cen ? \"[Cen]\" : \"\"\n" + "VerStyled := Ver = 1 ? \"\" : \"v\" Ver\n" + "\n" + "FileName := AT \" \" EpNoPad VerStyled \" - \" ET \" \" GT isDepr isCen SrcStyled\n" + "PathName := \"E:\\Anime\\!Processed\\\" AT"; + +static const char *rulesStrECMA = + "var AT = alt(ATr, ATe, ATk);\n" + "var ET = alt(ETe, ETr, ETk);\n" + "var GT = \"[\" + alt(GTs, GTl) + \"]\";\n" + "var EpNoPad = pad(EpNo, max(len(EpHiNo), len(EpCount)), \"0\");\n" + "var SrcStyled = \"[\" + Source + \"]\";\n" + "\n" + "var isMovieType = (Type == \"Movie\") ? \"True\" : \"False\";\n" + "var isDepr = parseInt(Depr) ? \"[Depr]\" : \"\";\n" + "var isCen = parseInt(Cen) ? \"[Cen]\" : \"\";\n" + "var VerStyled = Ver == \"1\" ? \"\" : \"v\" + Ver;\n" + "\n" + "var FileName = AT + \" \" + EpNoPad + VerStyled + \" - \" + ET + \" \" + GT + isDepr + isCen + SrcStyled;\n" + "var PathName = \"E:\\\\Anime\\\\!Processed\\\\\" + AT;"; + +static const char *envStrAniAdd = + "ATr := \"Suzumiya Haruhi no Yuuutsu (2009)\"\n" + "ATe := \"The Melancholy of Haruhi Suzumiya (2009)\"\n" + "ATk := \"涼宮ハルヒの憂鬱 (2009)\"\n" + "ETr := \"Sasa no Ha Rhapsody\"\n" + "ETe := \"Bamboo Leaf Rhapsody\"\n" + "ETk := \"笹の葉ラプソディ\"\n" + "GTs := \"a.f.k.\"\n" + "GTl := \"a.f.k. (Long)\"\n" + "EpNo := \"1\"\n" + "EpHiNo := \"1\"\n" + "EpCount := \"1\"\n" + "Type := \"TV\"\n" + "Depr := \"0\"\n" + "Cen := \"0\"\n" + "Ver := \"1\"\n" + "Source := \"HDTV\""; + +static const char *envStrECMA = + "var ATr = \"Suzumiya Haruhi no Yuuutsu (2009)\";\n" + "var ATe = \"The Melancholy of Haruhi Suzumiya (2009)\";\n" + "var ATk = \"涼宮ハルヒの憂鬱 (2009)\";\n" + "var ETr = \"Sasa no Ha Rhapsody\";\n" + "var ETe = \"Bamboo Leaf Rhapsody\";\n" + "var ETk = \"笹の葉ラプソディ\";\n" + "var GTs = \"a.f.k.\";\n" + "var GTl = \"a.f.k. (Long)\";\n" + "var EpNo = 1;\n" + "var EpHiNo = 1;\n" + "var EpCount = 1;\n" + "var Type = \"TV\";\n" + "var Depr = 0;\n" + "var Cen = 0;\n" + "var Ver = 1;\n" + "var Source = \"HDTV\";"; + + +RenameSettingsDialog::RenameSettingsDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::RenameSettingsDialog) +{ + ui->setupUi(this); + + environmentEngine = new RenameParser::RenameEngine; + rulesEngine = new RenameParser::RenameEngine; + + ui->input->setPlainText(QString::fromUtf8(envStrAniAdd)); + ui->renameScript->setPlainText(rulesStrAniAdd); + + QStringList parsers; + parsers << "AniAdd" + << "ECMAScript"; + + ui->scriptLanguage->addItems(parsers); +} + +RenameSettingsDialog::~RenameSettingsDialog() +{ + delete ui; +} + +QString RenameSettingsDialog::renameEnv() const +{ + return ui->input->toPlainText(); +} + +void RenameSettingsDialog::setRenameEnv(const QString &renameEnv) +{ + ui->input->setPlainText(renameEnv); +} + +bool RenameSettingsDialog::filterResults() const +{ + return ui->filterResultsCheckbox->isChecked(); +} + +void RenameSettingsDialog::setFilterResults(bool filterResults) +{ + ui->filterResultsCheckbox->setChecked(filterResults); +} + +RenameParser::RenameEngine::ParserType RenameSettingsDialog::parserType() const +{ + return RenameParser::RenameEngine::ParserType(ui->scriptLanguage->currentIndex()); +} + +void RenameSettingsDialog::setParserType(RenameParser::RenameEngine::ParserType parserType) +{ + ui->scriptLanguage->setCurrentIndex(parserType); +} + + +void RenameSettingsDialog::on_input_textChanged() +{ + bool success = environmentEngine->parse(ui->input->toPlainText() + "\n"); + + RenameParser::Environment newEnv; + environmentEngine->evaluate(newEnv); + env = newEnv; + + rulesEngine->evaluate(newEnv); + updateResult(newEnv); +} + +void RenameSettingsDialog::on_renameScript_textChanged() +{ + RenameParser::Environment newEnv = env; + + bool success = rulesEngine->parse(ui->renameScript->toPlainText() + "\n"); + + rulesEngine->evaluate(newEnv); + updateResult(newEnv); + +} + +void RenameSettingsDialog::on_scriptLanguage_currentIndexChanged() +{ + rulesEngine->setCurrentParserType(RenameParser::RenameEngine::ParserType(ui->scriptLanguage->currentIndex())); + on_input_textChanged(); +} + +void RenameSettingsDialog::updateResult(const RenameParser::Environment &env) +{ + QString s; + if (ui->filterResultsCheckbox->isChecked()) + { + s += "FileName := \"" + env["FileName"] + "\"\n"; + s += "PathName := \"" + env["PathName"] + "\""; + } + else + { + for (RenameParser::Environment::const_iterator i = env.constBegin(); i != env.constEnd(); ++i) + { + s += i.key() + " := \"" + i.value() + "\"\n"; + } + } + ui->result->setPlainText(s); +} + +void RenameSettingsDialog::on_filterResultsCheckbox_toggled() +{ + on_renameScript_textChanged(); +} + +QString RenameSettingsDialog::renameString() const +{ + return ui->renameScript->toPlainText(); +} + +void RenameSettingsDialog::setRenameString(const QString &renameScript) +{ + ui->renameScript->setPlainText(renameScript); +} + +void RenameSettingsDialog::on_buttonBox_clicked(QAbstractButton *button) +{ + +} + diff --git a/renamesettingsdialog.h b/renamesettingsdialog.h new file mode 100644 index 0000000..5bd5a66 --- /dev/null +++ b/renamesettingsdialog.h @@ -0,0 +1,57 @@ +#ifndef RENAMESETTINGSDIALOG_H +#define RENAMESETTINGSDIALOG_H + +#include +#include + +namespace Ui { + class RenameSettingsDialog; +} + +class QAbstractButton; + +class RenameSettingsDialog : public QDialog +{ + Q_OBJECT + Q_PROPERTY(QString renameString READ renameString WRITE setRenameString) + +public: + explicit RenameSettingsDialog(QWidget *parent = 0); + ~RenameSettingsDialog(); + + QString renameString() const; + void setRenameString(const QString &renameString); + + QString renameEnv() const; + void setRenameEnv(const QString &renameEnv); + + bool filterResults() const; + void setFilterResults(bool filterResults); + + RenameParser::RenameEngine::ParserType parserType() const; + void setParserType(RenameParser::RenameEngine::ParserType parserType); + +public slots: + void on_input_textChanged(); + void on_renameScript_textChanged(); + + void on_scriptLanguage_currentIndexChanged(); + +private slots: + void on_filterResultsCheckbox_toggled(); + + void on_buttonBox_clicked(QAbstractButton *button); + +private: + void updateResult(const RenameParser::Environment &env); + + Ui::RenameSettingsDialog *ui; + + + RenameParser::RenameEngine *environmentEngine; + RenameParser::RenameEngine *rulesEngine; + + RenameParser::Environment env; +}; + +#endif // RENAMESETTINGSDIALOG_H diff --git a/renamesettingsdialog.ui b/renamesettingsdialog.ui new file mode 100644 index 0000000..4d60156 --- /dev/null +++ b/renamesettingsdialog.ui @@ -0,0 +1,145 @@ + + + RenameSettingsDialog + + + + 0 + 0 + 601 + 596 + + + + Rename Script + + + + + + + + Input + + + + + + + + + + + + Result + + + + + + + + + Only show FileName and PathName + + + true + + + + + + + + + + + + Rename Script + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Script Language: + + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults + + + + + + + + + buttonBox + accepted() + RenameSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + RenameSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +