Refactoring

This commit is contained in:
driftingsun 2020-12-04 00:45:21 +03:00
parent 3e223f0e4b
commit c9bc8aa8c1
23 changed files with 117 additions and 2280 deletions

2
README.md Normal file
View file

@ -0,0 +1,2 @@
# Amnezia

76
client/AmniziaVPN.pro Normal file
View file

@ -0,0 +1,76 @@
QT += widgets core gui network xml
TARGET = AmneziaVPN
TEMPLATE = app
#CONFIG += console
DEFINES += QT_DEPRECATED_WARNINGS
HEADERS += \
core/router.h \
debug.h \
defines.h \
runguard.h \
ui/Controls/SlidingStackedWidget.h \
ui/mainwindow.h \
SOURCES += \
core/router.cpp \
debug.cpp \
main.cpp \
runguard.cpp \
ui/Controls/SlidingStackedWidget.cpp \
ui/mainwindow.cpp \
FORMS += ui/mainwindow.ui
RESOURCES += \
resources.qrc
TRANSLATIONS = \
translations/amneziavpn.en.ts \
translations/amneziavpn.ru.ts
win32 {
OTHER_FILES += platform_win/vpnclient.rc
RC_FILE = platform_win/vpnclient.rc
HEADERS +=
SOURCES +=
#CONFIG -= embed_manifest_exe
#DEFINES += _CRT_SECURE_NO_WARNINGS VPNCLIENT_TAPSIGNED
#QMAKE_LFLAGS += /MANIFESTUAC:\"level=\'requireAdministrator\' uiAccess=\'false\'\"
VERSION = 1.1.1.1
QMAKE_TARGET_COMPANY = "AmneziaVPN"
QMAKE_TARGET_PRODUCT = "AmneziaVPN"
#CONFIG -= embed_manifest_exe
LIBS += \
-luser32 \
-lrasapi32 \
-lshlwapi \
-liphlpapi \
-lws2_32 \
-liphlpapi \
-lgdi32
#LIBS += -L$$PWD/../../../../../../../OpenSSL-Win32/lib/ -llibcrypto
#MT_PATH = \"C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/bin/x64/mt.exe\"
#WIN_PWD = $$replace(PWD, /, \\)
#OUT_PWD_WIN = $$replace(OUT_PWD, /, \\)
#!win32-g++: QMAKE_POST_LINK = "$$MT_PATH -manifest $$quote($$WIN_PWD\\platform_win\\$$basename(TARGET).exe.manifest) -outputresource:$$quote($$OUT_PWD_WIN\\$(DESTDIR_TARGET);1)"
# else: QMAKE_POST_LINK = "$$MT_PATH -manifest $$PWD/platform_win/$$basename(TARGET).exe.manifest -outputresource:$$OUT_PWD/$(DESTDIR_TARGET)"
}
macx {
ICON = $$PWD/images/app.icns
}

View file

