[add] Added more VMess share options, fixed #162

This commit is contained in:
Leroy.H.Y 2019-12-22 10:52:42 +08:00
parent a5aaff1cb6
commit 151890b7cc
No known key found for this signature in database
GPG Key ID: 6AC1673B587DC37D
5 changed files with 82 additions and 32 deletions

View File

@ -1 +1 @@
1939
1954

View File

@ -29,7 +29,6 @@
#define QV2RAY_CONFIG_DIR (Qv2ray::Utils::GetConfigDirPath())
#define QV2RAY_CONFIG_FILE (QV2RAY_CONFIG_DIR + "Qv2ray.conf")
#define QV2RAY_SUBSCRIPTION_DIR (QV2RAY_CONFIG_DIR + "subscriptions/")
#define QV2RAY_QRCODE_DIR (QV2RAY_CONFIG_DIR + "qr_images/")
// Get GFWList and PAC file path.
#define QV2RAY_RULES_DIR (QV2RAY_CONFIG_DIR + "rules/")

View File

@ -1,5 +1,6 @@
#include "w_ExportConfig.hpp"
#include "QvUtils.hpp"
#include <QFileDialog>
// Private initialiser
ConfigExporter::ConfigExporter(QWidget *parent) :
@ -58,14 +59,20 @@ void ConfigExporter::on_closeBtn_clicked()
void ConfigExporter::on_saveBtn_clicked()
{
// Save
if (!QDir(QV2RAY_QRCODE_DIR).exists()) {
QDir().mkpath(QV2RAY_QRCODE_DIR);
}
auto filePath = QV2RAY_QRCODE_DIR + QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss-z.png");
auto filePath = QFileDialog().getSaveFileName(this, tr("Save Image"), "", "Images (*.png)");
auto result = image.save(filePath);
QDesktopServices::openUrl(QUrl(QV2RAY_QRCODE_DIR));
QDesktopServices::openUrl(QUrl::fromUserInput(filePath));
LOG(MODULE_FILE, "Saving an image to: " + filePath.toStdString() + " result: " + (result ? "OK" : "Failed"))
// If succeed, we disable future save.
saveBtn->setEnabled(result);
}
void ConfigExporter::on_copyImageBtn_clicked()
{
QGuiApplication::clipboard()->setImage(image);
QvMessageBox(this, tr("Share Connection"), tr("Image has been copied to the clipboard."));
}
void ConfigExporter::on_copyVMessBtn_clicked()
{
QGuiApplication::clipboard()->setText(message);
QvMessageBox(this, tr("Share Connection"), tr("VMess string has been copied to the clipboard."));
}

View File

@ -19,6 +19,10 @@ class ConfigExporter : public QDialog, private Ui::ExportConfigWindow
void on_saveBtn_clicked();
void on_copyImageBtn_clicked();
void on_copyVMessBtn_clicked();
private:
explicit ConfigExporter(QWidget *parent);
QZXing qzxing;

View File

@ -6,16 +6,19 @@
<rect>
<x>0</x>
<y>0</y>
<width>532</width>
<height>666</height>
<width>661</width>
<height>347</height>
</rect>
</property>
<property name="windowTitle">
<string>Export Config</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="10,0,3,0">
<item>
<layout class="QGridLayout" name="gridLayout" rowstretch="1,0" columnstretch="1,1">
<item row="0" column="0">
<widget class="QLabel" name="imageLabel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
@ -31,23 +34,60 @@
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Text Message</string>
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="messageTxt">
<property name="readOnly">
<bool>true</bool>
<item row="0" column="1">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Share Options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>VMess Connection String</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="messageTxt">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="saveBtn">
<property name="text">
<string>Save Image</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="copyImageBtn">
<property name="text">
<string>Copy Image</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="copyVMessBtn">
<property name="text">
<string>Copy VMess</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
@ -62,13 +102,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="saveBtn">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closeBtn">
<property name="text">
@ -80,6 +113,13 @@
</item>
</layout>
</widget>
<tabstops>
<tabstop>messageTxt</tabstop>
<tabstop>saveBtn</tabstop>
<tabstop>copyImageBtn</tabstop>
<tabstop>copyVMessBtn</tabstop>
<tabstop>closeBtn</tabstop>
</tabstops>
<resources>
<include location="../../resources.qrc"/>
</resources>