1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-18 20:40:43 +01:00

More commandline options. Fixes issue #95

This commit is contained in:
David Sansome 2010-04-12 23:35:47 +00:00
parent 2ec6ca45c8
commit c59c7ee0ec
13 changed files with 373 additions and 58 deletions

View File

@ -33,17 +33,30 @@ const char* CommandlineOptions::kHelpText =
" -s, --stop %8\n"
" -r, --previous %9\n"
" -f, --next %10\n"
" -v, --volume <value> %11\n"
" --volume-up %12\n"
" --volume-down %13\n"
" --seek-to <seconds> %14\n"
"\n"
"%11:\n"
" -a, --append %12\n"
" -l, --load %13\n";
"%15:\n"
" -a, --append %16\n"
" -l, --load %17\n"
" -k, --play-track <n> %18\n"
"\n"
"%19:\n"
" -o, --show-osd %20\n";
CommandlineOptions::CommandlineOptions(int argc, char** argv)
: argc_(argc),
argv_(argv),
url_list_action_(UrlList_Append),
player_action_(Player_None)
player_action_(Player_None),
set_volume_(-1),
volume_modifier_(0),
seek_to_(-1),
play_track_at_(-1),
show_osd_(false)
{
}
@ -51,23 +64,31 @@ bool CommandlineOptions::Parse() {
static const struct option kOptions[] = {
{"help", no_argument, 0, 'h'},
{"append", no_argument, 0, 'a'},
{"load", no_argument, 0, 'l'},
{"play", no_argument, 0, 'p'},
{"play-pause", no_argument, 0, 't'},
{"pause", no_argument, 0, 'u'},
{"stop", no_argument, 0, 's'},
{"previous", no_argument, 0, 'r'},
{"next", no_argument, 0, 'f'},
{"volume", required_argument, 0, 'v'},
{"volume-up", no_argument, 0, VolumeUp},
{"volume-down", no_argument, 0, VolumeDown},
{"seek-to", required_argument, 0, SeekTo},
{"append", no_argument, 0, 'a'},
{"load", no_argument, 0, 'l'},
{"play-track", required_argument, 0, 'k'},
{"show-osd", no_argument, 0, 'o'},
{0, 0, 0, 0}
};
// Parse the arguments
int option_index = 0;
bool ok = false;
forever {
int c = getopt_long(argc_, argv_, "", kOptions, &option_index);
int c = getopt_long(argc_, argv_, "hptusrfv:alk:o", kOptions, &option_index);
// End of the options
if (c == -1)
@ -76,29 +97,55 @@ bool CommandlineOptions::Parse() {
switch (c) {
case 'h': {
QString translated_help_text = QString(kHelpText).arg(
tr("Usage"), tr("options"), tr("files or URL(s)"), tr("Options"),
tr("Usage"), tr("options"), tr("URL(s)"), tr("Player options"),
tr("Start the playlist currently playing"),
tr("Play if stopped, pause if playing"),
tr("Pause playback"),
tr("Stop playback"),
tr("Skip backwards in playlist")).arg(
tr("Skip forwards in playlist"),
tr("Additional options"),
tr("Set the volume to <value> percent"),
tr("Increase the volume by 4%"),
tr("Decrease the volume by 4%"),
tr("Seek the currently playing track"),
tr("Playlist options"),
tr("Append files/URLs to the playlist"),
tr("Loads files/URLs, replacing current playlist"));
tr("Loads files/URLs, replacing current playlist"),
tr("Play the <n>th track in the playlist")).arg(
tr("Other options"),
tr("Display the on-screen-display"));
std::cout << translated_help_text.toLocal8Bit().constData();
return false;
}
case 'a': url_list_action_ = UrlList_Append; break;
case 'l': url_list_action_ = UrlList_Load; break;
case 'p': player_action_ = Player_Play; break;
case 't': player_action_ = Player_PlayPause; break;
case 'u': player_action_ = Player_Pause; break;
case 's': player_action_ = Player_Stop; break;
case 'r': player_action_ = Player_Previous; break;
case 'f': player_action_ = Player_Next; break;
case 'a': url_list_action_ = UrlList_Append; break;
case 'l': url_list_action_ = UrlList_Load; break;
case 'o': show_osd_ = true; break;
case VolumeUp: volume_modifier_ = +4; break;
case VolumeDown: volume_modifier_ = -4; break;
case 'v':
set_volume_ = QString(optarg).toInt(&ok);
if (!ok) set_volume_ = -1;
break;
case SeekTo:
seek_to_ = QString(optarg).toInt(&ok);
if (!ok) seek_to_ = -1;
break;
case 'k':
play_track_at_ = QString(optarg).toInt(&ok);
if (!ok) play_track_at_ = -1;
break;
case '?':
default:
return false;
@ -117,6 +164,16 @@ bool CommandlineOptions::Parse() {
return true;
}
bool CommandlineOptions::is_empty() const {
return player_action_ == Player_None &&
set_volume_ == -1 &&
volume_modifier_ == 0 &&
seek_to_ == -1 &&
play_track_at_ == -1 &&
show_osd_ == false &&
urls_.isEmpty();
}
QByteArray CommandlineOptions::Serialize() const {
QBuffer buf;
buf.open(QIODevice::WriteOnly);
@ -144,6 +201,11 @@ QString CommandlineOptions::tr(const char *source_text) {
QDataStream& operator<<(QDataStream& s, const CommandlineOptions& a) {
s << qint32(a.player_action_)
<< qint32(a.url_list_action_)
<< a.set_volume_
<< a.volume_modifier_
<< a.seek_to_
<< a.play_track_at_
<< a.show_osd_
<< a.urls_;
return s;
@ -152,6 +214,11 @@ QDataStream& operator<<(QDataStream& s, const CommandlineOptions& a) {
QDataStream& operator>>(QDataStream& s, CommandlineOptions& a) {
s >> reinterpret_cast<qint32&>(a.player_action_)
>> reinterpret_cast<qint32&>(a.url_list_action_)
>> a.set_volume_
>> a.volume_modifier_
>> a.seek_to_
>> a.play_track_at_
>> a.show_osd_
>> a.urls_;
return s;

View File

@ -48,14 +48,27 @@ class CommandlineOptions {
bool Parse();
bool is_empty() const;
UrlListAction url_list_action() const { return url_list_action_; }
PlayerAction player_action() const { return player_action_; }
int set_volume() const { return set_volume_; }
int volume_modifier() const { return volume_modifier_; }
int seek_to() const { return seek_to_; }
int play_track_at() const { return play_track_at_; }
bool show_osd() const { return show_osd_; }
QList<QUrl> urls() const { return urls_; }
QByteArray Serialize() const;
void Load(const QByteArray& serialized);
private:
enum LongOptions {
VolumeUp = 256,
VolumeDown,
SeekTo,
};
QString tr(const char* source_text);
private:
@ -65,6 +78,13 @@ class CommandlineOptions {
UrlListAction url_list_action_;
PlayerAction player_action_;
// Don't change the type of these.
int set_volume_;
int volume_modifier_;
int seek_to_;
int play_track_at_;
bool show_osd_;
QList<QUrl> urls_;
};

View File

@ -104,7 +104,8 @@ int main(int argc, char *argv[]) {
return 1;
if (a.isRunning()) {
qDebug() << "Clementine is already running - activating existing window";
if (options.is_empty())
qDebug() << "Clementine is already running - activating existing window";
if (a.sendMessage(options.Serialize()))
return 0;
// Couldn't send the message so start anyway
@ -130,11 +131,8 @@ int main(int argc, char *argv[]) {
// Window
MainWindow w(&network);
a.setActivationWindow(&w);
QObject::connect(&a, SIGNAL(messageReceived(QByteArray)), &w, SLOT(show()));
QObject::connect(&a, SIGNAL(messageReceived(QByteArray)), &w, SLOT(CommandlineOptionsReceived(QByteArray)));
w.CommandlineOptionsReceived(options);
return a.exec();

View File

@ -192,6 +192,7 @@ MainWindow::MainWindow(QNetworkAccessManager* network, QWidget *parent)
connect(player_, SIGNAL(Paused()), osd_, SLOT(Paused()));
connect(player_, SIGNAL(Stopped()), osd_, SLOT(Stopped()));
connect(player_, SIGNAL(VolumeChanged(int)), osd_, SLOT(VolumeChanged(int)));
connect(player_, SIGNAL(VolumeChanged(int)), ui_.volume, SLOT(setValue(int)));
connect(player_, SIGNAL(ForceShowOSD(Song)), osd_, SLOT(SongChanged(Song)));
connect(playlist_, SIGNAL(CurrentSongChanged(Song)), osd_, SLOT(SongChanged(Song)));
connect(playlist_, SIGNAL(CurrentSongChanged(Song)), player_, SLOT(CurrentMetadataChanged(Song)));
@ -885,7 +886,12 @@ void MainWindow::CommandlineOptionsReceived(const QByteArray& serialized_options
CommandlineOptions options;
options.Load(serialized_options);
CommandlineOptionsReceived(options);
if (options.is_empty()) {
show();
activateWindow();
}
else
CommandlineOptionsReceived(options);
}
void MainWindow::CommandlineOptionsReceived(const CommandlineOptions &options) {
@ -922,4 +928,19 @@ void MainWindow::CommandlineOptionsReceived(const CommandlineOptions &options) {
playlist_->InsertPaths(options.urls(), -1);
break;
}
if (options.set_volume() != -1)
player_->SetVolume(options.set_volume());
if (options.volume_modifier() != 0)
player_->SetVolume(player_->GetVolume() + options.volume_modifier());
if (options.seek_to() != -1)
player_->Seek(options.seek_to());
if (options.play_track_at() != -1)
player_->PlayAt(options.play_track_at(), Engine::Manual);
if (options.show_osd())
player_->ShowOSD();
}

View File

@ -187,10 +187,14 @@ void Player::EngineStateChanged(Engine::State state) {
}
void Player::SetVolume(int value) {
int old_volume = engine_->volume();
int volume = qBound(0, value, 100);
settings_.setValue("volume", volume);
engine_->SetVolume(volume);
emit VolumeChanged(volume);
if (volume != old_volume)
emit VolumeChanged(volume);
}
int Player::GetVolume() const {

View File

@ -490,11 +490,12 @@ msgstr ""
msgid "options"
msgstr "Upozornění"
msgid "files or URL(s)"
msgid "URL(s)"
msgstr ""
msgid "Options"
msgstr ""
#, fuzzy
msgid "Player options"
msgstr "Upozornění"
msgid "Start the playlist currently playing"
msgstr ""
@ -516,15 +517,38 @@ msgstr ""
msgid "Skip forwards in playlist"
msgstr ""
msgid "Additional options"
msgid "Set the volume to <value> percent"
msgstr ""
msgid "Increase the volume by 4%"
msgstr ""
msgid "Decrease the volume by 4%"
msgstr ""
msgid "Seek the currently playing track"
msgstr ""
#, fuzzy
msgid "Playlist options"
msgstr "Dokončen seznam skladeb"
msgid "Append files/URLs to the playlist"
msgstr ""
msgid "Loads files/URLs, replacing current playlist"
msgstr ""
msgid "Play the <n>th track in the playlist"
msgstr ""
#, fuzzy
msgid "Other options"
msgstr "Upozornění"
msgid "Display the on-screen-display"
msgstr ""
msgid "Clementine"
msgstr "Clementine"
@ -675,6 +699,9 @@ msgstr "Přidat novou složku..."
msgid "Remove folder"
msgstr "Odstranit složku"
msgid "Options"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""

View File

@ -493,10 +493,11 @@ msgstr ""
msgid "options"
msgstr "Επιλογές"
msgid "files or URL(s)"
msgid "URL(s)"
msgstr ""
msgid "Options"
#, fuzzy
msgid "Player options"
msgstr "Επιλογές"
msgid "Start the playlist currently playing"
@ -519,15 +520,38 @@ msgstr ""
msgid "Skip forwards in playlist"
msgstr ""
msgid "Additional options"
msgid "Set the volume to <value> percent"
msgstr ""
msgid "Increase the volume by 4%"
msgstr ""
msgid "Decrease the volume by 4%"
msgstr ""
msgid "Seek the currently playing track"
msgstr ""
#, fuzzy
msgid "Playlist options"
msgstr "Η λίστα τελείωσε"
msgid "Append files/URLs to the playlist"
msgstr ""
msgid "Loads files/URLs, replacing current playlist"
msgstr ""
msgid "Play the <n>th track in the playlist"
msgstr ""
#, fuzzy
msgid "Other options"
msgstr "Επιλογές"
msgid "Display the on-screen-display"
msgstr ""
msgid "Clementine"
msgstr "Clementine"
@ -678,6 +702,9 @@ msgstr "Προσθήκη νέου φακέλου..."
msgid "Remove folder"
msgstr "Αφαίρεση φακέλου"
msgid "Options"
msgstr "Επιλογές"
msgid "Automatically open single categories in the library tree"
msgstr "Άνοιξε αυτόμα τις μόνες κατηγορίες του δέντρου της βιβλιοθήκης"

View File

@ -492,10 +492,11 @@ msgstr ""
msgid "options"
msgstr "Opciones"
msgid "files or URL(s)"
msgid "URL(s)"
msgstr ""
msgid "Options"
#, fuzzy
msgid "Player options"
msgstr "Opciones"
msgid "Start the playlist currently playing"
@ -518,15 +519,40 @@ msgstr ""
msgid "Skip forwards in playlist"
msgstr ""
msgid "Additional options"
msgid "Set the volume to <value> percent"
msgstr ""
#, fuzzy
msgid "Increase the volume by 4%"
msgstr "Aumentar Volúmen"
#, fuzzy
msgid "Decrease the volume by 4%"
msgstr "Disminuir Volumen"
msgid "Seek the currently playing track"
msgstr ""
#, fuzzy
msgid "Playlist options"
msgstr "Lista de reproducción finalizada"
msgid "Append files/URLs to the playlist"
msgstr ""
msgid "Loads files/URLs, replacing current playlist"
msgstr ""
msgid "Play the <n>th track in the playlist"
msgstr ""
#, fuzzy
msgid "Other options"
msgstr "Opciones"
msgid "Display the on-screen-display"
msgstr ""
msgid "Clementine"
msgstr "Clementine"
@ -678,6 +704,9 @@ msgstr "Añadir nueva carpeta..."
msgid "Remove folder"
msgstr "Remover carpeta"
msgid "Options"
msgstr "Opciones"
msgid "Automatically open single categories in the library tree"
msgstr ""
"Automaticamente expandir los artitas con un solo disco en el arbol de la "
@ -1085,12 +1114,6 @@ msgstr ""
#~ msgid "Previous Track"
#~ msgstr "Pista anterior"
#~ msgid "Increase Volume"
#~ msgstr "Aumentar Volúmen"
#~ msgid "Decrease Volume"
#~ msgstr "Disminuir Volumen"
#~ msgid "Mute Volume"
#~ msgstr "Silencio"

View File

@ -492,11 +492,12 @@ msgstr ""
msgid "options"
msgstr "Notifications"
msgid "files or URL(s)"
msgid "URL(s)"
msgstr ""
msgid "Options"
msgstr ""
#, fuzzy
msgid "Player options"
msgstr "Notifications"
msgid "Start the playlist currently playing"
msgstr ""
@ -518,15 +519,38 @@ msgstr ""
msgid "Skip forwards in playlist"
msgstr ""
msgid "Additional options"
msgid "Set the volume to <value> percent"
msgstr ""
msgid "Increase the volume by 4%"
msgstr ""
msgid "Decrease the volume by 4%"
msgstr ""
msgid "Seek the currently playing track"
msgstr ""
#, fuzzy
msgid "Playlist options"
msgstr "Liste de lecture terminée"
msgid "Append files/URLs to the playlist"
msgstr ""
msgid "Loads files/URLs, replacing current playlist"
msgstr ""
msgid "Play the <n>th track in the playlist"
msgstr ""
#, fuzzy
msgid "Other options"
msgstr "Notifications"
msgid "Display the on-screen-display"
msgstr ""
msgid "Clementine"
msgstr "Clementine"
@ -679,6 +703,9 @@ msgstr "Ajouter un nouveau dossier..."
msgid "Remove folder"
msgstr "Supprimer un dossier"
msgid "Options"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""

View File

@ -488,10 +488,11 @@ msgstr ""
msgid "options"
msgstr "Opcje"
msgid "files or URL(s)"
msgid "URL(s)"
msgstr ""
msgid "Options"
#, fuzzy
msgid "Player options"
msgstr "Opcje"
msgid "Start the playlist currently playing"
@ -514,15 +515,38 @@ msgstr ""
msgid "Skip forwards in playlist"
msgstr ""
msgid "Additional options"
msgid "Set the volume to <value> percent"
msgstr ""
msgid "Increase the volume by 4%"
msgstr ""
msgid "Decrease the volume by 4%"
msgstr ""
msgid "Seek the currently playing track"
msgstr ""
#, fuzzy
msgid "Playlist options"
msgstr "Zakończono playlistę"
msgid "Append files/URLs to the playlist"
msgstr ""
msgid "Loads files/URLs, replacing current playlist"
msgstr ""
msgid "Play the <n>th track in the playlist"
msgstr ""
#, fuzzy
msgid "Other options"
msgstr "Opcje"
msgid "Display the on-screen-display"
msgstr ""
msgid "Clementine"
msgstr ""
@ -673,6 +697,9 @@ msgstr "Dodaj nowy katalog..."
msgid "Remove folder"
msgstr "Usuń katalog"
msgid "Options"
msgstr "Opcje"
msgid "Automatically open single categories in the library tree"
msgstr "Automatycznie otwieraj pojedyńcze kategorie w drzewie Biblioteki"

View File

@ -488,11 +488,12 @@ msgstr ""
msgid "options"
msgstr "Уведомления"
msgid "files or URL(s)"
msgid "URL(s)"
msgstr ""
msgid "Options"
msgstr ""
#, fuzzy
msgid "Player options"
msgstr "Уведомления"
msgid "Start the playlist currently playing"
msgstr ""
@ -514,15 +515,38 @@ msgstr ""
msgid "Skip forwards in playlist"
msgstr ""
msgid "Additional options"
msgid "Set the volume to <value> percent"
msgstr ""
msgid "Increase the volume by 4%"
msgstr ""
msgid "Decrease the volume by 4%"
msgstr ""
msgid "Seek the currently playing track"
msgstr ""
#, fuzzy
msgid "Playlist options"
msgstr "Плейлист закончен"
msgid "Append files/URLs to the playlist"
msgstr ""
msgid "Loads files/URLs, replacing current playlist"
msgstr ""
msgid "Play the <n>th track in the playlist"
msgstr ""
#, fuzzy
msgid "Other options"
msgstr "Уведомления"
msgid "Display the on-screen-display"
msgstr ""
msgid "Clementine"
msgstr "Clementine"
@ -674,6 +698,9 @@ msgstr "Добавить каталог..."
msgid "Remove folder"
msgstr "Удалить каталог"
msgid "Options"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""

View File

@ -491,10 +491,11 @@ msgstr ""
msgid "options"
msgstr "Možnosti"
msgid "files or URL(s)"
msgid "URL(s)"
msgstr ""
msgid "Options"
#, fuzzy
msgid "Player options"
msgstr "Možnosti"
msgid "Start the playlist currently playing"
@ -515,15 +516,40 @@ msgstr ""
msgid "Skip forwards in playlist"
msgstr ""
msgid "Additional options"
msgid "Set the volume to <value> percent"
msgstr ""
#, fuzzy
msgid "Increase the volume by 4%"
msgstr "Zvýšenie hlasitosti"
#, fuzzy
msgid "Decrease the volume by 4%"
msgstr "Zníženie hlasitosti"
msgid "Seek the currently playing track"
msgstr ""
#, fuzzy
msgid "Playlist options"
msgstr "Playlist skončený"
msgid "Append files/URLs to the playlist"
msgstr ""
msgid "Loads files/URLs, replacing current playlist"
msgstr ""
msgid "Play the <n>th track in the playlist"
msgstr ""
#, fuzzy
msgid "Other options"
msgstr "Možnosti"
msgid "Display the on-screen-display"
msgstr ""
msgid "Clementine"
msgstr ""
@ -674,6 +700,9 @@ msgstr "Pridať nový priečinok..."
msgid "Remove folder"
msgstr "Odobrať priečinok"
msgid "Options"
msgstr "Možnosti"
msgid "Automatically open single categories in the library tree"
msgstr "Automaticky otvoriť jednotlivé kategórie v strome zbierky"
@ -1073,12 +1102,6 @@ msgstr ""
#~ msgid "Previous Track"
#~ msgstr "Predchádzajúca skladba"
#~ msgid "Increase Volume"
#~ msgstr "Zvýšenie hlasitosti"
#~ msgid "Decrease Volume"
#~ msgstr "Zníženie hlasitosti"
#~ msgid "Mute Volume"
#~ msgstr "Umlčanie hlasitosti"

View File

@ -483,10 +483,10 @@ msgstr ""
msgid "options"
msgstr ""
msgid "files or URL(s)"
msgid "URL(s)"
msgstr ""
msgid "Options"
msgid "Player options"
msgstr ""
msgid "Start the playlist currently playing"
@ -507,7 +507,19 @@ msgstr ""
msgid "Skip forwards in playlist"
msgstr ""
msgid "Additional options"
msgid "Set the volume to <value> percent"
msgstr ""
msgid "Increase the volume by 4%"
msgstr ""
msgid "Decrease the volume by 4%"
msgstr ""
msgid "Seek the currently playing track"
msgstr ""
msgid "Playlist options"
msgstr ""
msgid "Append files/URLs to the playlist"
@ -516,6 +528,15 @@ msgstr ""
msgid "Loads files/URLs, replacing current playlist"
msgstr ""
msgid "Play the <n>th track in the playlist"
msgstr ""
msgid "Other options"
msgstr ""
msgid "Display the on-screen-display"
msgstr ""
msgid "Clementine"
msgstr ""
@ -666,6 +687,9 @@ msgstr ""
msgid "Remove folder"
msgstr ""
msgid "Options"
msgstr ""
msgid "Automatically open single categories in the library tree"
msgstr ""