Make the Windows 7 thumbbar actually work. Move it to a different class that deals with QActions. Fixes issue #851
This commit is contained in:
parent
da2ab82712
commit
2c8e038b44
@ -205,6 +205,7 @@ set(SOURCES
|
|||||||
ui/screensaver.cpp
|
ui/screensaver.cpp
|
||||||
ui/settingsdialog.cpp
|
ui/settingsdialog.cpp
|
||||||
ui/systemtrayicon.cpp
|
ui/systemtrayicon.cpp
|
||||||
|
ui/windows7thumbbar.cpp
|
||||||
|
|
||||||
widgets/autoexpandingtreeview.cpp
|
widgets/autoexpandingtreeview.cpp
|
||||||
widgets/busyindicator.cpp
|
widgets/busyindicator.cpp
|
||||||
@ -377,6 +378,7 @@ set(HEADERS
|
|||||||
ui/qtsystemtrayicon.h
|
ui/qtsystemtrayicon.h
|
||||||
ui/settingsdialog.h
|
ui/settingsdialog.h
|
||||||
ui/systemtrayicon.h
|
ui/systemtrayicon.h
|
||||||
|
ui/windows7thumbbar.h
|
||||||
|
|
||||||
widgets/autoexpandingtreeview.h
|
widgets/autoexpandingtreeview.h
|
||||||
widgets/busyindicator.h
|
widgets/busyindicator.h
|
||||||
|
@ -15,10 +15,6 @@
|
|||||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
|
||||||
# define _WIN32_WINNT 0x0600
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include "core/backgroundstreams.h"
|
#include "core/backgroundstreams.h"
|
||||||
@ -81,6 +77,7 @@
|
|||||||
#include "ui/qtsystemtrayicon.h"
|
#include "ui/qtsystemtrayicon.h"
|
||||||
#include "ui/settingsdialog.h"
|
#include "ui/settingsdialog.h"
|
||||||
#include "ui/systemtrayicon.h"
|
#include "ui/systemtrayicon.h"
|
||||||
|
#include "ui/windows7thumbbar.h"
|
||||||
#include "widgets/errordialog.h"
|
#include "widgets/errordialog.h"
|
||||||
#include "widgets/fileview.h"
|
#include "widgets/fileview.h"
|
||||||
#include "widgets/multiloadingindicator.h"
|
#include "widgets/multiloadingindicator.h"
|
||||||
@ -123,9 +120,6 @@
|
|||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
# include <qtsparkle/Updater>
|
# include <qtsparkle/Updater>
|
||||||
# include <windows.h>
|
|
||||||
# include <commctrl.h>
|
|
||||||
# include <shobjidl.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -156,6 +150,7 @@ MainWindow::MainWindow(
|
|||||||
QWidget* parent)
|
QWidget* parent)
|
||||||
: QMainWindow(parent),
|
: QMainWindow(parent),
|
||||||
ui_(new Ui_MainWindow),
|
ui_(new Ui_MainWindow),
|
||||||
|
thumbbar_(new Windows7ThumbBar(this)),
|
||||||
tray_icon_(tray_icon),
|
tray_icon_(tray_icon),
|
||||||
osd_(osd),
|
osd_(osd),
|
||||||
task_manager_(task_manager),
|
task_manager_(task_manager),
|
||||||
@ -191,8 +186,7 @@ MainWindow::MainWindow(
|
|||||||
playlist_menu_(new QMenu(this)),
|
playlist_menu_(new QMenu(this)),
|
||||||
library_sort_model_(new QSortFilterProxyModel(this)),
|
library_sort_model_(new QSortFilterProxyModel(this)),
|
||||||
track_position_timer_(new QTimer(this)),
|
track_position_timer_(new QTimer(this)),
|
||||||
was_maximized_(false),
|
was_maximized_(false)
|
||||||
taskbar_list_(NULL)
|
|
||||||
{
|
{
|
||||||
// Create some objects in the database thread
|
// Create some objects in the database thread
|
||||||
playlist_backend_ = new PlaylistBackend;
|
playlist_backend_ = new PlaylistBackend;
|
||||||
@ -499,6 +493,16 @@ MainWindow::MainWindow(
|
|||||||
connect(tray_icon_, SIGNAL(ShowHide()), SLOT(ToggleShowHide()));
|
connect(tray_icon_, SIGNAL(ShowHide()), SLOT(ToggleShowHide()));
|
||||||
connect(tray_icon_, SIGNAL(ChangeVolume(int)), SLOT(VolumeWheelEvent(int)));
|
connect(tray_icon_, SIGNAL(ChangeVolume(int)), SLOT(VolumeWheelEvent(int)));
|
||||||
|
|
||||||
|
// Windows 7 thumbbar buttons
|
||||||
|
thumbbar_->SetActions(QList<QAction*>()
|
||||||
|
<< ui_->action_previous_track
|
||||||
|
<< ui_->action_play_pause
|
||||||
|
<< ui_->action_stop
|
||||||
|
<< ui_->action_next_track
|
||||||
|
<< NULL // spacer
|
||||||
|
<< ui_->action_love
|
||||||
|
<< ui_->action_ban);
|
||||||
|
|
||||||
#if (defined(Q_OS_DARWIN) && defined(HAVE_SPARKLE)) || defined(Q_OS_WIN32)
|
#if (defined(Q_OS_DARWIN) && defined(HAVE_SPARKLE)) || defined(Q_OS_WIN32)
|
||||||
// Add check for updates item to application menu.
|
// Add check for updates item to application menu.
|
||||||
QAction* check_updates = ui_->menu_tools->addAction(tr("Check for updates..."));
|
QAction* check_updates = ui_->menu_tools->addAction(tr("Check for updates..."));
|
||||||
@ -1651,51 +1655,8 @@ void MainWindow::ShowScriptDialog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
static const int kTaskbarIconSize = 16;
|
bool MainWindow::winEvent(MSG* msg, long*) {
|
||||||
|
thumbbar_->HandleWinEvent(msg);
|
||||||
static void SetButton(const QIcon& icon, const QString& tooltip, uint id,
|
|
||||||
THUMBBUTTON* button) {
|
|
||||||
button->dwMask = THUMBBUTTONMASK(THB_ICON | THB_TOOLTIP | THB_FLAGS);
|
|
||||||
button->iId = id;
|
|
||||||
button->dwFlags = THBF_ENABLED;
|
|
||||||
button->hIcon = icon.pixmap(kTaskbarIconSize).toWinHICON();
|
|
||||||
tooltip.toWCharArray(button->szTip);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MainWindow::winEvent(MSG* m, long* result) {
|
|
||||||
static UINT sTaskbarButtonCreated = WM_NULL;
|
|
||||||
|
|
||||||
if (sTaskbarButtonCreated == WM_NULL) {
|
|
||||||
// Compute the value for the TaskbarButtonCreated message
|
|
||||||
sTaskbarButtonCreated = RegisterWindowMessage("TaskbarButtonCreated");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m->message == sTaskbarButtonCreated) {
|
|
||||||
if (!taskbar_list_) {
|
|
||||||
// Get the interface
|
|
||||||
if (CoCreateInstance(CLSID_ITaskbarList, NULL, CLSCTX_ALL,
|
|
||||||
IID_ITaskbarList3, (void**) &taskbar_list_)) {
|
|
||||||
qWarning() << "Error creating the ITaskbarList3 interface";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ITaskbarList3* taskbar_list = reinterpret_cast<ITaskbarList3*>(taskbar_list_);
|
|
||||||
if (taskbar_list->HrInit()) {
|
|
||||||
taskbar_list->Release();
|
|
||||||
taskbar_list_ = NULL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the playback control buttons
|
|
||||||
THUMBBUTTON buttons[4] = {};
|
|
||||||
SetButton(IconLoader::Load("media-skip-backward"), tr("Previous track"), 0, &buttons[0]);
|
|
||||||
SetButton(IconLoader::Load("media-playback-start"), tr("Pause"), 1, &buttons[1]);
|
|
||||||
SetButton(IconLoader::Load("media-playback-stop"), tr("Stop"), 2, &buttons[2]);
|
|
||||||
SetButton(IconLoader::Load("media-skip-forward"), tr("Next track"), 3, &buttons[3]);
|
|
||||||
|
|
||||||
taskbar_list->ThumbBarAddButtons(winId(), 4, buttons);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif // Q_OS_WIN32
|
#endif // Q_OS_WIN32
|
||||||
|
@ -67,6 +67,7 @@ class TaskManager;
|
|||||||
class TranscodeDialog;
|
class TranscodeDialog;
|
||||||
class VisualisationContainer;
|
class VisualisationContainer;
|
||||||
class WiimotedevShortcuts;
|
class WiimotedevShortcuts;
|
||||||
|
class Windows7ThumbBar;
|
||||||
class Ui_MainWindow;
|
class Ui_MainWindow;
|
||||||
|
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
@ -216,6 +217,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Ui_MainWindow* ui_;
|
Ui_MainWindow* ui_;
|
||||||
|
Windows7ThumbBar* thumbbar_;
|
||||||
|
|
||||||
SystemTrayIcon* tray_icon_;
|
SystemTrayIcon* tray_icon_;
|
||||||
OSD* osd_;
|
OSD* osd_;
|
||||||
@ -284,9 +286,6 @@ class MainWindow : public QMainWindow, public PlatformInterface {
|
|||||||
bool autoclear_playlist_;
|
bool autoclear_playlist_;
|
||||||
|
|
||||||
BackgroundStreams* background_streams_;
|
BackgroundStreams* background_streams_;
|
||||||
|
|
||||||
// Really an ITaskbarList3* but I don't want to have to include windows.h here
|
|
||||||
void* taskbar_list_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
140
src/ui/windows7thumbbar.cpp
Normal file
140
src/ui/windows7thumbbar.cpp
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
/* This file is part of Clementine.
|
||||||
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
||||||
|
|
||||||
|
Clementine 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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "windows7thumbbar.h"
|
||||||
|
|
||||||
|
#include <QAction>
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
# define _WIN32_WINNT 0x0600
|
||||||
|
# include <windows.h>
|
||||||
|
# include <commctrl.h>
|
||||||
|
# include <shobjidl.h>
|
||||||
|
#endif // Q_OS_WIN32
|
||||||
|
|
||||||
|
|
||||||
|
const int Windows7ThumbBar::kIconSize = 16;
|
||||||
|
const int Windows7ThumbBar::kMaxButtonCount = 7;
|
||||||
|
|
||||||
|
|
||||||
|
Windows7ThumbBar::Windows7ThumbBar(QWidget* widget)
|
||||||
|
: QObject(widget),
|
||||||
|
widget_(widget),
|
||||||
|
button_created_message_id_(0),
|
||||||
|
taskbar_list_(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Windows7ThumbBar::SetActions(const QList<QAction*>& actions) {
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
Q_ASSERT(actions.count() <= kMaxButtonCount);
|
||||||
|
|
||||||
|
actions_ = actions;
|
||||||
|
foreach (QAction* action, actions) {
|
||||||
|
if (action) {
|
||||||
|
connect(action, SIGNAL(changed()), SLOT(ActionChanged()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // Q_OS_WIN32
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
static void SetupButton(const QAction* action, THUMBBUTTON* button) {
|
||||||
|
if (action) {
|
||||||
|
button->hIcon = action->icon().pixmap(Windows7ThumbBar::kIconSize).toWinHICON();
|
||||||
|
button->dwFlags = action->isEnabled() ? THBF_ENABLED : THBF_DISABLED;
|
||||||
|
action->text().toWCharArray(button->szTip);
|
||||||
|
button->szTip[action->text().count()] = '\0';
|
||||||
|
|
||||||
|
if (!action->isVisible()) {
|
||||||
|
button->dwFlags = THUMBBUTTONFLAGS(button->dwFlags | THBF_HIDDEN);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
button->hIcon = 0;
|
||||||
|
button->szTip[0] = '\0';
|
||||||
|
button->dwFlags = THBF_NOBACKGROUND;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // Q_OS_WIN32
|
||||||
|
|
||||||
|
void Windows7ThumbBar::HandleWinEvent(MSG* msg) {
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
if (button_created_message_id_ == 0) {
|
||||||
|
// Compute the value for the TaskbarButtonCreated message
|
||||||
|
button_created_message_id_ = RegisterWindowMessage("TaskbarButtonCreated");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg->message == button_created_message_id_) {
|
||||||
|
if (!taskbar_list_) {
|
||||||
|
// Create the taskbar list for the first time
|
||||||
|
if (CoCreateInstance(CLSID_ITaskbarList, NULL, CLSCTX_ALL,
|
||||||
|
IID_ITaskbarList3, (void**) &taskbar_list_)) {
|
||||||
|
qWarning() << "Error creating the ITaskbarList3 interface";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ITaskbarList3* taskbar_list = reinterpret_cast<ITaskbarList3*>(taskbar_list_);
|
||||||
|
if (taskbar_list->HrInit()) {
|
||||||
|
taskbar_list->Release();
|
||||||
|
taskbar_list_ = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the buttons
|
||||||
|
THUMBBUTTON buttons[kMaxButtonCount];
|
||||||
|
for (int i=0 ; i<actions_.count() ; ++i) {
|
||||||
|
const QAction* action = actions_[i];
|
||||||
|
THUMBBUTTON* button = &buttons[i];
|
||||||
|
|
||||||
|
button->dwMask = THUMBBUTTONMASK(THB_ICON | THB_TOOLTIP | THB_FLAGS);
|
||||||
|
button->iId = i;
|
||||||
|
SetupButton(action, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
taskbar_list->ThumbBarAddButtons(widget_->winId(), actions_.count(), buttons);
|
||||||
|
}
|
||||||
|
} else if (msg->message == WM_COMMAND) {
|
||||||
|
const int button_id = LOWORD(msg->wParam);
|
||||||
|
|
||||||
|
if (button_id >= 0 && button_id < actions_.count()) {
|
||||||
|
actions_[button_id]->activate(QAction::Trigger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // Q_OS_WIN32
|
||||||
|
}
|
||||||
|
|
||||||
|
void Windows7ThumbBar::ActionChanged() {
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
if (!taskbar_list_)
|
||||||
|
return;
|
||||||
|
ITaskbarList3* taskbar_list = reinterpret_cast<ITaskbarList3*>(taskbar_list_);
|
||||||
|
|
||||||
|
THUMBBUTTON buttons[kMaxButtonCount];
|
||||||
|
for (int i=0 ; i<actions_.count() ; ++i) {
|
||||||
|
const QAction* action = actions_[i];
|
||||||
|
THUMBBUTTON* button = &buttons[i];
|
||||||
|
|
||||||
|
button->dwMask = THUMBBUTTONMASK(THB_ICON | THB_TOOLTIP | THB_FLAGS);
|
||||||
|
button->iId = i;
|
||||||
|
SetupButton(action, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
taskbar_list->ThumbBarUpdateButtons(widget_->winId(), actions_.count(), buttons);
|
||||||
|
#endif // Q_OS_WIN32
|
||||||
|
}
|
59
src/ui/windows7thumbbar.h
Normal file
59
src/ui/windows7thumbbar.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/* This file is part of Clementine.
|
||||||
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
||||||
|
|
||||||
|
Clementine 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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WINDOWS7THUMBBAR_H
|
||||||
|
#define WINDOWS7THUMBBAR_H
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
#ifndef Q_OS_WIN32
|
||||||
|
typedef void MSG;
|
||||||
|
#endif // Q_OS_WIN32
|
||||||
|
|
||||||
|
class Windows7ThumbBar : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Creates a list of buttons in the taskbar icon for this window. Does
|
||||||
|
// nothing and is safe to use on other operating systems too.
|
||||||
|
Windows7ThumbBar(QWidget* widget = 0);
|
||||||
|
|
||||||
|
static const int kIconSize;
|
||||||
|
static const int kMaxButtonCount;
|
||||||
|
|
||||||
|
// You must call this in the parent widget's constructor before returning
|
||||||
|
// to the event loop. If an action is NULL it becomes a spacer.
|
||||||
|
void SetActions(const QList<QAction*>& actions);
|
||||||
|
|
||||||
|
// Call this from the parent's winEvent() function.
|
||||||
|
void HandleWinEvent(MSG* msg);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void ActionChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QWidget* widget_;
|
||||||
|
QList<QAction*> actions_;
|
||||||
|
|
||||||
|
unsigned int button_created_message_id_;
|
||||||
|
|
||||||
|
// Really an ITaskbarList3* but I don't want to have to include windows.h here
|
||||||
|
void* taskbar_list_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WINDOWS7THUMBBAR_H
|
Loading…
x
Reference in New Issue
Block a user