Skip to content

Commit

Permalink
Fixed a few things and added a few more bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamothe committed May 12, 2011
1 parent af3bc08 commit 7610edd
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 84 deletions.
36 changes: 8 additions & 28 deletions client/main_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void MainWindow::on_timeout()
}
catch(...)
{
on_exception();
handle_error();
}
}

Expand Down Expand Up @@ -439,6 +439,11 @@ void MainWindow::on_hide()
stop_broadcasting();
save_geometry();
Gtk::Window::on_hide();

if (quit_on_close)
{
signal_quit();
}
}

bool MainWindow::on_delete_event(GdkEventAny* event)
Expand Down Expand Up @@ -721,31 +726,6 @@ void MainWindow::on_fullscreen()
}
}

void MainWindow::show_error(const Glib::ustring& message)
{
set_status_text(message);
}

void MainWindow::on_exception()
{
try
{
throw;
}
catch (const Exception& exception)
{
show_error(exception.what());
}
catch (const Glib::Error& exception)
{
show_error(exception.what());
}
catch (...)
{
show_error("Unhandled exception");
}
}

void MainWindow::select_channel_to_play()
{
if (get_epg().empty())
Expand Down Expand Up @@ -793,9 +773,9 @@ void MainWindow::on_stop_broadcasting()
}
}

void MainWindow::on_error(const Glib::ustring& message)
void MainWindow::on_error(const String& message)
{
show_error(message);
set_status_text(message);
}

void MainWindow::set_offset(gint value)
Expand Down
3 changes: 0 additions & 3 deletions client/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,10 @@ class MainWindow : public Gtk::Window

static MainWindow* create(Glib::RefPtr<Gtk::Builder> builder);

void on_exception();

void show_channels_dialog();
void show_preferences_dialog();
void show_scheduled_recordings_dialog();
void show_epg_event_search_dialog();
void show_error(const Glib::ustring& message);
};

#endif
53 changes: 34 additions & 19 deletions client/me-tv-client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ static UniqueResponse on_message_received (
return response;
}

void on_error_gtk(const String& message)
{
Gtk::MessageDialog dialog(message);
dialog.set_title(PACKAGE_NAME);
dialog.run();
}

