141 lines
4.3 KiB
Vala
141 lines
4.3 KiB
Vala
/*
|
|
* pdf-presenter - advanced pdf presentation util
|
|
*
|
|
* Copyright (C) 2009-2012 Sebastian Reichel <sre@ring0.de>
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*/
|
|
|
|
/* Global Stuff */
|
|
Monitor monitor;
|
|
Config config;
|
|
ControlWindow control_window;
|
|
PresentationWindow presentation_window;
|
|
|
|
namespace Option {
|
|
static string[] files;
|
|
static bool version;
|
|
static string presentation_monitor;
|
|
static string control_monitor;
|
|
}
|
|
|
|
const OptionEntry[] option_entries = {
|
|
{ "version", 'v', OptionFlags.IN_MAIN, OptionArg.NONE, ref Option.version, "output version information and exit", null },
|
|
{ "presentation-monitor", 'p', OptionFlags.IN_MAIN, OptionArg.STRING, ref Option.presentation_monitor, "monitor used for the presentation", null },
|
|
{ "control-monitor", 'c', OptionFlags.IN_MAIN, OptionArg.STRING, ref Option.control_monitor, "monitor used for the controller", null },
|
|
{ "", 0, 0, OptionArg.FILENAME_ARRAY, ref Option.files, "input project file", "FILE" },
|
|
{null}
|
|
};
|
|
|
|
void version(string name) {
|
|
stdout.printf("%s - 0.1\n", name);
|
|
}
|
|
|
|
int main(string[] args) {
|
|
Poppler.Document document = null;
|
|
Gtk.init(ref args);
|
|
|
|
/* init global objects */
|
|
config = new Config();
|
|
monitor = new Monitor();
|
|
|
|
config.presentation_monitor = "VGA1";
|
|
config.control_monitor = "LVDS1";
|
|
|
|
/* parse parameters from shell */
|
|
var context = new OptionContext("- PDF Presenter");
|
|
context.set_help_enabled(true);
|
|
context.add_main_entries(option_entries, "pdf-presenter");
|
|
context.add_group(Gtk.get_option_group(true));
|
|
|
|
try {
|
|
context.parse(ref args);
|
|
} catch(OptionError e) {
|
|
stderr.puts(e.message + "\n");
|
|
return 1;
|
|
}
|
|
|
|
if(Option.version) {
|
|
version(args[0]);
|
|
return 0;
|
|
}
|
|
|
|
if(Option.files == null) {
|
|
stdout.printf(context.get_help(true, null));
|
|
return 1;
|
|
}
|
|
|
|
if(Option.presentation_monitor != null)
|
|
config.presentation_monitor = Option.presentation_monitor;
|
|
|
|
if(Option.control_monitor != null)
|
|
config.control_monitor = Option.control_monitor;
|
|
|
|
var file = File.new_for_commandline_arg(Option.files[0]);
|
|
|
|
try {
|
|
document = new Poppler.Document.from_file(file.get_uri(), "");
|
|
} catch(GLib.ConvertError e) {
|
|
new ErrorDialog("This is not a correct filename", "Please specify a valid filename.");
|
|
Gtk.main();
|
|
return 1;
|
|
} catch(GLib.Error e) {
|
|
new ErrorDialog("File not found", e.message);
|
|
Gtk.main();
|
|
return 1;
|
|
}
|
|
|
|
control_window = new ControlWindow(document);
|
|
control_window.show_all();
|
|
|
|
presentation_window = new PresentationWindow(document, 0);
|
|
control_window.page_changed.connect((n) => {presentation_window.set_page(n);});
|
|
|
|
config.configuration_changed.connect(update_monitor_configuration);
|
|
monitor.connected.connect((s) => {update_monitor_configuration();});
|
|
monitor.disconnected.connect((s) => {update_monitor_configuration();});
|
|
|
|
update_monitor_configuration();
|
|
|
|
Gtk.main();
|
|
return 0;
|
|
}
|
|
|
|
void update_monitor_configuration() {
|
|
int x,y,w,h;
|
|
|
|
if(monitor.get_size(config.presentation_monitor, out x, out y, out w, out h)) {
|
|
presentation_window.fullscreen();
|
|
presentation_window.show_all();
|
|
presentation_window.move(x,y);
|
|
} else {
|
|
presentation_window.hide();
|
|
}
|
|
|
|
if(config.control_fullscreen)
|
|
control_window.fullscreen();
|
|
else
|
|
control_window.unfullscreen();
|
|
|
|
if(monitor.get_size(config.control_monitor, out x, out y, out w, out h)) {
|
|
control_window.show_all();
|
|
control_window.move(x,y);
|
|
}
|
|
}
|