summaryrefslogtreecommitdiffstats
path: root/moviemappingpage.cpp
blob: e7d8f45a782aa6eec006d99655d58ecad87f2683 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
  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 <QHBoxLayout>
#include <QSqlQuery>
#include <QSettings>

#include "moviemappingpage.h"
#include "newmoviewizard.h"
#include "smglobals.h"

MovieMappingPage::MovieMappingPage(const QString &table, QWidget *parent) : QWizardPage(parent), mTable(table){
    QString title = QString(tr("Edit %1")).arg(table);
    QString subTitle = QString(tr("Edit %1 by adding them from the text field below")).arg(table);
    setTitle(title);
    setSubTitle(subTitle);

    mWidget = new MappingEditorWidget(table, true);
    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addWidget(mWidget);

    setLayout(mainLayout);
}

void MovieMappingPage::initializePage(){
    QSqlDatabase db = QSqlDatabase::database("treedb");
    if(mTable.toLower() == "actors"){
        QStringList actors;
        QSqlQuery actorsQ("SELECT tactorname FROM actors", db);
        while(actorsQ.next()){
            actors << actorsQ.value(0).toString();
        }
        mWidget->fillCompleter(actors);
        mWidget->setDecorationItem(SmGlobals::instance()->iconFor("actor"));
        auto wiz = static_cast<NewMovieWizard*>(wizard());
        QStringList possibleActors = wiz->getPossibleActors();
        if(!possibleActors.empty()){
            mWidget->clear();
            mWidget->setCurrentItems(possibleActors);
        }
    }else if(mTable.toLower() == "genres"){
        QStringList genres;
        QSqlQuery genresQ("SELECT tgenrename FROM genres", db);
        while(genresQ.next()){
            genres << genresQ.value(0).toString();
        }
        mWidget->fillCompleter(genres);
        mWidget->setDecorationItem(SmGlobals::instance()->iconFor("genre"));
    }
    QSettings s;
    bool clearPage = s.value("ui/clearnewmoviewizard").toBool();
    if(clearPage){
        mWidget->clear();
    }
}