ip2cupdatebox.cpp
1 //------------------------------------------------------------------------------
2 // ip2cupdatebox.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "ip2cupdatebox.h"
24 #include "ui_ip2cupdatebox.h"
25 
26 #include "doomseekerfilepaths.h"
27 
28 #include <QDateTime>
29 #include "ip2c/ip2cupdater.h"
30 
31 DClass<IP2CUpdateBox> : public Ui::IP2CUpdateBox
32 {
33 public:
34  IP2CUpdater *ip2cUpdater;
35 };
36 
37 DPointered(IP2CUpdateBox)
38 
39 IP2CUpdateBox::IP2CUpdateBox(QWidget* parent)
40 : QDialog(parent)
41 {
42  d->setupUi(this);
43 
44  connect(d->btnUpdate, SIGNAL( clicked() ), this, SLOT( accept() ) );
45  connect(d->btnCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
46  d->progressBar->hide();
47 
48  d->ip2cUpdater = new IP2CUpdater(this);
49  this->connect(d->ip2cUpdater, SIGNAL(updateNeeded(int)), SLOT(updateInfo(int)));
50  d->ip2cUpdater->needsUpdate(DoomseekerFilePaths::ip2cDatabase());
51 
52  start();
53 }
54 
55 IP2CUpdateBox::~IP2CUpdateBox()
56 {
57 }
58 
59 void IP2CUpdateBox::start()
60 {
61  QString filePath = DoomseekerFilePaths::ip2cDatabase();
62 
63  d->lblIP2CFileLocation->setText(filePath);
64 
65  QFileInfo fileInfo(filePath);
66  if (fileInfo.exists())
67  {
68  d->lblDatabaseStatus->setText(tr("Verifying checksum ..."));
69  d->progressBar->show();
70  }
71  else
72  {
73  d->lblDatabaseStatus->setText(tr("IP2C database file was not found. "
74  "Precompiled database will be used. "
75  "Use update button if you want to download the newest database."));
76  }
77 }
78 
79 void IP2CUpdateBox::updateInfo(int status)
80 {
81  d->progressBar->hide();
82  switch (status)
83  {
84  case IP2CUpdater::UpdateNeeded:
85  d->lblDatabaseStatus->setText(tr("Update required."));
86  break;
87  case IP2CUpdater::UpToDate:
88  d->lblDatabaseStatus->setText(tr("Database is up-to-date."));
89  break;
90  case IP2CUpdater::UpdateCheckError:
91  d->lblDatabaseStatus->setText(tr("Database status check failed. See log for details."));
92  break;
93  default:
94  d->lblDatabaseStatus->setText(tr("Unhandled update check status."));
95  break;
96  }
97 }
IP2CUpdater is responsible for downloading a new version of database from the site.
Definition: ip2cupdater.h:40