@ -1,104 +0,0 @@
QT += widgets core gui network xml
TARGET = amnezia-client
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
win32 {
#win32-g++ {
# QMAKE_CXXFLAGS += -Werror
#}
#win32-msvc*{
# QMAKE_CXXFLAGS += /WX
#}
FORMS += ui/mainwindow.ui
RESOURCES += \
res.qrc
OTHER_FILES += platform_win/vpnclient.rc
RC_FILE = platform_win/vpnclient.rc
HEADERS += publib/winhelp.h
SOURCES += publib/winhelp.cpp
CONFIG -= embed_manifest_exe
DEFINES += _CRT_SECURE_NO_WARNINGS VPNCLIENT_TAPSIGNED
#QMAKE_LFLAGS += /MANIFESTUAC:\"level=\'requireAdministrator\' uiAccess=\'false\'\"
VERSION = 1.1.1.1
QMAKE_TARGET_COMPANY = "AmneziaVPN"
QMAKE_TARGET_PRODUCT = "AmneziaVPN"
CONFIG -= embed_manifest_exe
LIBS += -luser32 \
-lrasapi32 \
-lshlwapi \
-liphlpapi \
-lws2_32 \
-liphlpapi \
-lgdi32
MT_PATH = \"C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/bin/x64/mt.exe\"
WIN_PWD = $$replace(PWD, /, \\)
OUT_PWD_WIN = $$replace(OUT_PWD, /, \\)
!win32-g++: QMAKE_POST_LINK = "$$MT_PATH -manifest $$quote($$WIN_PWD\\platform_win\\$$basename(TARGET).exe.manifest) -outputresource:$$quote($$OUT_PWD_WIN\\$(DESTDIR_TARGET);1)"
else: QMAKE_POST_LINK = "$$MT_PATH -manifest $$PWD/platform_win/$$basename(TARGET).exe.manifest -outputresource:$$OUT_PWD/$(DESTDIR_TARGET)"
}
macx {
OBJECTIVE_HEADERS +=
OBJECTIVE_SOURCES += publib/macos_functions.mm
HEADERS += \
SOURCES += \
QMAKE_OBJECTIVE_CFLAGS += -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks
FORMS += ui/mainwindow_mac.ui
LIBS += -framework CoreServices -framework Foundation -framework AppKit
RESOURCES += \
res_mac.qrc
ICON = images/main.icns
}
SOURCES += main.cpp\
core/router.cpp \
publib/debug.cpp \
publib/runguard.cpp \
publib/winhelp.cpp \
ui/Controls/SlidingStackedWidget.cpp \
ui/mainwindow.cpp \
ui/customshadoweffect.cpp
HEADERS += ui/mainwindow.h \
core/router.h \
publib/debug.h \
publib/runguard.h \
publib/winhelp.h \
ui/customshadoweffect.h \
ui/Controls/SlidingStackedWidget.h
FORMS += ui/mainwindow.ui
TRANSLATIONS = translations/amneziavpn.en.ts \
translations/amneziavpn.ru.ts
win32: LIBS += -L$$PWD/../../../../../../../OpenSSL-Win32/lib/ -llibcrypto

View file

@ -3,7 +3,6 @@
#include <QProcess> #include <QProcess>
Router &Router::Instance() Router &Router::Instance()
{ {
static Router s; static Router s;
@ -12,6 +11,8 @@ Router &Router::Instance()
bool Router::routeAdd(const QString &ip, const QString &gw, QString mask) bool Router::routeAdd(const QString &ip, const QString &gw, QString mask)
{ {
#ifdef Q_OS_WIN
qDebug().noquote() << QString("ROUTE ADD: IP:%1 %2 GW %3") qDebug().noquote() << QString("ROUTE ADD: IP:%1 %2 GW %3")
.arg(ip) .arg(ip)
.arg(mask) .arg(mask)
@ -107,6 +108,8 @@ bool Router::routeAdd(const QString &ip, const QString &gw, QString mask)
free(pIpForwardTable); free(pIpForwardTable);
return (dwStatus == NO_ERROR); return (dwStatus == NO_ERROR);
#endif
} }
int Router::routeAddList(const QString &gw, const QStringList &ips) int Router::routeAddList(const QString &gw, const QStringList &ips)
@ -118,6 +121,8 @@ int Router::routeAddList(const QString &gw, const QStringList &ips)
qDebug().noquote() << QString("ROUTE ADD List: IPs:\n%1") qDebug().noquote() << QString("ROUTE ADD List: IPs:\n%1")
.arg(ips.join("\n")); .arg(ips.join("\n"));
#ifdef Q_OS_WIN
PMIB_IPFORWARDTABLE pIpForwardTable = NULL; PMIB_IPFORWARDTABLE pIpForwardTable = NULL;
DWORD dwSize = 0; DWORD dwSize = 0;
BOOL bOrder = FALSE; BOOL bOrder = FALSE;
@ -224,10 +229,14 @@ int Router::routeAddList(const QString &gw, const QStringList &ips)
qDebug() << "Router::routeAddList finished, success: " << success_count << "/" << ips.size(); qDebug() << "Router::routeAddList finished, success: " << success_count << "/" << ips.size();
return success_count; return success_count;
#endif
} }
bool Router::clearSavedRoutes() bool Router::clearSavedRoutes()
{ {
#ifdef Q_OS_WIN
if (ipForwardRows.isEmpty()) return true; if (ipForwardRows.isEmpty()) return true;
qDebug() << "forward rows size:" << ipForwardRows.size(); qDebug() << "forward rows size:" << ipForwardRows.size();
@ -274,6 +283,8 @@ bool Router::clearSavedRoutes()
ipForwardRows.clear(); ipForwardRows.clear();
return true; return true;
#endif
} }
bool Router::routeDelete(const QString &ip) bool Router::routeDelete(const QString &ip)

