Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
95 KB
Referenced Files
None
Subscribers
None
diff --git a/lightscreen.pro b/lightscreen.pro
index 061c34a..5a26e7f 100644
--- a/lightscreen.pro
+++ b/lightscreen.pro
@@ -1,86 +1,87 @@
TEMPLATE = app
TARGET = lightscreen
HEADERS += dialogs/areadialog.h \
dialogs/historydialog.h \
dialogs/namingdialog.h \
dialogs/optionsdialog.h \
dialogs/previewdialog.h \
dialogs/updaterdialog.h \
lightscreenwindow.h \
tools/os.h \
tools/screenshot.h \
tools/screenshotmanager.h \
tools/windowpicker.h \
updater/updater.h \
widgets/hotkeywidget.h \
tools/qtsingleapplication/qtlockedfile.h \
tools/qtsingleapplication/qtsinglecoreapplication.h \
tools/uploader/imageuploader.h \
tools/uploader/imguruploader.h \
tools/uploader/uploader.h
SOURCES += dialogs/areadialog.cpp \
dialogs/historydialog.cpp \
dialogs/namingdialog.cpp \
dialogs/optionsdialog.cpp \
dialogs/previewdialog.cpp \
dialogs/updaterdialog.cpp \
lightscreenwindow.cpp \
main.cpp \
tools/os.cpp \
tools/screenshot.cpp \
tools/screenshotmanager.cpp \
tools/windowpicker.cpp \
updater/updater.cpp \
widgets/hotkeywidget.cpp \
tools/qtsingleapplication/qtlockedfile.cpp \
tools/qtsingleapplication/qtlockedfile_unix.cpp \
tools/qtsingleapplication/qtlockedfile_win.cpp \
tools/qtsingleapplication/qtsinglecoreapplication.cpp \
tools/uploader/imageuploader.cpp \
tools/uploader/imguruploader.cpp \
tools/uploader/uploader.cpp
FORMS += dialogs/historydialog.ui \
dialogs/namingdialog.ui \
dialogs/optionsdialog.ui \
lightscreenwindow.ui
RESOURCES += lightscreen.qrc
RC_FILE += lightscreen.rc
CODECFORSRC = UTF-8
QT += core gui network sql multimedia
-include($$PWD/tools/qxtglobalshortcut/qxtglobalshortcut.pri)
include($$PWD/tools/qtsingleapplication/qtsingleapplication.pri)
+include($$PWD/tools/UGlobalHotkey/uglobalhotkey.pri)
windows {
QT += winextras
contains(QMAKE_CC, gcc){
LIBS += libgdi32 libgcc libuser32 libole32 libshell32 libshlwapi libcomctl32
QMAKE_CXXFLAGS = -Wextra -Wall -Wpointer-arith
}
contains(QMAKE_CC, cl){
LIBS += gdi32.lib user32.lib ole32.lib shell32.lib shlwapi.lib comctl32.lib
}
-
+ CONFIG += embed_manifest_exe
+ QMAKE_LFLAGS_WINDOWS += /MANIFESTUAC:level=\'asInvoker\'
QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01
QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE,5.01
DEFINES += _ATL_XP_TARGETING
QMAKE_CFLAGS += /D _USING_V110_SDK71
QMAKE_CXXFLAGS += /D _USING_V110_SDK71
}
unix:LIBS += -lX11
unix:QT += x11extras
OTHER_FILES += TODO.txt
diff --git a/lightscreenwindow.cpp b/lightscreenwindow.cpp
index 8ad54dd..234555d 100644
--- a/lightscreenwindow.cpp
+++ b/lightscreenwindow.cpp
@@ -1,1059 +1,1052 @@
/*
* Copyright (C) 2016 Christian Kaiser
*
* 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <QDate>
#include <QDesktopServices>
#include <QDesktopWidget>
#include <QFileInfo>
#include <QKeyEvent>
#include <QMainWindow>
#include <QMenu>
#include <QMessageBox>
#include <QPointer>
#include <QProcess>
#include <QSettings>
#include <QSystemTrayIcon>
#include <QTimer>
#include <QToolTip>
#include <QUrl>
#include <QSound>
+#include <QKeyEvent>
#ifdef Q_OS_WIN
#include <windows.h>
#include <QtWinExtras>
#endif
/*
* Lightscreen includes
*/
#include "lightscreenwindow.h"
#include "dialogs/optionsdialog.h"
#include "dialogs/previewdialog.h"
#include "dialogs/historydialog.h"
#include "tools/os.h"
#include "tools/screenshot.h"
#include "tools/screenshotmanager.h"
-#include "tools/qxtglobalshortcut/qxtglobalshortcut.h"
-
+#include "tools/UGlobalHotkey/uglobalhotkeys.h"
#include "tools/uploader/uploader.h"
#include "updater/updater.h"
LightscreenWindow::LightscreenWindow(QWidget *parent) :
QMainWindow(parent),
mDoCache(false),
mHideTrigger(false),
mReviveMain(false),
mWasVisible(true),
mLastMessage(0),
mLastMode(-1),
mLastScreenshot(),
mHasTaskbarButton(false)
{
ui.setupUi(this);
ui.screenPushButton->setIcon(os::icon("screen.big"));
ui.areaPushButton->setIcon(os::icon("area.big"));
ui.windowPushButton->setIcon(os::icon("pickWindow.big"));
ui.optionsPushButton->setIcon(os::icon("configure"));
ui.folderPushButton->setIcon(os::icon("folder"));
ui.imgurPushButton->setIcon(os::icon("imgur"));
createUploadMenu();
#ifdef Q_OS_WIN
- if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7) {
+ if (QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS7) {
mTaskbarButton = new QWinTaskbarButton(this);
mHasTaskbarButton = true;
if (QtWin::isCompositionEnabled()) {
setAttribute(Qt::WA_NoSystemBackground);
QtWin::enableBlurBehindWindow(this);
QtWin::extendFrameIntoClientArea(this, QMargins(-1, -1, -1, -1));
}
}
- if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS7) {
+ if (QSysInfo::WindowsVersion < QSysInfo::WV_WINDOWS7) {
ui.centralWidget->setStyleSheet("QPushButton { padding: 2px; border: 1px solid #acacac; background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 #eaeaea, stop:1 #e5e5e5);} QPushButton:hover { border: 1px solid #7eb4ea; background-color: #e4f0fc; }");
}
#endif
setMaximumSize(size());
setMinimumSize(size());
setWindowFlags(windowFlags() ^ Qt::WindowMaximizeButtonHint);
// Actions
connect(ui.screenPushButton, SIGNAL(clicked()), this, SLOT(screenshotAction()));
connect(ui.areaPushButton , SIGNAL(clicked()), this, SLOT(areaHotkey()));
connect(ui.windowPushButton, SIGNAL(clicked()), this, SLOT(windowPickerHotkey()));
connect(ui.optionsPushButton, SIGNAL(clicked()), this, SLOT(showOptions()));
connect(ui.folderPushButton , SIGNAL(clicked()), this, SLOT(goToFolder()));
// Shortcuts
- connect(&mScreenShortcut , &QxtGlobalShortcut::activated, this, &LightscreenWindow::screenHotkey);
- connect(&mAreaShortcut , &QxtGlobalShortcut::activated, this, &LightscreenWindow::areaHotkey);
- connect(&mWindowShortcut , &QxtGlobalShortcut::activated, this, &LightscreenWindow::windowHotkey);
- connect(&mWindowPickerShortcut, &QxtGlobalShortcut::activated, this, &LightscreenWindow::windowPickerHotkey);
- connect(&mOpenShortcut , &QxtGlobalShortcut::activated, this, &LightscreenWindow::show);
- connect(&mDirectoryShortcut , &QxtGlobalShortcut::activated, this, &LightscreenWindow::goToFolder);
+ mGlobalHotkeys = new UGlobalHotkeys(this);
+
+ connect(mGlobalHotkeys, &UGlobalHotkeys::activated, [&](size_t id) {
+ if (id >= 0 && id <= 3) {
+ screenshotAction(id);
+ }
+ else if (id == 4) {
+ show();
+ }
+ else if (id == 5) {
+ goToFolder();
+ }
+ else {
+ qWarning() << "Uknown hotkey ID: " << id;
+ }
+ });
// Uploader
connect(Uploader::instance(), SIGNAL(progress(int)), this, SLOT(uploadProgress(int)));
connect(Uploader::instance(), SIGNAL(done(QString, QString, QString)), this, SLOT(showUploaderMessage(QString, QString)));
connect(Uploader::instance(), SIGNAL(error(QString)), this, SLOT(showUploaderError(QString)));
// Manager
connect(ScreenshotManager::instance(), SIGNAL(confirm(Screenshot*)), this, SLOT(preview(Screenshot*)));
connect(ScreenshotManager::instance(), SIGNAL(windowCleanup(Screenshot::Options&)), this, SLOT(cleanup(Screenshot::Options&)));
connect(ScreenshotManager::instance(), SIGNAL(activeCountChange()), this, SLOT(updateStatus()));
if (!settings()->contains("file/format")) {
showOptions(); // There are no options (or the options config is invalid or incomplete)
}
else {
QTimer::singleShot(0 , this, SLOT(applySettings()));
QTimer::singleShot(5000, this, SLOT(checkForUpdates()));
}
}
LightscreenWindow::~LightscreenWindow()
{
settings()->setValue("lastScreenshot", mLastScreenshot);
settings()->sync();
}
void LightscreenWindow::action(int mode)
{
if (mode == 4) {
goToFolder();
}
else {
show();
}
}
void LightscreenWindow::areaHotkey()
{
screenshotAction(2);
}
void LightscreenWindow::checkForUpdates()
{
if (settings()->value("options/disableUpdater", false).toBool())
return;
if (settings()->value("lastUpdateCheck").toInt() + 7
> QDate::currentDate().dayOfYear())
return; // If 7 days have not passed since the last update check.
mUpdater = new Updater(this);
connect(mUpdater, SIGNAL(done(bool)), this, SLOT(updaterDone(bool)));
mUpdater->check();
}
void LightscreenWindow::cleanup(Screenshot::Options &options)
{
// Reversing settings
if (settings()->value("options/hide").toBool()) {
#ifndef Q_OS_LINUX // X is not quick enough and the notification ends up everywhere but in the icon
if (settings()->value("options/tray").toBool() && mTrayIcon) {
mTrayIcon->show();
}
#endif
if (mPreviewDialog) {
if (mPreviewDialog->count() <= 1 && mWasVisible) {
show();
}
mPreviewDialog->show();
}
else if (mWasVisible) {
show();
}
mHideTrigger = false;
}
if (settings()->value("options/tray").toBool() && mTrayIcon) {
notify(options.result);
if (settings()->value("options/message").toBool() && options.file && !options.upload) {
// This message wll get shown only when messages are enabled and the file won't get another upload pop-up soon.
showScreenshotMessage(options.result, options.fileName);
}
}
if (settings()->value("options/playSound", false).toBool()) {
if (options.result == Screenshot::Success) {
QSound::play("sounds/ls.screenshot.wav");
}
else {
#ifdef Q_OS_WIN
QSound::play("afakepathtomakewindowsplaythedefaultsoundtheresprobablyabetterwaybuticantbebothered");
#else
QSound::play("sound/ls.error.wav");
#endif
}
}
updateStatus();
if (options.result != Screenshot::Success)
return;
mLastScreenshot = options.fileName;
}
void LightscreenWindow::closeToTrayWarning()
{
if (!settings()->value("options/closeToTrayWarning", true).toBool())
return;
mLastMessage = 3;
mTrayIcon->showMessage(tr("Closed to tray"), tr("Lightscreen will keep running, you can disable this in the options menu."));
settings()->setValue("options/closeToTrayWarning", false);
}
bool LightscreenWindow::closingWithoutTray()
{
if (settings()->value("options/disableHideAlert", false).toBool())
return false;
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Lightscreen"));
msgBox.setText(tr("You have chosen to hide Lightscreen when there's no system tray icon, so you will not be able to access the program <b>unless you have selected a hotkey to do so</b>.<br>What do you want to do?"));
msgBox.setIcon(QMessageBox::Warning);
msgBox.setStyleSheet("QPushButton { padding: 4px 8px; }");
QPushButton *enableButton = msgBox.addButton(tr("Hide but enable tray"),
QMessageBox::ActionRole);
QPushButton *enableAndDenotifyButton = msgBox.addButton(tr("Hide and don't warn"),
QMessageBox::ActionRole);
QPushButton *hideButton = msgBox.addButton(tr("Just hide"),
QMessageBox::ActionRole);
QPushButton *abortButton = msgBox.addButton(QMessageBox::Cancel);
Q_UNUSED(abortButton);
msgBox.exec();
if (msgBox.clickedButton() == hideButton) {
return true;
}
else if (msgBox.clickedButton() == enableAndDenotifyButton) {
settings()->setValue("options/disableHideAlert", true);
applySettings();
return true;
}
else if (msgBox.clickedButton() == enableButton) {
settings()->setValue("options/tray", true);
applySettings();
return true;
}
return false; // Cancel.
}
void LightscreenWindow::createUploadMenu()
{
QMenu* imgurMenu = new QMenu(tr("Upload"));
QAction *uploadAction = new QAction(os::icon("imgur"), tr("&Upload last"), imgurMenu);
uploadAction->setToolTip(tr("Upload the last screenshot you took to imgur.com"));
connect(uploadAction, SIGNAL(triggered()), this, SLOT(uploadLast()));
QAction *cancelAction = new QAction(os::icon("no"), tr("&Cancel upload"), imgurMenu);
cancelAction->setToolTip(tr("Cancel the currently uploading screenshots"));
cancelAction->setEnabled(false);
connect(this, SIGNAL(uploading(bool)), cancelAction, SLOT(setEnabled(bool)));
connect(cancelAction, SIGNAL(triggered()), this, SLOT(uploadCancel()));
QAction *historyAction = new QAction(os::icon("view-history"), tr("View &History"), imgurMenu);
connect(historyAction, SIGNAL(triggered()), this, SLOT(showHistoryDialog()));
imgurMenu->addAction(uploadAction);
imgurMenu->addAction(cancelAction);
imgurMenu->addAction(historyAction);
imgurMenu->addSeparator();
connect(imgurMenu, SIGNAL(aboutToShow()), this, SLOT(uploadMenuShown()));
ui.imgurPushButton->setMenu(imgurMenu);
}
void LightscreenWindow::goToFolder()
{
#ifdef Q_OS_WIN
if (!mLastScreenshot.isEmpty() && QFile::exists(mLastScreenshot)) {
QProcess::startDetached("explorer /select, \"" + mLastScreenshot +"\"");
}
else {
#endif
QString folder = settings()->value("file/target").toString();
if (folder.isEmpty())
folder = qApp->applicationDirPath();
if (QDir::toNativeSeparators(folder.at(folder.size()-1)) != QDir::separator())
folder.append(QDir::separator());
QDesktopServices::openUrl("file:///"+folder);
#ifdef Q_OS_WIN
}
#endif
}
void LightscreenWindow::messageClicked()
{
if (mLastMessage == 1) {
goToFolder();
}
else if (mLastMessage == 3) {
QTimer::singleShot(0, this, SLOT(showOptions()));
}
else {
QDesktopServices::openUrl(QUrl(Uploader::instance()->lastUrl()));
}
}
void LightscreenWindow::messageReceived(const QString &message)
{
if (message.contains(' ')) {
foreach (QString argument, message.split(' ')) {
messageReceived(argument);
}
}
if (message == "--wake") {
show();
qApp->alert(this, 500);
return;
}
if (message == "--screen")
screenshotAction();
else if (message == "--area")
screenshotAction(2);
else if (message == "--activewindow")
screenshotAction(1);
else if (message == "--pickwindow")
screenshotAction(3);
else if (message == "--folder")
action(4);
else if (message == "--uploadlast")
uploadLast();
else if (message == "--viewhistory")
showHistoryDialog();
else if (message == "--options")
showOptions();
else if (message == "--quit")
qApp->quit();
}
void LightscreenWindow::notify(const Screenshot::Result &result)
{
switch (result)
{
case Screenshot::Success:
mTrayIcon->setIcon(QIcon(":/icons/lightscreen.yes"));
if (mHasTaskbarButton) {
mTaskbarButton->setOverlayIcon(os::icon("yes"));
}
setWindowTitle(tr("Success!"));
break;
case Screenshot::Fail:
mTrayIcon->setIcon(QIcon(":/icons/lightscreen.no"));
setWindowTitle(tr("Failed!"));
if (mHasTaskbarButton) {
mTaskbarButton->setOverlayIcon(os::icon("no"));
}
break;
case Screenshot::Cancel:
setWindowTitle(tr("Cancelled!"));
break;
}
QTimer::singleShot(2000, this, SLOT(restoreNotification()));
}
void LightscreenWindow::preview(Screenshot* screenshot)
{
if (screenshot->options().preview) {
if (!mPreviewDialog) {
mPreviewDialog = new PreviewDialog(this);
}
mPreviewDialog->add(screenshot);
}
else {
screenshot->confirm(true);
}
}
void LightscreenWindow::quit()
{
settings()->setValue("position", pos());
int answer = 0;
QString doing;
if (ScreenshotManager::instance()->activeCount() > 0) {
doing = tr("processing");
}
if (Uploader::instance()->uploading() > 0) {
if (doing.isEmpty()) {
doing = tr("uploading");
}
else {
doing = tr("processing and uploading");
}
}
if (!doing.isEmpty()) {
answer = QMessageBox::question(this,
tr("Are you sure you want to quit?"),
tr("Lightscreen is currently %1 screenshots. Are you sure you want to quit?").arg(doing),
tr("Quit"),
tr("Don't Quit"));
}
if (answer == 0)
emit finished();
}
void LightscreenWindow::restoreNotification()
{
if (mTrayIcon)
mTrayIcon->setIcon(QIcon(":/icons/lightscreen.small"));
if (mHasTaskbarButton) {
mTaskbarButton->clearOverlayIcon();
mTaskbarButton->progress()->setVisible(false);
mTaskbarButton->progress()->stop();
mTaskbarButton->progress()->reset();
}
updateStatus();
}
void LightscreenWindow::screenshotAction(int mode)
{
int delayms = -1;
bool optionsHide = settings()->value("options/hide").toBool(); // Option cache, used a couple of times.
if (!mHideTrigger) {
mWasVisible = isVisible();
mHideTrigger = true;
}
// Applying pre-screenshot settings
if (optionsHide) {
hide();
#ifndef Q_OS_LINUX // X is not quick enough and the notification ends up everywhere but in the icon
if (mTrayIcon)
mTrayIcon->hide();
#endif
}
// Screenshot delay
delayms = settings()->value("options/delay", 0).toInt();
delayms = delayms * 1000; // Converting the delay to milliseconds.
delayms += 400;
if (optionsHide && mPreviewDialog) {
if (mPreviewDialog->count() >= 1) {
mPreviewDialog->hide();
}
}
// The delayed functions works using the static variable lastMode
// which keeps the argument so a QTimer can call this function again.
if (delayms > 0) {
if (mLastMode < 0) {
mLastMode = mode;
QTimer::singleShot(delayms, this, SLOT(screenshotAction()));
return;
}
else {
mode = mLastMode;
mLastMode = -1;
}
}
static Screenshot::Options options;
if (!mDoCache) {
// Populating the option object that will then be passed to the screenshot engine (sounds fancy huh?)
options.file = settings()->value("file/enabled").toBool();
options.format = (Screenshot::Format) settings()->value("file/format").toInt();
options.prefix = settings()->value("file/prefix").toString();
QDir dir(settings()->value("file/target").toString());
dir.makeAbsolute();
options.directory = dir;
options.quality = settings()->value("options/quality", 100).toInt();
options.currentMonitor = settings()->value("options/currentMonitor", false).toBool();
options.clipboard = settings()->value("options/clipboard", true).toBool();
options.imgurClipboard = settings()->value("options/imgurClipboard", false).toBool();
options.preview = settings()->value("options/preview", false).toBool();
options.magnify = settings()->value("options/magnify", false).toBool();
options.cursor = settings()->value("options/cursor", true).toBool();
options.saveAs = settings()->value("options/saveAs", false).toBool();
options.animations = settings()->value("options/animations", true).toBool();
options.replace = settings()->value("options/replace", false).toBool();
options.upload = settings()->value("options/uploadAuto", false).toBool();
options.optimize = settings()->value("options/optipng", false).toBool();
Screenshot::NamingOptions namingOptions;
namingOptions.naming = (Screenshot::Naming) settings()->value("file/naming").toInt();
namingOptions.leadingZeros = settings()->value("options/naming/leadingZeros", 0).toInt();
namingOptions.flip = settings()->value("options/flip", false).toBool();
namingOptions.dateFormat = settings()->value("options/naming/dateFormat", "yyyy-MM-dd").toString();
options.namingOptions = namingOptions;
mDoCache = true;
}
options.mode = mode;
ScreenshotManager::instance()->take(options);
}
void LightscreenWindow::screenshotActionTriggered(QAction* action)
{
screenshotAction(action->data().toInt());
}
void LightscreenWindow::screenHotkey()
{
screenshotAction(0);
}
void LightscreenWindow::showHotkeyError(const QStringList &hotkeys)
{
static bool dontShow = false;
if (dontShow)
return;
QString messageText;
messageText = tr("Some hotkeys could not be registered, they might already be in use");
if (hotkeys.count() > 1) {
messageText += tr("<br>The failed hotkeys are the following:") + "<ul>";
foreach(const QString &hotkey, hotkeys) {
messageText += QString("%1%2%3").arg("<li><b>").arg(hotkey).arg("</b></li>");
}
messageText += "</ul>";
}
else {
messageText += tr("<br>The failed hotkey is <b>%1</b>").arg(hotkeys[0]);
}
messageText += tr("<br><i>What do you want to do?</i>");
QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("Lightscreen"));
msgBox.setText(messageText);
QPushButton *changeButton = msgBox.addButton(tr("Change") , QMessageBox::ActionRole);
QPushButton *disableButton = msgBox.addButton(tr("Disable"), QMessageBox::ActionRole);
QPushButton *exitButton = msgBox.addButton(tr("Quit") , QMessageBox::ActionRole);
msgBox.exec();
if (msgBox.clickedButton() == exitButton) {
dontShow = true;
QTimer::singleShot(10, this, SLOT(quit()));
}
else if (msgBox.clickedButton() == changeButton) {
showOptions();
}
else if (msgBox.clickedButton() == disableButton) {
foreach(const QString &hotkey, hotkeys) {
settings()->setValue(QString("actions/%1/enabled").arg(hotkey), false);
}
}
}
void LightscreenWindow::showHistoryDialog()
{
HistoryDialog historyDialog(this);
historyDialog.exec();
updateStatus();
}
void LightscreenWindow::showOptions()
{
- mScreenShortcut.setEnabled(false);
- mAreaShortcut.setEnabled(false);
- mWindowShortcut.setEnabled(false);
- mWindowPickerShortcut.setEnabled(false);
- mOpenShortcut.setEnabled(false);
- mDirectoryShortcut.setEnabled(false);
-
+ mGlobalHotkeys->unregisterAllHotkeys();
QPointer<OptionsDialog> optionsDialog = new OptionsDialog(this);
optionsDialog->exec();
optionsDialog->deleteLater();
applySettings();
}
void LightscreenWindow::showScreenshotMessage(const Screenshot::Result &result, const QString &fileName)
{
if (result == Screenshot::Cancel)
return;
// Showing message.
QString title;
QString message;
if (result == Screenshot::Success) {
title = QFileInfo(fileName).fileName();
if (settings()->value("file/target").toString().isEmpty()) {
message = QDir::toNativeSeparators(QCoreApplication::applicationDirPath());
}
else {
message = tr("Saved to \"%1\"").arg(settings()->value("file/target").toString());
}
}
else {
title = tr("The screenshot was not taken");
message = tr("An error occurred.");
}
mLastMessage = 1;
mTrayIcon->showMessage(title, message);
}
void LightscreenWindow::showUploaderError(const QString &error)
{
mLastMessage = -1;
updateStatus();
if (mTrayIcon && !error.isEmpty() && settings()->value("options/message").toBool()) {
mTrayIcon->showMessage(tr("Upload error"), error);
}
notify(Screenshot::Fail);
}
void LightscreenWindow::showUploaderMessage(QString fileName, QString url)
{
if (mTrayIcon && settings()->value("options/message").toBool() && !url.isEmpty()) {
QString screenshot = QFileInfo(fileName).fileName();
if (screenshot.startsWith(".lstemp."))
screenshot = tr("Screenshot");
mLastMessage = 2;
mTrayIcon->showMessage(tr("%1 uploaded").arg(screenshot), tr("Click here to go to %1").arg(url));
}
updateStatus();
}
void LightscreenWindow::toggleVisibility(QSystemTrayIcon::ActivationReason reason)
{
if (reason != QSystemTrayIcon::DoubleClick)
return;
if (isVisible()) {
hide();
}
else {
show();
os::setForegroundWindow(this);
}
}
void LightscreenWindow::updateStatus()
{
int uploadCount = Uploader::instance()->uploading();
int activeCount = ScreenshotManager::instance()->activeCount();
if (mHasTaskbarButton) {
mTaskbarButton->progress()->setPaused(true);
mTaskbarButton->progress()->setVisible(true);
}
if (uploadCount > 0) {
setStatus(tr("%1 uploading").arg(uploadCount));
if (mHasTaskbarButton) {
mTaskbarButton->progress()->setRange(0, 100);
mTaskbarButton->progress()->resume();
}
emit uploading(true);
}
else {
if (activeCount > 1) {
setStatus(tr("%1 processing").arg(activeCount));
}
else if (activeCount == 1) {
setStatus(tr("processing"));
}
else {
setStatus();
if (mHasTaskbarButton) {
mTaskbarButton->progress()->setVisible(false);
}
}
emit uploading(false);
}
}
void LightscreenWindow::updaterDone(bool result)
{
settings()->setValue("lastUpdateCheck", QDate::currentDate().dayOfYear());
if (!result)
return;
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Lightscreen"));
msgBox.setText(tr("There's a new version of Lightscreen available.<br>Would you like to see more information?<br>(<em>You can turn this notification off</em>)"));
msgBox.setIcon(QMessageBox::Information);
QPushButton *yesButton = msgBox.addButton(QMessageBox::Yes);
QPushButton *turnOffButton = msgBox.addButton(tr("Turn Off"), QMessageBox::ActionRole);
QPushButton *remindButton = msgBox.addButton(tr("Remind Me Later"), QMessageBox::RejectRole);
Q_UNUSED(remindButton);
msgBox.exec();
if (msgBox.clickedButton() == yesButton) {
QDesktopServices::openUrl(QUrl("https://lightscreen.com.ar/whatsnew?from=" + qApp->applicationVersion()));
}
else if (msgBox.clickedButton() == turnOffButton) {
settings()->setValue("options/disableUpdater", true);
}
mUpdater->deleteLater();
}
void LightscreenWindow::upload(const QString &fileName)
{
Uploader::instance()->upload(fileName);
}
void LightscreenWindow::uploadCancel()
{
if (Uploader::instance()->uploading() <= 0) {
return;
}
int confirm = QMessageBox::question(this, tr("Upload cancel"), tr("Do you want to cancel all screenshot uploads?"), tr("Cancel"), tr("Don't Cancel"));
if (confirm == 0) {
Uploader::instance()->cancel();
updateStatus();
}
}
void LightscreenWindow::uploadLast()
{
upload(mLastScreenshot);
updateStatus();
}
void LightscreenWindow::uploadProgress(int progress)
{
if (mHasTaskbarButton) {
mTaskbarButton->progress()->setVisible(true);
mTaskbarButton->progress()->setValue(progress);
}
if (isVisible() && progress > 0) {
int uploadCount = Uploader::instance()->uploading();
if (uploadCount > 1) {
setWindowTitle(tr("%1% of %2 uploads - Lightscreen").arg(progress).arg(uploadCount));
}
else {
setWindowTitle(tr("%1% - Lightscreen").arg(progress));
}
}
}
void LightscreenWindow::uploadMenuShown()
{
QMenu *imgurMenu = qobject_cast<QMenu*>(sender());
imgurMenu->actions().at(0)->setEnabled(!mLastScreenshot.isEmpty());
}
void LightscreenWindow::windowHotkey()
{
screenshotAction(1);
}
void LightscreenWindow::windowPickerHotkey()
{
screenshotAction(3);
}
void LightscreenWindow::applySettings()
{
bool tray = settings()->value("options/tray", true).toBool();
if (tray && !mTrayIcon) {
createTrayIcon();
mTrayIcon->setVisible(true);
}
else if (!tray && mTrayIcon) {
mTrayIcon->setVisible(false);
}
connectHotkeys();
mDoCache = false;
if (settings()->value("lastScreenshot").isValid() && mLastScreenshot.isEmpty())
mLastScreenshot = settings()->value("lastScreenshot").toString();
os::setStartup(settings()->value("options/startup").toBool(), settings()->value("options/startupHide").toBool());
}
void LightscreenWindow::connectHotkeys()
{
- bool screen = mScreenShortcut.setShortcut(settings()->value("actions/screen/hotkey").value<QKeySequence>());
- mScreenShortcut.setEnabled(settings()->value("actions/screen/enabled").toBool());
-
- bool area = mAreaShortcut.setShortcut(settings()->value("actions/area/hotkey").value<QKeySequence>());
- mAreaShortcut.setEnabled(settings()->value("actions/area/enabled").toBool());
-
- bool window = mWindowShortcut.setShortcut(settings()->value("actions/window/hotkey").value<QKeySequence>());
- mWindowShortcut.setEnabled(settings()->value("actions/window/enabled").toBool());
-
- bool windowPicker = mWindowPickerShortcut.setShortcut(settings()->value("actions/windowPicker/hotkey").value<QKeySequence>());
- mWindowPickerShortcut.setEnabled(settings()->value("actions/windowPicker/enabled").toBool());
-
- bool open = mOpenShortcut.setShortcut(settings()->value("actions/open/hotkey").value<QKeySequence>());
- mOpenShortcut.setEnabled(settings()->value("actions/open/enabled").toBool());
-
- bool directory = mOpenShortcut.setShortcut(settings()->value("actions/directory/hotkey").value<QKeySequence>());
- mDirectoryShortcut.setEnabled(settings()->value("actions/directory/enabled").toBool());
-
- QStringList failed;
- if (!screen) failed << "screen";
- if (!area) failed << "area";
- if (!window) failed << "window";
- if (!windowPicker) failed << "window picker";
- if (!open) failed << "open";
- if (!directory) failed << "directory";
+ QStringList failed;
+ QStringList actions = {"screen", "window", "area", "windowPicker", "open", "directory"};
+ size_t i = 0;
+
+ foreach (const QString &action, actions) {
+ if (settings()->value("actions/" + action + "/enabled").toBool()) {
+ if (!mGlobalHotkeys->registerHotkey(settings()->value("actions/" + action + "/hotkey").toString(), i)) {
+ failed << action;
+ }
+ }
+
+ i++;
+ }
- if (!failed.isEmpty())
- showHotkeyError(failed);
+ if (!failed.isEmpty()) {
+ showHotkeyError(failed);
+ }
}
void LightscreenWindow::createTrayIcon()
{
mTrayIcon = new QSystemTrayIcon(QIcon(":/icons/lightscreen.small"), this);
updateStatus();
connect(mTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleVisibility(QSystemTrayIcon::ActivationReason)));
connect(mTrayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked()));
QAction *hideAction = new QAction(QIcon(":/icons/lightscreen.small"), tr("Show&/Hide"), mTrayIcon);
connect(hideAction, SIGNAL(triggered()), this, SLOT(toggleVisibility()));
QAction *screenAction = new QAction(os::icon("screen"), tr("&Screen"), mTrayIcon);
screenAction->setData(QVariant(0));
QAction *windowAction = new QAction(os::icon("window"), tr("Active &Window"), this);
windowAction->setData(QVariant(1));
QAction *windowPickerAction = new QAction(os::icon("pickWindow"), tr("&Pick Window"), this);
windowPickerAction->setData(QVariant(3));
QAction *areaAction = new QAction(os::icon("area"), tr("&Area"), mTrayIcon);
areaAction->setData(QVariant(2));
QActionGroup *screenshotGroup = new QActionGroup(mTrayIcon);
screenshotGroup->addAction(screenAction);
screenshotGroup->addAction(areaAction);
screenshotGroup->addAction(windowAction);
screenshotGroup->addAction(windowPickerAction);
connect(screenshotGroup, SIGNAL(triggered(QAction*)), this, SLOT(screenshotActionTriggered(QAction*)));
// Duplicated for the screenshot button :(
QAction *uploadAction = new QAction(os::icon("imgur"), tr("&Upload last"), mTrayIcon);
uploadAction->setToolTip(tr("Upload the last screenshot you took to imgur.com"));
connect(uploadAction, SIGNAL(triggered()), this, SLOT(uploadLast()));
QAction *cancelAction = new QAction(os::icon("no"), tr("&Cancel upload"), mTrayIcon);
cancelAction->setToolTip(tr("Cancel the currently uploading screenshots"));
cancelAction->setEnabled(false);
connect(this, SIGNAL(uploading(bool)), cancelAction, SLOT(setEnabled(bool)));
connect(cancelAction, SIGNAL(triggered()), this, SLOT(uploadCancel()));
QAction *historyAction = new QAction(os::icon("view-history"), tr("View History"), mTrayIcon);
connect(historyAction, SIGNAL(triggered()), this, SLOT(showHistoryDialog()));
//
QAction *optionsAction = new QAction(os::icon("configure"), tr("View &Options"), mTrayIcon);
connect(optionsAction, SIGNAL(triggered()), this, SLOT(showOptions()));
QAction *goAction = new QAction(os::icon("folder"), tr("&Go to Folder"), mTrayIcon);
connect(goAction, SIGNAL(triggered()), this, SLOT(goToFolder()));
QAction *quitAction = new QAction(tr("&Quit"), mTrayIcon);
connect(quitAction, SIGNAL(triggered()), this, SLOT(quit()));
QMenu* screenshotMenu = new QMenu(tr("Screenshot"));
screenshotMenu->addAction(screenAction);
screenshotMenu->addAction(areaAction);
screenshotMenu->addAction(windowAction);
screenshotMenu->addAction(windowPickerAction);
// Duplicated for the screenshot button :(
QMenu* imgurMenu = new QMenu(tr("Upload"));
imgurMenu->addAction(uploadAction);
imgurMenu->addAction(cancelAction);
imgurMenu->addAction(historyAction);
imgurMenu->addSeparator();
QMenu* trayIconMenu = new QMenu;
trayIconMenu->addAction(hideAction);
trayIconMenu->addSeparator();
trayIconMenu->addMenu(imgurMenu);
trayIconMenu->addSeparator();
trayIconMenu->addMenu(screenshotMenu);
trayIconMenu->addAction(optionsAction);
trayIconMenu->addAction(goAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
mTrayIcon->setContextMenu(trayIconMenu);
}
void LightscreenWindow::setStatus(QString status)
{
if (status.isEmpty()) {
status = tr("Lightscreen");
}
else {
status += tr(" - Lightscreen");
}
if (mTrayIcon) {
mTrayIcon->setToolTip(status);
}
setWindowTitle(status);
}
QSettings *LightscreenWindow::settings() const
{
return ScreenshotManager::instance()->settings();
}
// Event handling
bool LightscreenWindow::event(QEvent *event)
{
if (event->type() == QEvent::Show)
{
if (mHasTaskbarButton) {
mTaskbarButton->setWindow(windowHandle());
}
}
else if (event->type() == QEvent::Hide) {
settings()->setValue("position", pos());
}
else if (event->type() == QEvent::Close) {
if (settings()->value("options/tray").toBool() && settings()->value("options/closeHide").toBool()) {
closeToTrayWarning();
hide();
}
else if (settings()->value("options/closeHide").toBool()) {
if (closingWithoutTray())
hide();
}
else {
quit();
}
}
else if (event->type() == QEvent::Show) {
QPoint savedPosition = settings()->value("position").toPoint();
if (!savedPosition.isNull() && qApp->desktop()->availableGeometry().contains(QRect(savedPosition, size())))
move(savedPosition);
}
else if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
#ifdef Q_WS_MAC
if (keyEvent->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_Period) {
keyEvent->ignore();
if(isVisible())
toggleVisibility();
return false;
}
else
#endif
if (!keyEvent->modifiers() && keyEvent->key() == Qt::Key_Escape) {
keyEvent->ignore();
if(isVisible())
toggleVisibility();
return false;
}
}
else if (event->type() == QEvent::LanguageChange) {
ui.retranslateUi(this);
resize(minimumSizeHint());
}
return QMainWindow::event(event);
}
diff --git a/lightscreenwindow.h b/lightscreenwindow.h
index 47bd296..ffea47a 100644
--- a/lightscreenwindow.h
+++ b/lightscreenwindow.h
@@ -1,152 +1,147 @@
/*
* Copyright (C) 2016 Christian Kaiser
*
* 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef LIGHTSCREENWINDOW_H
#define LIGHTSCREENWINDOW_H
#include <QMainWindow>
#include <QPointer>
#include <QSystemTrayIcon>
#include "updater/updater.h"
#include "tools/screenshot.h"
-#include "tools/qxtglobalshortcut/qxtglobalshortcut.h"
#include "dialogs/previewdialog.h"
#include "ui_lightscreenwindow.h"
class Updater;
class QSettings;
class QProgressBar;
class QWinTaskbarButton;
+class UGlobalHotkeys;
class LightscreenWindow : public QMainWindow
{
Q_OBJECT
public:
LightscreenWindow(QWidget *parent = 0);
~LightscreenWindow();
public slots:
void action(int mode = 3);
void areaHotkey();
void checkForUpdates();
void cleanup(Screenshot::Options &options);
void closeToTrayWarning();
bool closingWithoutTray();
void createUploadMenu();
void goToFolder();
void messageClicked();
void messageReceived(const QString &message);
void notify(const Screenshot::Result &result);
void preview(Screenshot* screenshot);
void quit();
void restoreNotification();
void setStatus(QString status = "");
void screenshotAction(int mode = 0);
void screenshotActionTriggered(QAction* action);
void screenHotkey();
void showHotkeyError(const QStringList &hotkeys);
void showHistoryDialog();
void showOptions();
void showScreenshotMessage(const Screenshot::Result &result, const QString &fileName);
void showUploaderError(const QString &error);
void showUploaderMessage(QString fileName, QString url);
void toggleVisibility(QSystemTrayIcon::ActivationReason reason = QSystemTrayIcon::DoubleClick);
void updateStatus();
void updaterDone(bool result);
void upload(const QString &fileName);
void uploadCancel();
void uploadLast();
void uploadProgress(int progress);
void uploadMenuShown();
void windowHotkey();
void windowPickerHotkey();
private slots:
void applySettings();
signals:
void uploading(bool uploading);
void finished();
private:
void connectHotkeys();
void createTrayIcon();
#ifdef Q_OS_WIN
bool winEvent(MSG *message, long *result);
#endif
// Convenience function
QSettings *settings() const;
protected:
bool event(QEvent *event);
private:
bool mDoCache;
bool mHideTrigger;
bool mReviveMain;
bool mWasVisible;
int mLastMessage;
int mLastMode;
QString mLastScreenshot;
QPointer<QSystemTrayIcon> mTrayIcon;
QPointer<PreviewDialog> mPreviewDialog;
QPointer<Updater> mUpdater;
Ui::LightscreenWindowClass ui;
- QxtGlobalShortcut mScreenShortcut;
- QxtGlobalShortcut mAreaShortcut;
- QxtGlobalShortcut mWindowShortcut;
- QxtGlobalShortcut mWindowPickerShortcut;
- QxtGlobalShortcut mOpenShortcut;
- QxtGlobalShortcut mDirectoryShortcut;
+ QPointer<UGlobalHotkeys> mGlobalHotkeys;
bool mHasTaskbarButton;
#ifdef Q_OS_WIN
QPointer<QWinTaskbarButton> mTaskbarButton;
#else
class QWinTaskbarProgressDummy {
public:
void setVisible(bool v) { Q_UNUSED(v) }
void setPaused(bool p) { Q_UNUSED(p) }
void resume() {}
void stop() {}
void reset() {}
void setRange(int m, int m2) { Q_UNUSED(m) Q_UNUSED(m2) }
void setValue(int v) { Q_UNUSED(v) }
};
class QWinTaskbarDummy : public QObject {
public:
void setOverlayIcon(QIcon i) { Q_UNUSED(i) }
void clearOverlayIcon() {}
QWinTaskbarProgressDummy* progress() { return 0; }
void setWindow(QWindow* w) { Q_UNUSED(w) }
};
QWinTaskbarDummy* mTaskbarButton;
#endif
};
#endif // LIGHTSCREENWINDOW_H
diff --git a/tools/qxtglobalshortcut/qxtglobal.cpp b/tools/qxtglobalshortcut/qxtglobal.cpp
deleted file mode 100644
index 3da47c1..0000000
--- a/tools/qxtglobalshortcut/qxtglobal.cpp
+++ /dev/null
@@ -1,251 +0,0 @@
-
-/****************************************************************************
-** Copyright (c) 2006 - 2011, the LibQxt project.
-** See the Qxt AUTHORS file for a list of authors and copyright holders.
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in the
-** documentation and/or other materials provided with the distribution.
-** * Neither the name of the LibQxt project nor the
-** names of its contributors may be used to endorse or promote products
-** derived from this software without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
-** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-** <http://libqxt.org> <foundation@libqxt.org>
-*****************************************************************************/
-
-#include "qxtglobal.h"
-
-/*!
- \headerfile <QxtGlobal>
- \title Global Qxt Declarations
- \inmodule QxtCore
-
- \brief The <QxtGlobal> header provides basic declarations and
- is included by all other Qxt headers.
- */
-
-/*!
- \macro QXT_VERSION
- \relates <QxtGlobal>
-
- This macro expands a numeric value of the form 0xMMNNPP (MM =
- major, NN = minor, PP = patch) that specifies Qxt's version
- number. For example, if you compile your application against Qxt
- 0.4.0, the QXT_VERSION macro will expand to 0x000400.
-
- You can use QXT_VERSION to use the latest Qt features where
- available. For example:
- \code
- #if QXT_VERSION >= 0x000400
- qxtTabWidget->setTabMovementMode(QxtTabWidget::InPlaceMovement);
- #endif
- \endcode
-
- \sa QXT_VERSION_STR, qxtVersion()
- */
-
-/*!
- \macro QXT_VERSION_STR
- \relates <QxtGlobal>
-
- This macro expands to a string that specifies Qxt's version number
- (for example, "0.4.0"). This is the version against which the
- application is compiled.
-
- \sa qxtVersion(), QXT_VERSION
- */
-
-/*!
- \relates <QxtGlobal>
-
- Returns the version number of Qxt at run-time as a string (for
- example, "0.4.0"). This may be a different version than the
- version the application was compiled against.
-
- \sa QXT_VERSION_STR
- */
-const char * qxtVersion()
-{
- return QXT_VERSION_STR;
-}
-
-/*!
-\headerfile <QxtPimpl>
-\title The Qxt private implementation
-\inmodule QxtCore
-
-\brief The <QxtPimpl> header provides tools for hiding
-details of a class.
-
-Application code generally doesn't have to be concerned about hiding its
-implementation details, but when writing library code it is important to
-maintain a constant interface, both source and binary. Maintaining a constant
-source interface is easy enough, but keeping the binary interface constant
-means moving implementation details into a private class. The PIMPL, or
-d-pointer, idiom is a common method of implementing this separation. QxtPimpl
-offers a convenient way to connect the public and private sides of your class.
-
-\section1 Getting Started
-Before you declare the public class, you need to make a forward declaration
-of the private class. The private class must have the same name as the public
-class, followed by the word Private. For example, a class named MyTest would
-declare the private class with:
-\code
-class MyTestPrivate;
-\endcode
-
-\section1 The Public Class
-Generally, you shouldn't keep any data members in the public class without a
-good reason. Functions that are part of the public interface should be declared
-in the public class, and functions that need to be available to subclasses (for
-calling or overriding) should be in the protected section of the public class.
-To connect the private class to the public class, include the
-QXT_DECLARE_PRIVATE macro in the private section of the public class. In the
-example above, the private class is connected as follows:
-\code
-private:
- QXT_DECLARE_PRIVATE(MyTest)
-\endcode
-
-Additionally, you must include the QXT_INIT_PRIVATE macro in the public class's
-constructor. Continuing with the MyTest example, your constructor might look
-like this:
-\code
-MyTest::MyTest() {
- // initialization
- QXT_INIT_PRIVATE(MyTest);
-}
-\endcode
-
-\section1 The Private Class
-As mentioned above, data members should usually be kept in the private class.
-This allows the memory layout of the private class to change without breaking
-binary compatibility for the public class. Functions that exist only as
-implementation details, or functions that need access to private data members,
-should be implemented here.
-
-To define the private class, inherit from the template QxtPrivate class, and
-include the QXT_DECLARE_PUBLIC macro in its public section. The template
-parameter should be the name of the public class. For example:
-\code
-class MyTestPrivate : public QxtPrivate<MyTest> {
-public:
- MyTestPrivate();
- QXT_DECLARE_PUBLIC(MyTest)
-};
-\endcode
-
-\section1 Accessing Private Members
-Use the qxt_d() function (actually a function-like object) from functions in
-the public class to access the private class. Similarly, functions in the
-private class can invoke functions in the public class by using the qxt_p()
-function (this one's actually a function).
-
-For example, assume that MyTest has methods named getFoobar and doBaz(),
-and MyTestPrivate has a member named foobar and a method named doQuux().
-The code might resemble this example:
-\code
-int MyTest::getFoobar() {
- return qxt_d().foobar;
-}
-
-void MyTestPrivate::doQuux() {
- qxt_p().doBaz(foobar);
-}
-\endcode
-*/
-
-/*!
- * \macro QXT_DECLARE_PRIVATE(PUB)
- * \relates <QxtPimpl>
- * Declares that a public class has a related private class.
- *
- * This shuold be put in the private section of the public class. The
- * parameter \a PUB must be the name of the public class.
- */
-
-/*!
- * \macro QXT_DECLARE_PUBLIC(PUB)
- * \relates <QxtPimpl>
- * Declares that a private class has a related public class named \a PUB.
- *
- * This may be put anywhere in the declaration of the private class. The parameter is the name of the public class.
- */
-
-/*!
- * \macro QXT_INIT_PRIVATE(PUB)
- * \relates <QxtPimpl>
- * Initializes resources owned by the private class.
- *
- * This should be called from the public class's constructor,
- * before qxt_d() is used for the first time. The parameter \a PUB must be
- * the name of the public class.
- */
-
-/*!
- * \macro QXT_D(PUB)
- * \relates <QxtPimpl>
- * Returns a reference in the current scope named "d" to the private class
- * associated with the public class \a PUB.
- *
- * This function is only available in a class using QXT_DECLARE_PRIVATE().
- */
-
-/*!
- * \macro QXT_P(PUB)
- * \relates <QxtPimpl>
- * Creates a reference in the current scope named "q" to the public class
- * named \a PUB.
- *
- * This macro only works in a class using QXT_DECLARE_PUBLIC().
- */
-
-/*!
- * \fn QxtPrivate<PUB>& PUB::qxt_d()
- * \relates <QxtPimpl>
- * Returns a reference to the private class.
- *
- * This function is only available in a class using \a QXT_DECLARE_PRIVATE.
- */
-
-/*!
- * \fn const QxtPrivate<PUB>& PUB::qxt_d() const
- * \relates <QxtPimpl>
- * Returns a const reference to the private class.
- *
- * This function is only available in a class using \a QXT_DECLARE_PRIVATE.
- * This overload will be automatically used in const functions.
- */
-
-/*!
- * \fn PUB& QxtPrivate::qxt_p()
- * \relates <QxtPimpl>
- * Returns a reference to the public class.
- *
- * This function is only available in a class using QXT_DECLARE_PUBLIC().
- */
-
-/*!
- * \fn const PUB& QxtPrivate::qxt_p() const
- * \relates <QxtPimpl>
- * Returns a const reference to the public class.
- *
- * This function is only available in a class using QXT_DECLARE_PUBLIC().
- * This overload will be automatically used in const functions.
- */
diff --git a/tools/qxtglobalshortcut/qxtglobal.h b/tools/qxtglobalshortcut/qxtglobal.h
deleted file mode 100644
index 7d5abfb..0000000
--- a/tools/qxtglobalshortcut/qxtglobal.h
+++ /dev/null
@@ -1,233 +0,0 @@
-
-/****************************************************************************
-** Copyright (c) 2006 - 2011, the LibQxt project.
-** See the Qxt AUTHORS file for a list of authors and copyright holders.
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in the
-** documentation and/or other materials provided with the distribution.
-** * Neither the name of the LibQxt project nor the
-** names of its contributors may be used to endorse or promote products
-** derived from this software without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
-** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-** <http://libqxt.org> <foundation@libqxt.org>
-*****************************************************************************/
-
-#ifndef QXTGLOBAL_H
-#define QXTGLOBAL_H
-
-#include <QtGlobal>
-
-#define QXT_VERSION 0x000700
-#define QXT_VERSION_STR "0.7.0"
-
-//--------------------------global macros------------------------------
-
-#ifndef QXT_NO_MACROS
-
-#ifndef _countof
-#define _countof(x) (sizeof(x)/sizeof(*x))
-#endif
-
-#endif // QXT_NO_MACROS
-
-//--------------------------export macros------------------------------
-
-#define QXT_DLLEXPORT DO_NOT_USE_THIS_ANYMORE
-
-#if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
-# if defined(BUILD_QXT_CORE)
-# define QXT_CORE_EXPORT Q_DECL_EXPORT
-# else
-# define QXT_CORE_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define QXT_CORE_EXPORT
-#endif // BUILD_QXT_CORE
-
-#if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
-# if defined(BUILD_QXT_GUI)
-# define QXT_GUI_EXPORT Q_DECL_EXPORT
-# else
-# define QXT_GUI_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define QXT_GUI_EXPORT
-#endif // BUILD_QXT_GUI
-
-#if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
-# if defined(BUILD_QXT_NETWORK)
-# define QXT_NETWORK_EXPORT Q_DECL_EXPORT
-# else
-# define QXT_NETWORK_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define QXT_NETWORK_EXPORT
-#endif // BUILD_QXT_NETWORK
-
-#if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
-# if defined(BUILD_QXT_SQL)
-# define QXT_SQL_EXPORT Q_DECL_EXPORT
-# else
-# define QXT_SQL_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define QXT_SQL_EXPORT
-#endif // BUILD_QXT_SQL
-
-#if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
-# if defined(BUILD_QXT_WEB)
-# define QXT_WEB_EXPORT Q_DECL_EXPORT
-# else
-# define QXT_WEB_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define QXT_WEB_EXPORT
-#endif // BUILD_QXT_WEB
-
-#if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
-# if defined(BUILD_QXT_BERKELEY)
-# define QXT_BERKELEY_EXPORT Q_DECL_EXPORT
-# else
-# define QXT_BERKELEY_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define QXT_BERKELEY_EXPORT
-#endif // BUILD_QXT_BERKELEY
-
-#if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
-# if defined(BUILD_QXT_ZEROCONF)
-# define QXT_ZEROCONF_EXPORT Q_DECL_EXPORT
-# else
-# define QXT_ZEROCONF_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define QXT_ZEROCONF_EXPORT
-#endif // QXT_ZEROCONF_EXPORT
-
-#if defined(BUILD_QXT_CORE) || defined(BUILD_QXT_GUI) || defined(BUILD_QXT_SQL) || defined(BUILD_QXT_NETWORK) || defined(BUILD_QXT_WEB) || defined(BUILD_QXT_BERKELEY) || defined(BUILD_QXT_ZEROCONF)
-# define BUILD_QXT
-#endif
-
-QXT_CORE_EXPORT const char* qxtVersion();
-
-#ifndef QT_BEGIN_NAMESPACE
-#define QT_BEGIN_NAMESPACE
-#endif
-
-#ifndef QT_END_NAMESPACE
-#define QT_END_NAMESPACE
-#endif
-
-#ifndef QT_FORWARD_DECLARE_CLASS
-#define QT_FORWARD_DECLARE_CLASS(Class) class Class;
-#endif
-
-/****************************************************************************
-** This file is derived from code bearing the following notice:
-** The sole author of this file, Adam Higerd, has explicitly disclaimed all
-** copyright interest and protection for the content within. This file has
-** been placed in the public domain according to United States copyright
-** statute and case law. In jurisdictions where this public domain dedication
-** is not legally recognized, anyone who receives a copy of this file is
-** permitted to use, modify, duplicate, and redistribute this file, in whole
-** or in part, with no restrictions or conditions. In these jurisdictions,
-** this file shall be copyright (C) 2006-2008 by Adam Higerd.
-****************************************************************************/
-
-#define QXT_DECLARE_PRIVATE(PUB) friend class PUB##Private; QxtPrivateInterface<PUB, PUB##Private> qxt_d;
-#define QXT_DECLARE_PUBLIC(PUB) friend class PUB;
-#define QXT_INIT_PRIVATE(PUB) qxt_d.setPublic(this);
-#define QXT_D(PUB) PUB##Private& d = qxt_d()
-#define QXT_P(PUB) PUB& p = qxt_p()
-
-template <typename PUB>
-class QxtPrivate
-{
-public:
- virtual ~QxtPrivate()
- {}
- inline void QXT_setPublic(PUB* pub)
- {
- qxt_p_ptr = pub;
- }
-
-protected:
- inline PUB& qxt_p()
- {
- return *qxt_p_ptr;
- }
- inline const PUB& qxt_p() const
- {
- return *qxt_p_ptr;
- }
- inline PUB* qxt_ptr()
- {
- return qxt_p_ptr;
- }
- inline const PUB* qxt_ptr() const
- {
- return qxt_p_ptr;
- }
-
-private:
- PUB* qxt_p_ptr;
-};
-
-template <typename PUB, typename PVT>
-class QxtPrivateInterface
-{
- friend class QxtPrivate<PUB>;
-public:
- QxtPrivateInterface()
- {
- pvt = new PVT;
- }
- ~QxtPrivateInterface()
- {
- delete pvt;
- }
-
- inline void setPublic(PUB* pub)
- {
- pvt->QXT_setPublic(pub);
- }
- inline PVT& operator()()
- {
- return *static_cast<PVT*>(pvt);
- }
- inline const PVT& operator()() const
- {
- return *static_cast<PVT*>(pvt);
- }
- inline PVT * operator->()
- {
- return static_cast<PVT*>(pvt);
- }
- inline const PVT * operator->() const
- {
- return static_cast<PVT*>(pvt);
- }
-private:
- QxtPrivateInterface(const QxtPrivateInterface&) { }
- QxtPrivateInterface& operator=(const QxtPrivateInterface&) { }
- QxtPrivate<PUB>* pvt;
-};
-
-#endif // QXT_GLOBAL
diff --git a/tools/qxtglobalshortcut/qxtglobalshortcut.cpp b/tools/qxtglobalshortcut/qxtglobalshortcut.cpp
deleted file mode 100644
index e74d21d..0000000
--- a/tools/qxtglobalshortcut/qxtglobalshortcut.cpp
+++ /dev/null
@@ -1,212 +0,0 @@
-#include "qxtglobalshortcut.h"
-/****************************************************************************
-** Copyright (c) 2006 - 2011, the LibQxt project.
-** See the Qxt AUTHORS file for a list of authors and copyright holders.
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in the
-** documentation and/or other materials provided with the distribution.
-** * Neither the name of the LibQxt project nor the
-** names of its contributors may be used to endorse or promote products
-** derived from this software without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
-** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-** <http://libqxt.org> <foundation@libqxt.org>
-*****************************************************************************/
-
-#include "qxtglobalshortcut_p.h"
-#include <QAbstractEventDispatcher>
-#include <QtDebug>
-
-#ifndef Q_WS_MAC
-int QxtGlobalShortcutPrivate::ref = 0;
-#endif // Q_WS_MAC
-QHash<QPair<quint32, quint32>, QxtGlobalShortcut*> QxtGlobalShortcutPrivate::shortcuts;
-
-QxtGlobalShortcutPrivate::QxtGlobalShortcutPrivate() : enabled(true), key(Qt::Key(0)), mods(Qt::NoModifier)
-{
-#ifndef Q_WS_MAC
- if (ref == 0) {
- QAbstractEventDispatcher::instance()->installNativeEventFilter(this);
- }
- ++ref;
-#endif // Q_WS_MAC
-}
-
-QxtGlobalShortcutPrivate::~QxtGlobalShortcutPrivate()
-{
-#ifndef Q_WS_MAC
- --ref;
- if (ref == 0) {
- QAbstractEventDispatcher *ed = QAbstractEventDispatcher::instance();
- if (ed != 0) {
- ed->removeNativeEventFilter(this);
- }
- }
-#endif // Q_WS_MAC
-}
-
-bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut)
-{
- Qt::KeyboardModifiers allMods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier;
- key = shortcut.isEmpty() ? Qt::Key(0) : Qt::Key((shortcut[0] ^ allMods) & shortcut[0]);
- mods = shortcut.isEmpty() ? Qt::KeyboardModifiers(0) : Qt::KeyboardModifiers(shortcut[0] & allMods);
- const quint32 nativeKey = nativeKeycode(key);
- const quint32 nativeMods = nativeModifiers(mods);
- const bool res = registerShortcut(nativeKey, nativeMods);
- if (res)
- shortcuts.insert(qMakePair(nativeKey, nativeMods), &qxt_p());
- else
- qWarning() << "QxtGlobalShortcut failed to register:" << QKeySequence(key + mods).toString();
- return res;
-}
-
-bool QxtGlobalShortcutPrivate::unsetShortcut()
-{
- bool res = false;
- const quint32 nativeKey = nativeKeycode(key);
- const quint32 nativeMods = nativeModifiers(mods);
- if (shortcuts.value(qMakePair(nativeKey, nativeMods)) == &qxt_p())
- res = unregisterShortcut(nativeKey, nativeMods);
- if (res)
- shortcuts.remove(qMakePair(nativeKey, nativeMods));
- else
- qWarning() << "QxtGlobalShortcut failed to unregister:" << QKeySequence(key + mods).toString();
- key = Qt::Key(0);
- mods = Qt::KeyboardModifiers(0);
- return res;
-}
-
-void QxtGlobalShortcutPrivate::activateShortcut(quint32 nativeKey, quint32 nativeMods)
-{
- QxtGlobalShortcut* shortcut = shortcuts.value(qMakePair(nativeKey, nativeMods));
- if (shortcut && shortcut->isEnabled())
- emit shortcut->activated();
-}
-
-/*!
- \class QxtGlobalShortcut
- \inmodule QxtWidgets
- \brief The QxtGlobalShortcut class provides a global shortcut aka "hotkey".
-
- A global shortcut triggers even if the application is not active. This
- makes it easy to implement applications that react to certain shortcuts
- still if some other application is active or if the application is for
- example minimized to the system tray.
-
- Example usage:
- \code
- QxtGlobalShortcut* shortcut = new QxtGlobalShortcut(window);
- connect(shortcut, SIGNAL(activated()), window, SLOT(toggleVisibility()));
- shortcut->setShortcut(QKeySequence("Ctrl+Shift+F12"));
- \endcode
-
- \bold {Note:} Since Qxt 0.6 QxtGlobalShortcut no more requires QxtApplication.
- */
-
-/*!
- \fn QxtGlobalShortcut::activated()
-
- This signal is emitted when the user types the shortcut's key sequence.
-
- \sa shortcut
- */
-
-/*!
- Constructs a new QxtGlobalShortcut with \a parent.
- */
-QxtGlobalShortcut::QxtGlobalShortcut(QObject* parent)
- : QObject(parent)
-{
- QXT_INIT_PRIVATE(QxtGlobalShortcut);
-}
-
-/*!
- Constructs a new QxtGlobalShortcut with \a shortcut and \a parent.
- */
-QxtGlobalShortcut::QxtGlobalShortcut(const QKeySequence& shortcut, QObject* parent)
- : QObject(parent)
-{
- QXT_INIT_PRIVATE(QxtGlobalShortcut);
- setShortcut(shortcut);
-}
-
-/*!
- Destructs the QxtGlobalShortcut.
- */
-QxtGlobalShortcut::~QxtGlobalShortcut()
-{
- if (qxt_d().key != 0)
- qxt_d().unsetShortcut();
-}
-
-/*!
- \property QxtGlobalShortcut::shortcut
- \brief the shortcut key sequence
-
- \bold {Note:} Notice that corresponding key press and release events are not
- delivered for registered global shortcuts even if they are disabled.
- Also, comma separated key sequences are not supported.
- Only the first part is used:
-
- \code
- qxtShortcut->setShortcut(QKeySequence("Ctrl+Alt+A,Ctrl+Alt+B"));
- Q_ASSERT(qxtShortcut->shortcut() == QKeySequence("Ctrl+Alt+A"));
- \endcode
- */
-QKeySequence QxtGlobalShortcut::shortcut() const
-{
- return QKeySequence(qxt_d().key | qxt_d().mods);
-}
-
-bool QxtGlobalShortcut::setShortcut(const QKeySequence& shortcut)
-{
- if (qxt_d().key != 0)
- qxt_d().unsetShortcut();
- return qxt_d().setShortcut(shortcut);
-}
-
-/*!
- \property QxtGlobalShortcut::enabled
- \brief whether the shortcut is enabled
-
- A disabled shortcut does not get activated.
-
- The default value is \c true.
-
- \sa setDisabled()
- */
-bool QxtGlobalShortcut::isEnabled() const
-{
- return qxt_d().enabled;
-}
-
-void QxtGlobalShortcut::setEnabled(bool enabled)
-{
- qxt_d().enabled = enabled;
-}
-
-/*!
- Sets the shortcut \a disabled.
-
- \sa enabled
- */
-void QxtGlobalShortcut::setDisabled(bool disabled)
-{
- qxt_d().enabled = !disabled;
-}
diff --git a/tools/qxtglobalshortcut/qxtglobalshortcut.h b/tools/qxtglobalshortcut/qxtglobalshortcut.h
deleted file mode 100644
index f3083f4..0000000
--- a/tools/qxtglobalshortcut/qxtglobalshortcut.h
+++ /dev/null
@@ -1,64 +0,0 @@
-#ifndef QXTGLOBALSHORTCUT_H
-/****************************************************************************
-** Copyright (c) 2006 - 2011, the LibQxt project.
-** See the Qxt AUTHORS file for a list of authors and copyright holders.
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in the
-** documentation and/or other materials provided with the distribution.
-** * Neither the name of the LibQxt project nor the
-** names of its contributors may be used to endorse or promote products
-** derived from this software without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
-** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-** <http://libqxt.org> <foundation@libqxt.org>
-*****************************************************************************/
-
-#define QXTGLOBALSHORTCUT_H
-
-#include "qxtglobal.h"
-#include <QObject>
-#include <QKeySequence>
-class QxtGlobalShortcutPrivate;
-
-class QxtGlobalShortcut : public QObject
-{
- Q_OBJECT
- QXT_DECLARE_PRIVATE(QxtGlobalShortcut)
- Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
- Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut)
-
-public:
- explicit QxtGlobalShortcut(QObject* parent = 0);
- explicit QxtGlobalShortcut(const QKeySequence& shortcut, QObject* parent = 0);
- virtual ~QxtGlobalShortcut();
-
- QKeySequence shortcut() const;
- bool setShortcut(const QKeySequence& shortcut);
-
- bool isEnabled() const;
-
-public Q_SLOTS:
- void setEnabled(bool enabled = true);
- void setDisabled(bool disabled = true);
-
-Q_SIGNALS:
- void activated();
-};
-
-#endif // QXTGLOBALSHORTCUT_H
diff --git a/tools/qxtglobalshortcut/qxtglobalshortcut.pri b/tools/qxtglobalshortcut/qxtglobalshortcut.pri
deleted file mode 100644
index 2b34277..0000000
--- a/tools/qxtglobalshortcut/qxtglobalshortcut.pri
+++ /dev/null
@@ -1,17 +0,0 @@
-!qws:!symbian {
- HEADERS += $$PWD/qxtglobalshortcut.h
- HEADERS += $$PWD/qxtglobalshortcut_p.h
-
- SOURCES += $$PWD/qxtglobalshortcut.cpp
-
- unix:!macx {
- SOURCES += $$PWD/qxtglobalshortcut_x11.cpp
- }
- macx {
- SOURCES += $$PWD/qxtglobalshortcut_mac.cpp
- }
- win32 {
- SOURCES += $$PWD/qxtglobalshortcut_win.cpp
- }
-}
-
diff --git a/tools/qxtglobalshortcut/qxtglobalshortcut_mac.cpp b/tools/qxtglobalshortcut/qxtglobalshortcut_mac.cpp
deleted file mode 100644
index be2e632..0000000
--- a/tools/qxtglobalshortcut/qxtglobalshortcut_mac.cpp
+++ /dev/null
@@ -1,258 +0,0 @@
-#include <Carbon/Carbon.h>
-/****************************************************************************
-** Copyright (c) 2006 - 2011, the LibQxt project.
-** See the Qxt AUTHORS file for a list of authors and copyright holders.
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in the
-** documentation and/or other materials provided with the distribution.
-** * Neither the name of the LibQxt project nor the
-** names of its contributors may be used to endorse or promote products
-** derived from this software without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
-** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-** <http://libqxt.org> <foundation@libqxt.org>
-*****************************************************************************/
-
-#include "qxtglobalshortcut_p.h"
-#include <QMap>
-#include <QHash>
-#include <QtDebug>
-#include <QApplication>
-
-typedef QPair<uint, uint> Identifier;
-static QMap<quint32, EventHotKeyRef> keyRefs;
-static QHash<Identifier, quint32> keyIDs;
-static quint32 hotKeySerial = 0;
-static bool qxt_mac_handler_installed = false;
-
-OSStatus qxt_mac_handle_hot_key(EventHandlerCallRef nextHandler, EventRef event, void* data)
-{
- Q_UNUSED(nextHandler);
- Q_UNUSED(data);
- if (GetEventClass(event) == kEventClassKeyboard && GetEventKind(event) == kEventHotKeyPressed)
- {
- EventHotKeyID keyID;
- GetEventParameter(event, kEventParamDirectObject, typeEventHotKeyID, NULL, sizeof(keyID), NULL, &keyID);
- Identifier id = keyIDs.key(keyID.id);
- QxtGlobalShortcutPrivate::activateShortcut(id.second, id.first);
- }
- return noErr;
-}
-
-quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers)
-{
- quint32 native = 0;
- if (modifiers & Qt::ShiftModifier)
- native |= shiftKey;
- if (modifiers & Qt::ControlModifier)
- native |= cmdKey;
- if (modifiers & Qt::AltModifier)
- native |= optionKey;
- if (modifiers & Qt::MetaModifier)
- native |= controlKey;
- if (modifiers & Qt::KeypadModifier)
- native |= kEventKeyModifierNumLockMask;
- return native;
-}
-
-quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key)
-{
- UTF16Char ch;
- // Constants found in NSEvent.h from AppKit.framework
- switch (key)
- {
- case Qt::Key_Return:
- return kVK_Return;
- case Qt::Key_Enter:
- return kVK_ANSI_KeypadEnter;
- case Qt::Key_Tab:
- return kVK_Tab;
- case Qt::Key_Space:
- return kVK_Space;
- case Qt::Key_Backspace:
- return kVK_Delete;
- case Qt::Key_Control:
- return kVK_Command;
- case Qt::Key_Shift:
- return kVK_Shift;
- case Qt::Key_CapsLock:
- return kVK_CapsLock;
- case Qt::Key_Option:
- return kVK_Option;
- case Qt::Key_Meta:
- return kVK_Control;
- case Qt::Key_F17:
- return kVK_F17;
- case Qt::Key_VolumeUp:
- return kVK_VolumeUp;
- case Qt::Key_VolumeDown:
- return kVK_VolumeDown;
- case Qt::Key_F18:
- return kVK_F18;
- case Qt::Key_F19:
- return kVK_F19;
- case Qt::Key_F20:
- return kVK_F20;
- case Qt::Key_F5:
- return kVK_F5;
- case Qt::Key_F6:
- return kVK_F6;
- case Qt::Key_F7:
- return kVK_F7;
- case Qt::Key_F3:
- return kVK_F3;
- case Qt::Key_F8:
- return kVK_F8;
- case Qt::Key_F9:
- return kVK_F9;
- case Qt::Key_F11:
- return kVK_F11;
- case Qt::Key_F13:
- return kVK_F13;
- case Qt::Key_F16:
- return kVK_F16;
- case Qt::Key_F14:
- return kVK_F14;
- case Qt::Key_F10:
- return kVK_F10;
- case Qt::Key_F12:
- return kVK_F12;
- case Qt::Key_F15:
- return kVK_F15;
- case Qt::Key_Help:
- return kVK_Help;
- case Qt::Key_Home:
- return kVK_Home;
- case Qt::Key_PageUp:
- return kVK_PageUp;
- case Qt::Key_Delete:
- return kVK_ForwardDelete;
- case Qt::Key_F4:
- return kVK_F4;
- case Qt::Key_End:
- return kVK_End;
- case Qt::Key_F2:
- return kVK_F2;
- case Qt::Key_PageDown:
- return kVK_PageDown;
- case Qt::Key_F1:
- return kVK_F1;
- case Qt::Key_Left:
- return kVK_LeftArrow;
- case Qt::Key_Right:
- return kVK_RightArrow;
- case Qt::Key_Down:
- return kVK_DownArrow;
- case Qt::Key_Up:
- return kVK_UpArrow;
- default:
- ;
- }
-
- if (key == Qt::Key_Escape) ch = 27;
- else if (key == Qt::Key_Return) ch = 13;
- else if (key == Qt::Key_Enter) ch = 3;
- else if (key == Qt::Key_Tab) ch = 9;
- else ch = key;
-
- CFDataRef currentLayoutData;
- TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
-
- if (currentKeyboard == NULL)
- return 0;
-
- currentLayoutData = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
- CFRelease(currentKeyboard);
- if (currentLayoutData == NULL)
- return 0;
-
- UCKeyboardLayout* header = (UCKeyboardLayout*)CFDataGetBytePtr(currentLayoutData);
- UCKeyboardTypeHeader* table = header->keyboardTypeList;
-
- uint8_t *data = (uint8_t*)header;
- // God, would a little documentation for this shit kill you...
- for (quint32 i=0; i < header->keyboardTypeCount; i++)
- {
- UCKeyStateRecordsIndex* stateRec = 0;
- if (table[i].keyStateRecordsIndexOffset != 0)
- {
- stateRec = reinterpret_cast<UCKeyStateRecordsIndex*>(data + table[i].keyStateRecordsIndexOffset);
- if (stateRec->keyStateRecordsIndexFormat != kUCKeyStateRecordsIndexFormat) stateRec = 0;
- }
-
- UCKeyToCharTableIndex* charTable = reinterpret_cast<UCKeyToCharTableIndex*>(data + table[i].keyToCharTableIndexOffset);
- if (charTable->keyToCharTableIndexFormat != kUCKeyToCharTableIndexFormat) continue;
-
- for (quint32 j=0; j < charTable->keyToCharTableCount; j++)
- {
- UCKeyOutput* keyToChar = reinterpret_cast<UCKeyOutput*>(data + charTable->keyToCharTableOffsets[j]);
- for (quint32 k=0; k < charTable->keyToCharTableSize; k++)
- {
- if (keyToChar[k] & kUCKeyOutputTestForIndexMask)
- {
- long idx = keyToChar[k] & kUCKeyOutputGetIndexMask;
- if (stateRec && idx < stateRec->keyStateRecordCount)
- {
- UCKeyStateRecord* rec = reinterpret_cast<UCKeyStateRecord*>(data + stateRec->keyStateRecordOffsets[idx]);
- if (rec->stateZeroCharData == ch) return k;
- }
- }
- else if (!(keyToChar[k] & kUCKeyOutputSequenceIndexMask) && keyToChar[k] < 0xFFFE)
- {
- if (keyToChar[k] == ch) return k;
- }
- } // for k
- } // for j
- } // for i
- return 0;
-}
-
-bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods)
-{
- if (!qxt_mac_handler_installed)
- {
- EventTypeSpec t;
- t.eventClass = kEventClassKeyboard;
- t.eventKind = kEventHotKeyPressed;
- InstallApplicationEventHandler(&qxt_mac_handle_hot_key, 1, &t, NULL, NULL);
- }
-
- EventHotKeyID keyID;
- keyID.signature = 'cute';
- keyID.id = ++hotKeySerial;
-
- EventHotKeyRef ref = 0;
- bool rv = !RegisterEventHotKey(nativeKey, nativeMods, keyID, GetApplicationEventTarget(), 0, &ref);
- if (rv)
- {
- keyIDs.insert(Identifier(nativeMods, nativeKey), keyID.id);
- keyRefs.insert(keyID.id, ref);
- }
- return rv;
-}
-
-bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods)
-{
- Identifier id(nativeMods, nativeKey);
- if (!keyIDs.contains(id)) return false;
-
- EventHotKeyRef ref = keyRefs.take(keyIDs[id]);
- keyIDs.remove(id);
- return !UnregisterEventHotKey(ref);
-}
diff --git a/tools/qxtglobalshortcut/qxtglobalshortcut_p.h b/tools/qxtglobalshortcut/qxtglobalshortcut_p.h
deleted file mode 100644
index 732c41e..0000000
--- a/tools/qxtglobalshortcut/qxtglobalshortcut_p.h
+++ /dev/null
@@ -1,74 +0,0 @@
-#ifndef QXTGLOBALSHORTCUT_P_H
-/****************************************************************************
-** Copyright (c) 2006 - 2011, the LibQxt project.
-** See the Qxt AUTHORS file for a list of authors and copyright holders.
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in the
-** documentation and/or other materials provided with the distribution.
-** * Neither the name of the LibQxt project nor the
-** names of its contributors may be used to endorse or promote products
-** derived from this software without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
-** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-** <http://libqxt.org> <foundation@libqxt.org>
-*****************************************************************************/
-
-#define QXTGLOBALSHORTCUT_P_H
-
-#include "qxtglobalshortcut.h"
-#include <QAbstractEventDispatcher>
-#include <QKeySequence>
-#include <QHash>
-
-#include <QAbstractNativeEventFilter>
-
-class QxtGlobalShortcutPrivate : public QxtPrivate<QxtGlobalShortcut>
- ,public QAbstractNativeEventFilter
-{
-public:
- QXT_DECLARE_PUBLIC(QxtGlobalShortcut)
- QxtGlobalShortcutPrivate();
- ~QxtGlobalShortcutPrivate();
-
- bool enabled;
- Qt::Key key;
- Qt::KeyboardModifiers mods;
-
- bool setShortcut(const QKeySequence& shortcut);
- bool unsetShortcut();
-
- static bool error;
-#ifndef Q_WS_MAC
- static int ref;
- virtual bool nativeEventFilter(const QByteArray & eventType, void * message, long * result);
-#endif // Q_WS_MAC
-
- static void activateShortcut(quint32 nativeKey, quint32 nativeMods);
-
-private:
- static quint32 nativeKeycode(Qt::Key keycode);
- static quint32 nativeModifiers(Qt::KeyboardModifiers modifiers);
-
- static bool registerShortcut(quint32 nativeKey, quint32 nativeMods);
- static bool unregisterShortcut(quint32 nativeKey, quint32 nativeMods);
-
- static QHash<QPair<quint32, quint32>, QxtGlobalShortcut*> shortcuts;
-};
-
-#endif // QXTGLOBALSHORTCUT_P_H
diff --git a/tools/qxtglobalshortcut/qxtglobalshortcut_win.cpp b/tools/qxtglobalshortcut/qxtglobalshortcut_win.cpp
deleted file mode 100644
index 631b692..0000000
--- a/tools/qxtglobalshortcut/qxtglobalshortcut_win.cpp
+++ /dev/null
@@ -1,241 +0,0 @@
-#include "qxtglobalshortcut_p.h"
-/****************************************************************************
-** Copyright (c) 2006 - 2011, the LibQxt project.
-** See the Qxt AUTHORS file for a list of authors and copyright holders.
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in the
-** documentation and/or other materials provided with the distribution.
-** * Neither the name of the LibQxt project nor the
-** names of its contributors may be used to endorse or promote products
-** derived from this software without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
-** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-** <http://libqxt.org> <foundation@libqxt.org>
-*****************************************************************************/
-
-#include <qt_windows.h>
-
-#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
-bool QxtGlobalShortcutPrivate::eventFilter(void* message)
-{
-#else
-bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
- void * message, long * result)
-{
- Q_UNUSED(eventType);
- Q_UNUSED(result);
-#endif
- MSG* msg = static_cast<MSG*>(message);
-
- if (msg->message == WM_HOTKEY)
- {
- const quint32 keycode = HIWORD(msg->lParam);
- const quint32 modifiers = LOWORD(msg->lParam);
- activateShortcut(keycode, modifiers);
- }
- return false;
-}
-
-
-quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers)
-{
- // MOD_ALT, MOD_CONTROL, (MOD_KEYUP), MOD_SHIFT, MOD_WIN
- quint32 native = 0;
- if (modifiers & Qt::ShiftModifier)
- native |= MOD_SHIFT;
- if (modifiers & Qt::ControlModifier)
- native |= MOD_CONTROL;
- if (modifiers & Qt::AltModifier)
- native |= MOD_ALT;
- if (modifiers & Qt::MetaModifier)
- native |= MOD_WIN;
- return native;
-}
-
-quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key)
-{
- switch (key)
- {
- case Qt::Key_Escape:
- return VK_ESCAPE;
- case Qt::Key_Tab:
- case Qt::Key_Backtab:
- return VK_TAB;
- case Qt::Key_Backspace:
- return VK_BACK;
- case Qt::Key_Return:
- case Qt::Key_Enter:
- return VK_RETURN;
- case Qt::Key_Insert:
- return VK_INSERT;
- case Qt::Key_Delete:
- return VK_DELETE;
- case Qt::Key_Pause:
- return VK_PAUSE;
- case Qt::Key_Print:
- return VK_SNAPSHOT;
- case Qt::Key_Clear:
- return VK_CLEAR;
- case Qt::Key_Home:
- return VK_HOME;
- case Qt::Key_End:
- return VK_END;
- case Qt::Key_Left:
- return VK_LEFT;
- case Qt::Key_Up:
- return VK_UP;
- case Qt::Key_Right:
- return VK_RIGHT;
- case Qt::Key_Down:
- return VK_DOWN;
- case Qt::Key_PageUp:
- return VK_PRIOR;
- case Qt::Key_PageDown:
- return VK_NEXT;
- case Qt::Key_F1:
- return VK_F1;
- case Qt::Key_F2:
- return VK_F2;
- case Qt::Key_F3:
- return VK_F3;
- case Qt::Key_F4:
- return VK_F4;
- case Qt::Key_F5:
- return VK_F5;
- case Qt::Key_F6:
- return VK_F6;
- case Qt::Key_F7:
- return VK_F7;
- case Qt::Key_F8:
- return VK_F8;
- case Qt::Key_F9:
- return VK_F9;
- case Qt::Key_F10:
- return VK_F10;
- case Qt::Key_F11:
- return VK_F11;
- case Qt::Key_F12:
- return VK_F12;
- case Qt::Key_F13:
- return VK_F13;
- case Qt::Key_F14:
- return VK_F14;
- case Qt::Key_F15:
- return VK_F15;
- case Qt::Key_F16:
- return VK_F16;
- case Qt::Key_F17:
- return VK_F17;
- case Qt::Key_F18:
- return VK_F18;
- case Qt::Key_F19:
- return VK_F19;
- case Qt::Key_F20:
- return VK_F20;
- case Qt::Key_F21:
- return VK_F21;
- case Qt::Key_F22:
- return VK_F22;
- case Qt::Key_F23:
- return VK_F23;
- case Qt::Key_F24:
- return VK_F24;
- case Qt::Key_Space:
- return VK_SPACE;
- case Qt::Key_Asterisk:
- return VK_MULTIPLY;
- case Qt::Key_Plus:
- return VK_ADD;
- case Qt::Key_Comma:
- return VK_SEPARATOR;
- case Qt::Key_Minus:
- return VK_SUBTRACT;
- case Qt::Key_Slash:
- return VK_DIVIDE;
- case Qt::Key_MediaNext:
- return VK_MEDIA_NEXT_TRACK;
- case Qt::Key_MediaPrevious:
- return VK_MEDIA_PREV_TRACK;
- case Qt::Key_MediaPlay:
- return VK_MEDIA_PLAY_PAUSE;
- case Qt::Key_MediaStop:
- return VK_MEDIA_STOP;
- case Qt::Key_VolumeDown:
- return VK_VOLUME_DOWN;
- case Qt::Key_VolumeUp:
- return VK_VOLUME_UP;
- case Qt::Key_VolumeMute:
- return VK_VOLUME_MUTE;
-
- // numbers
- case Qt::Key_0:
- case Qt::Key_1:
- case Qt::Key_2:
- case Qt::Key_3:
- case Qt::Key_4:
- case Qt::Key_5:
- case Qt::Key_6:
- case Qt::Key_7:
- case Qt::Key_8:
- case Qt::Key_9:
- return key;
-
- // letters
- case Qt::Key_A:
- case Qt::Key_B:
- case Qt::Key_C:
- case Qt::Key_D:
- case Qt::Key_E:
- case Qt::Key_F:
- case Qt::Key_G:
- case Qt::Key_H:
- case Qt::Key_I:
- case Qt::Key_J:
- case Qt::Key_K:
- case Qt::Key_L:
- case Qt::Key_M:
- case Qt::Key_N:
- case Qt::Key_O:
- case Qt::Key_P:
- case Qt::Key_Q:
- case Qt::Key_R:
- case Qt::Key_S:
- case Qt::Key_T:
- case Qt::Key_U:
- case Qt::Key_V:
- case Qt::Key_W:
- case Qt::Key_X:
- case Qt::Key_Y:
- case Qt::Key_Z:
- return key;
-
- default:
- return 0;
- }
-}
-
-bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods)
-{
- return RegisterHotKey(0, nativeMods ^ nativeKey, nativeMods, nativeKey);
-}
-
-bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods)
-{
- return UnregisterHotKey(0, nativeMods ^ nativeKey);
-}
diff --git a/tools/qxtglobalshortcut/qxtglobalshortcut_x11.cpp b/tools/qxtglobalshortcut/qxtglobalshortcut_x11.cpp
deleted file mode 100644
index a10c702..0000000
--- a/tools/qxtglobalshortcut/qxtglobalshortcut_x11.cpp
+++ /dev/null
@@ -1,215 +0,0 @@
-#include "qxtglobalshortcut_p.h"
-/****************************************************************************
-** Copyright (c) 2006 - 2011, the LibQxt project.
-** See the Qxt AUTHORS file for a list of authors and copyright holders.
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in the
-** documentation and/or other materials provided with the distribution.
-** * Neither the name of the LibQxt project nor the
-** names of its contributors may be used to endorse or promote products
-** derived from this software without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
-** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-** <http://libqxt.org> <foundation@libqxt.org>
-*****************************************************************************/
-
-#include <QVector>
-#include <X11/Xlib.h>
-#include <QX11Info>
-#include <xcb/xcb.h>
-
-namespace {
-
-const QVector<quint32> maskModifiers = QVector<quint32>()
- << 0 << Mod2Mask << LockMask << (Mod2Mask | LockMask);
-
-typedef int (*X11ErrorHandler)(Display *display, XErrorEvent *event);
-
-class QxtX11ErrorHandler {
-public:
- static bool error;
-
- static int qxtX11ErrorHandler(Display *display, XErrorEvent *event)
- {
- Q_UNUSED(display);
- switch (event->error_code)
- {
- case BadAccess:
- case BadValue:
- case BadWindow:
- if (event->request_code == 33 /* X_GrabKey */ ||
- event->request_code == 34 /* X_UngrabKey */)
- {
- error = true;
- //TODO:
- //char errstr[256];
- //XGetErrorText(dpy, err->error_code, errstr, 256);
- }
- }
- return 0;
- }
-
- QxtX11ErrorHandler()
- {
- error = false;
- m_previousErrorHandler = XSetErrorHandler(qxtX11ErrorHandler);
- }
-
- ~QxtX11ErrorHandler()
- {
- XSetErrorHandler(m_previousErrorHandler);
- }
-
-private:
- X11ErrorHandler m_previousErrorHandler;
-};
-
-bool QxtX11ErrorHandler::error = false;
-
-class QxtX11Data {
-public:
- QxtX11Data()
- {
- m_display = QX11Info::display();
- }
-
- bool isValid()
- {
- return m_display != 0;
- }
-
- Display *display()
- {
- Q_ASSERT(isValid());
- return m_display;
- }
-
- Window rootWindow()
- {
- return DefaultRootWindow(display());
- }
-
- bool grabKey(quint32 keycode, quint32 modifiers, Window window)
- {
- QxtX11ErrorHandler errorHandler;
-
- for (int i = 0; !errorHandler.error && i < maskModifiers.size(); ++i) {
- XGrabKey(display(), keycode, modifiers | maskModifiers[i], window, True,
- GrabModeAsync, GrabModeAsync);
- }
-
- if (errorHandler.error) {
- ungrabKey(keycode, modifiers, window);
- return false;
- }
-
- return true;
- }
-
- bool ungrabKey(quint32 keycode, quint32 modifiers, Window window)
- {
- QxtX11ErrorHandler errorHandler;
-
- foreach (quint32 maskMods, maskModifiers) {
- XUngrabKey(display(), keycode, modifiers | maskMods, window);
- }
-
- return !errorHandler.error;
- }
-
-private:
- Display *m_display;
-};
-
-} // namespace
-
-bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
- void *message, long *result)
-{
- Q_UNUSED(result);
-
- xcb_key_press_event_t *kev = 0;
- if (eventType == "xcb_generic_event_t") {
- xcb_generic_event_t *ev = static_cast<xcb_generic_event_t *>(message);
- if ((ev->response_type & 127) == XCB_KEY_PRESS)
- kev = static_cast<xcb_key_press_event_t *>(message);
- }
-
- if (kev != 0) {
- unsigned int keycode = kev->detail;
- unsigned int keystate = 0;
- if(kev->state & XCB_MOD_MASK_1)
- keystate |= Mod1Mask;
- if(kev->state & XCB_MOD_MASK_CONTROL)
- keystate |= ControlMask;
- if(kev->state & XCB_MOD_MASK_4)
- keystate |= Mod4Mask;
- if(kev->state & XCB_MOD_MASK_SHIFT)
- keystate |= ShiftMask;
- activateShortcut(keycode,
- // Mod1Mask == Alt, Mod4Mask == Meta
- keystate & (ShiftMask | ControlMask | Mod1Mask | Mod4Mask));
- }
- return false;
-}
-
-quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers)
-{
- // ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, and Mod5Mask
- quint32 native = 0;
- if (modifiers & Qt::ShiftModifier)
- native |= ShiftMask;
- if (modifiers & Qt::ControlModifier)
- native |= ControlMask;
- if (modifiers & Qt::AltModifier)
- native |= Mod1Mask;
- if (modifiers & Qt::MetaModifier)
- native |= Mod4Mask;
-
- // TODO: resolve these?
- //if (modifiers & Qt::MetaModifier)
- //if (modifiers & Qt::KeypadModifier)
- //if (modifiers & Qt::GroupSwitchModifier)
- return native;
-}
-
-quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key)
-{
- QxtX11Data x11;
- if (!x11.isValid())
- return 0;
-
- KeySym keysym = XStringToKeysym(QKeySequence(key).toString().toLatin1().data());
- if (keysym == NoSymbol)
- keysym = static_cast<ushort>(key);
-
- return XKeysymToKeycode(x11.display(), keysym);
-}
-
-bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods)
-{
- QxtX11Data x11;
- return x11.isValid() && x11.grabKey(nativeKey, nativeMods, x11.rootWindow());
-}
-
-bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods)
-{
- QxtX11Data x11;
- return x11.isValid() && x11.ungrabKey(nativeKey, nativeMods, x11.rootWindow());
-}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Jun 15, 11:28 PM (2 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69783
Default Alt Text
(95 KB)

Event Timeline