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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/*********************************************************************************
NixNote - An open-source client for the Evernote service.
Copyright (C) 2014 Randy Baumgarte
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
***********************************************************************************/
#include "notehistoryselect.h"
#include <QDateTime>
#include "global.h"
extern Global global;
NoteHistorySelect::NoteHistorySelect(QWidget *parent) :
QDialog(parent)
{
importPressed = false;
this->setWindowTitle(tr("Note History"));
cancelButton.setText(tr("Cancel"));
importButton.setText(tr("Import"));
importButton.setEnabled(false);
replace = new QCheckBox();
replace->setCheckable(true);
replace->setChecked(false);
replace->setText(tr("Replace current note?"));
connect(&importButton, SIGNAL(clicked()), this, SLOT(importButtonPressed()));
connect(&cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonPressed()));
connect(&list, SIGNAL(itemSelectionChanged()), this, SLOT(enableImport()));
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QHBoxLayout *entryLayout = new QHBoxLayout(this);
entryLayout->addWidget(&list);
entryLayout->addWidget(&importButton);
mainLayout->addLayout(entryLayout);
mainLayout->addWidget(replace);
this->setLayout(mainLayout);
QHBoxLayout *buttonLayout = new QHBoxLayout(this);
buttonLayout->addWidget(&importButton);
buttonLayout->addWidget(&cancelButton);
mainLayout->addLayout(buttonLayout);
this->setFont(global.getGuiFont(font()));
}
void NoteHistorySelect::importButtonPressed() {
this->importPressed = true;
this->close();
}
void NoteHistorySelect::cancelButtonPressed() {
this->importPressed = false;
this->close();
}
void NoteHistorySelect::loadData(QList<NoteVersionId> &versions) {
// Add the current generation
QListWidgetItem *item = new QListWidgetItem(&list);
item->setData(Qt::UserRole, 0);
QString text = tr("Current copy on Evernote");
item->setText(text);
list.addItem(item);
this->versions = &versions;
for (int i=0; i<versions.size(); i++) {
QListWidgetItem *item = new QListWidgetItem(&list);
item->setData(Qt::UserRole, versions.at(i).updateSequenceNum);
QString text;
QDateTime timestamp;
timestamp.setTime_t(versions.at(i).saved/1000);
if (timestamp.date() == QDate::currentDate())
text = tr("Today") +" " + timestamp.time().toString(Qt::SystemLocaleShortDate);
if (timestamp.date() == QDate::currentDate().addDays(-1))
text = tr("Yesterday") +" " + timestamp.time().toString(Qt::SystemLocaleShortDate);
text = timestamp.toString(global.dateFormat + " " +global.timeFormat);
text = text + " : "+ versions.at(i).title;
item->setText(text);
list.addItem(item);
}
}
void NoteHistorySelect::enableImport() {
importButton.setEnabled(true);
usn = this->list.selectedItems().at(0)->data(Qt::UserRole).toInt();
}
bool NoteHistorySelect::replaceCurrentNote() {
return this->replace->isChecked();
}
|