Commit 929ef9cb authored by Michael Pyne's avatar Michael Pyne
Browse files

Add a user-defined literal to grab themed icons and port to use it.

Also some miscellaneous cleanups for whitespace but that's the bulk of
this commit.
parent b89e8234
......@@ -94,6 +94,7 @@ set(juk_SRCS
filerenamerconfigdlg.cpp
webimagefetcher.cpp
historyplaylist.cpp
iconsupport.cpp
juk.cpp
juktag.cpp
keydialog.cpp
......
......@@ -29,13 +29,15 @@
#include <QCheckBox>
#include <QVBoxLayout>
#include "iconsupport.h"
//////////////////////////////////////////////////////////////////////////////
// DeleteWidget implementation
//////////////////////////////////////////////////////////////////////////////
DeleteWidget::DeleteWidget(QWidget *parent)
: QWidget(parent)
, m_ui(new Ui::DeleteDialogBase)
: QWidget(parent)
, m_ui(new Ui::DeleteDialogBase)
{
m_ui->setupUi(this);
......@@ -67,16 +69,18 @@ bool DeleteWidget::shouldDelete() const
void DeleteWidget::slotShouldDelete(bool shouldDelete)
{
using namespace IconSupport;
if(shouldDelete) {
m_ui->ddDeleteText->setText(i18n("<qt>These items will be <b>permanently "
"deleted</b> from your hard disk.</qt>"));
m_ui->ddWarningIcon->setPixmap(
QIcon::fromTheme("dialog-warning").pixmap(KIconLoader::SizeLarge));
("dialog-warning"_icon).pixmap(KIconLoader::SizeLarge));
}
else {
m_ui->ddDeleteText->setText(i18n("<qt>These items will be moved to the Trash Bin.</qt>"));
m_ui->ddWarningIcon->setPixmap(
QIcon::fromTheme("user-trash-full").pixmap(KIconLoader::SizeLarge));
("user-trash-full"_icon).pixmap(KIconLoader::SizeLarge));
}
}
......
......@@ -45,14 +45,15 @@
#include <QPushButton>
#include <QHeaderView>
#include "juktag.h"
#include "filerenameroptions.h"
#include "filehandle.h"
#include "exampleoptions.h"
#include "playlistitem.h"
#include "playlist.h" // processEvents()
#include "coverinfo.h"
#include "exampleoptions.h"
#include "filehandle.h"
#include "filerenameroptions.h"
#include "iconsupport.h"
#include "juk_debug.h"
#include "juktag.h"
#include "playlist.h" // processEvents()
#include "playlistitem.h"
class ConfirmationDialog : public QDialog
{
......@@ -61,6 +62,8 @@ public:
QWidget *parent = nullptr)
: QDialog(parent)
{
using namespace IconSupport; // ""_icon
setModal(true);
setWindowTitle(i18nc("warning about mass file rename", "Warning"));
......@@ -70,7 +73,7 @@ public:
vboxLayout->addWidget(hbox);
QLabel *l = new QLabel(hbox);
l->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(KIconLoader::SizeLarge));
l->setPixmap(("dialog-warning"_icon).pixmap(KIconLoader::SizeLarge));
hboxVLayout->addWidget(l);
l = new QLabel(i18n("You are about to rename the following files. "
......@@ -342,8 +345,10 @@ FileRenamerWidget::~FileRenamerWidget()
int FileRenamerWidget::addRowCategory(TagType category)
{
static QIcon up = QIcon::fromTheme("go-up");
static QIcon down = QIcon::fromTheme("go-down");
using namespace IconSupport; // ""_icon
static QIcon up = "go-up"_icon;
static QIcon down = "go-down"_icon;
// Find number of categories already of this type.
int categoryCount = std::count_if(m_rows.cbegin(), m_rows.cend(),
......
/**
* Copyright (C) 2021 Michael Pyne <mpyne@kde.org>
*
* 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 program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "iconsupport.h"
#include <QIcon>
namespace IconSupport {
QIcon operator ""_icon(const char *latin1Name, std::size_t len)
{
QString iconName = QString::fromLatin1(latin1Name, len);
return QIcon::fromTheme(iconName);
}
};
/**
* Copyright (C) 2021 Michael Pyne <mpyne@kde.org>
*
* 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 program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef JUK_ICONSUPPORT_H
#define JUK_ICONSUPPORT_H
#include <cstddef>
class QIcon;
// Adds a user-defined literal for icons, so keep in a separate namespace
namespace IconSupport {
QIcon operator ""_icon(const char *latin1Name, std::size_t len);
};
#endif
// vim: set et sw=4 tw=0 sta:
......@@ -51,6 +51,7 @@
#include "collectionlist.h"
#include "covermanager.h"
#include "filerenamerconfigdlg.h"
#include "iconsupport.h"
#include "keydialog.h"
#include "playlistsplitter.h"
#include "scrobbleconfigdlg.h"
......@@ -63,7 +64,8 @@
#include "juk_debug.h"
using namespace ActionCollection;
using namespace ActionCollection; // ""_act and others
using namespace IconSupport; // ""_icon
JuK* JuK::m_instance;
......@@ -134,11 +136,11 @@ JuK::JuK(const QStringList &filesToOpen, QWidget *parent)
connect(m_player, &PlayerManager::signalPlay, pmInterface, [=] () {
QDBusReply<uint> reply;
if (pmInterface->isValid() && (m_pmToken == 0)) {
if(pmInterface->isValid() && (m_pmToken == 0)) {
reply = pmInterface->call(QStringLiteral("Inhibit"),
KAboutData::applicationData().componentName(),
QStringLiteral("playing audio"));
if (reply.isValid()) {
if(reply.isValid()) {
m_pmToken = reply.value();
}
}
......@@ -146,9 +148,9 @@ JuK::JuK(const QStringList &filesToOpen, QWidget *parent)
auto uninhibitPowerManagement = [=] () {
QDBusMessage reply;
if (pmInterface->isValid() && (m_pmToken != 0)) {
if(pmInterface->isValid() && (m_pmToken != 0)) {
reply = pmInterface->call(QStringLiteral("UnInhibit"), m_pmToken);
if (reply.errorName().isEmpty()) {
if(reply.errorName().isEmpty()) {
m_pmToken = 0;
}
}
......@@ -253,26 +255,26 @@ void JuK::setupActions()
// Setup the menu which handles the random play options.
KActionMenu *actionMenu = collection->add<KActionMenu>("actionMenu");
actionMenu->setText(i18n("&Random Play"));
actionMenu->setIcon(QIcon::fromTheme(QLatin1String("media-playlist-shuffle")));
actionMenu->setIcon("media-playlist-shuffle"_icon);
actionMenu->setPopupMode(QToolButton::InstantPopup);
QActionGroup* randomPlayGroup = new QActionGroup(this);
QAction *act = collection->add<KToggleAction>("disableRandomPlay");
act->setText(i18n("&Disable Random Play"));
act->setIcon(QIcon::fromTheme(QLatin1String("go-down")));
act->setIcon("go-down"_icon);
act->setActionGroup(randomPlayGroup);
actionMenu->addAction(act);
m_randomPlayAction = collection->add<KToggleAction>("randomPlay");
m_randomPlayAction->setText(i18n("Use &Random Play"));
m_randomPlayAction->setIcon(QIcon::fromTheme(QLatin1String("media-playlist-shuffle")));
m_randomPlayAction->setIcon("media-playlist-shuffle"_icon);
m_randomPlayAction->setActionGroup(randomPlayGroup);
actionMenu->addAction(m_randomPlayAction);
act = collection->add<KToggleAction>("albumRandomPlay");
act->setText(i18n("Use &Album Random Play"));
act->setIcon(QIcon::fromTheme(QLatin1String("media-playlist-shuffle")));
act->setIcon("media-playlist-shuffle"_icon);
act->setActionGroup(randomPlayGroup);
connect(act, &QAction::toggled,
this, &JuK::slotCheckAlbumNextAction);
......@@ -280,23 +282,23 @@ void JuK::setupActions()
act = collection->addAction("removeFromPlaylist", clear, SLOT(clear()));
act->setText(i18n("Remove From Playlist"));
act->setIcon(QIcon::fromTheme( QLatin1String( "list-remove" )));
act->setIcon("list-remove"_icon);
act = collection->addAction("play", m_player, SLOT(play()));
act->setText(i18n("&Play"));
act->setIcon(QIcon::fromTheme( QLatin1String( "media-playback-start" )));
act->setIcon("media-playback-start"_icon);
act = collection->addAction("pause", m_player, SLOT(pause()));
act->setEnabled(false);
act->setText(i18n("P&ause"));
act->setIcon(QIcon::fromTheme( QLatin1String( "media-playback-pause" )));
act->setIcon("media-playback-pause"_icon);
act = collection->addAction("stop", m_player, SLOT(stop()));
act->setEnabled(false);
act->setText(i18n("&Stop"));
act->setIcon(QIcon::fromTheme( QLatin1String( "media-playback-stop" )));
act->setIcon("media-playback-stop"_icon);
act = new KToolBarPopupAction(QIcon::fromTheme( QLatin1String( "media-skip-backward") ), i18nc("previous track", "Previous" ), collection);
act = new KToolBarPopupAction("media-skip-backward"_icon, i18nc("previous track", "Previous" ), collection);
act->setEnabled(false);
collection->addAction("back", act);
connect(act, SIGNAL(triggered(bool)), m_player, SLOT(back()));
......@@ -304,7 +306,7 @@ void JuK::setupActions()
act = collection->addAction("forward", m_player, SLOT(forward()));
act->setEnabled(false);
act->setText(i18nc("next track", "&Next"));
act->setIcon(QIcon::fromTheme( QLatin1String( "media-skip-forward" )));
act->setIcon("media-skip-forward"_icon);
act = collection->addAction("loopPlaylist");
act->setText(i18n("&Loop Playlist"));
......@@ -317,27 +319,27 @@ void JuK::setupActions()
act = collection->addAction("mute", m_player, SLOT(mute()));
act->setText(i18nc("silence playback", "Mute"));
act->setIcon(QIcon::fromTheme( QLatin1String( "audio-volume-muted" )));
act->setIcon("audio-volume-muted"_icon);
act = collection->addAction("volumeUp", m_player, SLOT(volumeUp()));
act->setText(i18n("Volume Up"));
act->setIcon(QIcon::fromTheme( QLatin1String( "audio-volume-high" )));
act->setIcon("audio-volume-high"_icon);
act = collection->addAction("volumeDown", m_player, SLOT(volumeDown()));
act->setText(i18n("Volume Down"));
act->setIcon(QIcon::fromTheme( QLatin1String( "audio-volume-low" )));
act->setIcon("audio-volume-low"_icon);
act = collection->addAction("playPause", m_player, SLOT(playPause()));
act->setText(i18n("Play / Pause"));
act->setIcon(QIcon::fromTheme( QLatin1String( "media-playback-start" )));
act->setIcon("media-playback-start"_icon);
act = collection->addAction("seekForward", m_player, SLOT(seekForward()));
act->setText(i18n("Seek Forward"));
act->setIcon(QIcon::fromTheme( QLatin1String( "media-seek-forward" )));
act->setIcon("media-seek-forward"_icon);
act = collection->addAction("seekBack", m_player, SLOT(seekBack()));
act->setText(i18n("Seek Back"));
act->setIcon(QIcon::fromTheme( QLatin1String( "media-seek-backward" )));
act->setIcon("media-seek-backward"_icon);
act = collection->addAction("showHide", this, SLOT(slotShowHide()));
act->setText(i18n("Show / Hide"));
......
......@@ -28,22 +28,27 @@
#include <KConfigGroup>
#include <KSharedConfig>
#include "juktag.h"
#include "actioncollection.h"
#include "iconsupport.h"
#include "juk_debug.h"
#include "juktag.h"
static const QUrl BASE_LYRICS_URL = QUrl("https://lyrics.fandom.com/");
LyricsWidget::LyricsWidget(QWidget* parent): QTextBrowser(parent),
m_networkAccessManager(new QNetworkAccessManager),
m_lyricsCurrent(false)
using namespace IconSupport; // ""_icon
using namespace ActionCollection; // ""_act
LyricsWidget::LyricsWidget(QWidget* parent)
: QTextBrowser(parent)
, m_networkAccessManager(new QNetworkAccessManager)
, m_lyricsCurrent(false)
{
setMinimumWidth(200);
setReadOnly(true);
setWordWrapMode(QTextOption::WordWrap);
setOpenExternalLinks(true);
KToggleAction *show = new KToggleAction(QIcon::fromTheme(QLatin1String("view-media-lyrics")),
KToggleAction *show = new KToggleAction("view-media-lyrics"_icon,
i18n("Show &Lyrics"), this);
ActionCollection::actions()->addAction("showLyrics", show);
connect(show, SIGNAL(toggled(bool)), this, SLOT(setVisible(bool)));
......@@ -63,7 +68,7 @@ LyricsWidget::~LyricsWidget()
void LyricsWidget::saveConfig()
{
KConfigGroup config(KSharedConfig::openConfig(), "LyricsWidget");
config.writeEntry("Show", ActionCollection::action<KToggleAction>("showLyrics")->isChecked());
config.writeEntry("Show", "showLyrics"_act->isChecked());
}
void LyricsWidget::makeLyricsRequest()
......
......@@ -30,7 +30,6 @@
#include <ktoolbarpopupaction.h>
#include <kactionmenu.h>
#include <ktoggleaction.h>
#include <kselectaction.h>
#include <QCursor>
#include <QDir>
......@@ -65,27 +64,29 @@
#include <cmath>
#include <algorithm>
#include <random>
#include <utility>
#include "actioncollection.h"
#include "cache.h"
#include "collectionlist.h"
#include "coverdialog.h"
#include "coverinfo.h"
#include "deletedialog.h"
#include "directoryloader.h"
#include "playlistitem.h"
#include "filerenamer.h"
#include "iconsupport.h"
#include "juk_debug.h"
#include "juktag.h"
#include "mediafiles.h"
#include "playlistcollection.h"
#include "playlistitem.h"
#include "playlistsearch.h"
#include "playlistsharedsettings.h"
#include "mediafiles.h"
#include "collectionlist.h"
#include "filerenamer.h"
#include "actioncollection.h"
#include "juktag.h"
#include "tagtransactionmanager.h"
#include "upcomingplaylist.h"
#include "deletedialog.h"
#include "webimagefetcher.h"
#include "coverinfo.h"
#include "coverdialog.h"
#include "tagtransactionmanager.h"
#include "cache.h"
#include "juk_debug.h"
using namespace ActionCollection;
using namespace ActionCollection; // ""_act and others
/**
* Used to give every track added in the program a unique identifier. See
......@@ -99,7 +100,7 @@ quint32 g_trackID = 0;
static bool manualResize()
{
return action<KToggleAction>("resizeColumnsManually")->isChecked();
return "resizeColumnsManually"_act->isChecked();
}
////////////////////////////////////////////////////////////////////////////////
......@@ -120,11 +121,11 @@ Playlist::Playlist(
bool delaySetup, const QString &name,
PlaylistCollection *collection, const QString &iconName,
int extraCols)
: QTreeWidget(collection->playlistStack())
, m_collection(collection)
, m_playlistName(name)
, m_refillDebounce(new QTimer(this))
, m_fetcher(new WebImageFetcher(this))
: QTreeWidget(collection->playlistStack())
, m_collection(collection)
, m_playlistName(name)
, m_refillDebounce(new QTimer(this))
, m_fetcher(new WebImageFetcher(this))
{
setup(extraCols);
......@@ -1665,6 +1666,46 @@ int Playlist::leftMostVisibleColumn() const
return i < PlaylistItem::lastColumn() ? i : 0;
}
// used with slotShowRMBMenu
void Playlist::createPlaylistRMBMenu()
{
using namespace IconSupport; // ""_icon
m_rmbMenu = new QMenu(this);
m_rmbMenu->addAction("go-jump-today"_icon, i18n("Add to Play Queue"),
this, &Playlist::slotAddToUpcoming);
m_rmbMenu->addSeparator();
if(!this->readOnly()) {
m_rmbMenu->addAction(action("edit_cut"));
m_rmbMenu->addAction(action("edit_copy"));
m_rmbMenu->addAction(action("edit_paste"));
m_rmbMenu->addSeparator();
m_rmbMenu->addAction(action("removeFromPlaylist"));
}
else
m_rmbMenu->addAction(action("edit_copy"));
m_rmbEdit = m_rmbMenu->addAction(i18n("Edit"));
m_rmbMenu->addAction(action("refresh"));
m_rmbMenu->addAction(action("removeItem"));
m_rmbMenu->addSeparator();
m_rmbMenu->addAction(action("guessTag"));
m_rmbMenu->addAction(action("renameFile"));
m_rmbMenu->addAction(action("coverManager"));
m_rmbMenu->addSeparator();
m_rmbMenu->addAction("folder-new"_icon,
i18n("Create Playlist From Selected Items..."),
this, &Playlist::slotCreateGroup);
}
PlaylistItemList Playlist::items(QTreeWidgetItemIterator::IteratorFlags flags)
{
PlaylistItemList list;
......@@ -2001,43 +2042,7 @@ void Playlist::slotShowRMBMenu(const QPoint &point)
// Create the RMB menu on demand.
if(!m_rmbMenu) {
// Probably more of these actions should be ported over to using KActions.
m_rmbMenu = new QMenu(this);
m_rmbMenu->addAction(QIcon::fromTheme("go-jump-today"),
i18n("Add to Play Queue"), this, &Playlist::slotAddToUpcoming);
m_rmbMenu->addSeparator();
if(!readOnly()) {
m_rmbMenu->addAction(action("edit_cut"));
m_rmbMenu->addAction(action("edit_copy"));
m_rmbMenu->addAction(action("edit_paste"));
m_rmbMenu->addSeparator();
m_rmbMenu->addAction(action("removeFromPlaylist"));
}
else
m_rmbMenu->addAction(action("edit_copy"));
m_rmbEdit = m_rmbMenu->addAction(i18n("Edit"));
m_rmbMenu->addAction(action("refresh"));
m_rmbMenu->addAction(action("removeItem"));
m_rmbMenu->addSeparator();
m_rmbMenu->addAction(action("guessTag"));
m_rmbMenu->addAction(action("renameFile"));
m_rmbMenu->addAction(action("coverManager"));
m_rmbMenu->addSeparator();
m_rmbMenu->addAction(
QIcon::fromTheme("folder-new"),
i18n("Create Playlist From Selected Items..."),
this, &Playlist::slotCreateGroup);
createPlaylistRMBMenu();
}
// Ignore any columns added by subclasses.
......
......@@ -551,6 +551,9 @@ private:
*/
int leftMostVisibleColumn() const;
/// Creates the context menu on demand
void createPlaylistRMBMenu();
/**
* This method is used internally to provide the backend to the other item
* lists.
......
......@@ -42,22 +42,24 @@
#include <QHeaderView>
#include <QElapsedTimer>
#include "playlist.h"
#include "actioncollection.h"
#include "cache.h"
#include "collectionlist.h"
#include "dbuscollectionproxy.h"
#include "dynamicplaylist.h"
#include "upcomingplaylist.h"
#include "historyplaylist.h"
#include "viewmode.h"
#include "iconsupport.h"
#include "juk_debug.h"
#include "playermanager.h"
#include "playlist.h"
#include "searchplaylist.h"
#include "treeviewitemplaylist.h"
#include "actioncollection.h"
#include "cache.h"
#include "tagtransactionmanager.h"
#include "playermanager.h"
#include "dbuscollectionproxy.h"
#include "juk_debug.h"
#include "treeviewitemplaylist.h"
#include "upcomingplaylist.h"
#include "viewmode.h"
using namespace ActionCollection;
using namespace ActionCollection; // ""_act and others
using namespace IconSupport; // ""_icon
////////////////////////////////////////////////////////////////////////////////
// PlaylistBox public methods
......@@ -102,22 +104,22 @@ PlaylistBox::PlaylistBox(PlayerManager *player, QWidget *parent, QStackedWidget
// add the view modes stuff
KSelectAction *viewModeAction =
new KSelectAction( QIcon::fromTheme(QStringLiteral("view-choose")), i18n("View Modes"), ActionCollection::actions());
new KSelectAction("view-choose"_icon, i18n("View Modes"), ActionCollection::actions());
ActionCollection::actions()->addAction("viewModeMenu", viewModeAction);
ViewMode* viewmode = new ViewMode(this);
m_viewModes.append(viewmode);
viewModeAction->addAction(QIcon::fromTheme(QStringLiteral("view-list-details")), viewmode->name());
viewModeAction->addAction("view-list-details"_icon, viewmode->name());
CompactViewMode* compactviewmode = new CompactViewMode(this);
m_viewModes.append(compactviewmode);
viewModeAction->addAction(QIcon::fromTheme(QStringLiteral("view-list-text")), compactviewmode->name());
viewModeAction->addAction("view-list-text"_icon, compactviewmode->name());
// TODO: Fix the broken tree view mode
#if 0
TreeViewMode* treeviewmode = new TreeViewMode(this);
m_viewModes.append(treeviewmode);
viewModeAction->addAction(QIcon::fromTheme(QStringLiteral("view-list-tree")), treeviewmode->name());
viewModeAction->addAction("view-list-tree"_icon, treeviewmode->name());
#endif
CollectionList::initialize(this);
......@@ -160,7 +162,7 @@ PlaylistBox::PlaylistBox(PlayerManager *player, QWidget *parent, QStackedWidget
this, &PlaylistBox::slotLoadCachedPlaylists);
KToggleAction *historyAction =
new KToggleAction(QIcon::fromTheme(QStringLiteral("view-history")), i18n("Show &History"), ActionCollection::actions());
new KToggleAction("view-history"_icon, i18n("Show &History"), ActionCollection::actions());
ActionCollection::actions()->addAction("showHistory", historyAction);
connect(historyAction, &KToggleAction::triggered,
this, &PlaylistBox::slotSetHistoryPlaylistEnabled);
......@@ -611,11 +613,11 @@ void PlaylistBox::slotPlaylistChanged()
if(playlists.front() == upcomingPlaylist()) {
action("deleteItemPlaylist")->setText(i18n("Hid&e"));
action("deleteItemPlaylist")->setIcon(QIcon::fromTheme("list-remove"));
action("deleteItemPlaylist")->setIcon("list-remove"_icon);
}
else {
action("deleteItemPlaylist")->setText(i18n("R&emove"));
action("deleteItemPlaylist")->setIcon(QIcon::fromTheme("user-trash"));
action("deleteItemPlaylist")->setIcon("user-trash"_icon);
}
}
else if(!playlists.isEmpty())
......
......@@ -41,18 +41,19 @@
#include <sys/types.h>
#include <dirent.h>
#include "collectionlist.h"
#include "actioncollection.h"
#include "advancedsearchdialog.h"