-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimestamp.cpp
More file actions
91 lines (80 loc) · 2.49 KB
/
timestamp.cpp
File metadata and controls
91 lines (80 loc) · 2.49 KB
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
#include "timestamp.h"
#include <QApplication>
#include <QMap>
#include <QMessageBox>
#include <QDialog>
#include <QVBoxLayout>
#include <QTextEdit>
#include <QLabel>
#include <QPushButton>
#include <QRegularExpression>
#include <QTranslator>
#include <QLocale>
#include <QDebug>
#include "timestampshowdialog.h"
int Timestamp::init(QMap<QString, QString> params, QWidget *parent)
{
Q_UNUSED(params);
m_action = new QAction(tr("Timestamp"), parent);
connect(m_action, &QAction::triggered, [&,parent](){
QMessageBox::information(parent, tr("Timestamp"),
tr(
"Timestamp\nThis is a plugin to convert timestamps."
));
});
return 0;
}
QList<QAction *> Timestamp::terminalContextAction(QString selectedText, QString workingDirectory, QMenu *parentMenu)
{
Q_UNUSED(workingDirectory);
if(selectedText.isEmpty()) {
return QList<QAction *>();
}
QList<QAction *> actions;
QLocale locale;
bool isUInt64Number = false;
uint64_t number = 0;
if(selectedText.startsWith("0x")) {
QString testText = selectedText.mid(2);
number = testText.toULongLong(&isUInt64Number,16);
} else {
number = selectedText.toULongLong(&isUInt64Number,10);
if(!isUInt64Number) {
number = locale.toULongLong(selectedText,&isUInt64Number);
}
}
if(isUInt64Number) {
QAction *textStatistics = new QAction(tr("Show Timestamp"), parentMenu);
actions.append(textStatistics);
connect(textStatistics, &QAction::triggered, this, [=](){
TimestampShowDialog dialog(number,parentMenu);
dialog.setWindowTitle(tr("Show Timestamp"));
dialog.exec();
});
}
return actions;
}
void Timestamp::setLanguage(const QLocale &language,QApplication *app) {
static QTranslator *qtTranslator = nullptr;
if(qtTranslator == nullptr) {
qtTranslator = new QTranslator(app);
} else {
app->removeTranslator(qtTranslator);
delete qtTranslator;
qtTranslator = new QTranslator(app);
}
switch(language.language()) {
case QLocale::Chinese:
if(qtTranslator->load(":/lang/timestamp_zh_CN.qm"))
app->installTranslator(qtTranslator);
break;
default:
case QLocale::English:
if(qtTranslator->load(":/lang/timestamp_en_US.qm"))
app->installTranslator(qtTranslator);
break;
}
}
void Timestamp::retranslateUi() {
m_action->setText(tr("Timestamp"));
}