Пример #1
0
/**
* Sets up the main window.
*/
GtkMainWindow::GtkMainWindow(GtkWindow *win, const Glib::RefPtr<Gtk::Builder> rbuilder) : Gtk::Window(win), builder(rbuilder), m_core(Application::getSingleton()->getCore())
{
	notify_init ("gTorrent");

	GtkTorrentSideBar *sidebar;
	Gtk::Revealer *revealer;

	builder->get_widget(  "addTorrentButton", addTorrentButton);
	builder->get_widget(  "addTorrentButton", addTorrentButton);
	builder->get_widget(   "addMagnetButton",  addMagnetButton);
	builder->get_widget(      "resumeButton",     resumeButton);
	builder->get_widget(       "pauseButton",      pauseButton);
	builder->get_widget(      "deleteButton",     removeButton);
	//builder->get_widget( "preferencesButton", propertiesButton);
	builder->get_widget(    "settingsButton",   settingsButton);
	builder->get_widget(             "panel",            panel);
	builder->get_widget(    "scrolledWindow",   scrolledWindow);
	builder->get_widget(           "vSepOne",    vSeparatorOne);
	builder->get_widget(           "vSepTwo",    vSeparatorTwo);
	builder->get_widget(        "sidebarRev",         revealer);
	builder->get_widget_derived(   "infobar",        m_infobar);
	builder->get_widget_derived(  "treeview",       m_treeview);
	builder->get_widget_derived(   "sidebar",          sidebar);

	panel->pack2(*m_infobar);

	// Apparently can't use lambdas on these two unless doing something awful
	Glib::signal_timeout().connect_seconds(sigc::mem_fun(*this, &GtkMainWindow::onSecTick), 1);
	signal_delete_event().connect(sigc::mem_fun(*this, &GtkMainWindow::onDestroy));

	addTorrentButton->signal_clicked().connect([this](){        onAddBtnClicked();});
	pauseButton     ->signal_clicked().connect([this](){      onPauseBtnClicked();});
	resumeButton    ->signal_clicked().connect([this](){     onResumeBtnClicked();});
	removeButton    ->signal_clicked().connect([this](){     onRemoveBtnClicked();});
	settingsButton  ->signal_clicked().connect([this](){   onSettingsBtnClicked();});
	addMagnetButton ->signal_clicked().connect([this](){  onAddMagnetBtnClicked();});
	//propertiesButton->signal_clicked().connect([revealer](){ revealer->set_reveal_child(!revealer->get_reveal_child());});

	magEntry   = Gtk::manage(new Gtk::Entry());
	revealer->set_reveal_child(true);
	magEntry->set_visible();
	magEntry->set_width_chars(75);
	magPopover = Gtk::manage(new Gtk::Popover());

	magPopover->add(*magEntry);
	magPopover->set_relative_to(*addMagnetButton);
	addMagnetButton->set_popover(*magPopover);
	magPopover->set_position(Gtk::POS_LEFT);
	
	sidebar_scrolledwindow->set_min_content_width(150);

	for(auto tor : Application::getSingleton()->getCore()->getTorrents())
	{
		tor->onStateChanged = [this](int oldstate, std::shared_ptr<gt::Torrent> t){ torrentStateChangedCallback(oldstate, t); };
		m_treeview->addCell(tor);
	}

	if (gt::Settings::settings["FileAssociation"] == "" ||
		gt::Settings::settings["FileAssociation"] == "-1")
	{
		GtkAssociationDialog *dialog = 0;
		builder->get_widget_derived("fileAssociationDialog", dialog);
		dialog->set_transient_for(*this);
		dialog->set_default_response(1);
		int code = dialog->run();
		if(code != -1)
			gt::Platform::associate(dialog->aWithMagnets, dialog->aWithTorrents);
		gt::Settings::settings["FileAssociation"] = std::to_string(code);
		delete dialog;
	}

	d = new GtkSettingsDialog(this);
}
Пример #2
0
void profile_selection::set_accounts(const std::vector<std::string>& accounts) {
    utils::debug::scope_log log(DBG_LVL_1("gtox"), {});
    m_accounts = accounts;

    Glib::ustring tox_name;
    Glib::ustring tox_status;
    toxmm::contactAddrPublic tox_addr;

    for (auto acc : accounts) {
        int tox_error = 0;
        bool can_write = false;

        //TRY TO LOAD TOX DATA
        try {
            toxmm::core::try_load(acc, tox_name, tox_status, tox_addr, can_write);
            if (tox_name.empty()) {
                tox_name = tox_addr;
            }
        } catch (toxmm::exception exception) {
            if (exception.type() == typeid(TOX_ERR_NEW)) {
                switch (exception.what_id()) {
                    case TOX_ERR_NEW_LOAD_BAD_FORMAT:
                        tox_error = 1;
                        break;
                    case TOX_ERR_NEW_LOAD_ENCRYPTED:
                        tox_error = 2;
                        break;
                    default:
                        tox_error = 3;
                        break;
                }
            } else {
                tox_error = 3;
            }
        } catch (std::exception exp) {
            std::cerr << "Couldn't load profile \"" + acc + "\"" << std::endl;
            std::cerr << exp.what() << std::endl;
            tox_error = 3;
        } catch (...) {
            std::cerr << "Couldn't load profile \"" + acc + "\"" << std::endl;
            std::cerr << "Unexpected error" << std::endl;
            tox_error = 3;
        }

        utils::debug::scope_log log(DBG_LVL_2("gtox"), {});
        utils::builder builder = Gtk::Builder::create_from_resource("/org/gtox/ui/list_item_profile.ui");
        Gtk::ListBoxRow* row = nullptr;
        builder->get_widget("pofile_list_item", row);
        if (row) {
            Gtk::Label* name = nullptr;
            Gtk::Label* status = nullptr;
            Gtk::Label* path = nullptr;
            builder.get_widget("name", name);
            builder.get_widget("status", status);
            builder.get_widget("path", path);
            builder.get_widget_derived<widget::avatar>("avatar", tox_addr);

            path->set_text(acc);
            row->set_sensitive(false);
            switch (tox_error) {
                case 0:
                    name->set_text(tox_name);
                    status->set_text(tox_status);
                    if (can_write) {
                        row->set_sensitive(true);
                    }
                    break;
                case 1:
                    name->set_text(_("Corrupted profile"));
                    status->set_text(_("Profile couldn't be loaded"));
                    break;
                case 2:
                    name->set_text(_("Encrypted profile"));
                    status->set_text(_("Profile couldn't be loaded"));
                    break;
                default:
                    name->set_text(_("Profile not loaded for an unknown reason"));
                    status->set_text(_("Profile couldn't be loaded"));
                    break;
            }

            //reveale profil
            Gtk::Revealer* revealer;
            builder.get_widget("revealer", revealer);
            revealer->set_reveal_child(true);

            row->show();
            m_profile_list->add(*row);
        }
    }

    m_revealer->set_reveal_child(false);
}