gtktreeview 迴圈該怎麼放?
請問一下
我的程式如下
**********************************************************************************************
//gcc test.c -o test `pkg-config --cflags --libs gtk+-2.0`//
#include <gtk/gtk.h>
#include <stdio.h>
enum
{
col_ssid = 0,
col_strength,
col_security,
n_cols
};
void iwlist( GtkWidget *widget, gpointer data )
{
system("iwlist wlan0 scanning |grep -c ESSID");
//計算ssid 個數//
system("iwlist wlan0 scanning |grep ESSID |cut -c 28-|sed 's/.$//'>ssid");
//取得ssid 名稱//
system("iwconfig wlan0 essid #entry_text");
//希望能把ssid 帶入 #entry_text
system("dhclient wlan0");
}
void entry( GtkWidget *widget,GtkWidget *entry )
{
const gchar *entry_text;
entry_text = gtk_entry_get_text (GTK_ENTRY (entry));
}
int main( int argc,char *argv[] )
{
GtkWidget *main_window;
GtkWidget *hbox;
GtkWidget *left_vbox;
GtkWidget *frame;
GtkWidget *alignment;
GtkWidget *scrolledwindow;
GtkWidget *treeview;
GtkWidget *ap_list_label;
GtkWidget *left_hbox;
GtkWidget *pass;
GtkWidget *exit;
GtkWidget *connect;
GtkWidget *right_vbox;
GtkWidget *assign_ap_label;
GtkWidget *entry;
GtkWidget *scan;
gint i,count,strength;
gchar ssid;
gtk_init (&argc, &argv);
main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
hbox = gtk_hbox_new (FALSE, 0);
left_vbox = gtk_vbox_new (FALSE, 0);
frame = gtk_frame_new (NULL);
alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
treeview = gtk_tree_view_new ();
ap_list_label = gtk_label_new (("<b>AP List</b>"));
left_hbox = gtk_hbox_new (FALSE, 0);
pass = gtk_button_new_with_mnemonic (("Pass"));
exit = gtk_button_new_with_mnemonic (("Exit"));
connect = gtk_button_new_with_mnemonic (("Connect"));
right_vbox = gtk_vbox_new (FALSE, 0);
assign_ap_label = gtk_label_new (("AP Name"));
entry = gtk_entry_new ();
scan = gtk_button_new_with_mnemonic (("Scan AP"));
gtk_container_add (GTK_CONTAINER (main_window), hbox);
gtk_container_add (GTK_CONTAINER (frame),alignment);
gtk_container_add (GTK_CONTAINER (scrolledwindow), treeview);
gtk_container_add (GTK_CONTAINER (alignment), scrolledwindow);
gtk_box_pack_start (GTK_BOX (hbox),left_vbox, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (left_vbox),frame, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (left_vbox), left_hbox, FALSE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (left_hbox),pass, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (left_hbox),exit, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (left_hbox),connect, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), right_vbox, FALSE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (right_vbox), assign_ap_label, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (right_vbox), entry, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (right_vbox), scan, FALSE, FALSE, 0);
gtk_entry_set_max_length (GTK_ENTRY (entry), 3);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
gtk_frame_set_label_widget (GTK_FRAME (frame), ap_list_label);
gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_SHADOW_IN);
gtk_label_set_use_markup (GTK_LABEL (ap_list_label), TRUE);
gtk_window_set_default_size(GTK_WINDOW(main_window), 500, 250);
gtk_widget_set_size_request (right_vbox, 300, -1);
gtk_widget_set_size_request (left_hbox, -1, 60);
gtk_widget_set_size_request (scan, -1, 80);
gtk_widget_set_size_request (entry, -1, 50);
gtk_widget_show_all (main_window);
g_signal_connect_swapped (G_OBJECT (scan), "clicked", G_CALLBACK (iwlist), main_window);
g_signal_connect ((gpointer) exit, "clicked",G_CALLBACK (gtk_main_quit),NULL);
g_signal_connect (G_OBJECT (entry), "activate",G_CALLBACK (entry),entry);
////////////////////////////////////////////////////////////////////////////////////////////////
GtkTreeModel* create_model()
{
GtkListStore *store= gtk_list_store_new (n_cols,G_TYPE_STRING,G_TYPE_UINT,G_TYPE_STRING);;
return GTK_TREE_MODEL(store);
}
void list_view(GtkWidget* treeview)
{
GtkCellRenderer* renderer= gtk_cell_renderer_text_new ();;
gtk_tree_view_insert_column_with_attributes(
GTK_TREE_VIEW(treeview), -1, "ESSID", renderer, "text", col_ssid, NULL);
gtk_tree_view_insert_column_with_attributes(
GTK_TREE_VIEW(treeview), -1, "STRENGTH", renderer, "text", col_strength, NULL);
gtk_tree_view_insert_column_with_attributes(
GTK_TREE_VIEW(treeview), -1, "Security", renderer, "text", col_security, NULL);
}
void list(GtkTreeModel* store,const gchar* ssid, const guint strength,const gchar* security )
{
gtk_list_store_append(GTK_LIST_STORE(store), &iter);
gtk_list_store_set(GTK_LIST_STORE(store), &iter,
col_ssid, ssid,
col_strength, strength,
col_security, security,
-1);
}
list_view(treeview);
GtkTreeModel* store = create_model();
gtk_tree_view_set_model ( GTK_TREE_VIEW(treeview), store);
list(store,"ssid",strength,"secutiry");
g_object_unref( store );
///////////////////////////////////////////////////////////////////////////////////
gtk_main ();
return 0;
}
**********************************************************************************************
請問一下,我想把拿到得ssid 名稱填到treeview 裡面,我應該怎麼做阿?
並且能訂時更新?
謝謝
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论