在任务栏显示网速
Tofloor
poster avatar
海天鹰
deepin
2016-05-15 00:43
Author
已经移植GTK网速到 StartOS 的 GNOME Panel Applet ,可以在任务栏显示网速,求教程移植到Deepin!





官方文档:https://projects.gnome.org/ORBit2/appletstutorial.html


需要安装以下库:
Ubuntu:libpanel-applet

StartOS:
gnome-panel-dev
gconf-dev
gorbit-dev
libbonobo-dev
libbonoboui-dev
libgnomecanvas-dev
libart-lgpl-dev
gnome-vfs-dev
libcanberra-dev
popt-dev


信息文件路径:/usr/lib/bonobo/servers/*.server
内容:

   
        
               
               
        
        
        
   

   
        
               
               
               
        
        
        
        
        
   



程序内容:
#include
#include
#include
GtkWidget *label;
long long r1=0,t1=0,r0=0,t0=0;

char *B2G(long long b)
{
static char g[10];
if(b>999999999){
  sprintf(g,"%.2fGB",(float)b/1073741824);
}else{
  if(b>999999){
   sprintf(g,"%.2fMB",(float)b/1048576);
  }else{
   if(b>999){
    sprintf(g,"%.2fKB",(float)b/1024);
   }else{
    sprintf(g,"%dB",b);
   }
  }
}
return g;
}

void netdev()
{
FILE *fp;
char ch[150],ch4[150],itf[10];
int r2,r3,r4,r5,r6,r7,r8,t2,t3,t4,t5,t6,t7,t8;
fp=fopen("/proc/net/dev","r");
fgets(ch,sizeof(ch),fp);
fgets(ch,sizeof(ch),fp);
fgets(ch,sizeof(ch),fp); //deepin delete this line
fgets(ch4,sizeof(ch4),fp);
fclose(fp);
//printf("%s\n",ch4);
sscanf(ch4,"%s%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d",itf,&r1,&r2,&r3,&r4,&r5,&r6,&r7,&r8,&t1,&t2,&t3,&t4,&t5,&t6,&t7,&t8);
//printf("%d,%d\n",r1,t1);
}

gint settime(gpointer data)
{
char lt[50],cr[10],ct[10],crs[10],cts[10];
int rs,ts;
netdev();
rs=r1-r0;
ts=t1-t0;
strcpy(cr,B2G(r1));
strcpy(ct,B2G(t1));
strcpy(crs,B2G(rs));
strcpy(cts,B2G(ts));
sprintf(lt,"D:%s/s\nU:%s/s",crs,cts);
g_message(lt);
gtk_label_set_text(GTK_LABEL(label),lt);
r0=r1;
t0=t1;
return TRUE;
}

static gboolean myexample_applet_fill (PanelApplet *applet, const gchar *iid, gpointer data)
{

        if (strcmp (iid, "OAFIID:ExampleApplet") != 0)
                return FALSE;
        label = gtk_label_new ("D:0B/s\nU:0B/s");
        gtk_container_add (GTK_CONTAINER (applet), label);
        gtk_widget_show_all (GTK_WIDGET (applet));
gint s=g_timeout_add(1000,settime,NULL);
        return TRUE;
}
PANEL_APPLET_BONOBO_FACTORY ("OAFIID:ExampleApplet_Factory", PANEL_TYPE_APPLET, "The Hello World Applet", "0", myexample_applet_fill, NULL);


Reply Favorite View the author
All Replies
avatar
186******00
deepin
2016-05-15 07:39
#1
startos现在还有人维护???
Reply View the author
avatar
MatchYangWanQing
deepin
2016-05-15 08:20
#2
Dock插件开发文档https://github.com/linuxdeepin/developer-center/wiki/DDE-Dock-Plugin-Development
Reply View the author
avatar
jingle
deepin
2016-05-15 16:27
#3
顶楼上,希望感兴趣的自己动手试试。
Reply View the author
avatar
海天鹰
deepin
2016-05-16 16:23
#4
https://bbs.deepin.org/post/39434
Dock插件开发文档https://github.com/linuxdeepin/developer-center/wiki/DDE-Dock-Plugin-Development ...

非常感谢!
Reply View the author
avatar
海天鹰
deepin
2016-05-16 16:24
#5
https://bbs.deepin.org/post/39434
startos现在还有人维护???

编个小程序而已。
Reply View the author
avatar
iiLinux
deepin
2016-10-12 18:48
#6
嗯,先回复试试看@~@.qkt8
Reply View the author