-
Notifications
You must be signed in to change notification settings - Fork 0
/
winhistory.cpp
executable file
·137 lines (118 loc) · 4.12 KB
/
winhistory.cpp
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "winhistory.h"
#include "ui_winhistory.h"
#include "window.h"
#include "config.h"
#include <QMainWindow>
#include <QSettings>
#include <QWidget>
#include <QLineEdit>
#include <QDebug>
#include <QMessageBox>
#include <QUrl>
#include <QDesktopServices>
#include <QDebug>
#include <QClipboard>
#include <QFile>
QString cImg;
QUrl url2;
QDesktopServices *dServ2;
winHistory::winHistory(QWidget *parent) : QMainWindow(parent), ui(new Ui::winHistory){
qDebug() << config::getWPath();
ui->setupUi(this);
hide();
strSearchBy = "title";
refreshList();
}
void winHistory::hideEvent(QHideEvent *eve){
config::winHistoryVisible = false;
}
void winHistory::hotkeyPressed(){
QMessageBox::information(this, "Good", "Hot key triggered", "yes", "no");
}
winHistory::~winHistory(){
delete ui;
}
void winHistory::resizeEvent(QResizeEvent *){
ui->centralwidget->resize(this->width(),this->height());
ui->tblHistory->resize(this->width(),this->height()-100);
}
void winHistory::refreshList(){
QSettings settings( config::getWPath() + "/history.ini", QSettings::IniFormat);
settings.beginGroup("history");
int size = settings.value("itemscount").toInt();
settings.endGroup();
ui->tblHistory->clearContents();
ui->tblHistory->setRowCount(size);
int i = 0;
int b = 0;
bool filtering = true;
while(filtering){
QString headd = "uploaded" + QString::number(b);
b++;
settings.beginGroup(headd);
if( ui->txtSearch->text().trimmed().length() == 0 ){
ui->tblHistory->setItem( i, 0, new QTableWidgetItem( settings.value("title").toString( ) ) );
ui->tblHistory->setItem( i, 1, new QTableWidgetItem( settings.value("desc").toString() ) );
ui->tblHistory->setItem( i, 2, new QTableWidgetItem( settings.value("date").toString() ) );
ui->tblHistory->setItem( i, 3, new QTableWidgetItem( settings.value("url").toString() ) );
if( b <= size){
i++;
}
} else {
if( settings.value(strSearchBy).toString().toLower().indexOf( ui->txtSearch->text().toLower(), 0 ) >= 0 ) {
ui->tblHistory->setItem( i, 0, new QTableWidgetItem( settings.value("title").toString( ) ) );
ui->tblHistory->setItem( i, 1, new QTableWidgetItem( settings.value("desc").toString() ) );
ui->tblHistory->setItem( i, 2, new QTableWidgetItem( settings.value("date").toString() ) );
ui->tblHistory->setItem( i, 3, new QTableWidgetItem( settings.value("url").toString() ) );
i++;
}
}
settings.endGroup();
if( b > size){
filtering = false;
}
}
ui->tblHistory->setRowCount(i);
i = 0;
}
void winHistory::on_txtSearch_textChanged(const QString &arg1){
refreshList();
}
void winHistory::on_tblHistory_cellClicked(int row, int column){
intSearchBy = column;
ui->txtUrl->setText( ui->tblHistory->item( row, 3 )->text() );
switch (column) {
case 0:
strSearchBy = "title";
break;
case 1:
strSearchBy = "desc";
break;
case 2:
strSearchBy = "date";
break;
case 3:
cImg = ui->tblHistory->item(row,column)->text();
url2 = QUrl( cImg );
dServ2->openUrl(url2);
break;
default:
strSearchBy = "title";
break;
}
}
void winHistory::on_btnClearAll_clicked(){
if( QMessageBox::question(this, "Delete all history...","Are You sure?", QMessageBox::Yes | QMessageBox::Abort ) == QMessageBox::Yes ){
QFile tmp(config::getWPath() + "/history.ini");
tmp.close();
tmp.remove();
refreshList();
}
}
void winHistory::on_tblHistory_activated(const QModelIndex &index){
}
void winHistory::on_btnToClipboard_clicked(){
QClipboard *cb = QApplication::clipboard();
cb->setText( ui->txtUrl->text(),
QClipboard::Clipboard );
}