├── AUTHORS ├── COPYING ├── ChangeLog ├── Makefile.am ├── NEWS ├── README ├── autogen.sh ├── configure.ac.in ├── icons ├── 16x16 │ ├── Makefile.am │ └── xfce4-netspeed-plugin.png ├── 22x22 │ ├── Makefile.am │ └── xfce4-netspeed-plugin.png ├── 48x48 │ ├── Makefile.am │ └── xfce4-netspeed-plugin.png └── Makefile.am ├── panel-plugin ├── Makefile.am ├── configure.c ├── configure.h ├── device_info.c ├── device_info.h ├── options.c ├── options.h ├── utils.c ├── utils.h ├── xfce4-netspeed-plugin.desktop.in.in ├── xfce4_netspeed_plugin.c └── xfce4_netspeed_plugin.h └── po └── POTFILES.in /AUTHORS: -------------------------------------------------------------------------------- 1 | Authors: 2 | Calin Crisan 3 | 4 | Thanks to: 5 | Jörgen Scheibengruber (Gnome's NetSpeed applet) 6 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) year name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | @SET_MAKE@ 2 | 3 | SUBDIRS = panel-plugin po icons 4 | 5 | distclean-local: 6 | rm -rf *.cache *~ 7 | 8 | dist-bz2: dist 9 | zcat $(PACKAGE)-$(VERSION).tar.gz | bzip2 --best -c > $(PACKAGE)-$(VERSION).tar.bz2 10 | 11 | distcheck-bz2: distcheck 12 | zcat $(PACKAGE)-$(VERSION).tar.gz | bzip2 --best -c > $(PACKAGE)-$(VERSION).tar.bz2 13 | 14 | EXTRA_DIST = \ 15 | README \ 16 | intltool-extract.in \ 17 | intltool-merge.in \ 18 | intltool-update.in 19 | 20 | DISTCLEANFILES = \ 21 | intltool-extract \ 22 | intltool-merge \ 23 | intltool-update 24 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccrisan/xfce4-netspeed-plugin/77751f83c4f5737dc1b1af12ad0d0567cc2b18b2/NEWS -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | ********************************************* 2 | *********** xfce4-netspeed-plugin ********** 3 | ********************************************* 4 | 5 | xfce4-netspeed-plugin shows the instant download / upload speed in the Xfce Panel. 6 | 7 | ** Requirements ** 8 | 9 | * libxfce4util 4.3.90 10 | * libxfce4ui 4.3.90 11 | * libxfce4panel 4.3.90 12 | * libgtop 2.0 13 | 14 | ** Building ** 15 | 16 | ./configure 17 | make 18 | make install (as root) 19 | 20 | ** Usage ** 21 | 22 | After properly installing it, you should find this plugin in the "Add New Items..." Xfce Panel dialog, 23 | under the name "Network Speed Plugin". You can then tweak the plugin using the configuration dialog. 24 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2002-2009 4 | # The Xfce development team. All rights reserved. 5 | # 6 | # Written for Xfce by Benedikt Meurer . 7 | 8 | export XDT_AUTOGEN_REQUIRED_VERSION="4.7.0" 9 | 10 | (type xdt-autogen) >/dev/null 2>&1 || { 11 | cat >&2 <]) 11 | AC_INIT([xfce4-netspeed-plugin], [xfce4_netspeed_plugin_version()], 12 | [ccrisan@gmail.com]) 13 | 14 | dnl Initialize automake 15 | AM_INIT_AUTOMAKE([AC_PACKAGE_TARNAME()], [AC_PACKAGE_VERSION()]) 16 | AM_CONFIG_HEADER([config.h]) 17 | AM_MAINTAINER_MODE() 18 | 19 | dnl Check for basic programs 20 | AC_PROG_CC 21 | #AM_PROG_CC_C_O 22 | AC_PROG_INSTALL 23 | AC_PROG_INTLTOOL() 24 | 25 | dnl Check for libtool 26 | LT_PREREQ([2.2.6]) 27 | LT_INIT([disable-static]) 28 | 29 | dnl Check for i18n support 30 | XDT_I18N([@LINGUAS@]) 31 | 32 | dnl configure the panel plugin 33 | XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.6.0]) 34 | XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.6.0]) 35 | XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.8.0]) 36 | XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-1], [4.8.0]) 37 | XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-1.0], [4.8.0]) 38 | XDT_CHECK_PACKAGE([LIBGTOP], [libgtop-2.0], [2.0.0]) 39 | 40 | AC_OUTPUT([ 41 | Makefile 42 | panel-plugin/Makefile 43 | icons/Makefile 44 | icons/16x16/Makefile 45 | icons/22x22/Makefile 46 | icons/48x48/Makefile 47 | po/Makefile.in 48 | ]) 49 | -------------------------------------------------------------------------------- /icons/16x16/Makefile.am: -------------------------------------------------------------------------------- 1 | iconsdir = $(datadir)/icons/hicolor/16x16/apps 2 | 3 | icons_DATA = \ 4 | xfce4-netspeed-plugin.png 5 | 6 | EXTRA_DIST = \ 7 | $(icons_DATA) 8 | -------------------------------------------------------------------------------- /icons/16x16/xfce4-netspeed-plugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccrisan/xfce4-netspeed-plugin/77751f83c4f5737dc1b1af12ad0d0567cc2b18b2/icons/16x16/xfce4-netspeed-plugin.png -------------------------------------------------------------------------------- /icons/22x22/Makefile.am: -------------------------------------------------------------------------------- 1 | iconsdir = $(datadir)/icons/hicolor/22x22/apps 2 | 3 | icons_DATA = \ 4 | xfce4-netspeed-plugin.png 5 | 6 | EXTRA_DIST = \ 7 | $(icons_DATA) 8 | -------------------------------------------------------------------------------- /icons/22x22/xfce4-netspeed-plugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccrisan/xfce4-netspeed-plugin/77751f83c4f5737dc1b1af12ad0d0567cc2b18b2/icons/22x22/xfce4-netspeed-plugin.png -------------------------------------------------------------------------------- /icons/48x48/Makefile.am: -------------------------------------------------------------------------------- 1 | iconsdir = $(datadir)/icons/hicolor/48x48/apps 2 | 3 | icons_DATA = \ 4 | xfce4-netspeed-plugin.png 5 | 6 | EXTRA_DIST = \ 7 | $(icons_DATA) 8 | -------------------------------------------------------------------------------- /icons/48x48/xfce4-netspeed-plugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccrisan/xfce4-netspeed-plugin/77751f83c4f5737dc1b1af12ad0d0567cc2b18b2/icons/48x48/xfce4-netspeed-plugin.png -------------------------------------------------------------------------------- /icons/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = \ 2 | 16x16 \ 3 | 22x22 \ 4 | 48x48 5 | 6 | gtk_update_icon_cache = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor 7 | 8 | install-data-hook: 9 | @-if test -z "$(DESTDIR)"; then \ 10 | echo "Updating Gtk icon cache."; \ 11 | $(gtk_update_icon_cache); \ 12 | else \ 13 | echo "*** Icon cache not updated. Remember to run:"; \ 14 | echo "***"; \ 15 | echo "*** $(gtk_update_icon_cache)"; \ 16 | echo "***"; \ 17 | fi 18 | -------------------------------------------------------------------------------- /panel-plugin/Makefile.am: -------------------------------------------------------------------------------- 1 | plugindir = $(libexecdir)/xfce4/panel-plugins 2 | plugin_PROGRAMS = xfce4-netspeed-plugin 3 | 4 | xfce4_netspeed_plugin_CFLAGS = \ 5 | -I$(top_srcdir) \ 6 | @LIBXFCE4PANEL_CFLAGS@ \ 7 | @LIBXFCE4UTIL_CFLAGS@ \ 8 | @LIBXFCE4UI_CFLAGS@ \ 9 | @LIBGTOP_CFLAGS@ \ 10 | -DPACKAGE_LOCALE_DIR=\"$(localedir)\" 11 | 12 | xfce4_netspeed_plugin_LDADD = \ 13 | @LIBXFCE4PANEL_LIBS@ \ 14 | @LIBXFCE4UTIL_LIBS@ \ 15 | @LIBXFCE4UI_LIBS@ \ 16 | @LIBGTOP_LIBS@ 17 | 18 | xfce4_netspeed_plugin_SOURCES = \ 19 | xfce4_netspeed_plugin.h \ 20 | xfce4_netspeed_plugin.c \ 21 | options.h \ 22 | options.c \ 23 | device_info.h \ 24 | device_info.c \ 25 | utils.h \ 26 | utils.c \ 27 | configure.h \ 28 | configure.c 29 | 30 | desktop_in_in_files = xfce4-netspeed-plugin.desktop.in.in 31 | desktop_in_files = $(desktop_in_in_files:.desktop.in.in=.desktop.in) 32 | 33 | desktopdir = $(datadir)/xfce4/panel-plugins 34 | desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) 35 | @INTLTOOL_DESKTOP_RULE@ 36 | 37 | EXTRA_DIST = \ 38 | $(desktop_in_in_files) 39 | 40 | DISTCLEANFILES = \ 41 | $(desktop_DATA) $(desktop_in_files) 42 | 43 | # get full path into .desktop file 44 | %.desktop.in: %.desktop.in.in 45 | sed -e "s^@PLUGIN_PATH@^$(libexecdir)/xfce4/panel-plugins^" \ 46 | $< > $@ 47 | -------------------------------------------------------------------------------- /panel-plugin/configure.c: -------------------------------------------------------------------------------- 1 | /* xfce4-netspeed-plugin 2 | * 3 | * Copyright (c) 2011 Calin Crisan 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include 22 | #endif 23 | 24 | #include 25 | 26 | #include "configure.h" 27 | 28 | #ifndef _ 29 | # include 30 | # define _(String) gettext (String) 31 | #endif 32 | 33 | 34 | static void net_speed_configure_response(GtkWidget *dialog, int response, NetSpeedConfigure *net_speed_configure); 35 | static void net_speed_configure_changed(GtkWidget *widget, NetSpeedConfigure *net_speed_configure); 36 | 37 | 38 | static void net_speed_configure_response(GtkWidget *dialog, int response, NetSpeedConfigure *net_speed_configure) { 39 | NetSpeedPlugin *net_speed_plugin = net_speed_configure->net_speed_plugin; 40 | 41 | xfce_panel_plugin_unblock_menu(net_speed_plugin->plugin); 42 | 43 | gtk_widget_destroy(dialog); 44 | 45 | net_speed_options_save(net_speed_plugin->options, net_speed_plugin->plugin); 46 | 47 | g_free(net_speed_configure); 48 | } 49 | 50 | static void net_speed_configure_changed(GtkWidget *widget, NetSpeedConfigure *net_speed_configure) { 51 | NetSpeedPlugin *net_speed_plugin = net_speed_configure->net_speed_plugin; 52 | 53 | /* device */ 54 | if (net_speed_plugin->options->device) { 55 | g_free(net_speed_plugin->options->device); 56 | } 57 | if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(net_speed_configure->auto_device_check_button))) { 58 | gtk_widget_set_sensitive(net_speed_configure->device_combo, FALSE); 59 | net_speed_plugin->options->device_auto = TRUE; 60 | net_speed_plugin->options->device = NULL; 61 | } 62 | else { 63 | gtk_widget_set_sensitive(net_speed_configure->device_combo, TRUE); 64 | net_speed_plugin->options->device_auto = FALSE; 65 | net_speed_plugin->options->device = 66 | gtk_combo_box_get_active_text(GTK_COMBO_BOX(net_speed_configure->device_combo)); 67 | } 68 | 69 | /* show frame */ 70 | net_speed_plugin->options->show_frame = 71 | gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(net_speed_configure->show_frame_check_button)); 72 | 73 | /* show icon */ 74 | net_speed_plugin->options->show_icon = 75 | gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(net_speed_configure->show_icon_check_button)); 76 | 77 | /* show bits */ 78 | net_speed_plugin->options->show_bits = 79 | gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(net_speed_configure->show_bits_check_button)); 80 | 81 | /* show sum */ 82 | net_speed_plugin->options->show_sum = 83 | gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(net_speed_configure->show_sum_check_button)); 84 | 85 | /* fixed width */ 86 | if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(net_speed_configure->fixed_width_check_button))) { 87 | net_speed_plugin->options->fixed_width = 88 | gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(net_speed_configure->fixed_width_spin_button)); 89 | gtk_widget_set_sensitive(net_speed_configure->fixed_width_spin_button, TRUE); 90 | } 91 | else { 92 | net_speed_plugin->options->fixed_width = 0; 93 | gtk_widget_set_sensitive(net_speed_configure->fixed_width_spin_button, FALSE); 94 | } 95 | 96 | net_speed_update_options(net_speed_plugin); 97 | } 98 | 99 | void net_speed_configure_show(XfcePanelPlugin *plugin, NetSpeedPlugin *net_speed_plugin) { 100 | GtkWidget *dialog; 101 | GtkWidget *dialog_vbox; 102 | GtkWidget *hbox; 103 | GtkWidget *label; 104 | GtkWidget *combo; 105 | GtkWidget *button; 106 | 107 | /* net speed configure */ 108 | NetSpeedConfigure *net_speed_configure = g_new0(NetSpeedConfigure, 1); 109 | net_speed_configure->net_speed_plugin = net_speed_plugin; 110 | 111 | /* dialog */ 112 | xfce_panel_plugin_block_menu(net_speed_plugin->plugin); 113 | net_speed_configure->dialog = dialog = xfce_titled_dialog_new_with_buttons(_("Network Speed Plugin"), 114 | NULL, GTK_DIALOG_NO_SEPARATOR, GTK_STOCK_CLOSE, GTK_RESPONSE_OK, NULL); 115 | xfce_titled_dialog_set_subtitle(XFCE_TITLED_DIALOG(dialog), _("Configuration")); 116 | 117 | gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); 118 | gtk_window_set_icon_name(GTK_WINDOW(dialog), "xfce4-netspeed-plugin"); 119 | gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE); 120 | gtk_window_stick(GTK_WINDOW(dialog)); 121 | 122 | dialog_vbox = GTK_DIALOG(dialog)->vbox; 123 | 124 | /* auto-device */ 125 | hbox = gtk_hbox_new(FALSE, 3); 126 | gtk_container_add(GTK_CONTAINER(dialog_vbox), hbox); 127 | gtk_container_set_border_width(GTK_CONTAINER(hbox), 3); 128 | 129 | net_speed_configure->auto_device_check_button = button = gtk_check_button_new_with_mnemonic(_("Automatically Choose Network Device")); 130 | gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); 131 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), net_speed_plugin->options->device_auto == TRUE); 132 | g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(net_speed_configure_changed), net_speed_configure); 133 | 134 | /* device */ 135 | hbox = gtk_hbox_new(FALSE, 3); 136 | gtk_container_add(GTK_CONTAINER(dialog_vbox), hbox); 137 | gtk_container_set_border_width(GTK_CONTAINER(hbox), 3); 138 | 139 | label = gtk_label_new(_("Network Device:")); 140 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); 141 | 142 | net_speed_configure->device_combo = combo = gtk_combo_box_new_text(); 143 | gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, TRUE, 0); 144 | 145 | GList *device, *devices = device_info_list_get(); 146 | gint index = 0, sel_index = -1; 147 | for (device = devices; device != NULL; device = g_list_next(device)) { 148 | gtk_combo_box_append_text(GTK_COMBO_BOX(combo), device->data); 149 | if (net_speed_plugin->options->device && !strcmp(device->data, net_speed_plugin->options->device)) { 150 | sel_index = index; 151 | } 152 | index++; 153 | } 154 | gtk_combo_box_set_active(GTK_COMBO_BOX(combo), sel_index); 155 | g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(net_speed_configure_changed), net_speed_configure); 156 | device_info_list_free(devices); 157 | 158 | gtk_widget_set_sensitive(net_speed_configure->device_combo, net_speed_plugin->options->device != NULL); 159 | 160 | /* show frame */ 161 | hbox = gtk_hbox_new(FALSE, 3); 162 | gtk_container_add(GTK_CONTAINER(dialog_vbox), hbox); 163 | gtk_container_set_border_width(GTK_CONTAINER(hbox), 3); 164 | 165 | net_speed_configure->show_frame_check_button = button = gtk_check_button_new_with_mnemonic(_("Show Frame")); 166 | gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); 167 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), net_speed_plugin->options->show_frame); 168 | g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(net_speed_configure_changed), net_speed_configure); 169 | 170 | /* show icon */ 171 | hbox = gtk_hbox_new(FALSE, 3); 172 | gtk_container_add(GTK_CONTAINER(dialog_vbox), hbox); 173 | gtk_container_set_border_width(GTK_CONTAINER(hbox), 3); 174 | 175 | net_speed_configure->show_icon_check_button = button = gtk_check_button_new_with_mnemonic(_("Show Icon")); 176 | gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); 177 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), net_speed_plugin->options->show_icon); 178 | g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(net_speed_configure_changed), net_speed_configure); 179 | 180 | /* show bits */ 181 | hbox = gtk_hbox_new(FALSE, 3); 182 | gtk_container_add(GTK_CONTAINER(dialog_vbox), hbox); 183 | gtk_container_set_border_width(GTK_CONTAINER(hbox), 3); 184 | 185 | net_speed_configure->show_bits_check_button = button = gtk_check_button_new_with_mnemonic(_("Show Bits Instead of Bytes")); 186 | gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); 187 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), net_speed_plugin->options->show_bits); 188 | g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(net_speed_configure_changed), net_speed_configure); 189 | 190 | /* show sum */ 191 | hbox = gtk_hbox_new(FALSE, 3); 192 | gtk_container_add(GTK_CONTAINER(dialog_vbox), hbox); 193 | gtk_container_set_border_width(GTK_CONTAINER(hbox), 3); 194 | 195 | net_speed_configure->show_sum_check_button = button = gtk_check_button_new_with_mnemonic(_("Show Sum of Download and Upload")); 196 | gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); 197 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), net_speed_plugin->options->show_sum); 198 | g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(net_speed_configure_changed), net_speed_configure); 199 | 200 | /* fixed width check button */ 201 | hbox = gtk_hbox_new(FALSE, 3); 202 | gtk_container_add(GTK_CONTAINER(dialog_vbox), hbox); 203 | gtk_container_set_border_width(GTK_CONTAINER(hbox), 3); 204 | 205 | net_speed_configure->fixed_width_check_button = button = gtk_check_button_new_with_mnemonic(_("Fixed Width")); 206 | gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); 207 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), (gboolean) net_speed_plugin->options->fixed_width); 208 | g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(net_speed_configure_changed), net_speed_configure); 209 | 210 | net_speed_configure->fixed_width_spin_button = button = gtk_spin_button_new_with_range(20, 500, 10); 211 | gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); 212 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(button), (gdouble) net_speed_plugin->options->fixed_width); 213 | g_signal_connect(G_OBJECT(button), "value-changed", G_CALLBACK(net_speed_configure_changed), net_speed_configure); 214 | 215 | g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(net_speed_configure_response), net_speed_configure); 216 | 217 | gtk_widget_show_all(dialog); 218 | } 219 | -------------------------------------------------------------------------------- /panel-plugin/configure.h: -------------------------------------------------------------------------------- 1 | /* xfce4-netspeed-plugin 2 | * 3 | * Copyright (c) 2011 Calin Crisan 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef _CONFIGURE_H 21 | #define _CONFIGURE_H 22 | 23 | #include "xfce4_netspeed_plugin.h" 24 | 25 | typedef struct { 26 | 27 | GtkWidget *dialog; 28 | 29 | GtkWidget *auto_device_check_button; 30 | GtkWidget *device_combo; 31 | GtkWidget *refresh_interval_spinner; 32 | GtkWidget *show_frame_check_button; 33 | GtkWidget *show_icon_check_button; 34 | GtkWidget *show_bits_check_button; 35 | GtkWidget *show_sum_check_button; 36 | GtkWidget *fixed_width_check_button; 37 | GtkWidget *fixed_width_spin_button; 38 | 39 | NetSpeedPlugin *net_speed_plugin; 40 | 41 | } NetSpeedConfigure; 42 | 43 | 44 | void net_speed_configure_show(XfcePanelPlugin *plugin, NetSpeedPlugin *net_speed_plugin); 45 | 46 | #endif /* _CONFIGURE_H */ 47 | -------------------------------------------------------------------------------- /panel-plugin/device_info.c: -------------------------------------------------------------------------------- 1 | /* xfce4-netspeed-plugin 2 | * 3 | * Copyright (c) 2011 Calin Crisan 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include 22 | #endif 23 | 24 | 25 | #include 26 | #include 27 | 28 | #include "device_info.h" 29 | 30 | 31 | DeviceInfo *device_info_new(char *device) { 32 | DeviceInfo *device_info = g_new0(DeviceInfo, 1); 33 | 34 | device_info->name = g_strdup(device); 35 | device_info_fill(device_info); 36 | 37 | return device_info; 38 | } 39 | 40 | void device_info_free(DeviceInfo *device_info) { 41 | g_free(device_info->name); 42 | g_free(device_info); 43 | } 44 | 45 | void device_info_fill(DeviceInfo *device_info) { 46 | glibtop_netload netload; 47 | glibtop_get_netload(&netload, device_info->name); 48 | 49 | device_info->tx = netload.bytes_out; 50 | device_info->rx = netload.bytes_in; 51 | 52 | device_info->up = (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_UP) ? TRUE : FALSE); 53 | device_info->running = (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_RUNNING) ? TRUE : FALSE); 54 | 55 | if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_LOOPBACK)) { 56 | device_info->type = DEVICE_TYPE_LOOPBACK; 57 | } 58 | else if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_WIRELESS)) { 59 | device_info->type = DEVICE_TYPE_WIRELESS; 60 | } 61 | else if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_POINTOPOINT)) { 62 | if (g_str_has_prefix(device_info->name, "plip")) { 63 | device_info->type = DEVICE_TYPE_PLIP; 64 | } 65 | else if (g_str_has_prefix(device_info->name, "sl")) { 66 | device_info->type = DEVICE_TYPE_SLIP; 67 | } 68 | else { 69 | device_info->type = DEVICE_TYPE_PPP; 70 | } 71 | } 72 | else { 73 | device_info->type = DEVICE_TYPE_ETHERNET; 74 | } 75 | } 76 | 77 | GList* device_info_list_get() { 78 | glibtop_netlist netlist; 79 | char **devices, **dev; 80 | GList *device_glist = NULL; 81 | 82 | devices = glibtop_get_netlist(&netlist); 83 | 84 | for (dev = devices; *dev; ++dev) { 85 | device_glist = g_list_prepend(device_glist, g_strdup(*dev)); 86 | } 87 | 88 | g_strfreev(devices); 89 | 90 | return device_glist; 91 | } 92 | 93 | void device_info_list_free(GList *list) { 94 | g_list_foreach(list, (GFunc) g_free, NULL); 95 | g_list_free(list); 96 | } 97 | -------------------------------------------------------------------------------- /panel-plugin/device_info.h: -------------------------------------------------------------------------------- 1 | /* xfce4-netspeed-plugin 2 | * 3 | * Copyright (c) 2011 Calin Crisan 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef _DEVICE_INFO_H 21 | #define _DEVICE_INFO_H 22 | 23 | #include 24 | 25 | #define DEVICE_TYPE_UNKNOWN 0 26 | #define DEVICE_TYPE_LOOPBACK 1 27 | #define DEVICE_TYPE_PLIP 2 28 | #define DEVICE_TYPE_SLIP 3 29 | #define DEVICE_TYPE_PPP 4 30 | #define DEVICE_TYPE_ETHERNET 5 31 | #define DEVICE_TYPE_WIRELESS 6 32 | 33 | 34 | typedef struct { 35 | 36 | gchar *name; 37 | gint type; 38 | guint64 rx; 39 | guint64 tx; 40 | gboolean up; 41 | gboolean running; 42 | 43 | } DeviceInfo; 44 | 45 | 46 | DeviceInfo *device_info_new(char *device); 47 | void device_info_free(DeviceInfo *device_info); 48 | void device_info_fill(DeviceInfo *device_info); 49 | GList* device_info_list_get(); 50 | void device_info_list_free(GList* list); 51 | 52 | 53 | #endif /* _DEVICE_INFO_H */ 54 | -------------------------------------------------------------------------------- /panel-plugin/options.c: -------------------------------------------------------------------------------- 1 | /* xfce4-netspeed-plugin 2 | * 3 | * Copyright (c) 2011 Calin Crisan 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include 22 | #endif 23 | 24 | #include 25 | 26 | #include "options.h" 27 | 28 | NetSpeedOptions *net_speed_options_new() { 29 | NetSpeedOptions *options = g_new0(NetSpeedOptions, 1); 30 | 31 | return options; 32 | } 33 | 34 | void net_speed_options_free(NetSpeedOptions *options) { 35 | if (options->device) { 36 | g_free(options->device); 37 | } 38 | 39 | g_free(options); 40 | } 41 | 42 | gboolean net_speed_options_load(NetSpeedOptions *options, XfcePanelPlugin *plugin) { 43 | gchar *file = xfce_panel_plugin_save_location(plugin, FALSE); 44 | if (G_UNLIKELY(!file)) 45 | return FALSE; 46 | 47 | XfceRc *rc = xfce_rc_simple_open(file, FALSE); 48 | g_free(file); 49 | 50 | options->refresh_interval = REFRESH_INTERVAL; 51 | 52 | options->show_frame = xfce_rc_read_bool_entry(rc, "show_frame", TRUE); 53 | options->show_icon = xfce_rc_read_bool_entry(rc, "show_icon", TRUE); 54 | options->show_bits = xfce_rc_read_bool_entry(rc, "show_bits", FALSE); 55 | options->show_sum = xfce_rc_read_bool_entry(rc, "show_sum", FALSE); 56 | options->device_auto = xfce_rc_read_bool_entry(rc, "device_auto", TRUE); 57 | options->device = (gchar *) xfce_rc_read_entry(rc, "device", NULL); 58 | options->device = g_strdup(options->device); 59 | options->fixed_width = xfce_rc_read_int_entry(rc, "fixed_width", 0); 60 | 61 | xfce_rc_close(rc); 62 | 63 | return TRUE; 64 | } 65 | 66 | gboolean net_speed_options_save(NetSpeedOptions *options, XfcePanelPlugin *plugin) { 67 | gchar *file = xfce_panel_plugin_save_location(plugin, TRUE); 68 | if (G_UNLIKELY(!file)) 69 | return FALSE; 70 | 71 | XfceRc *rc = xfce_rc_simple_open(file, FALSE); 72 | g_free(file); 73 | 74 | xfce_rc_write_bool_entry(rc, "show_frame", options->show_frame); 75 | xfce_rc_write_bool_entry(rc, "show_icon", options->show_icon); 76 | xfce_rc_write_bool_entry(rc, "show_bits", options->show_bits); 77 | xfce_rc_write_bool_entry(rc, "show_sum", options->show_sum); 78 | xfce_rc_write_bool_entry(rc, "device_auto", options->device_auto); 79 | xfce_rc_write_entry(rc, "device", options->device ? options->device : ""); 80 | xfce_rc_write_int_entry(rc, "fixed_width", options->fixed_width); 81 | 82 | xfce_rc_close(rc); 83 | 84 | return TRUE; 85 | } 86 | -------------------------------------------------------------------------------- /panel-plugin/options.h: -------------------------------------------------------------------------------- 1 | /* xfce4-netspeed-plugin 2 | * 3 | * Copyright (c) 2011 Calin Crisan 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef _OPTIONS_H 21 | #define _OPTIONS_H 22 | 23 | #include 24 | #include 25 | 26 | #define REFRESH_INTERVAL 1000 /* 1000 milliseconds */ 27 | 28 | 29 | typedef struct { 30 | 31 | guint refresh_interval; 32 | gchar *device; 33 | gboolean device_auto; /* 'Automatically Choose Network Device' */ 34 | gboolean show_frame; 35 | gboolean show_icon; 36 | gboolean show_bits; /* instead of bytes */ 37 | gboolean show_sum; /* instead of separate rx, tx */ 38 | gint fixed_width; 39 | 40 | } NetSpeedOptions; 41 | 42 | 43 | NetSpeedOptions * net_speed_options_new(); 44 | void net_speed_options_free(NetSpeedOptions *options); 45 | gboolean net_speed_options_load(NetSpeedOptions *options, XfcePanelPlugin *plugin); 46 | gboolean net_speed_options_save(NetSpeedOptions *options, XfcePanelPlugin *plugin); 47 | 48 | #endif /* _OPTIONS_H */ 49 | -------------------------------------------------------------------------------- /panel-plugin/utils.c: -------------------------------------------------------------------------------- 1 | /* xfce4-netspeed-plugin 2 | * 3 | * Copyright (c) 2011 Calin Crisan 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include 22 | #endif 23 | 24 | #ifndef _ 25 | # include 26 | # define _(String) gettext (String) 27 | #endif 28 | 29 | #include "utils.h" 30 | 31 | 32 | gchar* bytes_to_string(double bytes, gboolean per_sec, gboolean bits) { 33 | const char *format; 34 | const char *unit; 35 | guint kilo; /* no really a kilo : a kilo or kibi */ 36 | 37 | if (bits) { 38 | bytes *= 8; 39 | kilo = 1000; 40 | } 41 | else { 42 | kilo = 1024; 43 | } 44 | 45 | if (bytes < kilo) { 46 | format = "%.0f %s"; 47 | 48 | if (per_sec) 49 | unit = bits ? _("b/s") : _("B/s"); 50 | 51 | else 52 | unit = bits ? _("bits") : _("bytes"); 53 | 54 | } 55 | else if (bytes < (kilo * kilo)) { 56 | format = (bytes < (100 * kilo)) ? "%.1f %s" : "%.0f %s"; 57 | bytes /= kilo; 58 | 59 | if (per_sec) 60 | unit = bits ? _("kb/s") : _("KiB/s"); 61 | 62 | else 63 | unit = bits ? _("kb") : _("KiB"); 64 | 65 | } 66 | else { 67 | format = "%.1f %s"; 68 | bytes /= kilo * kilo; 69 | 70 | if (per_sec) 71 | unit = bits ? _("Mb/s") : _("MiB/s"); 72 | 73 | else 74 | unit = bits ? _("Mb") : _("MiB"); 75 | } 76 | 77 | return g_strdup_printf(format, bytes, unit); 78 | } 79 | -------------------------------------------------------------------------------- /panel-plugin/utils.h: -------------------------------------------------------------------------------- 1 | /* xfce4-netspeed-plugin 2 | * 3 | * Copyright (c) 2011 Calin Crisan 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef _UTILS_H 21 | #define _UTILS_H 22 | 23 | #include 24 | 25 | /* Converts a number of bytes into a human 26 | * readable string - in [M/k]bytes[/s] 27 | * The string has to be freed 28 | */ 29 | gchar* bytes_to_string(double bytes, gboolean per_sec, gboolean bits); 30 | 31 | #endif /* _UTILS_H */ 32 | -------------------------------------------------------------------------------- /panel-plugin/xfce4-netspeed-plugin.desktop.in.in: -------------------------------------------------------------------------------- 1 | [Xfce Panel] 2 | Type=X-XFCE-PanelPlugin 3 | Encoding=UTF-8 4 | _Name=Network Speed Monitor 5 | _Comment=Shows the network download/upload speed 6 | Icon=xfce4-netspeed-plugin 7 | X-XFCE-Exec=@PLUGIN_PATH@/xfce4-netspeed-plugin 8 | -------------------------------------------------------------------------------- /panel-plugin/xfce4_netspeed_plugin.c: -------------------------------------------------------------------------------- 1 | /* xfce4-netspeed-plugin 2 | * 3 | * Copyright (c) 2011 Calin Crisan 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include 22 | #endif 23 | 24 | #include "xfce4_netspeed_plugin.h" 25 | 26 | #ifndef _ 27 | # include 28 | # define _(String) gettext (String) 29 | #endif 30 | 31 | 32 | /* tcons for the network interfaces */ 33 | static const char* device_type_icons[DEVICE_TYPE_WIRELESS + 1] = { 34 | "network-workgroup", /* unknown */ 35 | "netspeed-loopback", /* looppack */ 36 | "netspeed-plip", /* plip */ 37 | "netspeed-slip", /* slip */ 38 | "netspeed-ppp", /* ppp */ 39 | "network-wired", /* ethernet */ 40 | "network-wireless" /* wireless */ 41 | }; 42 | 43 | 44 | /* local prototypes */ 45 | static void net_speed_restart_timeout(NetSpeedPlugin *net_speed_plugin); 46 | static gboolean net_speed_orientation_changed(XfcePanelPlugin *plugin, GtkOrientation orientation, NetSpeedPlugin *net_speed_plugin); 47 | static gboolean net_speed_size_changed(XfcePanelPlugin *plugin, gint size, NetSpeedPlugin *net_speed_plugin); 48 | 49 | static void net_speed_create_widgets(NetSpeedPlugin *net_speed_plugin); 50 | 51 | static void net_speed_save_options(XfcePanelPlugin *plugin, NetSpeedPlugin *net_speed_plugin); 52 | 53 | static void net_speed_new(XfcePanelPlugin *plugin); 54 | static void net_speed_free(XfcePanelPlugin *plugin, NetSpeedPlugin *net_speed_plugin); 55 | 56 | 57 | void net_speed_update_labels(NetSpeedPlugin *net_speed_plugin) { 58 | if (net_speed_plugin->device_info) { /* a device has been chosen */ 59 | if (net_speed_plugin->device_info->up) { /* interface up */ 60 | if (net_speed_plugin->options->show_sum) { /* rx + tx */ 61 | gchar *text = bytes_to_string((double) (net_speed_plugin->rx_speed + net_speed_plugin->tx_speed), TRUE, 62 | net_speed_plugin->options->show_bits); 63 | 64 | gtk_label_set_markup(GTK_LABEL(net_speed_plugin->rx_label), text); 65 | gtk_label_set_markup(GTK_LABEL(net_speed_plugin->tx_label), ""); 66 | 67 | g_free(text); 68 | 69 | gtk_widget_hide(GTK_WIDGET(net_speed_plugin->rx_icon)); 70 | gtk_widget_hide(GTK_WIDGET(net_speed_plugin->tx_icon)); 71 | } 72 | else { /* separate rx & tx */ 73 | gchar *text = bytes_to_string((double) net_speed_plugin->rx_speed, TRUE, net_speed_plugin->options->show_bits); 74 | gtk_label_set_markup(GTK_LABEL(net_speed_plugin->rx_label), text); 75 | g_free(text); 76 | 77 | text = bytes_to_string((double) net_speed_plugin->tx_speed, TRUE, net_speed_plugin->options->show_bits); 78 | gtk_label_set_markup(GTK_LABEL(net_speed_plugin->tx_label), text); 79 | g_free(text); 80 | 81 | gtk_widget_show(GTK_WIDGET(net_speed_plugin->rx_icon)); 82 | gtk_widget_show(GTK_WIDGET(net_speed_plugin->tx_icon)); 83 | } 84 | } 85 | else { /* interface down */ 86 | gtk_label_set_markup(GTK_LABEL(net_speed_plugin->rx_label), _("(network down)")); 87 | gtk_label_set_markup(GTK_LABEL(net_speed_plugin->tx_label), ""); 88 | 89 | gtk_widget_hide(GTK_WIDGET(net_speed_plugin->rx_icon)); 90 | gtk_widget_hide(GTK_WIDGET(net_speed_plugin->tx_icon)); 91 | } 92 | } 93 | else { /* no device has been chosen in the configuration */ 94 | gtk_label_set_markup(GTK_LABEL(net_speed_plugin->rx_label), _("(no device)")); 95 | gtk_label_set_markup(GTK_LABEL(net_speed_plugin->tx_label), ""); 96 | } 97 | 98 | /* update label's orientation */ 99 | if (xfce_panel_plugin_get_orientation(net_speed_plugin->plugin) == GTK_ORIENTATION_VERTICAL) { 100 | gtk_label_set_angle(GTK_LABEL(net_speed_plugin->rx_label), -90); 101 | gtk_label_set_angle(GTK_LABEL(net_speed_plugin->tx_label), -90); 102 | } 103 | else { 104 | gtk_label_set_angle(GTK_LABEL(net_speed_plugin->rx_label), 0); 105 | gtk_label_set_angle(GTK_LABEL(net_speed_plugin->tx_label), 0); 106 | } 107 | } 108 | 109 | void net_speed_update_tooltip(NetSpeedPlugin *net_speed_plugin) { 110 | gchar tooltip_text[256]; 111 | 112 | if (net_speed_plugin->device_info) { /* a device has been chosen */ 113 | gchar *rx_text = bytes_to_string((double) net_speed_plugin->rx_speed, TRUE, net_speed_plugin->options->show_bits); 114 | gchar *tx_text = bytes_to_string((double) net_speed_plugin->tx_speed, TRUE, net_speed_plugin->options->show_bits); 115 | 116 | g_snprintf(tooltip_text, 256, "%s: %s\n%s: %s %s: %s", 117 | _("Interface"), net_speed_plugin->device_info->name, _("Download"), rx_text, _("Upload"), tx_text); 118 | 119 | g_free(rx_text); 120 | g_free(tx_text); 121 | } 122 | else { /* no device has been chosen in the configuration */ 123 | g_snprintf(tooltip_text, 256, _("(no device)")); 124 | } 125 | 126 | gtk_tooltips_set_tip(net_speed_plugin->tooltip, net_speed_plugin->ebox, tooltip_text, NULL); 127 | } 128 | 129 | void net_speed_update_icon(NetSpeedPlugin *net_speed_plugin) { 130 | if (net_speed_plugin->icon) { /* destroy the previous icon */ 131 | gtk_widget_destroy(net_speed_plugin->icon); 132 | net_speed_plugin->icon = NULL; 133 | } 134 | 135 | if (net_speed_plugin->options->show_icon) { 136 | GtkIconTheme *icon_theme = gtk_icon_theme_get_default(); 137 | GdkPixbuf *buf = NULL; 138 | 139 | if (net_speed_plugin->device_info) { 140 | if (net_speed_plugin->device_info->up) { /* interface up */ 141 | buf = gtk_icon_theme_load_icon(icon_theme, 142 | device_type_icons[net_speed_plugin->device_info->type], net_speed_plugin->icon_size, 0, NULL); 143 | } 144 | else { /* interface down */ 145 | buf = gtk_icon_theme_load_icon(icon_theme, "gtk-dialog-error", net_speed_plugin->icon_size, 0, NULL); 146 | } 147 | } 148 | 149 | if (!buf) { /* no device selected / fallback */ 150 | buf = gtk_icon_theme_load_icon(icon_theme, 151 | device_type_icons[DEVICE_TYPE_UNKNOWN], net_speed_plugin->icon_size, 0, NULL); 152 | } 153 | 154 | net_speed_plugin->icon = gtk_image_new_from_pixbuf(buf); 155 | g_object_unref(buf); 156 | 157 | gtk_box_pack_start(GTK_BOX(net_speed_plugin->box), net_speed_plugin->icon, FALSE, FALSE, 0); 158 | gtk_widget_show(net_speed_plugin->icon); 159 | } 160 | } 161 | 162 | void net_speed_update_options(NetSpeedPlugin *net_speed_plugin) { 163 | /* device */ 164 | if (net_speed_plugin->device_info) { 165 | device_info_free(net_speed_plugin->device_info); 166 | net_speed_plugin->device_info = NULL; 167 | } 168 | 169 | if (net_speed_plugin->options->device) { 170 | net_speed_plugin->device_info = device_info_new(net_speed_plugin->options->device); 171 | } 172 | 173 | /* show/hide frame */ 174 | gtk_frame_set_shadow_type(GTK_FRAME(net_speed_plugin->frame), 175 | net_speed_plugin->options->show_frame ? GTK_SHADOW_IN : GTK_SHADOW_NONE); 176 | 177 | /* fixed width */ 178 | if (net_speed_plugin->options->fixed_width) { 179 | gtk_widget_set_size_request(net_speed_plugin->frame, net_speed_plugin->options->fixed_width, net_speed_plugin->options->fixed_width); 180 | } 181 | else { 182 | gtk_widget_set_size_request(net_speed_plugin->frame, -1, -1); 183 | } 184 | 185 | /* show/hide icon */ 186 | net_speed_update_icon(net_speed_plugin); 187 | 188 | /* clear the history */ 189 | net_speed_plugin->history_index = -1; 190 | net_speed_plugin->rx_speed = 0; 191 | net_speed_plugin->tx_speed = 0; 192 | 193 | /* restart the timer */ 194 | net_speed_restart_timeout(net_speed_plugin); 195 | 196 | gtk_widget_set_size_request(GTK_WIDGET(net_speed_plugin->plugin), -1, -1); 197 | 198 | /* update the plugin as well */ 199 | net_speed_update_plugin(net_speed_plugin); 200 | } 201 | 202 | gboolean net_speed_update_plugin(NetSpeedPlugin *net_speed_plugin) { 203 | /* if the is automatically chosen, 204 | * we need to iterate through the device list 205 | * with each plugin update, and find the most "active" one */ 206 | if (net_speed_plugin->options->device_auto == TRUE) { 207 | if (net_speed_plugin->device_info) { 208 | device_info_free(net_speed_plugin->device_info); 209 | net_speed_plugin->device_info = NULL; 210 | } 211 | 212 | GList *device, *devices = device_info_list_get(); 213 | DeviceInfo *device_info, *running_device_info = NULL; 214 | for (device = devices; device != NULL; device = g_list_next(device)) { 215 | device_info = device_info_new(device->data); 216 | device_info_fill(device_info); 217 | 218 | if (device_info->running && device_info->type != DEVICE_TYPE_LOOPBACK) { 219 | running_device_info = device_info; 220 | break; 221 | } 222 | else { 223 | device_info_free(device_info); 224 | } 225 | } 226 | device_info_list_free(devices); 227 | 228 | if (net_speed_plugin->device_info) { 229 | device_info_free(net_speed_plugin->device_info); 230 | } 231 | 232 | net_speed_plugin->device_info = running_device_info; 233 | } 234 | 235 | if (net_speed_plugin->device_info) { /* a device has been chosen */ 236 | gint i; 237 | 238 | if (net_speed_plugin->history_index >= HISTORY_LENGTH - 1) { 239 | /* shift the history by one position */ 240 | for (i = 0; i < HISTORY_LENGTH - 1; i++) { 241 | net_speed_plugin->history_rx[i] = net_speed_plugin->history_rx[i + 1]; 242 | net_speed_plugin->history_tx[i] = net_speed_plugin->history_tx[i + 1]; 243 | } 244 | } 245 | else { 246 | net_speed_plugin->history_index++; 247 | } 248 | 249 | gboolean old_up = net_speed_plugin->device_info->up; 250 | if (net_speed_plugin->options->device != NULL) { /* if device was guessed, the device_info is already filled */ 251 | device_info_fill(net_speed_plugin->device_info); 252 | } 253 | 254 | net_speed_plugin->history_rx[net_speed_plugin->history_index] = net_speed_plugin->device_info->rx; 255 | net_speed_plugin->history_tx[net_speed_plugin->history_index] = net_speed_plugin->device_info->tx; 256 | 257 | if (net_speed_plugin->history_index >= 1) { /* we have at least two values */ 258 | guint64 delta_rx = net_speed_plugin->history_rx[net_speed_plugin->history_index] - net_speed_plugin->history_rx[0]; 259 | guint64 delta_tx = net_speed_plugin->history_tx[net_speed_plugin->history_index] - net_speed_plugin->history_tx[0]; 260 | 261 | net_speed_plugin->rx_speed = (delta_rx) * 1000 / (net_speed_plugin->options->refresh_interval * net_speed_plugin->history_index); 262 | net_speed_plugin->tx_speed = (delta_tx) * 1000 / (net_speed_plugin->options->refresh_interval * net_speed_plugin->history_index); 263 | } 264 | 265 | net_speed_update_icon(net_speed_plugin); 266 | } 267 | 268 | net_speed_update_labels(net_speed_plugin); 269 | net_speed_update_tooltip(net_speed_plugin); 270 | 271 | return TRUE; 272 | } 273 | 274 | 275 | void net_speed_restart_timeout(NetSpeedPlugin *net_speed_plugin) { 276 | if (net_speed_plugin->timeout_handle) { 277 | g_source_remove(net_speed_plugin->timeout_handle); 278 | } 279 | 280 | net_speed_plugin->timeout_handle = g_timeout_add(net_speed_plugin->options->refresh_interval, 281 | (GSourceFunc) net_speed_update_plugin, net_speed_plugin); 282 | } 283 | 284 | static gboolean net_speed_orientation_changed(XfcePanelPlugin *plugin, GtkOrientation orientation, NetSpeedPlugin *net_speed_plugin) { 285 | gtk_orientable_set_orientation(GTK_ORIENTABLE(net_speed_plugin->box), orientation); 286 | net_speed_update_options(net_speed_plugin); 287 | 288 | return TRUE; 289 | } 290 | 291 | static gboolean net_speed_size_changed(XfcePanelPlugin *plugin, gint size, NetSpeedPlugin *net_speed_plugin) { 292 | net_speed_plugin->icon_size = size - 4; 293 | net_speed_update_options(net_speed_plugin); 294 | 295 | return TRUE; 296 | } 297 | 298 | static void net_speed_create_widgets(NetSpeedPlugin *net_speed_plugin) { 299 | GtkOrientation orientation = xfce_panel_plugin_get_orientation(net_speed_plugin->plugin); 300 | net_speed_plugin->icon_size = xfce_panel_plugin_get_size(net_speed_plugin->plugin) - 4; 301 | GtkIconTheme *icon_theme = gtk_icon_theme_get_default(); 302 | 303 | /* event box */ 304 | net_speed_plugin->ebox = gtk_event_box_new(); 305 | xfce_panel_plugin_add_action_widget(net_speed_plugin->plugin, net_speed_plugin->ebox); 306 | gtk_container_add(GTK_CONTAINER(net_speed_plugin->plugin), net_speed_plugin->ebox); 307 | 308 | /* frame */ 309 | net_speed_plugin->frame = gtk_frame_new(NULL); 310 | gtk_frame_set_shadow_type(GTK_FRAME(net_speed_plugin->frame), net_speed_plugin->options->show_frame ? GTK_SHADOW_IN : GTK_SHADOW_NONE); 311 | gtk_container_add(GTK_CONTAINER(net_speed_plugin->ebox), net_speed_plugin->frame); 312 | 313 | /* box */ 314 | net_speed_plugin->box = gtk_hbox_new(FALSE, WIDGET_SPACING); 315 | gtk_container_set_border_width(GTK_CONTAINER(net_speed_plugin->box), WIDGET_BORDER); 316 | gtk_container_add(GTK_CONTAINER(net_speed_plugin->frame), net_speed_plugin->box); 317 | 318 | /* tx label */ 319 | net_speed_plugin->tx_label = gtk_label_new(NULL); 320 | gtk_box_pack_end(GTK_BOX(net_speed_plugin->box), net_speed_plugin->tx_label, FALSE, FALSE, 0); 321 | gtk_widget_show(net_speed_plugin->tx_label); 322 | 323 | /* tx icon */ 324 | GdkPixbuf *tx_arrow_buf = gtk_icon_theme_load_icon(icon_theme, "gtk-go-up", 16, 0, NULL); 325 | if (tx_arrow_buf) { 326 | net_speed_plugin->tx_icon = gtk_image_new_from_pixbuf(tx_arrow_buf); 327 | g_object_unref(tx_arrow_buf); 328 | 329 | gtk_box_pack_end(GTK_BOX(net_speed_plugin->box), net_speed_plugin->tx_icon, FALSE, FALSE, 0); 330 | gtk_widget_show(net_speed_plugin->tx_icon); 331 | } 332 | 333 | /* rx label */ 334 | net_speed_plugin->rx_label = gtk_label_new(NULL); 335 | gtk_box_pack_end(GTK_BOX(net_speed_plugin->box), net_speed_plugin->rx_label, FALSE, FALSE, 0); 336 | gtk_widget_show(net_speed_plugin->rx_label); 337 | 338 | /* rx icon */ 339 | GdkPixbuf *rx_arrow_buf = gtk_icon_theme_load_icon(icon_theme, "gtk-go-down", 16, 0, NULL); 340 | if (rx_arrow_buf) { 341 | net_speed_plugin->rx_icon = gtk_image_new_from_pixbuf(rx_arrow_buf); 342 | g_object_unref(rx_arrow_buf); 343 | 344 | gtk_box_pack_end(GTK_BOX(net_speed_plugin->box), net_speed_plugin->rx_icon, FALSE, FALSE, 0); 345 | gtk_widget_show(net_speed_plugin->rx_icon); 346 | } 347 | 348 | /* tooltip */ 349 | net_speed_plugin->tooltip = gtk_tooltips_new(); 350 | g_object_ref(G_OBJECT(net_speed_plugin->tooltip)); 351 | gtk_tooltips_set_tip(net_speed_plugin->tooltip, net_speed_plugin->ebox, "", NULL); 352 | 353 | /* this will create, add & show the main icon; 354 | * it will also update the label and the tooltip */ 355 | net_speed_orientation_changed(net_speed_plugin->plugin, orientation, net_speed_plugin); 356 | 357 | /* show the containers */ 358 | gtk_widget_show(net_speed_plugin->frame); 359 | gtk_widget_show(net_speed_plugin->box); 360 | gtk_widget_show(net_speed_plugin->ebox); 361 | } 362 | 363 | static void net_speed_save_options(XfcePanelPlugin *plugin, NetSpeedPlugin *net_speed_plugin) { 364 | net_speed_options_save(net_speed_plugin->options, plugin); 365 | } 366 | 367 | static void net_speed_new(XfcePanelPlugin *plugin) { 368 | /* translations */ 369 | xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); 370 | 371 | /* plugin */ 372 | NetSpeedPlugin *net_speed_plugin = g_new0(NetSpeedPlugin, 1); 373 | net_speed_plugin->plugin = plugin; 374 | 375 | /* options */ 376 | net_speed_plugin->options = net_speed_options_new(); 377 | net_speed_options_load(net_speed_plugin->options, plugin); 378 | 379 | net_speed_create_widgets(net_speed_plugin); 380 | 381 | /* apply the options */ 382 | net_speed_update_options(net_speed_plugin); 383 | 384 | /* start the update timer */ 385 | net_speed_restart_timeout(net_speed_plugin); 386 | 387 | /* signals */ 388 | g_signal_connect(plugin, "free-data", G_CALLBACK(net_speed_free), net_speed_plugin); 389 | g_signal_connect(plugin, "save", G_CALLBACK(net_speed_save_options), net_speed_plugin); 390 | g_signal_connect(plugin, "size-changed", G_CALLBACK(net_speed_size_changed), net_speed_plugin); 391 | g_signal_connect(plugin, "orientation-changed", G_CALLBACK(net_speed_orientation_changed), net_speed_plugin); 392 | g_signal_connect(plugin, "configure-plugin", G_CALLBACK(net_speed_configure_show), net_speed_plugin); 393 | 394 | /* the configure and about menu items are hidden by default */ 395 | xfce_panel_plugin_menu_show_configure(plugin); 396 | } 397 | 398 | static void net_speed_free(XfcePanelPlugin *plugin, NetSpeedPlugin *net_speed_plugin) { 399 | if (net_speed_plugin->timeout_handle) 400 | g_source_remove(net_speed_plugin->timeout_handle); 401 | 402 | gtk_tooltips_set_tip(net_speed_plugin->tooltip, net_speed_plugin->ebox, NULL, NULL); 403 | g_object_unref(net_speed_plugin->tooltip); 404 | 405 | net_speed_plugin->plugin = NULL; 406 | 407 | net_speed_options_free(net_speed_plugin->options); 408 | if (net_speed_plugin->device_info) { 409 | device_info_free(net_speed_plugin->device_info); 410 | } 411 | 412 | g_free(net_speed_plugin); 413 | } 414 | 415 | XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL(net_speed_new); 416 | -------------------------------------------------------------------------------- /panel-plugin/xfce4_netspeed_plugin.h: -------------------------------------------------------------------------------- 1 | /* xfce4-netspeed-plugin 2 | * 3 | * Copyright (c) 2011 Calin Crisan 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef _XFCE4_NETSPEED_PLUGIN_H 21 | #define _XFCE4_NETSPEED_PLUGIN_H 22 | 23 | #include 24 | 25 | #include 26 | 27 | #include "options.h" 28 | #include "device_info.h" 29 | #include "utils.h" 30 | 31 | #define WIDGET_SPACING 2 /* space between the widgets */ 32 | #define WIDGET_BORDER 1 /* space between the frame and the widgets */ 33 | 34 | #define HISTORY_LENGTH 5 /* number of rx/tx samples to keep */ 35 | 36 | 37 | typedef struct { 38 | 39 | XfcePanelPlugin *plugin; 40 | 41 | /* Widgets */ 42 | GtkWidget *ebox; 43 | GtkWidget *frame; 44 | GtkWidget *box; 45 | GtkWidget *icon; 46 | GtkWidget *rx_icon; 47 | GtkWidget *tx_icon; 48 | GtkWidget *rx_label; 49 | GtkWidget *tx_label; 50 | GtkTooltips *tooltip; 51 | 52 | gint icon_size; 53 | 54 | NetSpeedOptions *options; 55 | gint timeout_handle; 56 | 57 | DeviceInfo *device_info; 58 | 59 | guint64 history_rx[HISTORY_LENGTH]; 60 | guint64 history_tx[HISTORY_LENGTH]; 61 | gint history_index; 62 | 63 | guint64 rx_speed; 64 | guint64 tx_speed; 65 | 66 | } NetSpeedPlugin; 67 | 68 | #include "configure.h" 69 | 70 | 71 | void net_speed_update_labels(NetSpeedPlugin *net_speed_plugin); 72 | void net_speed_update_tooltip(NetSpeedPlugin *net_speed_plugin); 73 | void net_speed_update_icon(NetSpeedPlugin *net_speed_plugin); 74 | void net_speed_update_options(NetSpeedPlugin *net_speed_plugin); 75 | gboolean net_speed_update_plugin(NetSpeedPlugin *net_speed_plugin); 76 | 77 | 78 | #endif /* _XFCE4_NETSPEED_PLUGIN_H */ 79 | -------------------------------------------------------------------------------- /po/POTFILES.in: -------------------------------------------------------------------------------- 1 | panel-plugin/xfce4_netspeed_plugin.c 2 | panel-plugin/options.c 3 | panel-plugin/device_info.c 4 | panel-plugin/utils.c 5 | panel-plugin/configure.c 6 | panel-plugin/xfce4-netspeed-plugin.desktop.in.in 7 | --------------------------------------------------------------------------------