From: APTX Date: Fri, 6 Jan 2012 19:04:58 +0000 (+0100) Subject: Add encryption settings, frameless & overlay mode and tray icon. X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=6708bde2cfa7abd2d672f464e28346f36bdb3da5;p=aniplayer-old.git Add encryption settings, frameless & overlay mode and tray icon. --- diff --git a/src/anidbconfigdialog.cpp b/src/anidbconfigdialog.cpp index 806c41f..bac4241 100644 --- a/src/anidbconfigdialog.cpp +++ b/src/anidbconfigdialog.cpp @@ -59,6 +59,26 @@ void AniDBConfigDialog::setPass(const QString &pass) m_ui->pass->setText(pass); } +bool AniDBConfigDialog::encryption() const +{ + return m_ui->encryption->isChecked(); +} + +void AniDBConfigDialog::setEncryption(bool enabled) +{ + m_ui->encryption->setChecked(enabled); +} + +QString AniDBConfigDialog::apiKey() +{ + return m_ui->apiKey->text(); +} + +void AniDBConfigDialog::setApiKey(const QString &apiKey) +{ + m_ui->apiKey->setText(apiKey); +} + int AniDBConfigDialog::automark() const { return m_ui->automark->value(); diff --git a/src/anidbconfigdialog.h b/src/anidbconfigdialog.h index 4e7d70f..73a36bc 100644 --- a/src/anidbconfigdialog.h +++ b/src/anidbconfigdialog.h @@ -29,6 +29,12 @@ public: QString pass() const; void setPass(const QString &pass); + bool encryption() const; + void setEncryption(bool enabled); + + QString apiKey(); + void setApiKey(const QString &apiKey); + int automark() const; void setAutomark(int percent); diff --git a/src/anidbconfigdialog.ui b/src/anidbconfigdialog.ui index 9f7a599..3cbae3a 100644 --- a/src/anidbconfigdialog.ui +++ b/src/anidbconfigdialog.ui @@ -6,8 +6,8 @@ 0 0 - 280 - 348 + 302 + 407 @@ -19,7 +19,7 @@ AniDB Connection Settings - + @@ -93,7 +93,7 @@ - + Password: @@ -112,6 +112,38 @@ + + + + Encryption + + + true + + + false + + + + + + API Key: + + + apiKey + + + + + + + QLineEdit::Password + + + + + + @@ -219,7 +251,8 @@ localPort user pass - groupBox_2 + encryption + apiKey automark paths opSkip @@ -234,11 +267,11 @@ accept() - 266 - 338 + 292 + 397 - 157 + 426 274 @@ -250,11 +283,11 @@ reject() - 270 - 338 + 292 + 397 - 279 + 548 274 diff --git a/src/aniplayer.cpp b/src/aniplayer.cpp index f7d18b3..f34ffd2 100644 --- a/src/aniplayer.cpp +++ b/src/aniplayer.cpp @@ -7,6 +7,8 @@ #include +#include + AniPlayer::AniPlayer(int &argc, char *argv[]) : QtSingleApplication(argc, argv) { m_instance = this; diff --git a/src/aniplayer.qrc b/src/aniplayer.qrc new file mode 100644 index 0000000..4d8ed66 --- /dev/null +++ b/src/aniplayer.qrc @@ -0,0 +1,3 @@ + + + diff --git a/src/src.pro b/src/src.pro index 6a61ef6..4ec033b 100644 --- a/src/src.pro +++ b/src/src.pro @@ -40,7 +40,10 @@ HEADERS += menu.h \ FORMS += menu.ui \ anidbconfigdialog.ui \ episodevotedialog.ui -win32:RC_FILE += aniplayer.rc +win32 { + RC_FILE += aniplayer.rc + LIBS += -luser32 -lgdi32 +} browserplugin { # CONFIG += qaxserver include(../lib/browserplugin-solution/src/qtbrowserplugin.pri) @@ -82,3 +85,7 @@ include(../lib/qtsingleapplication/src/qtsingleapplication.pri) OBJECTS_DIR = ../.tmp/obj MOC_DIR = ../.tmp/moc RCC_DIR = ../.tmp/rcc + +RESOURCES += \ + ../resource/aniplayer.qrc + diff --git a/src/videowidget.cpp b/src/videowidget.cpp index 606ee36..009a833 100644 --- a/src/videowidget.cpp +++ b/src/videowidget.cpp @@ -18,6 +18,31 @@ void VideoWidget::toggleFullScreen() void VideoWidget::mousePressEvent(QMouseEvent *event) { + if (!isFullScreen()) + { + event->ignore(); + return; + } + event->accept(); +} + +void VideoWidget::mouseMoveEvent(QMouseEvent *event) +{ + if (!isFullScreen()) + { + event->ignore(); + return; + } + event->accept(); +} + +void VideoWidget::mouseReleaseEvent(QMouseEvent *event) +{ + if (!isFullScreen()) + { + event->ignore(); + return; + } if (event->button() == Qt::LeftButton) emit menuToggleRequested(); #ifndef Q_WS_X11 @@ -27,7 +52,8 @@ void VideoWidget::mousePressEvent(QMouseEvent *event) # endif #endif else - Phonon::VideoWidget::mousePressEvent(event); + return Phonon::VideoWidget::mouseReleaseEvent(event); + event->accept(); } void VideoWidget::wheelEvent(QWheelEvent *event) diff --git a/src/videowidget.h b/src/videowidget.h index d1e3ec1..d144296 100644 --- a/src/videowidget.h +++ b/src/videowidget.h @@ -23,6 +23,8 @@ signals: protected: void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); void wheelEvent(QWheelEvent *event); void closeEvent(QCloseEvent *event); }; diff --git a/src/videowindow.cpp b/src/videowindow.cpp index a86828d..8114059 100644 --- a/src/videowindow.cpp +++ b/src/videowindow.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include "menu.h" @@ -29,6 +31,10 @@ #include +#ifdef Q_OS_WIN +# include +#endif + VideoWindow::VideoWindow(QWidget *parent) : QMainWindow(parent) #ifdef BROWSERPLUGIN_BUILD , QtNPBindable() @@ -49,6 +55,8 @@ VideoWindow::VideoWindow(QWidget *parent) : QMainWindow(parent) m_automark = 0; #endif + tray = new QSystemTrayIcon(this); + videoPlayer = new VideoPlayer(this, this); #ifdef GRAPHICS_VIEW_VIDEO @@ -87,9 +95,13 @@ VideoWindow::VideoWindow(QWidget *parent) : QMainWindow(parent) #ifndef BROWSERPLUGIN_BUILD addAction("togglePinMenu", "Pin Menu", QKeySequence(), true); addAction("toggleStayOnTop", "Stay on top", QKeySequence("T"), true); + addAction("toggleFrameless", "Frameless", QKeySequence("Y"), true); + addAction("toggleOverlay", "Overlay", QKeySequence("U"), true); m_actions["togglePinMenu"]->setChecked(true); m_actions["toggleStayOnTop"]->setChecked(false); + m_actions["toggleFrameless"]->setChecked(false); + m_actions["toggleOverlay"]->setChecked(false); #endif #ifndef NO_ANIDBUDPCLIENT addAction("markWatched", "Mark Watched", QKeySequence("CTRL+M")); @@ -99,6 +111,10 @@ VideoWindow::VideoWindow(QWidget *parent) : QMainWindow(parent) menu = new Menu(this); menu->addActions(QWidget::actions()); + tray->setContextMenu(new QMenu); + tray->contextMenu()->addActions(QWidget::actions()); + tray->setIcon(QIcon(":/icon.png")); + tray->show(); #ifdef GRAPHICS_VIEW_VIDEO videoSceneMenu = new Menu(); @@ -130,6 +146,8 @@ VideoWindow::VideoWindow(QWidget *parent) : QMainWindow(parent) connect(m_actions["togglePlay"], SIGNAL(triggered()), videoPlayer, SLOT(togglePlay())); connect(m_actions["togglePinMenu"], SIGNAL(toggled(bool)), this, SLOT(setPinMenu(bool))); connect(m_actions["toggleStayOnTop"], SIGNAL(toggled(bool)), this, SLOT(toggleStayOnTop())); + connect(m_actions["toggleFrameless"], SIGNAL(toggled(bool)), this, SLOT(toggleFrameless())); + connect(m_actions["toggleOverlay"], SIGNAL(toggled(bool)), this, SLOT(toggleOverlay())); #endif connect(m_actions["pause"], SIGNAL(triggered()), videoPlayer, SLOT(pause())); connect(m_actions["stop"], SIGNAL(triggered()), videoPlayer, SLOT(stop())); @@ -169,7 +187,6 @@ VideoWindow::VideoWindow(QWidget *parent) : QMainWindow(parent) AniDBUdpClient::Client::instance()->setCompression(true); AniDBUdpClient::Client::instance()->setIdlePolicy(AniDBUdpClient::ImmediateLogoutIdlePolicy); #endif - } VideoWindow::~VideoWindow() @@ -331,13 +348,17 @@ void VideoWindow::setPinMenu(bool pinned) void VideoWindow::toggleStayOnTop() { - setWindowFlags(windowFlags() ^ Qt::WindowStaysOnTopHint); -#ifdef Q_WS_X11 - bool menuVisible = menu->isVisible(); - menu->setWindowFlags(menu->windowFlags() ^ Qt::WindowStaysOnTopHint); - menu->setVisible(menuVisible); -#endif - show(); + updateWindowFlags(); +} + +void VideoWindow::toggleFrameless() +{ + updateWindowFlags(); +} + +void VideoWindow::toggleOverlay() +{ + updateWindowFlags(); } void VideoWindow::about() @@ -437,6 +458,36 @@ void VideoWindow::tick(qint64 time) void VideoWindow::mousePressEvent(QMouseEvent *event) { + if (event->button() == Qt::LeftButton) + { + dragPosition = event->globalPos() - frameGeometry().topLeft(); + dragged = true; + event->accept(); + } +} + +void VideoWindow::mouseMoveEvent(QMouseEvent *event) +{ + mouseMoved = true; + if (!dragged) + return; + + if (event->buttons() & Qt::LeftButton) + { + move(event->globalPos() - dragPosition); + event->accept(); + } +} + +void VideoWindow::mouseReleaseEvent(QMouseEvent *event) +{ + dragged = false; + if (mouseMoved) + { + mouseMoved = false; + return; + } + if (event->button() == Qt::LeftButton) { toggleMenu(); @@ -475,7 +526,7 @@ void VideoWindow::mousePressEvent(QMouseEvent *event) } else { - QMainWindow::mousePressEvent(event); + QMainWindow::mouseReleaseEvent(event); } } @@ -596,6 +647,8 @@ void VideoWindow::anidbSettings() dialog.setLocalPort(AniDBUdpClient::Client::instance()->localPort()); dialog.setUser(AniDBUdpClient::Client::instance()->user()); dialog.setPass(AniDBUdpClient::Client::instance()->pass()); + dialog.setEncryption(AniDBUdpClient::Client::instance()->encryptionEnabled()); + dialog.setApiKey(AniDBUdpClient::Client::instance()->apiKey()); dialog.setAutomark(m_automark); dialog.setPaths(m_automarkPaths); dialog.setOpSkip(m_opSkip); @@ -612,6 +665,8 @@ void VideoWindow::anidbSettings() AniDBUdpClient::Client::instance()->setLocalPort(dialog.localPort()); AniDBUdpClient::Client::instance()->setUser(dialog.user()); AniDBUdpClient::Client::instance()->setPass(dialog.pass()); + AniDBUdpClient::Client::instance()->setEncryptionEnabled(dialog.encryption()); + AniDBUdpClient::Client::instance()->setApiKey(dialog.apiKey()); m_automark = dialog.automark(); m_automarkPaths = dialog.paths(); m_opSkip = dialog.opSkip(); @@ -695,6 +750,7 @@ void VideoWindow::saveSettings() settings.beginGroup("videoWindow"); settings.setValue("geometry", saveGeometry()); settings.setValue("stayOnTop", m_actions["toggleStayOnTop"]->isChecked()); + settings.setValue("frameless", m_actions["toggleFrameless"]->isChecked()); settings.endGroup(); settings.beginGroup("menu"); settings.setValue("geometry", menu->saveGeometry()); @@ -708,6 +764,8 @@ void VideoWindow::saveSettings() settings.setValue("localPort", AniDBUdpClient::Client::instance()->localPort()); settings.setValue("user", AniDBUdpClient::Client::instance()->user()); settings.setValue("pass", AniDBUdpClient::Client::instance()->pass()); + settings.setValue("encryption", AniDBUdpClient::Client::instance()->encryptionEnabled()); + settings.setValue("apiKey", AniDBUdpClient::Client::instance()->apiKey()); settings.setValue("automark", m_automark); settings.setValue("paths", m_automarkPaths); settings.endGroup(); @@ -730,6 +788,7 @@ void VideoWindow::loadSettings() settings.beginGroup("videoWindow"); restoreGeometry(settings.value("geometry", saveGeometry()).toByteArray()); m_actions["toggleStayOnTop"]->setChecked(settings.value("stayOnTop", false).toBool()); + m_actions["toggleFrameless"]->setChecked(settings.value("frameless", false).toBool()); settings.endGroup(); settings.beginGroup("menu"); menu->restoreState(settings.value("state", menu->saveState()).toByteArray()); @@ -743,6 +802,8 @@ void VideoWindow::loadSettings() AniDBUdpClient::Client::instance()->setLocalPort(settings.value("localPort", 9001).toInt()); AniDBUdpClient::Client::instance()->setUser(settings.value("user").toString()); AniDBUdpClient::Client::instance()->setPass(settings.value("pass").toString()); + AniDBUdpClient::Client::instance()->setEncryptionEnabled(settings.value("encryption").toBool()); + AniDBUdpClient::Client::instance()->setApiKey(settings.value("apiKey").toString()); m_automark = settings.value("automark", 0).toInt(); m_automarkPaths = settings.value("paths", QStringList()).toStringList(); settings.endGroup(); @@ -777,6 +838,41 @@ void VideoWindow::updateCursor() #endif } +void VideoWindow::updateWindowFlags() +{ + if (m_actions["toggleStayOnTop"]->isChecked()) + setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); + else + setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint); + +#ifdef Q_WS_X11 + bool menuVisible = menu->isVisible(); + menu->setWindowFlags(menu->windowFlags() ^ Qt::WindowStaysOnTopHint); + menu->setVisible(menuVisible); +#endif + + if (m_actions["toggleFrameless"]->isChecked()) + setWindowFlags((windowFlags() & (Qt::Window | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint)) | Qt::FramelessWindowHint); + else + setWindowFlags((windowFlags() & (Qt::Window | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint)) & ~Qt::FramelessWindowHint); + + +#ifdef Q_OS_WIN + if (m_actions["toggleOverlay"]->isChecked()) + { + setWindowOpacity(.5); + SetWindowLongPtr(winId(), GWL_EXSTYLE, GetWindowLongPtr(winId(), GWL_EXSTYLE) | WS_EX_LAYERED | WS_EX_TRANSPARENT); + } + else + { + setWindowOpacity(1); + SetWindowLongPtr(winId(), GWL_EXSTYLE, GetWindowLongPtr(winId(), GWL_EXSTYLE) & ~WS_EX_TRANSPARENT); + } +#endif + + show(); +} + #ifdef BROWSERPLUGIN_BUILD bool VideoWindow::readData(QIODevice *source, const QString &format) { diff --git a/src/videowindow.h b/src/videowindow.h index 25ca4c1..5d00f46 100644 --- a/src/videowindow.h +++ b/src/videowindow.h @@ -33,6 +33,7 @@ # include #endif +class QSystemTrayIcon; class VideoPlayer; class VideoWidget; class Menu; @@ -77,16 +78,19 @@ public slots: void resizeToVideo(); void setPinMenu(bool pinned); void toggleStayOnTop(); - + void toggleFrameless(); + void toggleOverlay(); void about(); protected: - virtual void mousePressEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); - virtual void moveEvent(QMoveEvent *event); - virtual void resizeEvent(QResizeEvent *event); - virtual void wheelEvent(QWheelEvent *event); + void moveEvent(QMoveEvent *event); + void resizeEvent(QResizeEvent *event); + void wheelEvent(QWheelEvent *event); void updateMenuPosition(); @@ -119,6 +123,8 @@ private: void updateWindowTitle(const QFileInfo &file = QFileInfo()); void updateCursor(); + void updateWindowFlags(); + Menu *menu; #ifdef GRAPHICS_VIEW_VIDEO Menu *videoSceneMenu; @@ -141,6 +147,9 @@ private: bool destroyed; bool windowMoving; bool menuMoving; + bool mouseMoved; + QPoint dragPosition; + bool dragged; #ifdef Q_WS_X11 bool menuVisible; #endif @@ -158,11 +167,12 @@ private: DirectoryPlaylist *playlist; + QSystemTrayIcon *tray; #ifdef BROWSERPLUGIN_BUILD virtual bool readData( QIODevice *source, const QString &format); bool m_endBrowserStreamRead; -#endif +#endif }; #endif // VIDEOWINDOW_H