//------------------------------------------------------------------------------
void ColumnsModel::disable_edit_first_row(Gtk::CellRenderer* cell, const Gtk::TreeIter& iter) {
  Gtk::CellRendererText* txt = (Gtk::CellRendererText*)cell;
  if (txt) {
    Gtk::TreeModel::Path path = this->_treeview->get_model()->get_path(iter);
    if (path[0] == 0)
      txt->property_editable() = false;
    else
      txt->property_editable() = true;
  }
}
ArbitratorPropertyWindow::ArbitratorPropertyWindow(MainWindow* parent, 
                               Manager* manager, ApplicationWindow* appWnd)
{   
    m_pParent = parent;
    m_pManager = manager;
    m_pAppWindow = appWnd;
    m_arbPort.clear();

    /* Create a new scrolled window, with scrollbars only if needed */
    set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
    add(m_TreeView);

    /* create tree store */
    m_refTreeModel = Gtk::TreeStore::create(m_Columns);
    m_TreeView.set_model(m_refTreeModel);

    //Add the Model’s column to the View’s columns: 
    Gtk::CellRendererText* itemRenderer = Gtk::manage(new Gtk::CellRendererText());
    itemRenderer->property_editable() = false;
    Gtk::TreeViewColumn* itemCol = Gtk::manage(new Gtk::TreeViewColumn("Property", *itemRenderer));
    //itemCol->add_attribute(*itemRenderer, "background-gdk", m_Columns.m_col_color);
    itemCol->add_attribute(*itemRenderer, "text", m_Columns.m_col_name);
    itemCol->set_resizable(true);
    m_TreeView.append_column(*itemCol);



    Gtk::CellRendererText* valueRenderer = Gtk::manage(new Gtk::CellRendererText());
    valueRenderer->property_editable() = false;
    Gtk::TreeViewColumn* valueCol = Gtk::manage(new Gtk::TreeViewColumn("Value", *valueRenderer));
    valueCol->add_attribute(*valueRenderer, "foreground-gdk", m_Columns.m_col_color_value);
    valueCol->add_attribute(*valueRenderer, "text", m_Columns.m_col_value);
    valueCol->set_resizable(true);
    valueRenderer->property_editable() = true;
    //valueCol->set_cell_data_func(*valueRenderer, sigc::mem_fun(*this,
    //    &ArbitratorPropertyWindow::onCellData) );
    valueRenderer->signal_edited().connect( sigc::mem_fun(*this,
              &ArbitratorPropertyWindow::onCellEdited) );
    m_TreeView.append_column(*valueCol);
    valueCol->add_attribute(*valueRenderer, "editable", m_Columns.m_col_editable);   


    //m_TreeView.append_column_editable("Value", m_Columns.m_col_value);
    //m_TreeView.get_column(1)->set_resizable(true);
       //Tell the view column how to render the model values:
    m_TreeView.set_property("enable_grid_lines", true);
    show_all_children();
    m_TreeView.set_grid_lines(Gtk::TREE_VIEW_GRID_LINES_BOTH);
    m_TreeView.set_rules_hint(true);
}
const StringColumn&
ColumnsModel::append_string_column(const int bec_tm_idx, const std::string& name, const Editable editable, const Iconic have_icon)
{
  Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > *icon= 0;

  Gtk::TreeViewColumn *column= Gtk::manage(new Gtk::TreeViewColumn(bec::replace_string(name, "_", "__")));

  if ( have_icon == WITH_ICON )
  {
    icon = new Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> >;
    add(*icon);
    add_bec_index_mapping(bec_tm_idx);
    column->pack_start(*icon, false);

    _columns.push_back(icon);
  }

  Gtk::TreeModelColumn<Glib::ustring> *col = new Gtk::TreeModelColumn<Glib::ustring>;
  add(*col);
  add_bec_index_mapping(bec_tm_idx);
  column->pack_start(*col);

  _columns.push_back(col);

  int nr_of_cols= _treeview->append_column(*column);
  _treeview->get_column(nr_of_cols-1)->set_resizable(true);

  if (editable == EDITABLE || editable == EDITABLE_WO_FIRST)
  {

    std::vector<Gtk::CellRenderer*> rends= column->get_cell_renderers();

    Gtk::CellRendererText *cell = (Gtk::CellRendererText*)rends[icon ? 1 : 0];
    cell->property_editable()= true;
    cell->signal_edited().connect(sigc::bind
                                  (sigc::mem_fun(*_tmw
                                                ,&ListModelWrapper::after_cell_edit<Glib::ustring>
                                                )
                                                , sigc::ref(*col)
                                  )
                                 );

    if (editable == EDITABLE_WO_FIRST)
      column->set_cell_data_func(*cell, sigc::mem_fun(this, &ColumnsModel::disable_edit_first_row));
  }

  return *col;
}
Exemplo n.º 4
0
ModuleWindow::ModuleWindow(Module* module, MainWindow* parent,
                               Manager* manager)
{
    m_pModule = module;
    m_pParent = parent;
    m_pManager = manager;

    /* Create a new scrolled window, with scrollbars only if needed */
    set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
    add(m_TreeView);

    /* create tree store */
    m_refTreeModel = Gtk::TreeStore::create(m_Columns);
    m_TreeView.set_model(m_refTreeModel);

    //Add the Model’s column to the View’s columns:
    Gtk::CellRendererText* cellText = Gtk::manage(new Gtk::CellRendererText());
    cellText->property_style() = Pango::STYLE_ITALIC;
    Gtk::CellRendererPixbuf* cellPix = Gtk::manage(new Gtk::CellRendererPixbuf());
    Gtk::TreeViewColumn* col = Gtk::manage(new Gtk::TreeViewColumn("Item"));
    col->pack_start(*cellPix, false);
    col->pack_start(*cellText, true);
    col->add_attribute(*cellText, "text", 1);
    col->add_attribute(*cellPix, "pixbuf", 0);
    m_TreeView.append_column(*col);
    m_TreeView.get_column(0)->set_resizable(true);

    //m_TreeView.append_column("Value", m_Columns.m_col_value);
    //m_TreeView.get_column(1)->set_resizable(true);

    Gtk::CellRendererText* cellValue = Gtk::manage(new Gtk::CellRendererText());
    cellValue->property_editable() = false;
    cellValue->property_wrap_mode() = Pango::WRAP_WORD;
    cellValue->property_style() = Pango::STYLE_ITALIC;
    //cellValue->property_wrap_width() = m_Columns.m_col_width;
    Gtk::TreeViewColumn* valueCol = Gtk::manage(new Gtk::TreeViewColumn("Value", *cellValue));
    valueCol->add_attribute(*cellValue, "text", m_Columns.m_col_value);
    valueCol->add_attribute(*cellValue, "wrap_width", m_Columns.m_col_width);

    valueCol->set_resizable(true);
    m_TreeView.append_column(*valueCol);
    //m_TreeView.set_rules_hint(true);


    updateWidget();
    show_all_children();
}
Exemplo n.º 5
0
// Cringe.
void GtkTorrentSideBar::setupColumns()
{
	int cid = 0;
	Gtk::TreeViewColumn     *col = nullptr;
	Gtk::CellRendererText   *cell = Gtk::manage(new Gtk::CellRendererText());
	Gtk::CellRendererPixbuf *cellp = Gtk::manage(new Gtk::CellRendererPixbuf());

	cell->set_alignment(0, 0.5);
	cell->signal_edited().connect([this](const std::string& path,const std::string& name){ addedItem(path, name); });

	cid = append_column(*Gtk::manage(new Gtk::TreeViewColumn("Name")));	
	col = get_column(cid - 1);
	col->pack_start(*cellp);
	col->pack_start(*cell);
	col->add_attribute(cell->property_markup(), m_cols.name);
	col->add_attribute(cell->property_editable(), m_cols.editable);
	col->add_attribute(cellp->property_pixbuf(), m_cols.icon);

        // This really isn't "setupColumns" anymore from this point.
        // TODO Move to own function
	m_torrent_row = *(m_liststore->append());
	m_torrent_row[m_cols.name] = "Torrents";
	m_torrent_row[m_cols.editable] = false;
	m_torrent_row[m_cols.clickCallback] = [](){}; // clicks on titles don't do shit

	auto torrent_icon = Gdk::Pixbuf::create_from_resource("/org/gtk/gtorrent/icon-torrent.png");
	auto torrent_icon_scaled =  torrent_icon->scale_simple(16, 16, Gdk::INTERP_BILINEAR);
	m_torrent_row[m_cols.icon] = torrent_icon_scaled;

        // XXX TMP WILL REMOVE AND REPLACE WITH PROPER FUNCTION
        // Yes this is horrible. Bear with it for now.
        auto g = Application::getSingleton()->getCore()->getAllTorrents();
	Gtk::TreeModel::Row row = *(m_liststore->append(m_torrent_row.children()));
	row[m_cols.name] = "All";
	row[m_cols.title] = "All";
	row[m_cols.group] = g;
	row[m_cols.group_vector] = &g->m_torrents_all;

	Gtk::TreeModel::Row row2 = *(m_liststore->append(row.children()));
	row2[m_cols.name] = "Downloading";
	row2[m_cols.title] = "Downloading";
	row2[m_cols.group_vector] = &g->m_torrents_downloading;
        row2 = *(m_liststore->append(row.children()));
        row2[m_cols.name] = "Seeding";
        row2[m_cols.title] = "Seeding";
        row2[m_cols.group_vector] = &g->m_torrents_seeding;
        row2 = *(m_liststore->append(row.children()));
        row2[m_cols.name] = "Checking";
        row2[m_cols.title] = "Checking";
        row2[m_cols.group_vector] = &g->m_torrents_checking;
        row2 = *(m_liststore->append(row.children()));
        row2[m_cols.name] = "Finished";
        row2[m_cols.title] = "Finished";
        row2[m_cols.group_vector] = &g->m_torrents_finished;
        row2 = *(m_liststore->append(row.children()));
        row2[m_cols.name] = "Stopped";
        row2[m_cols.title] = "Stopped";
        row2[m_cols.group_vector] = &g->m_torrents_stopped;
        row2 = *(m_liststore->append(row.children()));
        row2[m_cols.name] = "Paused";
        row2[m_cols.title] = "Paused";
        row2[m_cols.group_vector] = &g->m_torrents_paused;

        // End of new horrible code
        // Continue horrible code from before
	//row = *(m_liststore->append(m_torrent_row.children()));
	//row[m_cols.name] = "Add a label";
	//row[m_cols.editable] = true;
	//row[m_cols.icon] = Gtk::IconTheme::get_default()->lookup_icon("list-add-symbolic", 16, Gtk::ICON_LOOKUP_USE_BUILTIN).load_icon();
	//row[m_cols.clickCallback] = [row](){};

	m_rssfeed_row = *(m_liststore->append());
	m_rssfeed_row[m_cols.name] = "RSS Feeds";
	m_rssfeed_row[m_cols.editable] = false;
	m_rssfeed_row[m_cols.clickCallback] = [](){};

	auto rss_icon = Gdk::Pixbuf::create_from_resource("/org/gtk/gtorrent/icon-rss.png");
	auto rss_icon_scaled =  rss_icon->scale_simple(16, 16, Gdk::INTERP_BILINEAR);
	m_rssfeed_row[m_cols.icon] = rss_icon_scaled;

	for(auto fg : Application::getSingleton()->getCore()->m_feeds)
	{
		row = *(m_liststore->append(m_rssfeed_row.children()));
		row[m_cols.name] = fg->name;
		row[m_cols.editable] = false;
		// TODO change icon to some sort of generic RSS icon
		row[m_cols.clickCallback] = [this, fg](){m_rss->run(fg->name);m_rss->hide();};

	}
	
	row = *(m_liststore->append(m_rssfeed_row.children()));
	row[m_cols.name] = "Add an RSS group";
	row[m_cols.editable] = true;

	row[m_cols.icon] = Gtk::IconTheme::get_default()->lookup_icon("list-add-symbolic", 16, Gtk::ICON_LOOKUP_USE_BUILTIN).load_icon();
	row[m_cols.clickCallback] = [row](){};

	//Maybe migrate settings there
/*	row = *(m_liststore->append());
	row[m_cols.name] = "Settings";
	row[m_cols.title] = true;
	row[m_cols.clickCallback] = [](){}; // clicks on titles don't do shit*/
}
Exemplo n.º 6
0
MessagesList::MessagesList(Gtk::Window* pParent) : bTimeStamp(false)
{
    m_pParent = pParent;

    /* Create a new scrolled window, with scrollbars only if needed */
    set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
    add(m_TreeView);

    /* create list store */
    m_refListStore = Gtk::ListStore::create(m_Columns);
    m_TreeView.set_model(m_refListStore);

    //Add the Model’s column to the View’s columns:
    Gtk::CellRendererText* textRenderer = Gtk::manage(new Gtk::CellRendererText());
    Gtk::TreeViewColumn* col = Gtk::manage(new Gtk::TreeViewColumn("Messages")); 
    textRenderer->property_editable() = false;
    col->pack_start(*textRenderer, true);
    col->add_attribute(*textRenderer, "text", 0);
    col->add_attribute(*textRenderer, "background-gdk", 1);
    m_TreeView.append_column(*col);
    m_TreeView.set_headers_visible(false);


    // adding popup menubar
    m_refActionGroup = Gtk::ActionGroup::create();
    m_refActionGroup->add( Gtk::Action::create("PMenuClear", Gtk::Stock::CLEAR, "_Clear log", "Clear log"),
                            sigc::mem_fun(*this, &MessagesList::onPMenuClear) );
    m_refActionGroup->add( Gtk::Action::create("PMenueSave", Gtk::Stock::SAVE, "_Save log...", "Save log..."),
                            sigc::mem_fun(*this, &MessagesList::onPMenuSave) );

    m_refUIManager = Gtk::UIManager::create();
    m_refUIManager->insert_action_group(m_refActionGroup);
    if(m_pParent)
        m_pParent->add_accel_group(m_refUIManager->get_accel_group());
    Glib::ustring ui_info =
        "<ui>"
        " <popup name='PopupMenu'>"
        "      <menuitem action='PMenuClear'/>"
        "      <menuitem action='PMenueSave'/>"
        " </popup>"
        "</ui>";


#ifdef GLIBMM_EXCEPTIONS_ENABLED
    try
    {
        m_refUIManager->add_ui_from_string(ui_info);
    }
    catch(const Glib::Error& ex)
    {
        std::cerr << "building popup menus failed: " << ex.what();
    }
#else
    std::auto_ptr<Glib::Error> ex;
    m_refUIManager->add_ui_from_string(ui_info, ex);
    if(ex.get())
    {
        std::cerr << "building popu menus failed: " << ex->what();
    }   
#endif //GLIBMM_EXCEPTIONS_ENABLED


    m_TreeView.signal_button_press_event().connect_notify(sigc::mem_fun(*this,
            &MessagesList::onTreeButtonPressed) );

    show_all_children();
}
Exemplo n.º 7
0
ModulePropertyWindow::ModulePropertyWindow(MainWindow* parent, 
                               Manager* manager, ApplicationWindow* appWnd) : m_pModule(NULL)
{   
    m_pParent = parent;
    m_pManager = manager;
    m_pModule = NULL;
    m_pAppWindow = appWnd;


    /* Create a new scrolled window, with scrollbars only if needed */
    set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
    add(m_TreeView);

    /* create tree store */
    m_refTreeModel = Gtk::TreeStore::create(m_Columns);
    m_TreeView.set_model(m_refTreeModel);

    //Add the Model’s column to the View’s columns: 
    Gtk::CellRendererText* itemRenderer = Gtk::manage(new Gtk::CellRendererText());
    itemRenderer->property_editable() = false;
    Gtk::TreeViewColumn* itemCol = Gtk::manage(new Gtk::TreeViewColumn("Property", *itemRenderer));
    itemCol->add_attribute(*itemRenderer, "foreground-gdk", m_Columns.m_col_color_item);
    itemCol->add_attribute(*itemRenderer, "text", m_Columns.m_col_name);
    itemCol->set_resizable(true);
    m_TreeView.append_column(*itemCol);


    Gtk::CellRendererCombo* valueRenderer = Gtk::manage(new Gtk::CellRendererCombo());
    Gtk::TreeView::Column* valueCol = Gtk::manage(new Gtk::TreeView::Column("Value"));
    valueCol->pack_start(*valueRenderer);
    valueCol->add_attribute(*valueRenderer, "foreground-gdk", m_Columns.m_col_color_value);
    //valueCol->set_resizable(true);
    valueCol->add_attribute(*valueRenderer, "editable", m_Columns.m_col_editable);   

  //Make this View column represent the m_col_itemchosen model column:
#ifdef GLIBMM_PROPERTIES_ENABLED
  valueCol->add_attribute(valueRenderer->property_text(), m_Columns.m_col_value);
#else
  pColumn->add_attribute(*valueRenderer, "text", m_Columns.m_col_value);
#endif

#ifdef GLIBMM_PROPERTIES_ENABLED
    valueCol->add_attribute(valueRenderer->property_model(), m_Columns.m_col_choices);
#else
    valueCol->add_attribute(*valueRenderer, "model", m_Columns.m_col_choices);
#endif 

#ifdef GLIBMM_PROPERTIES_ENABLED
    valueRenderer->property_text_column() = 0; 
#else
    valueRenderer->set_property("text_column", 0);
#endif
    valueRenderer->signal_edited().connect( sigc::mem_fun(*this,
              &ModulePropertyWindow::onCellEdited) );
    m_TreeView.append_column(*valueCol);

    m_TreeView.set_grid_lines(Gtk::TREE_VIEW_GRID_LINES_BOTH);
    m_TreeView.set_rules_hint(true);

    show_all_children();
}