int main (int argc, char *argv[])
{
#ifdef ENABLE_NLS
Expand Down Expand Up @@ -87,9 +94,11 @@ int main (int argc, char *argv[])
Gtk::Main main(argc, argv);

Glib::add_exception_handler(&handle_error);
signal_error.connect(sigc::ptr_fun(&on_error_gtk));

gint server_port = 1999;
String server_host;
gboolean non_unique = false;

g_log_set_handler(G_LOG_DOMAIN,
(GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION),
Expand All @@ -98,21 +107,30 @@ int main (int argc, char *argv[])
Glib::OptionEntry verbose_option_entry;
verbose_option_entry.set_long_name("verbose");
verbose_option_entry.set_short_name('v');
verbose_option_entry.set_description(_("Enable verbose messages"));
verbose_option_entry.set_description(_("Enable verbose messages."));

Glib::OptionEntry safe_mode_option_entry;
safe_mode_option_entry.set_long_name("safe-mode");
safe_mode_option_entry.set_short_name('s');
safe_mode_option_entry.set_description(_("Start in safe mode"));
safe_mode_option_entry.set_description(_("Start in safe mode."));

Glib::OptionEntry minimised_option_entry;
minimised_option_entry.set_long_name("minimised");
minimised_option_entry.set_short_name('m');
minimised_option_entry.set_description(_("Start minimised in notification area"));
minimised_option_entry.set_description(_("Start minimised in notification area."));

Glib::OptionEntry non_unique_option_entry;
non_unique_option_entry.set_long_name("non-unique");
non_unique_option_entry.set_description(_("Don't check for existing instances of Me TV."));

Glib::OptionEntry quit_on_close_option_entry;
quit_on_close_option_entry.set_long_name("quit-on-close");
quit_on_close_option_entry.set_short_name('q');
quit_on_close_option_entry.set_description(_("Quit Me TV when the main window is closed."));

Glib::OptionEntry disable_epg_thread_option_entry;
disable_epg_thread_option_entry.set_long_name("disable-epg-thread");
disable_epg_thread_option_entry.set_description(_("Disable the EPG thread. Me TV will stop collecting EPG events."));
disable_epg_thread_option_entry.set_description(_("Disable the EPG thread."));

Glib::OptionEntry disable_epg_option_entry;
disable_epg_option_entry.set_long_name("disable-epg");
Expand All @@ -129,19 +147,19 @@ int main (int argc, char *argv[])

Glib::OptionEntry devices_option_entry;
devices_option_entry.set_long_name("devices");
devices_option_entry.set_description(_("Only use the specified frontend devices (e.g. --devices=/dev/dvb/adapter0/frontend0,/dev/dvb/adapter0/frontend1)"));
devices_option_entry.set_description(_("Only use the specified frontend devices. (e.g. --devices=/dev/dvb/adapter0/frontend0,/dev/dvb/adapter0/frontend1)"));

Glib::OptionEntry host_option_entry;
host_option_entry.set_long_name("server-host");
host_option_entry.set_description(_("Me TV server host (default: localhost)"));
host_option_entry.set_description(_("Me TV server host. (default: localhost)"));

Glib::OptionEntry port_option_entry;
port_option_entry.set_long_name("server-port");
port_option_entry.set_description(_("Me TV server port (default: 1999)"));
port_option_entry.set_description(_("Me TV server port. (default: 1999)"));

Glib::OptionEntry read_timeout_option_entry;
read_timeout_option_entry.set_long_name("read-timeout");
read_timeout_option_entry.set_description(_("How long to wait (in seconds) before timing out while waiting for data from demuxer (default 5)."));
read_timeout_option_entry.set_description(_("How long to wait (in seconds) before timing out while waiting for data from demuxer. (default 5)"));

Glib::OptionGroup option_group(PACKAGE_NAME, "", _("Show Me TV help options"));
option_group.add_entry(verbose_option_entry, verbose_logging);
Expand All @@ -155,6 +173,8 @@ int main (int argc, char *argv[])
option_group.add_entry(host_option_entry, server_host);
option_group.add_entry(port_option_entry, server_port);
option_group.add_entry(engine_option_entry, engine_type);
option_group.add_entry(non_unique_option_entry, non_unique);
option_group.add_entry(quit_on_close_option_entry, quit_on_close);

Glib::OptionContext option_context;
option_context.set_summary(ME_TV_SUMMARY);
Expand All @@ -170,7 +190,7 @@ int main (int argc, char *argv[])
"run", (UniqueCommand)1,
(char*)NULL);

if (unique_app_is_running(unique_application))
if (unique_app_is_running(unique_application) && !non_unique)
{
g_debug("Me TV is already running");

Expand Down Expand Up @@ -262,10 +282,10 @@ int main (int argc, char *argv[])
network_server_thread = new NetworkServerThread (server_port);
network_server_thread->start();
}

gboolean registered = client.register_client(server_host, server_port);

if (!registered)
client.register_client(server_host, server_port);

if (!client.is_registered())
{
if (network_server_thread == NULL && (server_host == "localhost" || server_host == "127.0.0.1"))
{
Expand All @@ -278,7 +298,7 @@ int main (int argc, char *argv[])
start_server(server_host);

int wait_time = 0;
while (wait_time++ < 5 && !client.is_registered())
while (wait_time++ < 10 && !client.is_registered())
{
sleep(1);

Expand All @@ -293,16 +313,11 @@ int main (int argc, char *argv[])
handle_error();
}
}

if (!client.is_registered())
{
signal_error("Failed to register with Me TV Server");
}
}
}
}

if (!registered)
if (!client.is_registered())
{
throw Exception("Failed to communicate with Me TV server");
}
Expand Down
1 change: 1 addition & 0 deletions client/me-tv-ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "../common/exception.h"

