Esempio n. 1
0
profile_selection::profile_selection(BaseObjectType* cobject, utils::builder builder, const std::vector<std::string>& accounts):
    Gtk::Window(cobject),
    m_abort(true),
    m_quited(false) {
    utils::debug::scope_log log(DBG_LVL_1("gtox"), {});

    builder->get_widget("profile_list", m_profile_list);
    builder->get_widget("revealer", m_revealer);

    set_title(_("gTox"));
    set_default_geometry(300, 300);
    set_position(Gtk::WindowPosition::WIN_POS_CENTER);

    auto hbar = builder.get_widget<Gtk::HeaderBar>("headerbar");
    hbar->set_title(_("gTox"));
    hbar->set_subtitle(_("Select profile"));

    Gtk::ListBox* profile_selection_list   = builder.get_widget<Gtk::ListBox>("profile_list");
    Gtk::Button*  profile_selection_new    = builder.get_widget<Gtk::Button>("profile_new");
    Gtk::Button*  profile_selection_select = builder.get_widget<Gtk::Button>("profile_select");

    profile_selection_list->signal_row_selected().connect([this, profile_selection_select](Gtk::ListBoxRow* row) {
        utils::debug::scope_log log(DBG_LVL_2("gtox"), {});
        if (m_quited) {
            return;
        }
        if (profile_selection_select) {
            profile_selection_select->set_sensitive(row != nullptr);
        }
    });
    profile_selection_list->signal_row_activated().connect([this, profile_selection_select](Gtk::ListBoxRow*) {
        utils::debug::scope_log log(DBG_LVL_2("gtox"), {});
        if (profile_selection_select) {
            profile_selection_select->clicked();
        }
    });

    profile_selection_new->signal_clicked().connect([this](){
        utils::debug::scope_log log(DBG_LVL_2("gtox"), {});
        m_abort = false;
        quit();
    });

    profile_selection_list->signal_button_press_event().connect_notify([this, profile_selection_list](GdkEventButton* event) {
        utils::debug::scope_log log(DBG_LVL_2("gtox"), {});
        if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
            auto item = profile_selection_list->get_row_at_y(event->y);
            if (item) {
                profile_selection_list->select_row(*item);
                m_popup_menu.popup(event->button, event->time);
            }
        }
    });

    profile_selection_select->set_sensitive(false);
    profile_selection_select->signal_clicked().connect([this, profile_selection_list]() {
        utils::debug::scope_log log(DBG_LVL_2("gtox"), {});
        m_abort = false;

        auto row = profile_selection_list->get_selected_row();
        if (row) {
            m_selected_path = m_accounts[row->get_index()];
        }

        quit();
    });

    auto open_in_fm = Gtk::manage(new Gtk::MenuItem(_("Open this profile in file manager"), true));

    m_popup_menu.append(*open_in_fm);

    m_popup_menu.accelerate(*this);
    m_popup_menu.show_all();

    open_in_fm->signal_activate().connect([this, profile_selection_list]() {
        utils::debug::scope_log log(DBG_LVL_2("gtox"), {});
        auto row = profile_selection_list->get_selected_row();
        if (row) {
            try {
                Gio::AppInfo::get_default_for_type("inode/directory", true)->launch_uri(Glib::filename_to_uri(m_accounts[row->get_index()]));
            } catch (...) {
                //TODO: display error !
            }
        }
    });

    set_accounts(accounts);
}
Esempio n. 2
0
contact::contact(BaseObjectType* cobject,
                 utils::builder builder,
                 dialog::main& main,
                 std::shared_ptr<toxmm::contact> contact,
                 bool for_active_chats)
    : Gtk::ListBoxRow(cobject),
      m_main(main),
      m_contact(contact),
      m_for_active_chats(for_active_chats) {

    builder.get_widget("contact_list_grid_mini", m_contact_list_grid_mini);
    builder.get_widget("contact_list_grid", m_contact_list_grid);
    builder.get_widget("revealer", m_revealer);

    //builder.get_widget("avatar", m_avatar);
    m_avatar = builder.get_widget_derived<widget::avatar>("avatar", contact->property_addr_public());
    builder.get_widget("name", m_name);
    builder.get_widget("status", m_status_msg);
    builder.get_widget("status_icon", m_status_icon);
    builder.get_widget("spinner", m_spin);

    m_avatar_mini = builder.get_widget_derived<widget::avatar>("avatar_mini", contact->property_addr_public());
    builder.get_widget("name_mini", m_name_mini);
    builder.get_widget("status_mini", m_status_msg_mini);
    builder.get_widget("status_icon_mini", m_status_icon_mini);
    builder.get_widget("spinner_mini", m_spin_mini);

    m_bindings[0] = Glib::Binding::bind_property(m_status_icon->property_icon_name(),
                                                 m_status_icon_mini->property_icon_name(),
                                                 Glib::BINDING_DEFAULT |
                                                 Glib::BINDING_BIDIRECTIONAL |
                                                 Glib::BINDING_SYNC_CREATE);
    m_bindings[1] = Glib::Binding::bind_property(m_status_icon->property_icon_size(),
                                                 m_status_icon_mini->property_icon_size(),
                                                 Glib::BINDING_DEFAULT |
                                                 Glib::BINDING_BIDIRECTIONAL |
                                                 Glib::BINDING_SYNC_CREATE);
    m_bindings[2] = Glib::Binding::bind_property(m_spin->property_active(),
                                                 m_spin_mini->property_active(),
                                                 Glib::BINDING_DEFAULT |
                                                 Glib::BINDING_BIDIRECTIONAL |
                                                 Glib::BINDING_SYNC_CREATE);
    m_spin->stop();

    m_bindings[3] = Glib::Binding::bind_property(m_contact->property_name_or_addr(),
                                                 m_name->property_label(),
                                                 Glib::BINDING_DEFAULT |
                                                 Glib::BINDING_SYNC_CREATE);
    m_bindings[4] = Glib::Binding::bind_property(m_contact->property_name_or_addr(),
                                                 m_name_mini->property_label(),
                                                 Glib::BINDING_DEFAULT |
                                                 Glib::BINDING_SYNC_CREATE);
    m_bindings[5] = Glib::Binding::bind_property(m_contact->property_status_message(),
                                                 m_status_msg->property_label(),
                                                 Glib::BINDING_DEFAULT |
                                                 Glib::BINDING_SYNC_CREATE);
    m_bindings[6] = Glib::Binding::bind_property(m_contact->property_status_message(),
                                                 m_status_msg_mini->property_label(),
                                                 Glib::BINDING_DEFAULT |
                                                 Glib::BINDING_SYNC_CREATE);

    m_status_icon->set_from_icon_name("status_offline", Gtk::BuiltinIconSize::ICON_SIZE_BUTTON);

    m_contact->property_status().signal_changed().connect(sigc::track_obj([this]() {
        switch (m_contact->property_status().get_value()) {
            case TOX_USER_STATUS_AWAY:
                m_status_icon->set_from_icon_name("status_away", Gtk::BuiltinIconSize::ICON_SIZE_BUTTON);
                break;
            case TOX_USER_STATUS_BUSY:
                m_status_icon->set_from_icon_name("status_busy", Gtk::BuiltinIconSize::ICON_SIZE_BUTTON);
                break;
            case TOX_USER_STATUS_NONE:
                m_status_icon->set_from_icon_name("status_online", Gtk::BuiltinIconSize::ICON_SIZE_BUTTON);
                break;
        }
        m_status_icon->reset_style();
        m_status_icon->queue_resize();
    }, *this));

    m_contact->property_connection().signal_changed().connect(sigc::track_obj([this]() {
        if (m_contact->property_connection().get_value() == TOX_CONNECTION_NONE) {
            m_status_icon->set_from_icon_name("status_offline", Gtk::BuiltinIconSize::ICON_SIZE_BUTTON);
            m_status_icon->reset_style();
            m_status_icon->queue_resize();
        }
    }, *this));

    auto display_spinner = [this]() {
        m_spin->start();
    };

    m_contact->signal_recv_message().connect(sigc::hide(sigc::track_obj(display_spinner, *this)));
    m_contact->signal_recv_action().connect(sigc::hide(sigc::track_obj(display_spinner, *this)));

    auto update_visibility = [this]() {
        if (!m_for_active_chats &&
                !m_main.config()->property_contacts_compact_list().get_value()) {
            m_contact_list_grid_mini->hide();
            m_contact_list_grid->show();
        } else {
            m_contact_list_grid->hide();
            m_contact_list_grid_mini->show();
        }
        if (!m_for_active_chats) {
            show();
        }
    };
    update_visibility();
    m_main.config()->property_contacts_compact_list()
            .signal_changed().connect(sigc::track_obj(update_visibility, *this));


    if (m_for_active_chats) {
        return;
    }

    //callbacks for logging
    m_contact->signal_send_message().connect(sigc::track_obj([this](Glib::ustring message, std::shared_ptr<toxmm::receipt>) {
       dialog::chat::add_log(m_main.tox()->storage(), m_contact, [&](flatbuffers::FlatBufferBuilder& fbb) {
           return flatbuffers::Log::CreateItem(fbb,
                                               fbb.CreateString(m_main.tox()->property_addr_public().get_value()),
                                               Glib::DateTime::create_now_utc().to_unix(),
                                               flatbuffers::Log::Data_Message,
                                               flatbuffers::Log::CreateMessage(
                                                    fbb,
                                                    fbb.CreateString(message))
                                                     .Union());
       });
    }, *this));
    m_contact->signal_recv_message().connect(sigc::track_obj([this](Glib::ustring message) {
        dialog::chat::add_log(m_main.tox()->storage(), m_contact, [&](flatbuffers::FlatBufferBuilder& fbb) {
            return flatbuffers::Log::CreateItem(fbb,
                                                fbb.CreateString(m_contact->property_addr_public().get_value()),
                                                Glib::DateTime::create_now_utc().to_unix(),
                                                flatbuffers::Log::Data_Message,
                                                flatbuffers::Log::CreateMessage(
                                                     fbb,
                                                     fbb.CreateString(message))
                                                     .Union());
        });
    }, *this));
    m_contact->signal_send_action().connect(sigc::track_obj([this](Glib::ustring action, std::shared_ptr<toxmm::receipt>) {
        dialog::chat::add_log(m_main.tox()->storage(), m_contact, [&](flatbuffers::FlatBufferBuilder& fbb) {
            return flatbuffers::Log::CreateItem(fbb,
                                                fbb.CreateString(m_main.tox()->property_addr_public().get_value()),
                                                Glib::DateTime::create_now_utc().to_unix(),
                                                flatbuffers::Log::Data_Action,
                                                flatbuffers::Log::CreateAction(
                                                     fbb,
                                                     fbb.CreateString(action))
                                                      .Union());
        });
    }, *this));
    m_contact->signal_recv_action().connect(sigc::track_obj([this](Glib::ustring action) {
        dialog::chat::add_log(m_main.tox()->storage(), m_contact, [&](flatbuffers::FlatBufferBuilder& fbb) {
            return flatbuffers::Log::CreateItem(fbb,
                                                fbb.CreateString(m_contact->property_addr_public().get_value()),
                                                Glib::DateTime::create_now_utc().to_unix(),
                                                flatbuffers::Log::Data_Action,
                                                flatbuffers::Log::CreateAction(
                                                     fbb,
                                                     fbb.CreateString(action))
                                                     .Union());
        });
    },*this));
    auto fm = m_contact->file_manager();
    if (fm) {
        fm->signal_send_file().connect(sigc::track_obj([this](std::shared_ptr<toxmm::file>& file) {
            if (file->property_kind() != TOX_FILE_KIND_DATA) {
                return;
            }
            dialog::chat::add_log(m_main.tox()->storage(), m_contact, [&](flatbuffers::FlatBufferBuilder& fbb) {
                return flatbuffers::Log::CreateItem(fbb,
                                                    fbb.CreateString(m_main.tox()->property_addr_public().get_value()),
                                                    Glib::DateTime::create_now_utc().to_unix(),
                                                    flatbuffers::Log::Data_File,
                                                    flatbuffers::Log::CreateFile(
                                                         fbb,
                                                         fbb.CreateString(file->property_uuid().get_value()),
                                                         fbb.CreateString(file->property_name().get_value()),
                                                         fbb.CreateString(file->property_path().get_value()),
                                                         flatbuffers::Log::FileStatus_PENDING,
                                                         fbb.CreateString(m_contact->property_addr_public().get_value()))
                                                          .Union());
            });
        }, *this));
        fm->signal_recv_file().connect(sigc::track_obj([this](std::shared_ptr<toxmm::file>& file) {
            if (file->property_kind() != TOX_FILE_KIND_DATA) {
                return;
            }
            dialog::chat::add_log(m_main.tox()->storage(), m_contact, [&](flatbuffers::FlatBufferBuilder& fbb) {
                return flatbuffers::Log::CreateItem(fbb,
                                                    fbb.CreateString(m_contact->property_addr_public().get_value()),
                                                    Glib::DateTime::create_now_utc().to_unix(),
                                                    flatbuffers::Log::Data_Action,
                                                    flatbuffers::Log::CreateFile(
                                                         fbb,
                                                         fbb.CreateString(file->property_uuid().get_value()),
                                                         fbb.CreateString(file->property_name().get_value()),
                                                         fbb.CreateString(file->property_path().get_value()),
                                                         flatbuffers::Log::FileStatus_PENDING,
                                                         fbb.CreateString(m_contact->property_addr_public().get_value()))
                                                          .Union());
            });
        }, *this));
    }
}