Mercurial > audlegacy
comparison src/audtool/audtool_main.c @ 2922:89676d0b5efc trunk
File reorganization.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Fri, 29 Jun 2007 07:37:39 -0500 |
parents | src/audtool/audtool.c@8b7e1929aec1 |
children | cf35109c4c33 |
comparison
equal
deleted
inserted
replaced
2919:2abf3bb3e63d | 2922:89676d0b5efc |
---|---|
1 /* | |
2 * Audtool2 | |
3 * Copyright (c) 2007 Audacious development team | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions are | |
7 * met: | |
8 * | |
9 * 1. Redistributions of source code must retain the above copyright notice, | |
10 * this list of conditions and the following disclaimer. | |
11 * | |
12 * 2. Redistributions in binary form must reproduce the above copyright | |
13 * notice, this list of conditions and the following disclaimer in the | |
14 * documentation and/or other materials provided with the distribution. | |
15 * | |
16 * 3. The name of the author may not be used to endorse or promote products | |
17 * derived from this software without specific prior written permission. | |
18 * | |
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 * POSSIBILITY OF SUCH DAMAGE. | |
30 */ | |
31 | |
32 #include <stdlib.h> | |
33 #include <string.h> | |
34 #include <glib.h> | |
35 #include <mowgli.h> | |
36 #include <locale.h> | |
37 #include "libaudclient/audctrl.h" | |
38 #include "audtool.h" | |
39 | |
40 struct commandhandler handlers[] = { | |
41 {"<sep>", NULL, "Vital information"}, | |
42 {"current-song", get_current_song, "returns current song title"}, | |
43 {"current-song-filename", get_current_song_filename, "returns current song filename"}, | |
44 {"current-song-length", get_current_song_length, "returns current song length"}, | |
45 {"current-song-length-seconds", get_current_song_length_seconds, "returns current song length in seconds"}, | |
46 {"current-song-length-frames", get_current_song_length_frames, "returns current song length in frames"}, | |
47 {"current-song-output-length", get_current_song_output_length, "returns current song output length"}, | |
48 {"current-song-output-length-seconds", get_current_song_output_length_seconds, "returns current song output length in seconds"}, | |
49 {"current-song-output-length-frames", get_current_song_output_length_frames, "returns current song output length in frames"}, | |
50 {"current-song-bitrate", get_current_song_bitrate, "returns current song bitrate in bits per second"}, | |
51 {"current-song-bitrate-kbps", get_current_song_bitrate_kbps, "returns current song bitrate in kilobits per second"}, | |
52 {"current-song-frequency", get_current_song_frequency, "returns current song frequency in hertz"}, | |
53 {"current-song-frequency-khz", get_current_song_frequency_khz, "returns current song frequency in kilohertz"}, | |
54 {"current-song-channels", get_current_song_channels, "returns current song channels"}, | |
55 {"current-song-tuple-data", get_current_song_tuple_field_data, "returns the value of a tuple field for the current song"}, | |
56 {"<sep>", NULL, "Playlist manipulation"}, | |
57 {"playlist-advance", playlist_advance, "go to the next song in the playlist"}, | |
58 {"playlist-reverse", playlist_reverse, "go to the previous song in the playlist"}, | |
59 {"playlist-addurl", playlist_add_url_string, "adds a url to the playlist"}, | |
60 {"playlist-delete", playlist_delete, "deletes a song from the playlist"}, | |
61 {"playlist-length", playlist_length, "returns the total length of the playlist"}, | |
62 {"playlist-song", playlist_song, "returns the title of a song in the playlist"}, | |
63 {"playlist-song-filename", playlist_song_filename, "returns the filename of a song in the playlist"}, | |
64 {"playlist-song-length", playlist_song_length, "returns the length of a song in the playlist"}, | |
65 {"playlist-song-length-seconds", playlist_song_length_seconds, "returns the length of a song in the playlist in seconds"}, | |
66 {"playlist-song-length-frames", playlist_song_length_frames, "returns the length of a song in the playlist in frames"}, | |
67 {"playlist-display", playlist_display, "returns the entire playlist"}, | |
68 {"playlist-position", playlist_position, "returns the position in the playlist"}, | |
69 {"playlist-jump", playlist_jump, "jumps to a position in the playlist"}, | |
70 {"playlist-clear", playlist_clear, "clears the playlist"}, | |
71 {"playlist-repeat-status", playlist_repeat_status, "returns the status of playlist repeat"}, | |
72 {"playlist-repeat-toggle", playlist_repeat_toggle, "toggles playlist repeat"}, | |
73 {"playlist-shuffle-status", playlist_shuffle_status, "returns the status of playlist shuffle"}, | |
74 {"playlist-shuffle-toggle", playlist_shuffle_toggle, "toggles playlist shuffle"}, | |
75 {"playlist-tuple-data", playlist_tuple_field_data, "returns the value of a tuple field for a song in the playlist"}, | |
76 {"<sep>", NULL, "Playqueue manipulation"}, | |
77 {"playqueue-add", playqueue_add, "adds a song to the playqueue"}, | |
78 {"playqueue-remove", playqueue_remove, "removes a song from the playqueue"}, | |
79 {"playqueue-is-queued", playqueue_is_queued, "returns OK if a song is queued"}, | |
80 {"playqueue-get-position", playqueue_get_position, "returns the queue position of a song in the playlist"}, | |
81 {"playqueue-get-qposition", playqueue_get_qposition, "returns the playlist position of a song in the queue"}, | |
82 {"playqueue-length", playqueue_length, "returns the length of the playqueue"}, | |
83 {"playqueue-display", playqueue_display, "returns a list of currently-queued songs"}, | |
84 {"playqueue-clear", playqueue_clear, "clears the playqueue"}, | |
85 {"<sep>", NULL, "Playback manipulation"}, | |
86 {"playback-play", playback_play, "starts/unpauses song playback"}, | |
87 {"playback-pause", playback_pause, "(un)pauses song playback"}, | |
88 {"playback-playpause", playback_playpause, "plays/(un)pauses song playback"}, | |
89 {"playback-stop", playback_stop, "stops song playback"}, | |
90 {"playback-playing", playback_playing, "returns OK if audacious is playing"}, | |
91 {"playback-paused", playback_paused, "returns OK if audacious is paused"}, | |
92 {"playback-stopped", playback_stopped, "returns OK if audacious is stopped"}, | |
93 {"playback-status", playback_status, "returns the playback status"}, | |
94 {"playback-seek", playback_seek, "performs an absolute seek"}, | |
95 {"playback-seek-relative", playback_seek_relative, "performs a seek relative to the current position"}, | |
96 {"<sep>", NULL, "Volume control"}, | |
97 {"get-volume", get_volume, "returns the current volume level in percent"}, | |
98 {"set-volume", set_volume, "sets the current volume level in percent"}, | |
99 {"<sep>", NULL, "Miscellaneous"}, | |
100 {"mainwin-show", mainwin_show, "shows/hides the main window"}, | |
101 {"playlist-show", playlist_show, "shows/hides the playlist window"}, | |
102 {"equalizer-show", equalizer_show, "shows/hides the equalizer window"}, | |
103 {"preferences", show_preferences_window, "shows/hides the preferences window"}, | |
104 {"jumptofile", show_jtf_window, "shows the jump to file window"}, | |
105 {"shutdown", shutdown_audacious_server, "shuts down audacious"}, | |
106 {"<sep>", NULL, "Help system"}, | |
107 {"list-handlers", get_handlers_list, "shows handlers list"}, | |
108 {"help", get_handlers_list, "shows handlers list"}, | |
109 {NULL, NULL, NULL} | |
110 }; | |
111 | |
112 mowgli_error_context_t *e = NULL; | |
113 DBusGProxy *dbus_proxy = NULL; | |
114 static DBusGConnection *connection = NULL; | |
115 | |
116 static void audtool_connect(void) | |
117 { | |
118 GError *error = NULL; | |
119 | |
120 mowgli_error_context_push(e, "While attempting to connect to the D-Bus session bus"); | |
121 connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); | |
122 | |
123 if (connection == NULL) | |
124 mowgli_error_context_display_with_error(e, ":\n * ", g_strdup_printf("D-Bus Error: %s", error->message)); | |
125 | |
126 mowgli_error_context_pop(e); | |
127 | |
128 dbus_proxy = dbus_g_proxy_new_for_name(connection, AUDACIOUS_DBUS_SERVICE, | |
129 AUDACIOUS_DBUS_PATH, | |
130 AUDACIOUS_DBUS_INTERFACE); | |
131 } | |
132 | |
133 gint main(gint argc, gchar **argv) | |
134 { | |
135 gint i; | |
136 | |
137 setlocale(LC_CTYPE, ""); | |
138 g_type_init(); | |
139 mowgli_init(); | |
140 | |
141 e = mowgli_error_context_create(); | |
142 mowgli_error_context_push(e, "In program %s", argv[0]); | |
143 | |
144 audtool_connect(); | |
145 | |
146 mowgli_error_context_push(e, "While processing the commandline"); | |
147 | |
148 if (argc < 2) | |
149 mowgli_error_context_display_with_error(e, ":\n * ", "not enough parameters, use audtool --help for more information."); | |
150 | |
151 for (i = 0; handlers[i].name != NULL; i++) | |
152 { | |
153 if ((!g_strcasecmp(handlers[i].name, argv[1]) || | |
154 !g_strcasecmp(g_strconcat("--", handlers[i].name, NULL), argv[1])) | |
155 && g_strcasecmp("<sep>", handlers[i].name)) | |
156 { | |
157 handlers[i].handler(argc, argv); | |
158 exit(0); | |
159 } | |
160 } | |
161 | |
162 mowgli_error_context_display_with_error(e, ":\n * ", g_strdup_printf("Unknown command `%s' encountered, use audtool --help for a command list.", argv[1])); | |
163 | |
164 return 0; | |
165 } |