Glib::RefPtr<Gtk::UIManager> ui_manager;
bool quit_on_close;

ComboBoxText::ComboBoxText(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml)
: Gtk::ComboBox(cobject)
Expand Down
1 change: 1 addition & 0 deletions client/me-tv-ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "me-tv.h"

extern Glib::RefPtr<Gtk::UIManager> ui_manager;
extern bool quit_on_close;

// This class exists because I can't get Gtk::ComboBoxText to work properly
// it seems to have 2 columns
Expand Down
41 changes: 25 additions & 16 deletions common/epg_events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
#include "epg_events.h"
#include "data.h"
#include "global.h"
#include "../common/common.h"
#include "../common/exception.h"

void EpgEvents::add_epg_event(const EpgEvent& epg_event)
void EpgEvents::add_epg_event(Glib::RefPtr<Batch>& batch, const EpgEvent& epg_event)
{
Glib::RefPtr<SqlBuilder> builder = SqlBuilder::create(SQL_STATEMENT_INSERT);

Expand All @@ -37,26 +38,34 @@ void EpgEvents::add_epg_event(const EpgEvent& epg_event)

g_debug("Adding EPG event (%d,%d)", epg_event.channel_id, epg_event.event_id);

Glib::RefPtr<const Set> parameters = Set::create();
Glib::RefPtr<const Set> set_epg_event_id = Set::create();
data_connection->statement_execute_non_select(builder->get_statement(), parameters, set_epg_event_id);

int epg_event_id = set_epg_event_id->get_holder_value("+0").get_int();
batch->add_statement(builder->get_statement());

Glib::RefPtr<SqlParser> parser = SqlParser::create();

for (EpgEventTextList::const_iterator i = epg_event.texts.begin(); i != epg_event.texts.end(); i++)
{
const EpgEventText epg_event_text = *i;
Glib::RefPtr<SqlBuilder> builder_text = SqlBuilder::create(SQL_STATEMENT_INSERT);

g_debug("Adding text (%d,'%s')", epg_event_id, epg_event_text.title.c_str());
builder_text->set_table("epg_event_text");
builder_text->add_field_value("epg_event_id", epg_event_id);
builder_text->add_field_value("language", epg_event_text.language);
builder_text->add_field_value("title", epg_event_text.title);
builder_text->add_field_value("subtitle", epg_event_text.subtitle);
builder_text->add_field_value("description", epg_event_text.description);

data_connection->statement_execute_non_select_builder(builder_text);
g_debug("Adding text (%d,'%s')", epg_event.event_id, epg_event_text.title.c_str());

String title = epg_event_text.title;
String subtitle = epg_event_text.subtitle;
String description = epg_event_text.description;

replace_text(title, "'", "''");
replace_text(subtitle, "'", "''");
replace_text(description, "'", "''");

Glib::RefPtr<Statement> statement = parser->parse_string(
String::compose(
"insert into epg_event_text ("
"epg_event_id, language, title, subtitle, description"
") values ("
"(select id from epg_event where channel_id = %1 and event_id = %2), '%3', '%4', '%5', '%6');",
epg_event.channel_id, epg_event.event_id,
epg_event_text.language, title, subtitle, description
));
batch->add_statement(statement);
}
}

Expand Down
2 changes: 1 addition & 1 deletion common/epg_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ typedef std::list<EpgEvent> EpgEventList;
class EpgEvents
{
public:
static void add_epg_event(const EpgEvent& epg_event);
static void add_epg_event(Glib::RefPtr<Batch>& batch, const EpgEvent& epg_event);
static void update_epg_event(const EpgEvent& epg_event);
static gboolean get_current(guint channe_id, EpgEvent& epg_event);
static EpgEventList get_all(time_t start_time = 0, time_t end_time = -1);
Expand Down
Loading

0 comments on commit 7610edd

Please sign in to comment.