Add a "seek by n seconds" commandline option, and make sure stopping and starting again from the commandline restarts the same track. See issue #95

This commit is contained in:
David Sansome 2010-04-13 20:22:29 +00:00
parent f429b53212
commit aaa1ef8a7f
12 changed files with 78 additions and 33 deletions

View File

@ -37,14 +37,15 @@ const char* CommandlineOptions::kHelpText =
" --volume-up %12\n"
" --volume-down %13\n"
" --seek-to <seconds> %14\n"
" --seek-by <seconds> %15\n"
"\n"
"%15:\n"
" -a, --append %16\n"
" -l, --load %17\n"
" -k, --play-track <n> %18\n"
"%16:\n"
" -a, --append %17\n"
" -l, --load %18\n"
" -k, --play-track <n> %19\n"
"\n"
"%19:\n"
" -o, --show-osd %20\n";
"%20:\n"
" -o, --show-osd %21\n";
CommandlineOptions::CommandlineOptions(int argc, char** argv)
@ -55,6 +56,7 @@ CommandlineOptions::CommandlineOptions(int argc, char** argv)
set_volume_(-1),
volume_modifier_(0),
seek_to_(-1),
seek_by_(0),
play_track_at_(-1),
show_osd_(false)
{
@ -62,24 +64,25 @@ CommandlineOptions::CommandlineOptions(int argc, char** argv)
bool CommandlineOptions::Parse() {
static const struct option kOptions[] = {
{"help", no_argument, 0, 'h'},
{"help", no_argument, 0, 'h'},
{"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},
{"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},
{"seek-by", required_argument, 0, SeekBy},
{"append", no_argument, 0, 'a'},
{"load", no_argument, 0, 'l'},
{"play-track", required_argument, 0, 'k'},
{"append", no_argument, 0, 'a'},
{"load", no_argument, 0, 'l'},
{"play-track", required_argument, 0, 'k'},
{"show-osd", no_argument, 0, 'o'},
{"show-osd", no_argument, 0, 'o'},
{0, 0, 0, 0}
};
@ -107,11 +110,12 @@ bool CommandlineOptions::Parse() {
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("Seek the currently playing track to an absolute position"),
tr("Seek the currently playing track by a relative amount"),
tr("Playlist options"),
tr("Append files/URLs to the playlist"),
tr("Loads files/URLs, replacing current playlist"),
tr("Play the <n>th track in the playlist")).arg(
tr("Loads files/URLs, replacing current playlist")).arg(
tr("Play the <n>th track in the playlist"),
tr("Other options"),
tr("Display the on-screen-display"));
@ -141,6 +145,11 @@ bool CommandlineOptions::Parse() {
if (!ok) seek_to_ = -1;
break;
case SeekBy:
seek_by_ = QString(optarg).toInt(&ok);
if (!ok) seek_by_ = 0;
break;
case 'k':
play_track_at_ = QString(optarg).toInt(&ok);
if (!ok) play_track_at_ = -1;
@ -169,6 +178,7 @@ bool CommandlineOptions::is_empty() const {
set_volume_ == -1 &&
volume_modifier_ == 0 &&
seek_to_ == -1 &&
seek_by_ == 0 &&
play_track_at_ == -1 &&
show_osd_ == false &&
urls_.isEmpty();
@ -204,6 +214,7 @@ QDataStream& operator<<(QDataStream& s, const CommandlineOptions& a) {
<< a.set_volume_
<< a.volume_modifier_
<< a.seek_to_
<< a.seek_by_
<< a.play_track_at_
<< a.show_osd_
<< a.urls_;
@ -217,6 +228,7 @@ QDataStream& operator>>(QDataStream& s, CommandlineOptions& a) {
>> a.set_volume_
>> a.volume_modifier_
>> a.seek_to_
>> a.seek_by_
>> a.play_track_at_
>> a.show_osd_
>> a.urls_;

View File

@ -55,6 +55,7 @@ class CommandlineOptions {
int set_volume() const { return set_volume_; }
int volume_modifier() const { return volume_modifier_; }
int seek_to() const { return seek_to_; }
int seek_by() const { return seek_by_; }
int play_track_at() const { return play_track_at_; }
bool show_osd() const { return show_osd_; }
QList<QUrl> urls() const { return urls_; }
@ -63,10 +64,13 @@ class CommandlineOptions {
void Load(const QByteArray& serialized);
private:
// These are "invalid" characters to pass to getopt_long for options that
// shouldn't have a short (single character) option.
enum LongOptions {
VolumeUp = 256,
VolumeDown,
SeekTo,
SeekBy,
};
QString tr(const char* source_text);
@ -82,6 +86,7 @@ class CommandlineOptions {
int set_volume_;
int volume_modifier_;
int seek_to_;
int seek_by_;
int play_track_at_;
bool show_osd_;

View File

@ -937,6 +937,8 @@ void MainWindow::CommandlineOptionsReceived(const CommandlineOptions &options) {
if (options.seek_to() != -1)
player_->Seek(options.seek_to());
else if (options.seek_by() != 0)
player_->Seek(player_->PositionGet() / 1000 + options.seek_by());
if (options.play_track_at() != -1)
player_->PlayAt(options.play_track_at(), Engine::Manual);

View File

@ -395,7 +395,7 @@ void Player::Play() {
engine_->Unpause();
break;
default:
Next(Engine::Manual);
PlayPause();
break;
}
}

View File

@ -526,7 +526,10 @@ msgstr ""
msgid "Decrease the volume by 4%"
msgstr ""
msgid "Seek the currently playing track"
msgid "Seek the currently playing track to an absolute position"
msgstr ""
msgid "Seek the currently playing track by a relative amount"
msgstr ""
#, fuzzy

View File

@ -529,7 +529,10 @@ msgstr ""
msgid "Decrease the volume by 4%"
msgstr ""
msgid "Seek the currently playing track"
msgid "Seek the currently playing track to an absolute position"
msgstr ""
msgid "Seek the currently playing track by a relative amount"
msgstr ""
#, fuzzy

View File

@ -530,7 +530,10 @@ msgstr "Aumentar Volúmen"
msgid "Decrease the volume by 4%"
msgstr "Disminuir Volumen"
msgid "Seek the currently playing track"
msgid "Seek the currently playing track to an absolute position"
msgstr ""
msgid "Seek the currently playing track by a relative amount"
msgstr ""
#, fuzzy

View File

@ -528,7 +528,10 @@ msgstr ""
msgid "Decrease the volume by 4%"
msgstr ""
msgid "Seek the currently playing track"
msgid "Seek the currently playing track to an absolute position"
msgstr ""
msgid "Seek the currently playing track by a relative amount"
msgstr ""
#, fuzzy

View File

@ -524,7 +524,10 @@ msgstr ""
msgid "Decrease the volume by 4%"
msgstr ""
msgid "Seek the currently playing track"
msgid "Seek the currently playing track to an absolute position"
msgstr ""
msgid "Seek the currently playing track by a relative amount"
msgstr ""
#, fuzzy

View File

@ -525,7 +525,12 @@ msgstr "Увеличить громкость на 4%"
msgid "Decrease the volume by 4%"
msgstr "Уменьшить громкость на 4%"
msgid "Seek the currently playing track"
#, fuzzy
msgid "Seek the currently playing track to an absolute position"
msgstr "Искать в воспроизводимой композиции"
#, fuzzy
msgid "Seek the currently playing track by a relative amount"
msgstr "Искать в воспроизводимой композиции"
msgid "Playlist options"

View File

@ -527,7 +527,10 @@ msgstr "Zvýšenie hlasitosti"
msgid "Decrease the volume by 4%"
msgstr "Zníženie hlasitosti"
msgid "Seek the currently playing track"
msgid "Seek the currently playing track to an absolute position"
msgstr ""
msgid "Seek the currently playing track by a relative amount"
msgstr ""
#, fuzzy

View File

@ -516,7 +516,10 @@ msgstr ""
msgid "Decrease the volume by 4%"
msgstr ""
msgid "Seek the currently playing track"
msgid "Seek the currently playing track to an absolute position"
msgstr ""
msgid "Seek the currently playing track by a relative amount"
msgstr ""
msgid "Playlist options"