View file

@ -52,7 +52,9 @@ private:
Router(Router const &) = delete; Router(Router const &) = delete;
Router& operator= (Router const&) = delete; Router& operator= (Router const&) = delete;
#ifdef Q_OS_WIN
QList<MIB_IPFORWARDROW> ipForwardRows; QList<MIB_IPFORWARDROW> ipForwardRows;
#endif
}; };
#endif // ROUTER_H #endif // ROUTER_H

View file

@ -95,10 +95,6 @@ bool Debug::init(QDir& appDir)
#endif #endif
#endif #endif
#ifndef Q_OS_WIN
if (!fixOvpnLogPermissions())
qWarning() << "Debug: permissions for ovpn.log were not fixed";
#endif
return true; return true;
} }

7
client/defines.h Normal file
View file

@ -0,0 +1,7 @@
#ifndef DEFINES_H
#define DEFINES_H
#define APPLICATION_NAME "AmneziaVPN"
#define ORGANIZATION_NAME "AmneziaVPN.ORG"
#endif // DEFINES_H

BIN
client/images/app.icns Normal file

Binary file not shown.

View file

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Before After
Before After

View file

@ -2,28 +2,19 @@
#include <QFontDatabase> #include <QFontDatabase>
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QMessageBox> #include <QMessageBox>
#include <QFile>
#include <QTranslator> #include <QTranslator>
#include <QLibraryInfo>
#include "publib/runguard.h" #include "debug.h"
#include "publib/debug.h" #include "defines.h"
#include "runguard.h"
#include "ui/mainwindow.h" #include "ui/mainwindow.h"
#ifdef Q_OS_WIN
#include <Windows.h>
#endif
#define ApplicationName "AmneziaVPN"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
Q_INIT_RESOURCE(res);
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true); QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
RunGuard::instance(ApplicationName).activate(); RunGuard::instance(APPLICATION_NAME).activate();
QApplication app(argc, argv); QApplication app(argc, argv);
@ -44,12 +35,11 @@ int main(int argc, char *argv[])
QFontDatabase::addApplicationFont(":/fonts/Lato-Thin.ttf"); QFontDatabase::addApplicationFont(":/fonts/Lato-Thin.ttf");
QFontDatabase::addApplicationFont(":/fonts/Lato-ThinItalic.ttf"); QFontDatabase::addApplicationFont(":/fonts/Lato-ThinItalic.ttf");
{ {
QTranslator *translator = new QTranslator; QTranslator *translator = new QTranslator;
QLocale ru(QLocale("ru_RU")); QLocale ru(QLocale("ru_RU"));
QLocale::setDefault(ru); QLocale::setDefault(ru);
if (translator->load(QLocale(), "amnezia-client", ".", QLatin1String(":/translations"))) { if (translator->load(QLocale(), "amneziavpn", ".", QLatin1String(":/translations"))) {
bool ok = qApp->installTranslator(translator); bool ok = qApp->installTranslator(translator);
qDebug().noquote() << "Main: Installing translator for locale" << ru.name() << ok; qDebug().noquote() << "Main: Installing translator for locale" << ru.name() << ok;
} }
@ -58,38 +48,23 @@ int main(int argc, char *argv[])
} }
} }
app.setApplicationName(APPLICATION_NAME);
app.setOrganizationName("AmneziaVPN"); app.setOrganizationName(ORGANIZATION_NAME);
app.setOrganizationDomain("AmneziaVPN.ORG"); app.setApplicationDisplayName(APPLICATION_NAME);
app.setApplicationName(ApplicationName);
app.setApplicationDisplayName(ApplicationName);
app.setApplicationVersion("1.0.0.0"); app.setApplicationVersion("1.0.0.0");
//app.setQuitOnLastWindowClosed(false); //app.setQuitOnLastWindowClosed(false);
QCommandLineParser parser; QCommandLineParser parser;
parser.setApplicationDescription("AmneziaVPN"); parser.setApplicationDescription(APPLICATION_NAME);
parser.addHelpOption(); parser.addHelpOption();
parser.addVersionOption(); parser.addVersionOption();
QCommandLineOption debugToConsoleOption("d", QCoreApplication::translate("main", "Output to console instead log file")); QCommandLineOption debugToConsoleOption("d", QCoreApplication::translate("main", "Output to console instead log file"));
parser.addOption(debugToConsoleOption); parser.addOption(debugToConsoleOption);
parser.process(app); // Process the actual command line arguments given by the user
#ifdef Q_OS_MAC
QCommandLineOption forceUseBrightIconsOption("b", QCoreApplication::translate("main", "Force use bright icons"));
parser.addOption(forceUseBrightIconsOption);
#endif
// Process the actual command line arguments given by the user
parser.process(app);
bool debugToConsole = parser.isSet(debugToConsoleOption); bool debugToConsole = parser.isSet(debugToConsoleOption);
bool forceUseBrightIcons = false;
#ifdef Q_OS_MAC
forceUseBrightIcons = parser.isSet(forceUseBrightIconsOption);
#endif
qDebug() << "Set output to console: " << debugToConsole; qDebug() << "Set output to console: " << debugToConsole;
if (!debugToConsole) { if (!debugToConsole) {
@ -102,7 +77,7 @@ int main(int argc, char *argv[])
f.setStyleStrategy(QFont::PreferAntialias); f.setStyleStrategy(QFont::PreferAntialias);
app.setFont(f); app.setFont(f);
MainWindow mainWindow(forceUseBrightIcons); MainWindow mainWindow;
mainWindow.show(); mainWindow.show();
return app.exec(); return app.exec();

View file

@ -1,7 +1,7 @@
#include <windows.h> #include <windows.h>
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
IDI_ICON1 ICON "../images/main.ico" IDI_ICON1 ICON "../images/app.ico"
#define VER_FILEVERSION 1,1,1,1 #define VER_FILEVERSION 1,1,1,1
#define VER_FILEVERSION_STR "1.1.1.1\0" #define VER_FILEVERSION_STR "1.1.1.1\0"

View file

@ -1,37 +0,0 @@
#include "macos_functions.h"
#include <QDebug>
#import <AppKit/AppKit.h>
MacOSFunctions &MacOSFunctions::instance()
{
static MacOSFunctions s;
return s;
}
MacOSFunctions::MacOSFunctions()
{
registerThemeNotification();
}
bool MacOSFunctions::isMenuBarUseDarkTheme() const
{
NSDictionary *dict = [[NSUserDefaults standardUserDefaults] persistentDomainForName:NSGlobalDomain];
id style = [dict objectForKey:@"AppleInterfaceStyle"];
BOOL darkModeOn = ( style && [style isKindOfClass:[NSString class]] && NSOrderedSame == [style caseInsensitiveCompare:@"dark"] );
return darkModeOn;
}
void MacOSFunctions::registerThemeNotification()
{
// [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(darkModeChanged:) name:@"AppleInterfaceThemeChangedNotification" object:nil];
}
void darkModeChanged(NSNotification*notif)
{
Q_UNUSED(notif);
qDebug() << "Dark mode changed" << MacOSFunctions::instance().isMenuBarUseDarkTheme();
}

View file

@ -1,261 +0,0 @@
#include "winhelp.h"
#include <stdio.h>
#include <Windows.h>
#include <Shlwapi.h>
#include <TlHelp32.h>
#include <Ras.h>
#include <iphlpapi.h>
#define REG_AUTORUN_PATH "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
int winhelpGetRegistry(const char *name, const char *reg, char *value)
{
unsigned long nType = REG_SZ, nData = MAX_PATH;
if(ERROR_SUCCESS != SHGetValueA(HKEY_CURRENT_USER, reg,
name, &nType, value, &nData))
return -1;
return 1;
}
int winhelpSetRegistry(const char *name, const char *reg, const char *value)
{
if(ERROR_SUCCESS != SHSetValueA(HKEY_CURRENT_USER, reg,
name, REG_SZ, value, (DWORD)strlen(value)))
return -1;
return 1;
}
int winhelpLaunchStartupRegister(const char *name, int enable, const char *p)
{
char path[MAX_PATH] = {0};
if(p && strlen(p) == 0)
p = NULL;
if(p) {
if(enable)
strcpy(path, "\"");
else
strcpy(path, ";\"");
GetModuleFileNameA(NULL, path + strlen(path), MAX_PATH);
strcat(path, "\" ");
strcat(path, p);
} else {
if(enable)
strcpy(path, "");
else
strcpy(path, ";");
GetModuleFileNameA(NULL, path + strlen(path), MAX_PATH);
}
if(winhelpSetRegistry(name, REG_AUTORUN_PATH, path) < 0)
return -1;
return 1;
}
/* use the task scheduler, we do not need to care about UAC when start up */
int winhelpLaunchStartupTaskScheduler(const char *name, int enable, const char *p)
{
char cmd[MAX_PATH * 10] = {0};
char path[MAX_PATH] = {0};
UINT i = 0;
GetModuleFileNameA(NULL, path, MAX_PATH);
if (QString(path).contains("build-vpn-")) {
qDebug() << "winhelpLaunchStartupTaskScheduler : skipping auto launch for build dir";
return 0;
}
if(enable) {
if(p == NULL)
p = "";
sprintf(cmd, "schtasks /create /sc onlogon /tr \"\\\"%s\\\" %s\" "
"/tn \"%s\" /f /rl highest", path, p, name);
} else {
sprintf(cmd, "schtasks /delete /tn \"%s\" /f", name);
}
qDebug().noquote() << "winhelpLaunchStartupTaskScheduler cmd:" << cmd;
i = WinExec(cmd, SW_HIDE);
return 1;
}
int winhelpLaunchStartup(const char *name, int enable, const char *p)
{
OSVERSIONINFOA info = {0};
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
if(GetVersionExA(&info) < 0)
return -2;
if(info.dwMajorVersion >= 6)
return winhelpLaunchStartupTaskScheduler(name, enable, p);
else
return winhelpLaunchStartupRegister(name, enable, p);
}
int str2int(const char *s)
{
int r = 0;
while(*s && *(s + 1) && *(s + 2) && *(s + 3)) {
r += ((const int *)s)[0];
s += 4;
}
return r;
}
int winhelpOneProcess()
{
char path[MAX_PATH] = {0};
int i = 0, size = 0, cur = 0;
GetModuleFileNameA(NULL, path, MAX_PATH);
size = strlen(path);
for(i = size; i >= 0 && path[i] != '\\' ; i--);
cur = i + 1;
while(path[i] != '.' && path[i])i++;
path[i] = '\0';
sprintf(path, "ONE_%s", path + cur);
CreateEventA(NULL, FALSE, FALSE, path);
if(GetLastError())
return 0;
return 1;
}
int winhelpSystemBits()
{
typedef BOOL (WINAPI *LPFN_ISWOW64)(HANDLE, PBOOL);
int b64 = FALSE;
LPFN_ISWOW64 fnIsWow64 = (LPFN_ISWOW64)GetProcAddress(
GetModuleHandleA("kernel32"), "IsWow64Process");
if(NULL != fnIsWow64) {
if(!fnIsWow64(GetCurrentProcess(),&b64)) {
return -1;
}
}
return b64 ? 64 : 86;
}
bool winhelpIsSystem_x64()
{
typedef BOOL (WINAPI *LPFN_ISWOW64)(HANDLE, PBOOL);
int b64 = FALSE;
LPFN_ISWOW64 fnIsWow64 = (LPFN_ISWOW64)GetProcAddress(
GetModuleHandleA("kernel32"), "IsWow64Process");
if(NULL != fnIsWow64) {
if(!fnIsWow64(GetCurrentProcess(),&b64)) {
return false;
}
}
return b64 ? true : false;
}
typedef struct _PROCESS_QUERY
{
HANDLE h;
PROCESSENTRY32 d;
}PROCESS_QUERY;
int winhelpProcessQuery(void **p)
{
PROCESS_QUERY *q = (PROCESS_QUERY *)malloc(sizeof(PROCESS_QUERY));
if(q == NULL)
return -2;
q->h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(q->h == INVALID_HANDLE_VALUE) {
free(q);
return -1;
}
if(FALSE == Process32First(q->h, &q->d)) {
CloseHandle(q->h);
free(q);
return -3;
}
*p = (void *)q;
return 1;
}
int winhelpProcessNext(void *h, char *name)
{
PROCESS_QUERY *q = (PROCESS_QUERY *)h;
int pid = 0;
if(q == NULL)
return 0;
if(q->h == NULL) {
free(q);
return 0;
}
if(name)
wsprintfA(name, "%ls", q->d.szExeFile);
pid = (int)q->d.th32ProcessID;
if(FALSE == Process32Next(q->h, &q->d)) {
CloseHandle(q->h);
q->h = NULL;
}
return pid;
}
int winhelpRecvEvent(const char *event)
{
HANDLE hEvent = CreateEventA(NULL, FALSE, FALSE, event);
if(hEvent == NULL)
return 0;
WaitForSingleObject(hEvent, INFINITE);
CloseHandle(hEvent);
return 1;
}
int winhelpSendEvent(const char *event)
{
HANDLE hEvent = OpenEventA(EVENT_ALL_ACCESS, FALSE, event);
if(hEvent == NULL)
return 0;
SetEvent(hEvent);
CloseHandle(hEvent);
return 1;
}
int winhelpSystemVersion()
{
OSVERSIONINFOA ver = {0};
int version = 0;
ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
GetVersionExA(&ver);
version = ver.dwMajorVersion * 0x100 + ver.dwMinorVersion;
return version;
}
int winhelperSetMTUSize(const char *subname, int size)
{
char cmd[MAX_PATH] = {0};
sprintf(cmd, "netsh interface ipv4 set subinterface \"%s\" mtu=%d store=persistent",
subname, size);
return (int)WinExec(cmd, SW_HIDE);
}
int winhelpRecvSendBytes(const char *dev, int *recv, int *send)
{
MIB_IFTABLE *it = NULL;
DWORD size = sizeof(MIB_IFTABLE), ret = 0, i = 0;
DWORD tr = 0, ts = 0;
if(it = (MIB_IFTABLE *)malloc(sizeof (MIB_IFTABLE)), it == NULL)
return -1;
if(GetIfTable(it, &size, FALSE) == ERROR_INSUFFICIENT_BUFFER) {
free(it);
if(it = (MIB_IFTABLE *)malloc(size), it == NULL)
return -2;
}
if(ret = GetIfTable(it, &size, FALSE), ret != NO_ERROR) {
free(it);
return -3;
}
for(i = 0; i < it->dwNumEntries; i++) {
MIB_IFROW *ir = &it->table[i];
if(strstr((const char *)ir->bDescr, dev) == 0)
continue;
tr += (int)ir->dwInOctets;
ts += (int)ir->dwOutOctets;
}
*recv = tr;
*send = ts;
free(it);
return 1;
}

View file

@ -1,26 +0,0 @@
#ifndef WINHELP_H
#define WINHELP_H
#include <QDebug>
#ifdef __cplusplus
extern "C" {
#endif
extern int winhelpLaunchStartup(const char *, int, const char *);
extern int winhelpOneProcess();
extern int winhelpSystemBits();
extern bool winhelpIsSystem_x64();
extern int winhelpProcessQuery(void **);
extern int winhelpProcessNext(void *, char *);
extern int winhelpRecvEvent(const char *);
extern int winhelpSendEvent(const char *);
extern int winhelpSystemVersion();
extern int winhelperSetMTUSize(const char *, int);
extern int winhelpRecvSendBytes(const char *, int *, int *);
#ifdef __cplusplus
}
#endif
#endif /* WINHELP_H */

View file

@ -1,76 +0,0 @@
#include "customshadoweffect.h"
#include <QPainter>
CustomShadowEffect::CustomShadowEffect(QObject *parent) :
QGraphicsEffect(parent),
_distance(4.0f),
_blurRadius(10.0f),
_color(0, 0, 0, 80)
{
}
QT_BEGIN_NAMESPACE
extern Q_WIDGETS_EXPORT void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0 );
QT_END_NAMESPACE
void CustomShadowEffect::draw(QPainter* painter)
{
// if nothing to show outside the item, just draw source
if ((blurRadius() + distance()) <= 0) {
drawSource(painter);
return;
}
PixmapPadMode mode = QGraphicsEffect::PadToEffectiveBoundingRect;
QPoint offset;
const QPixmap px = sourcePixmap(Qt::DeviceCoordinates, &offset, mode);
// return if no source
if (px.isNull())
return;
// save world transform
QTransform restoreTransform = painter->worldTransform();
painter->setWorldTransform(QTransform());
// Calculate size for the background image
QSize szi(px.size().width() + 2 * distance(), px.size().height() + 2 * distance());
QImage tmp(szi, QImage::Format_ARGB32_Premultiplied);
QPixmap scaled = px.scaled(szi);
tmp.fill(0);
QPainter tmpPainter(&tmp);
tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
tmpPainter.drawPixmap(QPointF(-distance(), -distance()), scaled);
tmpPainter.end();
// blur the alpha channel
QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied);
blurred.fill(0);
QPainter blurPainter(&blurred);
qt_blurImage(&blurPainter, tmp, blurRadius(), false, true);
blurPainter.end();
tmp = blurred;
// blacken the image...
tmpPainter.begin(&tmp);
tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
tmpPainter.fillRect(tmp.rect(), color());
tmpPainter.end();
// draw the blurred shadow...
painter->drawImage(offset, tmp);
// draw the actual pixmap...
painter->drawPixmap(offset, px, QRectF());
// restore world transform
painter->setWorldTransform(restoreTransform);
}
QRectF CustomShadowEffect::boundingRectFor(const QRectF& rect) const
{
qreal delta = blurRadius() + distance();
return rect.united(rect.adjusted(-delta, -delta, delta, delta));
}

