Permalink
Browse files

Added 'Movie not found' message boxes and history feature

  • Loading branch information...
1 parent 4e91f6d commit a8ad7ce2c79c33fcecdb97f9ef4928e9ed22da17 @gnuvince committed Feb 24, 2011
View
@@ -1,6 +1,7 @@
#include <cmath>
#include "QDebug"
+#include "QMessageBox"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "imdb.h"
@@ -158,6 +159,13 @@ void MainWindow::dispatch(const QMap<QString, QStringList> &film, const QPixmap
// Full sized cover
emit film_set_full_sized_cover(get_field("full-size cover url", film));
+
+ if (film.size() <= 2) {
+ QMessageBox msgbox;
+ msgbox.setText(tr("Film introuvable."));
+ msgbox.setIcon(QMessageBox::Information);
+ msgbox.exec();
+ }
}
void MainWindow::search_film() {
@@ -1,6 +1,6 @@
#############################################################################
# Makefile for building: SimpleIMDB
-# Generated by qmake (2.01a) (Qt 4.7.0) on: Wed Feb 9 17:51:54 2011
+# Generated by qmake (2.01a) (Qt 4.7.0) on: Thu Feb 24 10:53:28 2011
# Project: ../SimpleIMDB/SimpleIMDB.pro
# Template: app
# Command: /opt/qtsdk-2010.05/qt/bin/qmake -spec /opt/qtsdk-2010.05/qt/mkspecs/linux-g++ CONFIG+=debug -o Makefile ../SimpleIMDB/SimpleIMDB.pro
@@ -1,7 +1,7 @@
/****************************************************************************
** Meta object code from reading C++ file 'mainwindow.h'
**
-** Created: Tue Feb 15 09:48:18 2011
+** Created: Thu Feb 24 11:05:01 2011
** by: The Qt Meta Object Compiler version 62 (Qt 4.7.0)
**
** WARNING! All changes made in this file will be lost!
@@ -23,7 +23,7 @@ static const uint qt_meta_data_MainWindow[] = {
5, // revision
0, // classname
0, 0, // classinfo
- 15, 14, // methods
+ 16, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
@@ -48,6 +48,7 @@ static const uint qt_meta_data_MainWindow[] = {
405, 394, 11, 11, 0x0a,
457, 11, 11, 11, 0x0a,
472, 327, 11, 11, 0x0a,
+ 511, 506, 11, 11, 0x0a,
0 // eod
};
@@ -67,6 +68,7 @@ static const char qt_meta_stringdata_MainWindow[] = {
"set_film_cover(QPixmap)\0film,image\0"
"field_dispatcher(QMap<QString,QStringList>,QPixmap)\0"
"search_movie()\0set_film_actors_slot(QStringList)\0"
+ "item\0load_existing_movie(QListWidgetItem*)\0"
};
const QMetaObject MainWindow::staticMetaObject = {
@@ -113,9 +115,10 @@ int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
case 12: field_dispatcher((*reinterpret_cast< const QMap<QString,QStringList>(*)>(_a[1])),(*reinterpret_cast< const QPixmap(*)>(_a[2]))); break;
case 13: search_movie(); break;
case 14: set_film_actors_slot((*reinterpret_cast< const QStringList(*)>(_a[1]))); break;
+ case 15: load_existing_movie((*reinterpret_cast< QListWidgetItem*(*)>(_a[1]))); break;
default: ;
}
- _id -= 15;
+ _id -= 16;
}
return _id;
}
@@ -1,7 +1,7 @@
/********************************************************************************
** Form generated from reading UI file 'mainwindow.ui'
**
-** Created: Tue Feb 15 09:48:34 2011
+** Created: Thu Feb 24 12:29:43 2011
** by: Qt User Interface Compiler version 4.7.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
@@ -67,12 +67,15 @@ class Ui_MainWindow
QLabel *film_genres;
QLabel *label_7;
QLabel *film_year;
+ QFrame *line_2;
+ QLabel *label_8;
+ QListWidget *history;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
- MainWindow->resize(455, 411);
+ MainWindow->resize(455, 496);
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(96);
sizePolicy.setVerticalStretch(96);
@@ -128,7 +131,8 @@ class Ui_MainWindow
sizePolicy1.setVerticalStretch(96);
sizePolicy1.setHeightForWidth(film_cover->sizePolicy().hasHeightForWidth());
film_cover->setSizePolicy(sizePolicy1);
- film_cover->setMinimumSize(QSize(0, 96));
+ film_cover->setMinimumSize(QSize(64, 96));
+ film_cover->setFrameShape(QFrame::Box);
horizontalLayout_2->addWidget(film_cover);
@@ -171,6 +175,7 @@ class Ui_MainWindow
film_plot = new QPlainTextEdit(centralWidget);
film_plot->setObjectName(QString::fromUtf8("film_plot"));
+ film_plot->setEnabled(false);
verticalLayout_3->addWidget(film_plot);
@@ -255,6 +260,24 @@ class Ui_MainWindow
verticalLayout_5->addLayout(verticalLayout_4);
+ line_2 = new QFrame(centralWidget);
+ line_2->setObjectName(QString::fromUtf8("line_2"));
+ line_2->setFrameShape(QFrame::HLine);
+ line_2->setFrameShadow(QFrame::Sunken);
+
+ verticalLayout_5->addWidget(line_2);
+
+ label_8 = new QLabel(centralWidget);
+ label_8->setObjectName(QString::fromUtf8("label_8"));
+
+ verticalLayout_5->addWidget(label_8);
+
+ history = new QListWidget(centralWidget);
+ history->setObjectName(QString::fromUtf8("history"));
+ history->setFlow(QListView::TopToBottom);
+
+ verticalLayout_5->addWidget(history);
+
MainWindow->setCentralWidget(centralWidget);
QWidget::setTabOrder(search_field, search_button);
QWidget::setTabOrder(search_button, film_plot);
@@ -290,6 +313,7 @@ class Ui_MainWindow
film_genres->setText(QString());
label_7->setText(QApplication::translate("MainWindow", "Ann\303\251e:", 0, QApplication::UnicodeUTF8));
film_year->setText(QString());
+ label_8->setText(QApplication::translate("MainWindow", "Historique", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
@@ -2,6 +2,7 @@
#include "ui_mainwindow.h"
#include "QDebug"
#include "QFile"
+#include "QMessageBox"
#include <cmath>
MainWindow::MainWindow(QWidget *parent) :
@@ -10,6 +11,7 @@ MainWindow::MainWindow(QWidget *parent) :
{
ui->setupUi(this);
imdb = new IMDb(this);
+ files = new QStringList;
connect(ui->search_button, SIGNAL(clicked()),
this, SLOT(search_movie()));
@@ -33,6 +35,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(this, SIGNAL(set_film_genres(const QString&)), ui->film_genres, SLOT(setText(QString)));
connect(this, SIGNAL(set_film_actors(const QStringList&)), this, SLOT(set_film_actors_slot(const QStringList&)));
connect(ui->search_field, SIGNAL(returnPressed()), ui->search_button, SIGNAL(clicked()));
+ connect(ui->history, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(load_existing_movie(QListWidgetItem*)));
}
MainWindow::~MainWindow()
@@ -78,7 +81,19 @@ void MainWindow::field_dispatcher(const QMap<QString, QStringList> &film, const
emit set_film_genres(film.value("genres", QStringList()).join(QString(", ")));
emit set_film_actors(film.value("cast", QStringList()));
- save_film(film);
+ if (film.size() <= 2) {
+ QMessageBox msgbox;
+ msgbox.setText(tr("Film introuvable."));
+ msgbox.setIcon(QMessageBox::Information);
+ msgbox.exec();
+ }
+ else {
+ QString filename = save_film(film);
+ if (!files->contains(filename)) {
+ files->append(filename);
+ ui->history->addItem(filename);
+ }
+ }
}
void MainWindow::set_film_actors_slot(const QStringList &actors) {
@@ -92,20 +107,22 @@ void MainWindow::search_movie() {
emit changeFilmInternet(title);
}
-void MainWindow::save_film(const QMap<QString, QStringList> &film) {
- QStringList fields = QStringList();
- fields << "title" << "rating" << "top 250 rank" << "countries"
- << "year" << "runtimes" << "plot outline" << "director"
- << "genres" << "cast" << "cover url";
- QString title = get_field("title", film).replace(QChar(' '), QChar('_'));
- QFile out(QString("/tmp/") + title);
+QString MainWindow::save_film(const QMap<QString, QStringList> &film) {
+ QString filename = get_field("title", film);
+ QFile out(QString("/tmp/") + filename);
if (out.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream stream(&out);
- foreach (QString field, fields) {
+ foreach (QString field, film.keys()) {
stream << field << " :\n";
foreach (QString info, film.value(field, QStringList())) {
stream << '\t' << info << "\n";
}
}
}
+ return filename;
+}
+
+void MainWindow::load_existing_movie(QListWidgetItem *item) {
+ QString filename = QString("/tmp/") + item->text();
+ imdb->changeFilmLocal(filename);
}
@@ -2,6 +2,7 @@
#define MAINWINDOW_H
#include <QMainWindow>
+#include <QtGui>
#include "imdb.h"
namespace Ui {
@@ -15,13 +16,14 @@ class MainWindow : public QMainWindow
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
- void save_film(const QMap<QString, QStringList> &film);
+ QString save_film(const QMap<QString, QStringList> &film);
public slots:
void field_dispatcher(const QMap<QString,QStringList> &film, const QPixmap &image);
void search_movie();
void set_film_actors_slot(const QStringList &actors);
+ void load_existing_movie(QListWidgetItem *item);
signals:
void changeFilmInternet(const QString &film);
@@ -40,6 +42,7 @@ public slots:
private:
Ui::MainWindow *ui;
IMDb *imdb;
+ QStringList *files;
};
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>455</width>
- <height>411</height>
+ <height>496</height>
</rect>
</property>
<property name="sizePolicy">
@@ -82,10 +82,13 @@
</property>
<property name="minimumSize">
<size>
- <width>0</width>
+ <width>64</width>
<height>96</height>
</size>
</property>
+ <property name="frameShape">
+ <enum>QFrame::Box</enum>
+ </property>
<property name="text">
<string/>
</property>
@@ -141,7 +144,11 @@
</layout>
</item>
<item>
- <widget class="QPlainTextEdit" name="film_plot"/>
+ <widget class="QPlainTextEdit" name="film_plot">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ </widget>
</item>
</layout>
</item>
@@ -238,6 +245,27 @@
</item>
</layout>
</item>
+ <item>
+ <widget class="Line" name="line_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_8">
+ <property name="text">
+ <string>Historique</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QListWidget" name="history">
+ <property name="flow">
+ <enum>QListView::TopToBottom</enum>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</widget>

0 comments on commit a8ad7ce

Please sign in to comment.