コード例 #1
0
ファイル: main_window.cpp プロジェクト: dxq-git/flush
void Main_window::save_settings(void)
{
	// Получаем текущие настройки -->
		if(this->gui->has_been_showed)
		{
			// Получаем настройки от GUI только в том случае, если окно было
			// отображено хотя бы один раз.
			//
			// Если окно ни разу не отображалось, то мы, скорее всего, получим
			// от GTK неверные значения.
			//
			// То, что мы отвергаем все настройки GUI - на самом деле не
			// страшно, как может показаться на первый взгляд, т. к. если окно
			// не было ни разу отображено, то и, соответсвенно, пользователь не
			// мог изменить какие-либо настройки.

			Main_window_settings& settings = get_client_settings().gui.main_window;

			m::gtk::Window::save_settings(settings.window);
			this->gui->torrents_viewport->save_settings(settings.torrents_viewport);
		}
	// Получаем текущие настройки <--

	// Записываем настройки в конфиг
	get_application().save_settings();
}
コード例 #2
0
ファイル: main_window.cpp プロジェクト: dxq-git/flush
bool Main_window::on_close_callback(GdkEventAny* event)
{
	if(!get_client_settings().gui.show_tray_icon || !get_client_settings().gui.close_to_tray)
		get_application().close();

	return false;
}
コード例 #3
0
ファイル: main_window.cpp プロジェクト: dxq-git/flush
void Main_window::open_torrent(const std::string& torrent_uri, const std::string& torrent_encoding)
{
	Client_settings& client_settings = get_client_settings();

	try
	{
		if(client_settings.gui.show_add_torrent_dialog)
		{
			m::gtk::Builder builder = MLIB_GTK_BUILDER_CREATE(
				m::fs::Path(APP_UI_PATH) / "dialog.add_torrent.glade", "add_torrent_dialog");

			Add_torrent_dialog* dialog;
			MLIB_GTK_BUILDER_GET_WIDGET_DERIVED(builder, "add_torrent_dialog", dialog);

			// Генерирует m::Exception
			dialog->process(*this, torrent_uri, torrent_encoding);
		}
		else
		{
			New_torrent_settings new_torrent_settings(
				client_settings.user.start_torrent_on_adding,
				client_settings.user.download_to,
				client_settings.user.copy_finished_to,
				torrent_encoding
			);

			get_application().add_torrent(torrent_uri, new_torrent_settings);
		}
	}
	catch(m::Exception& e)
	{
		MLIB_W(_("Opening torrent failed"), __("Opening torrent '%1' failed. %2", torrent_uri, EE(e)));
	}
}
コード例 #4
0
ファイル: main_window.cpp プロジェクト: dxq-git/flush
void Main_window::on_show_settings_window_callback(void)
{
	Daemon_settings daemon_settings;
	Client_settings& client_settings = get_client_settings();

	int gui_update_interval = client_settings.gui.update_interval;
	int max_log_lines = client_settings.gui.max_log_lines;

	// Получаем настройки демона -->
		try
		{
			daemon_settings = get_daemon_proxy().get_settings();
		}
		catch(m::Exception& e)
		{
			MLIB_W(EE(e));
			return;
		}
	// Получаем настройки демона <--

	Settings_window settings_window(*this, &client_settings, &daemon_settings);

	if(settings_window.run() == Gtk::RESPONSE_OK)
	{
		Gui_settings& gui = client_settings.gui;

		// Чтобы потом можно было не обновлять каждый раз заголовок, содержимое
		// которого будет постоянным.
		if(!gui.show_speed_in_window_title)
			Gtk::Window::set_title(this->gui->orig_window_title);

		this->show_tray_icon(gui.show_tray_icon);

		if(gui_update_interval != gui.update_interval)
			this->set_gui_update_interval(gui.update_interval);

		if(max_log_lines != gui.max_log_lines)
			this->gui->torrents_viewport->get_log_view().set_max_lines(gui.max_log_lines);

		/// Включаем или отключаем поддержку оповещений через libnotify
		get_application().update_notifications_support();

		try
		{
			get_daemon_proxy().set_settings(daemon_settings);
		}
		catch(m::Exception& e)
		{
			MLIB_W(EE(e));
		}

		// Обновляем GUI - возможно настройки повлияли на его внешний вид,
		// поэтому будет лучше, если пользователь сразу же увидит изменения.
		this->update_gui();

		// Сохраняем настройки клиента
		this->save_settings();
	}
}
コード例 #5
0
/* ------------------------- member functions (launcher_application) */
gboolean launcher_application_execute(struct launcher *launcher,
                                      const char *name,
                                      const char *long_name,
                                      const char *uri,
                                      GError **err)
{
        char *exec = NULL;
        gboolean retval = FALSE;
        gboolean terminal = FALSE;

        g_return_val_if_fail(launcher!=NULL, FALSE);
        g_return_val_if_fail(launcher==&launcher_application, FALSE);
        g_return_val_if_fail(name!=NULL, FALSE);
        g_return_val_if_fail(long_name!=NULL, FALSE);
        g_return_val_if_fail(uri!=NULL, FALSE);
        g_return_val_if_fail(err==NULL || *err==NULL, FALSE);


        printf("%s:%d: launching application %s using %s...\n", __FILE__, __LINE__, name, uri);

        if(get_application(uri, &exec, &terminal, err)) {
                int pid;

                printf("%s:%d: execute: '%s' (in terminal=%c)\n",
                       __FILE__,
                       __LINE__,
                       exec,
                       terminal ? 'y':'n');
                errno=0;
                if(terminal)
                        pid=gnome_execute_terminal_shell(NULL, exec);
                else
                        pid=gnome_execute_shell(NULL, exec);
                if(pid==-1) {
                        g_set_error(err,
                                    LAUNCHER_ERROR,
                                    LAUNCHER_EXTERNAL_ERROR,
                                    "launching '%s' failed: %s",
                                    exec,
                                    errno!=0 ? strerror(errno):"unknown error");
                } else {
                        printf("%s:%d: executed '%s' with PID %d\n",
                               __FILE__,
                               __LINE__,
                               exec,
                               pid);
                        retval=TRUE;
                }
        }

        if(exec) {
                g_free(exec);
        }
        g_assert(retval || err==NULL || *err!=NULL);
        return retval;
}
コード例 #6
0
ファイル: rpc.cpp プロジェクト: BackupGGCode/ewlibs
// FIXME: move the application class to core
//
void get_buffer_id_list(eedit::core::rpc_call *request, int ac,  char * av[])
{
	app_log << __PRETTY_FUNCTION__ << "\n";

	auto app = get_application();

	auto & list = app->buffer_desc_lst();

	char * ans_av[1 + list.size()];
	int i  = 1;
	ans_av[0] = ew::utils::c_string_dup("get_buffer_id_list");
	for (auto & ebid : list) {
		char buffer[32];
		snprintf(buffer,  sizeof (buffer),  "%lu", (uint64_t)ebid);
		ans_av[i] = ew::utils::c_string_dup(buffer);
		++i;
	}
	rpc_answer * rpc_ans = new rpc_answer(request, i, (const char **)ans_av);
	send_rpc_answer(request, rpc_ans);
}
コード例 #7
0
ファイル: main_window.cpp プロジェクト: dxq-git/flush
Main_window::Main_window(const Main_window_settings& settings)
:
	m::gtk::Window("", settings.window, 800, 600, 0),
	gui(new Gui)
{
	Client_settings& client_settings = get_client_settings();
	Main_window_settings& main_window_settings = client_settings.gui.main_window;

	// Заголовок окна -->
		this->gui->orig_window_title = APP_NAME;

		if(get_application().get_config_dir_path() != get_default_config_dir_path())
			this->gui->orig_window_title = " (" + get_application().get_config_dir_path() + ")";

		Gtk::Window::set_title(this->gui->orig_window_title);
	// Заголовок окна <--

	// Трей
	show_tray_icon(client_settings.gui.show_tray_icon);

	// Меню -->
		this->gui->ui_manager = Gtk::UIManager::create();
		Glib::RefPtr<Gtk::ActionGroup> action_group = Gtk::ActionGroup::create();


		action_group->add(
			app_icons::create_action("app", app_icons::ICON_APP, APP_NAME),
			sigc::mem_fun(*this, &Main_window::on_tray_activated)
		);


		action_group->add(Gtk::Action::create("file", _("_File")));
		action_group->add(
			Gtk::Action::create("create", Gtk::Stock::NEW, _("_Create")),
			sigc::mem_fun(*this, &Main_window::on_create_callback)
		);
		action_group->add(
			Gtk::Action::create("open", Gtk::Stock::OPEN, _("_Open a torrent")),
			sigc::mem_fun(*this, &Main_window::on_open_callback)
		);
		action_group->add(
			Gtk::Action::create("open_magnet", Gtk::Stock::JUMP_TO, _("_Open a magnet link")),
			sigc::mem_fun(*this, &Main_window::on_open_magnet_callback)
		);
		action_group->add(
			Gtk::Action::create("quit", Gtk::Stock::QUIT, _("_Quit")),
			sigc::mem_fun(get_application(), &Application::close
		));


		action_group->add(Gtk::Action::create("edit", _("_Edit")));
		action_group->add(
			app_icons::create_action("statistics", app_icons::ICON_STATISTICS, _("_Statistics")),
			sigc::mem_fun(*this, &Main_window::on_show_statistics_callback)
		);
		action_group->add(
			Gtk::Action::create("preferences", Gtk::Stock::PREFERENCES, _("_Preferences")),
			sigc::mem_fun(*this, &Main_window::on_show_settings_window_callback)
		);


		action_group->add(Gtk::Action::create("view", _("_View")));

		// Toolbar -->
			action_group->add(Gtk::Action::create("toolbar", _("_Toolbar")));

			this->gui->menu_show_toolbar_action = Gtk::ToggleAction::create(
				"toolbar/show", _Q("'Show ...' toggle|_Show"), "",
				get_client_settings().gui.show_toolbar
			);
			action_group->add(
				this->gui->menu_show_toolbar_action,
				sigc::mem_fun(*this, &Main_window::on_show_toolbar_toggled_callback)
			);

			// Стиль панели инструментов -->
			{
				Gtk::RadioButtonGroup radio_group;
				std::map< m::gtk::toolbar::Style, Glib::RefPtr<Gtk::RadioAction> > toolbar_style_buttons;

				action_group->add(Gtk::Action::create("toolbar/style", _("Toolbar _style")));

				action_group->add(
					toolbar_style_buttons[m::gtk::toolbar::DEFAULT] = Gtk::RadioAction::create(
						radio_group, "toolbar/style/default", _("_Desktop default")
					),
					sigc::bind<m::gtk::toolbar::Style>(
						sigc::mem_fun(*this, &Main_window::change_toolbar_style),
						m::gtk::toolbar::DEFAULT
					)
				);

				action_group->add(
					toolbar_style_buttons[m::gtk::toolbar::ICONS] = Gtk::RadioAction::create(
						radio_group, "toolbar/style/icons", _("_Icons")
					),
					sigc::bind<m::gtk::toolbar::Style>(
						sigc::mem_fun(*this, &Main_window::change_toolbar_style),
						m::gtk::toolbar::ICONS
					)
				);

				action_group->add(
					toolbar_style_buttons[m::gtk::toolbar::TEXT] = Gtk::RadioAction::create(
						radio_group, "toolbar/style/text", _("_Text")
					),
					sigc::bind<m::gtk::toolbar::Style>(
						sigc::mem_fun(*this, &Main_window::change_toolbar_style),
						m::gtk::toolbar::TEXT
					)
				);

				action_group->add(
					toolbar_style_buttons[m::gtk::toolbar::BOTH] = Gtk::RadioAction::create(
						radio_group, "toolbar/style/both", _("_Both")
					),
					sigc::bind<m::gtk::toolbar::Style>(
						sigc::mem_fun(*this, &Main_window::change_toolbar_style),
						m::gtk::toolbar::BOTH
					)
				);

				action_group->add(
					toolbar_style_buttons[m::gtk::toolbar::BOTH_HORIZ] = Gtk::RadioAction::create(
						radio_group, "toolbar/style/both_horiz", _("Both _horizontal")
					),
					sigc::bind<m::gtk::toolbar::Style>(
						sigc::mem_fun(*this, &Main_window::change_toolbar_style),
						m::gtk::toolbar::BOTH_HORIZ
					)
				);

				toolbar_style_buttons[get_client_settings().gui.toolbar_style]->set_active();
			}
			// Стиль панели инструментов <--
		// Toolbar <--

		// Categories <--
		{
			Glib::RefPtr<Gtk::ToggleAction> action;

			action_group->add(Gtk::Action::create("categories", _("_Categories")));

			action = Gtk::ToggleAction::create(
				"categories/show", _Q("'Show ...' toggle|_Show"), "",
				get_client_settings().gui.main_window.torrents_viewport.categories_view->visible
			);
			action_group->add(
				action,
				sigc::bind< Glib::RefPtr<Gtk::ToggleAction> >(
					sigc::mem_fun(*this->gui, &Main_window::Gui::on_show_categories_toggle_cb), action)
			);

			action = Gtk::ToggleAction::create(
				"categories/show_names", _("Show _names"), "",
				get_client_settings().gui.main_window.torrents_viewport.categories_view->show_names
			);
			action_group->add(
				action,
				sigc::bind< Glib::RefPtr<Gtk::ToggleAction> >(
					sigc::mem_fun(*this->gui, &Main_window::Gui::on_show_categories_names_toggle_cb), action)
			);

			action = Gtk::ToggleAction::create(
				"categories/show_counters", _("Show _counters"), "",
				get_client_settings().gui.main_window.torrents_viewport.categories_view->show_counters
			);
			action_group->add(
				action,
				sigc::bind< Glib::RefPtr<Gtk::ToggleAction> >(
					sigc::mem_fun(*this->gui, &Main_window::Gui::on_show_categories_counters_toggle_cb), action)
			);
		}
		// Categories <--

		// Torrents -->
			action_group->add(Gtk::Action::create("torrents", _("_Torrents")));


			action_group->add(Gtk::Action::create("resume", Gtk::Stock::MEDIA_PLAY, _("_Resume")));
			action_group->add(
				app_icons::create_action("resume/all", app_icons::ICON_DOWNLOAD_AND_UPLOAD, _("_All")),
				sigc::bind<Torrents_group>(
					sigc::mem_fun(*this, &Main_window::on_resume_torrents_callback),
					ALL
				)
			);
			action_group->add(
				app_icons::create_action("resume/downloads", app_icons::ICON_DOWNLOAD, _("_Downloads")),
				sigc::bind<Torrents_group>(
					sigc::mem_fun(*this, &Main_window::on_resume_torrents_callback),
					DOWNLOADS
				)
			);
			action_group->add(
				app_icons::create_action("resume/uploads", app_icons::ICON_UPLOAD, _("_Uploads")),
				sigc::bind<Torrents_group>(
					sigc::mem_fun(*this, &Main_window::on_resume_torrents_callback),
					UPLOADS
				)
			);


			action_group->add(Gtk::Action::create("pause", Gtk::Stock::MEDIA_PAUSE, _("_Pause")));
			action_group->add(
				app_icons::create_action("pause/all", app_icons::ICON_DOWNLOAD_AND_UPLOAD, _("_All")),
				sigc::bind<Torrents_group>(
					sigc::mem_fun(*this, &Main_window::on_pause_torrents_callback),
					ALL
				)
			);
			action_group->add(
				app_icons::create_action("pause/downloads", app_icons::ICON_DOWNLOAD, _("_Downloads")),
				sigc::bind<Torrents_group>(
					sigc::mem_fun(*this, &Main_window::on_pause_torrents_callback),
					DOWNLOADS
				)
			);
			action_group->add(
				app_icons::create_action("pause/uploads", app_icons::ICON_UPLOAD, _("_Uploads")),
				sigc::bind<Torrents_group>(
					sigc::mem_fun(*this, &Main_window::on_pause_torrents_callback),
					UPLOADS
				)
			);


			// Temporary -->
				gui->resume_temporary = Gtk::Action::create(
					"resume_temporary", Gtk::Stock::MEDIA_PLAY, _("R_esume temporary"));
				action_group->add(gui->resume_temporary);

				action_group->add(
					app_icons::create_action("resume_temporary/all", app_icons::ICON_DOWNLOAD_AND_UPLOAD, _("_All")),
					sigc::bind< std::pair<Temporary_action,Torrents_group> >(
						sigc::mem_fun(*this, &Main_window::on_temporary_process_torrents_cb),
						std::pair<Temporary_action,Torrents_group>( TEMPORARY_ACTION_RESUME, ALL )
					)
				);
				action_group->add(
					app_icons::create_action("resume_temporary/downloads", app_icons::ICON_DOWNLOAD, _("_Downloads")),
					sigc::bind< std::pair<Temporary_action,Torrents_group> >(
						sigc::mem_fun(*this, &Main_window::on_temporary_process_torrents_cb),
						std::pair<Temporary_action,Torrents_group>( TEMPORARY_ACTION_RESUME, DOWNLOADS )
					)
				);
				action_group->add(
					app_icons::create_action("resume_temporary/uploads", app_icons::ICON_UPLOAD, _("_Uploads")),
					sigc::bind< std::pair<Temporary_action,Torrents_group> >(
						sigc::mem_fun(*this, &Main_window::on_temporary_process_torrents_cb),
						std::pair<Temporary_action,Torrents_group>( TEMPORARY_ACTION_RESUME, UPLOADS )
					)
				);


				gui->pause_temporary = Gtk::Action::create(
					"pause_temporary", Gtk::Stock::MEDIA_PAUSE, _("P_ause temporary"));
				action_group->add(gui->pause_temporary);

				action_group->add(
					app_icons::create_action("pause_temporary/all", app_icons::ICON_DOWNLOAD_AND_UPLOAD, _("_All")),
					sigc::bind< std::pair<Temporary_action,Torrents_group> >(
						sigc::mem_fun(*this, &Main_window::on_temporary_process_torrents_cb),
						std::pair<Temporary_action,Torrents_group>( TEMPORARY_ACTION_PAUSE, ALL )
					)
				);
				action_group->add(
					app_icons::create_action("pause_temporary/downloads", app_icons::ICON_DOWNLOAD, _("_Downloads")),
					sigc::bind< std::pair<Temporary_action,Torrents_group> >(
						sigc::mem_fun(*this, &Main_window::on_temporary_process_torrents_cb),
						std::pair<Temporary_action,Torrents_group>( TEMPORARY_ACTION_PAUSE, DOWNLOADS )
					)
				);
				action_group->add(
					app_icons::create_action("pause_temporary/uploads", app_icons::ICON_UPLOAD, _("_Uploads")),
					sigc::bind< std::pair<Temporary_action,Torrents_group> >(
						sigc::mem_fun(*this, &Main_window::on_temporary_process_torrents_cb),
						std::pair<Temporary_action,Torrents_group>( TEMPORARY_ACTION_PAUSE, UPLOADS )
					)
				);

				gui->complete_temporary_action = Gtk::Action::create(
					"complete_temporary_action", Gtk::Stock::APPLY, _("C_omplete pending temporary action"));
				action_group->add(
					gui->complete_temporary_action,
					sigc::bind<bool>( sigc::mem_fun(*this, &Main_window::on_interrupt_temporary_action_cb), true )
				);

				gui->cancel_temporary_action = Gtk::Action::create(
					"cancel_temporary_action", Gtk::Stock::STOP, _("_Cancel pending temporary action"));
				action_group->add(
					gui->cancel_temporary_action,
					sigc::bind<bool>( sigc::mem_fun(*this, &Main_window::on_interrupt_temporary_action_cb), false )
				);
			// Temporary <--
		// Torrents <--


		action_group->add(
			app_icons::create_action("set_upload_rate_limit", app_icons::ICON_UPLOAD, _("Set _upload rate limit")),
			sigc::bind<Traffic_type>(
				sigc::mem_fun(*this, &Main_window::on_change_rate_limit_callback),
				UPLOAD
			)
		);
		action_group->add(
			app_icons::create_action("set_download_rate_limit",
				app_icons::ICON_DOWNLOAD, _("Set _download rate limit")),
			sigc::bind<Traffic_type>(
				sigc::mem_fun(*this, &Main_window::on_change_rate_limit_callback),
				DOWNLOAD
			)
		);


		action_group->add(Gtk::Action::create("help", _("_Help")));
		action_group->add(
			Gtk::Action::create("about", Gtk::Stock::ABOUT, _("_About")),
			sigc::mem_fun(*this, &Main_window::on_show_about_dialog_callback)
		);

		this->gui->ui_manager->insert_action_group(action_group);

		Glib::ustring ui_info =
			"<ui>"
			"	<menubar name='menu_bar'>"

			"		<menu action='file'>"
			"			<menuitem action='create'/>"
			"			<menuitem action='open'/>"
			"			<menuitem action='open_magnet'/>"
			"			<menuitem action='quit'/>"
			"		</menu>"

			"		<menu action='edit'>"
			"			<menuitem action='statistics'/>"
			"			<menuitem action='preferences'/>"
			"		</menu>"

			"		<menu action='view'>"
			"			<menu action='toolbar'>"
			"				<menuitem action='toolbar/show'/>"
			"				<menu action='toolbar/style'>"
			"					<menuitem action='toolbar/style/default'/>"
			"					<menuitem action='toolbar/style/icons'/>"
			"					<menuitem action='toolbar/style/text'/>"
			"					<menuitem action='toolbar/style/both'/>"
			"					<menuitem action='toolbar/style/both_horiz'/>"
			"				</menu>"
			"			</menu>"
			"			<menu action='categories'>"
			"				<menuitem action='categories/show'/>"
			"				<menuitem action='categories/show_names'/>"
			"				<menuitem action='categories/show_counters'/>"
			"			</menu>"
			"		</menu>"

			"		<menu action='torrents'>"

			"			<menu action='resume'>"
			"				<menuitem action='resume/all'/>"
			"				<menuitem action='resume/uploads'/>"
			"				<menuitem action='resume/downloads'/>"
			"			</menu>"
			"			<menu action='pause'>"
			"				<menuitem action='pause/all'/>"
			"				<menuitem action='pause/uploads'/>"
			"				<menuitem action='pause/downloads'/>"
			"			</menu>"

			"			<separator/>"

			"			<menu action='resume_temporary'>"
			"				<menuitem action='resume_temporary/all'/>"
			"				<menuitem action='resume_temporary/uploads'/>"
			"				<menuitem action='resume_temporary/downloads'/>"
			"			</menu>"
			"			<menu action='pause_temporary'>"
			"				<menuitem action='pause_temporary/all'/>"
			"				<menuitem action='pause_temporary/uploads'/>"
			"				<menuitem action='pause_temporary/downloads'/>"
			"			</menu>"
			"			<menuitem action='complete_temporary_action'/>"
			"			<menuitem action='cancel_temporary_action'/>"

			"		</menu>"

			"		<menu action='help'>"
			"			<menuitem action='about'/>"
			"		</menu>"

			"	</menubar>"


			"	<popup name='appindicator'>"
			"		<menuitem action='app'/>"

			"		<separator/>"

			"		<menuitem action='open'/>"
			"		<menuitem action='open_magnet'/>"

			"		<separator/>"

			"		<menu action='resume'>"
			"			<menuitem action='resume/all'/>"
			"			<menuitem action='resume/uploads'/>"
			"			<menuitem action='resume/downloads'/>"
			"		</menu>"
			"		<menu action='pause'>"
			"			<menuitem action='pause/all'/>"
			"			<menuitem action='pause/uploads'/>"
			"			<menuitem action='pause/downloads'/>"
			"		</menu>"

			"		<separator/>"

			"		<menu action='resume_temporary'>"
			"			<menuitem action='resume_temporary/all'/>"
			"			<menuitem action='resume_temporary/uploads'/>"
			"			<menuitem action='resume_temporary/downloads'/>"
			"		</menu>"
			"		<menu action='pause_temporary'>"
			"			<menuitem action='pause_temporary/all'/>"
			"			<menuitem action='pause_temporary/uploads'/>"
			"			<menuitem action='pause_temporary/downloads'/>"
			"		</menu>"
			"		<menuitem action='complete_temporary_action'/>"
			"		<menuitem action='cancel_temporary_action'/>"

			"		<separator/>"

			"		<menuitem action='set_upload_rate_limit'/>"
			"		<menuitem action='set_download_rate_limit'/>"

			"		<separator/>"

			"		<menuitem action='quit'/>"
			"	</popup>"


			"	<popup name='tray_popup_menu'>"
			"		<menuitem action='open'/>"
			"		<menuitem action='open_magnet'/>"

			"		<separator/>"

			"		<menu action='resume'>"
			"			<menuitem action='resume/all'/>"
			"			<menuitem action='resume/uploads'/>"
			"			<menuitem action='resume/downloads'/>"
			"		</menu>"
			"		<menu action='pause'>"
			"			<menuitem action='pause/all'/>"
			"			<menuitem action='pause/uploads'/>"
			"			<menuitem action='pause/downloads'/>"
			"		</menu>"

			"		<separator/>"

			"		<menu action='resume_temporary'>"
			"			<menuitem action='resume_temporary/all'/>"
			"			<menuitem action='resume_temporary/uploads'/>"
			"			<menuitem action='resume_temporary/downloads'/>"
			"		</menu>"
			"		<menu action='pause_temporary'>"
			"			<menuitem action='pause_temporary/all'/>"
			"			<menuitem action='pause_temporary/uploads'/>"
			"			<menuitem action='pause_temporary/downloads'/>"
			"		</menu>"
			"		<menuitem action='complete_temporary_action'/>"
			"		<menuitem action='cancel_temporary_action'/>"

			"		<separator/>"

			"		<menuitem action='set_upload_rate_limit'/>"
			"		<menuitem action='set_download_rate_limit'/>"

			"		<separator/>"

			"		<menuitem action='quit'/>"
			"	</popup>"

			"</ui>";

		this->gui->ui_manager->add_ui_from_string(ui_info);
		this->add_accel_group(this->gui->ui_manager->get_accel_group());
	// Меню <--


	Gtk::VBox* main_vbox = Gtk::manage(new Gtk::VBox());
	this->add(*main_vbox);

	// Панель меню -->
		Gtk::Widget* menu_bar = this->gui->ui_manager->get_widget("/menu_bar");
		main_vbox->pack_start(*menu_bar, false, true);
	// Панель меню <--

	// Панель инструментов
	main_vbox->pack_start(this->gui->toolbar, false, false);

	// Список торрентов -->
		this->gui->torrents_viewport = Gtk::manage(new Torrents_viewport(main_window_settings.torrents_viewport));
		main_vbox->pack_start(*this->gui->torrents_viewport, true, true);

		// Настройки отдельных виджетов
		this->gui->torrents_viewport->get_log_view().set_max_lines(client_settings.gui.max_log_lines);
	// Список торрентов <--

	// status bar -->
	{
		Gtk::Alignment* alignment = Gtk::manage(new Gtk::Alignment());
		alignment->property_top_padding() = m::gtk::VBOX_SPACING / 2;
		main_vbox->pack_start(*alignment, false, false);

		alignment->add(this->gui->status_bar);
		this->gui->status_bar.push("");
	}
	// status bar <--

	// AppIndicator -->
	#if HAVE_APP_INDICATOR
	{
		app_indicator_set_menu(this->gui->appindicator, GTK_MENU(
			gtk_ui_manager_get_widget(this->gui->ui_manager->gobj(), "/ui/appindicator")));

		g_signal_connect(G_OBJECT(this->gui->appindicator), APP_INDICATOR_SIGNAL_CONNECTION_CHANGED,
			G_CALLBACK(&Main_window::on_appindicator_connection_changed), this);
	}
	#endif
	// AppIndicator <--


	// Панель инструментов -->
	{
		// Заполнять ее лучше в самом конце, когда уже созданы все необходимые
		// виджеты.

		Gtk::ToolButton* button;


		button = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::NEW));
		button->set_label(_("Create"));
		button->set_tooltip_text(_("Create a new torrent"));
		button->set_is_important();
		this->gui->toolbar.append(
			*button,
			sigc::mem_fun(*this, &Main_window::on_create_callback)
		);

		button = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::OPEN));
		button->set_label(_("Open"));
		button->set_tooltip_text(_("Open a torrent"));
		button->set_is_important();
		this->gui->toolbar.append(
			*button,
			sigc::mem_fun(*this, &Main_window::on_open_callback)
		);


		button = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::JUMP_TO));
		button->set_label(_("Magnet link"));
		button->set_tooltip_text(_("Open a magnet link"));
		button->set_is_important();
		this->gui->toolbar.append(
			*button,
			sigc::mem_fun(*this, &Main_window::on_open_magnet_callback)
		);


		this->gui->toolbar.append(
			*Gtk::manage(new Gtk::SeparatorToolItem())
		);


		button = this->gui->toolbar_resume_button = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::MEDIA_PLAY));
		button->set_label(_("Resume"));
		button->set_tooltip_text(_("Resume torrent(s)"));
		button->set_is_important();
		this->gui->toolbar.append(
			*button,
			sigc::bind<Torrent_process_action>(
				sigc::mem_fun(*this->gui->torrents_viewport, &Torrents_viewport::process_torrents),
				RESUME
			)
		);

		button = this->gui->toolbar_pause_button = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::MEDIA_PAUSE));
		button->set_label(_("Pause"));
		button->set_tooltip_text(_("Pause torrent(s)"));
		button->set_is_important();
		this->gui->toolbar.append(
			*button,
			sigc::bind<Torrent_process_action>(
				sigc::mem_fun(*this->gui->torrents_viewport, &Torrents_viewport::process_torrents),
				PAUSE
			)
		);

		button = this->gui->toolbar_remove_button = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::REMOVE));
		button->set_label(_("Remove"));
		button->set_tooltip_text(_("Remove torrent(s)"));
		button->set_is_important();
		this->gui->toolbar.append(
			*button,
			sigc::bind<Torrent_process_action>(
				sigc::mem_fun(*this->gui->torrents_viewport, &Torrents_viewport::process_torrents),
				REMOVE
			)
		);


		this->gui->toolbar.append(
			*Gtk::manage(new Gtk::SeparatorToolItem())
		);


		button = Gtk::manage(new Gtk::ToolButton());
		button->set_label(_("Statistics"));
		app_icons::set_for_tool_button(*button, app_icons::ICON_STATISTICS);
		button->set_tooltip_text(_("Statistics"));
		button->set_is_important();
		this->gui->toolbar.append(
			*button,
			sigc::mem_fun(*this, &Main_window::on_show_statistics_callback)
		);

		button = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::PREFERENCES));
		button->set_label(_("Preferences"));
		button->set_tooltip_text(_("Preferences"));
		button->set_is_important();
		this->gui->toolbar.append(
			*button,
			sigc::mem_fun(*this, &Main_window::on_show_settings_window_callback)
		);


		this->gui->toolbar.show_all_children();
		if(get_client_settings().gui.show_toolbar)
			this->gui->toolbar.show();

		this->gui->toolbar.set_no_show_all();
	}
	// Панель инструментов <--


	// Устанавливаем интервал обновления GUI
	this->set_gui_update_interval(client_settings.gui.update_interval);

	// Обновление доступных в данный момент кнопок -->
		this->on_torrent_process_actions_changed_callback(0);

		gui->torrent_process_actions_changed_connection =
			this->gui->torrents_viewport->signal_torrent_process_actions_changed().connect(
				sigc::mem_fun(*this, &Main_window::on_torrent_process_actions_changed_callback)
			);
	// Обновление доступных в данный момент кнопок <--

	// Автоматическое сохранение настроек
	gui->autosave_settings_connection = Glib::signal_timeout().connect(
		sigc::mem_fun(*this, &Main_window::on_save_settings_timeout), SAVE_SETTINGS_INTERVAL
	);

	// Обработчик сигнала на изменение состояния окна
	this->signal_window_state_event().connect(sigc::mem_fun(
		*this, &Main_window::on_window_state_changed_callback
	));

	// Закрытие окна
	this->signal_delete_event().connect(sigc::mem_fun(*this, &Main_window::on_close_callback));

	if(client_settings.gui.show_tray_icon && client_settings.gui.hide_app_to_tray_at_startup)
		this->show_all_children();
	else
		this->show_all();

	// В gtkmm 2.16.0 (Ubuntu 9.04) есть небольшая бага, из-за которой
	// this->show_all() отображает даже элементы меню, для которых была
	// выполнена Gtk::Action::set_visible(false).
	// Поэтому скрываем элементы меню в самый последний момент.
	COMPATIBILITY
	gui->complete_temporary_action->set_visible(true);
	gui->cancel_temporary_action->set_visible(true);
}
コード例 #8
0
ファイル: application.cpp プロジェクト: BackupGGCode/ewlibs
/*
 this function create buffers from file list
 - generates buffer id
 - load text indexers

 TODO: like emacs:
  - scratch buffer
  - message buffer etc...
*/
bool application::application_private::setup_buffers()
{
	// TODO: font-family: normal/bold/italic/italic-bold
	// setup_font()
	// open fonts here
	app_log << " setup fonts\n";

	// replace : ft = font_family->normal()
	// have ft = ft->italic(1|0)->bold(1|0)

	auto ft = std::make_shared<ew::graphics::fonts::font>(get_application()->font_file_name().c_str(),
			get_application()->font_width(),
			get_application()->font_height());
	this->font = ft;
	if (ft->open() == false) {
		assert(0);
		return false;
	}

	// setup buffers
	for (const auto & filename : m_files_list) {

		// TODO: file path check/line/column

		// move this to editor_buffer_info ctor

		editor_buffer_id_t editor_buffer_id = editor_buffer_open(filename.c_str(), filename.c_str() /* buffer name */); // TODO "basename - [N]"
		if (editor_buffer_id == INVALID_EDITOR_BUFFER_ID) {
			assert(0);
			continue;
		}

		auto bid = editor_buffer_get_byte_buffer_id(editor_buffer_id);
		app_log << "allocated  bid['"<< filename  <<"'] = " << bid << "\n";
		app_log << "allocated editor_buffer_id['"<< filename  <<"'] = " << editor_buffer_id << "\n";

		if (editor_buffer_id == 0) {
			app_log << " cannot prepare buffer for '" << filename << "'\n";
			assert(0);
			continue;
		}

		app_log << " prepare buffer for '" << filename << "'\n";
		m_buffer_desc_list.emplace_back(editor_buffer_id);
	}

	// FIXME:
	// init log/message/scratch
	if (m_buffer_desc_list.size() == 0) {

		// TODO: file path check/line/column

		// move this to editor_buffer_info ctor
		auto filename = "dev/null";
		auto buffer_name = "dummy";

		editor_buffer_id_t editor_buffer_id = editor_buffer_open(filename, buffer_name); // TODO "basename - [N]"
		if (editor_buffer_id == INVALID_EDITOR_BUFFER_ID) {
			assert(0);
			return false;
		}

		auto bid = editor_buffer_get_byte_buffer_id(editor_buffer_id);
		app_log << "allocated  bid['"<< filename  <<"'] = " << bid << "\n";
		app_log << "allocated editor_buffer_id['"<< filename  <<"'] = " << editor_buffer_id << "\n";

		if (editor_buffer_id == 0) {
			app_log << " cannot prepare buffer for '" << filename << "'\n";
			assert(0);
			return false;
		}





	}

	return true;
}
コード例 #9
0
ファイル: application.cpp プロジェクト: BackupGGCode/ewlibs
bool application::parse_command_line(int ac, char ** av)
{
	// --- default ---
	char * home_dir = ew::core::program::getenv("HOME");
	if (!home_dir) {
		cerr << "HOME env is not set\n";
		return false;
	}

	const char * default_font_sufix = ".ew/eedit/config/fonts/default.ttf";
	int len = strlen(home_dir) + 1 /* / */ + strlen(default_font_sufix);

	char * font_file_name = new char [len + 1];
	snprintf(font_file_name, len + 1, "%s/%s", home_dir, default_font_sufix);
	get_application()->set_font_file_name(font_file_name);

	delete [] font_file_name;

	// bool check_file(filename, exists|readable|...)
	{
		file * fontfile = new file(get_application()->font_file_name().c_str());
		bool ret = fontfile->open(mode::read_only);
		if (ret == false) {
			cerr << "cannot open = '" << fontfile->name() << "'\n";
			exit(0);
		}
		fontfile->close();
		delete fontfile;
	}

	// --- parse command line ---
	bool   print_help = false;
	int c;
	while (1) {
		static struct option long_options[] = {
			{"help",       no_argument,       0,  1 },
			{"offscreen",  required_argument, 0,  2 },
			{"font.size",  required_argument, 0,  3 },
			{"line.num",   required_argument, 0,  4 },
			{"ui",         required_argument, 0,  5 },
			{0,            0,                 0,  0 },
		};

		int option_index;
		c = getopt_long(ac, av, "", long_options, &option_index);
		if (c == -1)
			break;
		switch (c) {
		case 1:
			print_help = true;
			break;

		case 2:
			get_application()->offscreen_buffer_flag() = (optarg[0] == 'y' ? true : false);
			break;

		case 3:
			this->set_default_font_size(atoi(optarg));
			cerr << "font_size_x = " << this->font_width() << "\n";
			break;

		case 4:
			this->build_index_flag() = (optarg[0] == 'y' ? true : false);
			break;

		case 5:
			cerr << "detected ui = " << optarg << "\n";
			if (this->set_ui_name(optarg) != true) {
				print_help = true;
			}
			break;

		case '?':
			break;

		default: {
			// printf("?? getopt returned character code 0%o ??\n", c);
		}
		break;
		}
	}

	if (print_help) {

		cerr << "usage : eedit [ --help ]"
		     << " [ --ui ew|ncurses|debug ]"
		     << " [ --offscreen y/n]"
		     << " [ --font.size size ]"
		     << " [ --line.num y/n ]"
		     << " file ...\n";

		exit(0);
	}

	if (optind < ac) {
		while (optind < ac) {
			cerr << "add to file list '" << av[optind] << "'\n";
			files_list().push_back(av[optind++]);
		}
	}

	return true;
}