View file

@ -1,31 +0,0 @@
#ifndef CUSTOMSHADOWEFFECT_H
#define CUSTOMSHADOWEFFECT_H
#include <QGraphicsDropShadowEffect>
#include <QGraphicsEffect>
class CustomShadowEffect : public QGraphicsEffect
{
Q_OBJECT
public:
explicit CustomShadowEffect(QObject *parent = 0);
void draw(QPainter* painter);
QRectF boundingRectFor(const QRectF& rect) const;
inline void setDistance(qreal distance) { _distance = distance; updateBoundingRect(); }
inline qreal distance() const { return _distance; }
inline void setBlurRadius(qreal blurRadius) { _blurRadius = blurRadius; updateBoundingRect(); }
inline qreal blurRadius() const { return _blurRadius; }
inline void setColor(const QColor& color) { _color = color; }
inline QColor color() const { return _color; }
private:
qreal _distance;
qreal _blurRadius;
QColor _color;
};
#endif // CUSTOMSHADOWEFFECT_H

View file

@ -1,32 +1,13 @@
#include <QMetaEnum>
#include <QMovie>
#include <QMessageBox>
#include <QMouseEvent>
#include <QScroller>
#include <QScrollBar>
#include <QDesktopWidget>
#include <QDesktopServices>
#include <QGridLayout>
#include <QTime>
#include "mainwindow.h" #include "mainwindow.h"
#ifdef Q_OS_WIN
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#endif
#ifdef Q_OS_MAC MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
#include "ui_mainwindow_mac.h"
#include "publib/macos_functions.h"
#endif
MainWindow::MainWindow(bool useForceUseBrightIcons, QWidget *parent) : QMainWindow(parent),
ui(new Ui::MainWindow),
forceUseBrightIcons(useForceUseBrightIcons)
{ {
ui->setupUi(this); ui->setupUi(this);
// Post initialization
ui->widget_tittlebar->hide();
ui->stackedWidget_main->setCurrentIndex(2);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()

View file

@ -2,18 +2,6 @@
#define MAINWINDOW_H #define MAINWINDOW_H
#include <QMainWindow> #include <QMainWindow>
#include <QSystemTrayIcon>
#include <QAction>
#include <QMenu>
#include <QJsonDocument>
#include <QClipboard>
#include <QStringListModel>
#include <QDataStream>
#include <QGraphicsBlurEffect>
#include "customshadoweffect.h"
namespace Ui { namespace Ui {
class MainWindow; class MainWindow;
@ -27,7 +15,7 @@ class MainWindow : public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(bool setForceUseBrightIcons = false, QWidget *parent = nullptr); explicit MainWindow(QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
public slots: public slots:
@ -37,7 +25,6 @@ private slots:
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
bool forceUseBrightIcons = false;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

File diff suppressed because it is too large Load diff