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 
30 DClass<IP2CUpdateBox> : public Ui::IP2CUpdateBox
31 {
32 };
33 
34 DPointered(IP2CUpdateBox)
35 
36 IP2CUpdateBox::IP2CUpdateBox(QWidget* parent)
37 : QDialog(parent)
38 {
39  d->setupUi(this);
40 
41  connect(d->btnUpdate, SIGNAL( clicked() ), this, SLOT( accept() ) );
42  connect(d->btnCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
43 
44  updateInfo();
45 }
46 
47 IP2CUpdateBox::~IP2CUpdateBox()
48 {
49 }
50 
51 void IP2CUpdateBox::updateInfo()
52 {
53  QString filePath = DoomseekerFilePaths::ip2cDatabase();
54 
55  d->lblIP2CFileLocation->setText(filePath);
56 
57  QFileInfo fileInfo(filePath);
58  if (fileInfo.exists())
59  {
60  QDateTime lastModified = fileInfo.lastModified();
61  QDateTime current = QDateTime::currentDateTime();
62 
63  int days = lastModified.daysTo(current);
64 
65  QString ageString = tr("This database is %n days old.", "", days);
66  d->lblDatabaseAge->setText(ageString);
67  }
68  else
69  {
70  d->lblDatabaseAge->setText(tr("This file cannot be found. Precompiled database will be used. Use update button if you want to fix this problem."));
71  }
72 
73 
74 
75 
76 }