From ace60a4b0e75dafa8bdf3df50915999dd283d6de Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 17 Feb 2010 01:19:37 +0000 Subject: Added KDE3 version of knetstats git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/knetstats@1091565 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/.svnignore | 2 + src/CHANGELOG | 69 +++++ src/COPYING-DOCS | 397 ++++++++++++++++++++++++ src/Doxyfile | 266 ++++++++++++++++ src/Makefile.am | 5 + src/doc/Makefile.am | 1 + src/doc/en/Makefile.am | 2 + src/doc/en/index.docbook | 130 ++++++++ src/doc/man/Makefile.am | 4 + src/doc/man/manpage.xml | 142 +++++++++ src/hi16-app-knetstats.png | Bin 0 -> 1964 bytes src/hi32-app-knetstats.png | Bin 0 -> 2648 bytes src/hi48-app-knetstats.png | Bin 0 -> 12510 bytes src/knetstats.desktop | 32 ++ src/src/Makefile.am | 22 ++ src/src/chart.cpp | 65 ++++ src/src/chart.h | 43 +++ src/src/configure.cpp | 161 ++++++++++ src/src/configure.h | 65 ++++ src/src/configurebase.ui | 684 ++++++++++++++++++++++++++++++++++++++++++ src/src/interface.cpp | 57 ++++ src/src/interface.h | 51 ++++ src/src/knetstats.cpp | 191 ++++++++++++ src/src/knetstats.h | 93 ++++++ src/src/knetstatsview.cpp | 402 +++++++++++++++++++++++++ src/src/knetstatsview.h | 258 ++++++++++++++++ src/src/main.cpp | 66 ++++ src/src/pics/Makefile.am | 5 + src/src/pics/icon_pci.png | Bin 0 -> 835 bytes src/src/pics/theme0_both.png | Bin 0 -> 1652 bytes src/src/pics/theme0_error.png | Bin 0 -> 1773 bytes src/src/pics/theme0_none.png | Bin 0 -> 1618 bytes src/src/pics/theme0_rx.png | Bin 0 -> 1657 bytes src/src/pics/theme0_tx.png | Bin 0 -> 1626 bytes src/src/pics/theme1_both.png | Bin 0 -> 1298 bytes src/src/pics/theme1_error.png | Bin 0 -> 641 bytes src/src/pics/theme1_none.png | Bin 0 -> 587 bytes src/src/pics/theme1_rx.png | Bin 0 -> 980 bytes src/src/pics/theme1_tx.png | Bin 0 -> 1021 bytes src/src/pics/theme2_both.png | Bin 0 -> 1416 bytes src/src/pics/theme2_error.png | Bin 0 -> 745 bytes src/src/pics/theme2_none.png | Bin 0 -> 849 bytes src/src/pics/theme2_rx.png | Bin 0 -> 1121 bytes src/src/pics/theme2_tx.png | Bin 0 -> 1164 bytes src/src/pics/theme3_both.png | Bin 0 -> 1152 bytes src/src/pics/theme3_error.png | Bin 0 -> 472 bytes src/src/pics/theme3_none.png | Bin 0 -> 461 bytes src/src/pics/theme3_rx.png | Bin 0 -> 799 bytes src/src/pics/theme3_tx.png | Bin 0 -> 943 bytes src/src/pics/theme4_both.png | Bin 0 -> 1033 bytes src/src/pics/theme4_error.png | Bin 0 -> 1328 bytes src/src/pics/theme4_none.png | Bin 0 -> 999 bytes src/src/pics/theme4_rx.png | Bin 0 -> 1036 bytes src/src/pics/theme4_tx.png | Bin 0 -> 1033 bytes src/src/statistics.cpp | 79 +++++ src/src/statistics.h | 66 ++++ src/src/statisticsbase.ui | 480 +++++++++++++++++++++++++++++ 57 files changed, 3838 insertions(+) create mode 100644 src/.svnignore create mode 100644 src/CHANGELOG create mode 100644 src/COPYING-DOCS create mode 100644 src/Doxyfile create mode 100644 src/Makefile.am create mode 100644 src/doc/Makefile.am create mode 100644 src/doc/en/Makefile.am create mode 100644 src/doc/en/index.docbook create mode 100644 src/doc/man/Makefile.am create mode 100644 src/doc/man/manpage.xml create mode 100644 src/hi16-app-knetstats.png create mode 100644 src/hi32-app-knetstats.png create mode 100644 src/hi48-app-knetstats.png create mode 100644 src/knetstats.desktop create mode 100644 src/src/Makefile.am create mode 100644 src/src/chart.cpp create mode 100644 src/src/chart.h create mode 100644 src/src/configure.cpp create mode 100644 src/src/configure.h create mode 100644 src/src/configurebase.ui create mode 100644 src/src/interface.cpp create mode 100644 src/src/interface.h create mode 100644 src/src/knetstats.cpp create mode 100644 src/src/knetstats.h create mode 100644 src/src/knetstatsview.cpp create mode 100644 src/src/knetstatsview.h create mode 100644 src/src/main.cpp create mode 100644 src/src/pics/Makefile.am create mode 100644 src/src/pics/icon_pci.png create mode 100644 src/src/pics/theme0_both.png create mode 100644 src/src/pics/theme0_error.png create mode 100644 src/src/pics/theme0_none.png create mode 100644 src/src/pics/theme0_rx.png create mode 100644 src/src/pics/theme0_tx.png create mode 100644 src/src/pics/theme1_both.png create mode 100644 src/src/pics/theme1_error.png create mode 100644 src/src/pics/theme1_none.png create mode 100644 src/src/pics/theme1_rx.png create mode 100644 src/src/pics/theme1_tx.png create mode 100644 src/src/pics/theme2_both.png create mode 100644 src/src/pics/theme2_error.png create mode 100644 src/src/pics/theme2_none.png create mode 100644 src/src/pics/theme2_rx.png create mode 100644 src/src/pics/theme2_tx.png create mode 100644 src/src/pics/theme3_both.png create mode 100644 src/src/pics/theme3_error.png create mode 100644 src/src/pics/theme3_none.png create mode 100644 src/src/pics/theme3_rx.png create mode 100644 src/src/pics/theme3_tx.png create mode 100644 src/src/pics/theme4_both.png create mode 100644 src/src/pics/theme4_error.png create mode 100644 src/src/pics/theme4_none.png create mode 100644 src/src/pics/theme4_rx.png create mode 100644 src/src/pics/theme4_tx.png create mode 100644 src/src/statistics.cpp create mode 100644 src/src/statistics.h create mode 100644 src/src/statisticsbase.ui (limited to 'src') diff --git a/src/.svnignore b/src/.svnignore new file mode 100644 index 0000000..896d115 --- /dev/null +++ b/src/.svnignore @@ -0,0 +1,2 @@ +Makefile.in +*Makefile.in diff --git a/src/CHANGELOG b/src/CHANGELOG new file mode 100644 index 0000000..befd2c5 --- /dev/null +++ b/src/CHANGELOG @@ -0,0 +1,69 @@ +v1.6.1 + +- Fixed crash when discovering a new interface. + +v1.6.0.1 + +- Disable the -ansi flag to avoid compile problems. + +v1.6 + +- More user-friendly, try to detect some things and start without importune the user with configuration dialogs. + +v1.5 + +- Added "Chart view". +- New Statistics dialog (show IP address, MAC address, etc). +- Using bksys as building tool. +- Carrier on/off detection. +- Reading interface date from /sys/class/net/INTERFACE/statistics instead of parse /proc/dev/net. +- New translation to romanian + +Note to BSD users: This version is not compatible with BSD, it uses some linux-only stuff. A BSD-compatible version is plained in a near future. + +v1.3.1 + +- Minor fix for Mandriva Linux (former Mandrake Linux). Env is now set for uic during build. + +v1.3 + +- New configuration dialog. +- Support to multiple interfaces. +- Is possible change the colors in the text mode view. +- Is possible change the icon theme of in icon mode. +- Added smooth speed meter. + +v1.2.1 + +- Added Russian translation (Edward Romantsov). +- Added Polish translation (Wiktor Wandachowicz). + +v1.2 + +- Now using SCons as building and install tool, so you will need to have Python installed in your distro to run SCons scripts and compile/install KNetStats. +- Added Brazilian portuguese translation (me). +- Added Kirghiz translation (Ilyas Bakirov). +- Added Italian translation (Roberto Leandrini). +- Added Spanish translation (Carlos Ortiz). +- Added Deutsch translation (Henrik Gebauer). +- Bug Fix: When network interface in changed, the Statistics window caption is changed too. +- Bug Fix: Statistics window now correctly format Download/Upload Speed. +- Bug Fix: When start KNetstats with a unavaliable interface, now upload speed is equals to 0pkts/s (not -2pkts/s) +- Bug Fix: When knetstats starts and statistics windows is hidden it is not updated. + +v1.1.2 + +- Build system now uses kde-config instead $KDEDIR env. variable. This will solve problems when compiling KNetstats on some distros (Suse 9.1, Fedora). + +v1.1.1 + +- Clicking on trayicon show/hide statistics window (suggestion by Fredy Yanardi). +- All dialogs now show the KNetStats icon on windows decoration. +- It's possible to change the font used in textmode (suggestion by Vik). + + +v1.1 + +- Bug Fix: Not saving UpdateInterval when the network interface is not changed. +- Litle optimizations +- Support to IconMode (Activity Led's) or TextMode (showing rx/tx transfer rate) \ No newline at end of file diff --git a/src/COPYING-DOCS b/src/COPYING-DOCS new file mode 100644 index 0000000..4a0fe1c --- /dev/null +++ b/src/COPYING-DOCS @@ -0,0 +1,397 @@ + GNU Free Documentation License + Version 1.2, November 2002 + + + Copyright (C) 2000,2001,2002 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + +0. PREAMBLE + +The purpose of this License is to make a manual, textbook, or other +functional and useful document "free" in the sense of freedom: to +assure everyone the effective freedom to copy and redistribute it, +with or without modifying it, either commercially or noncommercially. +Secondarily, this License preserves for the author and publisher a way +to get credit for their work, while not being considered responsible +for modifications made by others. + +This License is a kind of "copyleft", which means that derivative +works of the document must themselves be free in the same sense. It +complements the GNU General Public License, which is a copyleft +license designed for free software. + +We have designed this License in order to use it for manuals for free +software, because free software needs free documentation: a free +program should come with manuals providing the same freedoms that the +software does. But this License is not limited to software manuals; +it can be used for any textual work, regardless of subject matter or +whether it is published as a printed book. We recommend this License +principally for works whose purpose is instruction or reference. + + +1. APPLICABILITY AND DEFINITIONS + +This License applies to any manual or other work, in any medium, that +contains a notice placed by the copyright holder saying it can be +distributed under the terms of this License. Such a notice grants a +world-wide, royalty-free license, unlimited in duration, to use that +work under the conditions stated herein. The "Document", below, +refers to any such manual or work. Any member of the public is a +licensee, and is addressed as "you". You accept the license if you +copy, modify or distribute the work in a way requiring permission +under copyright law. + +A "Modified Version" of the Document means any work containing the +Document or a portion of it, either copied verbatim, or with +modifications and/or translated into another language. + +A "Secondary Section" is a named appendix or a front-matter section of +the Document that deals exclusively with the relationship of the +publishers or authors of the Document to the Document's overall subject +(or to related matters) and contains nothing that could fall directly +within that overall subject. (Thus, if the Document is in part a +textbook of mathematics, a Secondary Section may not explain any +mathematics.) The relationship could be a matter of historical +connection with the subject or with related matters, or of legal, +commercial, philosophical, ethical or political position regarding +them. + +The "Invariant Sections" are certain Secondary Sections whose titles +are designated, as being those of Invariant Sections, in the notice +that says that the Document is released under this License. If a +section does not fit the above definition of Secondary then it is not +allowed to be designated as Invariant. The Document may contain zero +Invariant Sections. If the Document does not identify any Invariant +Sections then there are none. + +The "Cover Texts" are certain short passages of text that are listed, +as Front-Cover Texts or Back-Cover Texts, in the notice that says that +the Document is released under this License. A Front-Cover Text may +be at most 5 words, and a Back-Cover Text may be at most 25 words. + +A "Transparent" copy of the Document means a machine-readable copy, +represented in a format whose specification is available to the +general public, that is suitable for revising the document +straightforwardly with generic text editors or (for images composed of +pixels) generic paint programs or (for drawings) some widely available +drawing editor, and that is suitable for input to text formatters or +for automatic translation to a variety of formats suitable for input +to text formatters. A copy made in an otherwise Transparent file +format whose markup, or absence of markup, has been arranged to thwart +or discourage subsequent modification by readers is not Transparent. +An image format is not Transparent if used for any substantial amount +of text. A copy that is not "Transparent" is called "Opaque". + +Examples of suitable formats for Transparent copies include plain +ASCII without markup, Texinfo input format, LaTeX input format, SGML +or XML using a publicly available DTD, and standard-conforming simple +HTML, PostScript or PDF designed for human modification. Examples of +transparent image formats include PNG, XCF and JPG. Opaque formats +include proprietary formats that can be read and edited only by +proprietary word processors, SGML or XML for which the DTD and/or +processing tools are not generally available, and the +machine-generated HTML, PostScript or PDF produced by some word +processors for output purposes only. + +The "Title Page" means, for a printed book, the title page itself, +plus such following pages as are needed to hold, legibly, the material +this License requires to appear in the title page. For works in +formats which do not have any title page as such, "Title Page" means +the text near the most prominent appearance of the work's title, +preceding the beginning of the body of the text. + +A section "Entitled XYZ" means a named subunit of the Document whose +title either is precisely XYZ or contains XYZ in parentheses following +text that translates XYZ in another language. (Here XYZ stands for a +specific section name mentioned below, such as "Acknowledgements", +"Dedications", "Endorsements", or "History".) To "Preserve the Title" +of such a section when you modify the Document means that it remains a +section "Entitled XYZ" according to this definition. + +The Document may include Warranty Disclaimers next to the notice which +states that this License applies to the Document. These Warranty +Disclaimers are considered to be included by reference in this +License, but only as regards disclaiming warranties: any other +implication that these Warranty Disclaimers may have is void and has +no effect on the meaning of this License. + + +2. VERBATIM COPYING + +You may copy and distribute the Document in any medium, either +commercially or noncommercially, provided that this License, the +copyright notices, and the license notice saying this License applies +to the Document are reproduced in all copies, and that you add no other +conditions whatsoever to those of this License. You may not use +technical measures to obstruct or control the reading or further +copying of the copies you make or distribute. However, you may accept +compensation in exchange for copies. If you distribute a large enough +number of copies you must also follow the conditions in section 3. + +You may also lend copies, under the same conditions stated above, and +you may publicly display copies. + + +3. COPYING IN QUANTITY + +If you publish printed copies (or copies in media that commonly have +printed covers) of the Document, numbering more than 100, and the +Document's license notice requires Cover Texts, you must enclose the +copies in covers that carry, clearly and legibly, all these Cover +Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on +the back cover. Both covers must also clearly and legibly identify +you as the publisher of these copies. The front cover must present +the full title with all words of the title equally prominent and +visible. You may add other material on the covers in addition. +Copying with changes limited to the covers, as long as they preserve +the title of the Document and satisfy these conditions, can be treated +as verbatim copying in other respects. + +If the required texts for either cover are too voluminous to fit +legibly, you should put the first ones listed (as many as fit +reasonably) on the actual cover, and continue the rest onto adjacent +pages. + +If you publish or distribute Opaque copies of the Document numbering +more than 100, you must either include a machine-readable Transparent +copy along with each Opaque copy, or state in or with each Opaque copy +a computer-network location from which the general network-using +public has access to download using public-standard network protocols +a complete Transparent copy of the Document, free of added material. +If you use the latter option, you must take reasonably prudent steps, +when you begin distribution of Opaque copies in quantity, to ensure +that this Transparent copy will remain thus accessible at the stated +location until at least one year after the last time you distribute an +Opaque copy (directly or through your agents or retailers) of that +edition to the public. + +It is requested, but not required, that you contact the authors of the +Document well before redistributing any large number of copies, to give +them a chance to provide you with an updated version of the Document. + + +4. MODIFICATIONS + +You may copy and distribute a Modified Version of the Document under +the conditions of sections 2 and 3 above, provided that you release +the Modified Version under precisely this License, with the Modified +Version filling the role of the Document, thus licensing distribution +and modification of the Modified Version to whoever possesses a copy +of it. In addition, you must do these things in the Modified Version: + +A. Use in the Title Page (and on the covers, if any) a title distinct + from that of the Document, and from those of previous versions + (which should, if there were any, be listed in the History section + of the Document). You may use the same title as a previous version + if the original publisher of that version gives permission. +B. List on the Title Page, as authors, one or more persons or entities + responsible for authorship of the modifications in the Modified + Version, together with at least five of the principal authors of the + Document (all of its principal authors, if it has fewer than five), + unless they release you from this requirement. +C. State on the Title page the name of the publisher of the + Modified Version, as the publisher. +D. Preserve all the copyright notices of the Document. +E. Add an appropriate copyright notice for your modifications + adjacent to the other copyright notices. +F. Include, immediately after the copyright notices, a license notice + giving the public permission to use the Modified Version under the + terms of this License, in the form shown in the Addendum below. +G. Preserve in that license notice the full lists of Invariant Sections + and required Cover Texts given in the Document's license notice. +H. Include an unaltered copy of this License. +I. Preserve the section Entitled "History", Preserve its Title, and add + to it an item stating at least the title, year, new authors, and + publisher of the Modified Version as given on the Title Page. If + there is no section Entitled "History" in the Document, create one + stating the title, year, authors, and publisher of the Document as + given on its Title Page, then add an item describing the Modified + Version as stated in the previous sentence. +J. Preserve the network location, if any, given in the Document for + public access to a Transparent copy of the Document, and likewise + the network locations given in the Document for previous versions + it was based on. These may be placed in the "History" section. + You may omit a network location for a work that was published at + least four years before the Document itself, or if the original + publisher of the version it refers to gives permission. +K. For any section Entitled "Acknowledgements" or "Dedications", + Preserve the Title of the section, and preserve in the section all + the substance and tone of each of the contributor acknowledgements + and/or dedications given therein. +L. Preserve all the Invariant Sections of the Document, + unaltered in their text and in their titles. Section numbers + or the equivalent are not considered part of the section titles. +M. Delete any section Entitled "Endorsements". Such a section + may not be included in the Modified Version. +N. Do not retitle any existing section to be Entitled "Endorsements" + or to conflict in title with any Invariant Section. +O. Preserve any Warranty Disclaimers. + +If the Modified Version includes new front-matter sections or +appendices that qualify as Secondary Sections and contain no material +copied from the Document, you may at your option designate some or all +of these sections as invariant. To do this, add their titles to the +list of Invariant Sections in the Modified Version's license notice. +These titles must be distinct from any other section titles. + +You may add a section Entitled "Endorsements", provided it contains +nothing but endorsements of your Modified Version by various +parties--for example, statements of peer review or that the text has +been approved by an organization as the authoritative definition of a +standard. + +You may add a passage of up to five words as a Front-Cover Text, and a +passage of up to 25 words as a Back-Cover Text, to the end of the list +of Cover Texts in the Modified Version. Only one passage of +Front-Cover Text and one of Back-Cover Text may be added by (or +through arrangements made by) any one entity. If the Document already +includes a cover text for the same cover, previously added by you or +by arrangement made by the same entity you are acting on behalf of, +you may not add another; but you may replace the old one, on explicit +permission from the previous publisher that added the old one. + +The author(s) and publisher(s) of the Document do not by this License +give permission to use their names for publicity for or to assert or +imply endorsement of any Modified Version. + + +5. COMBINING DOCUMENTS + +You may combine the Document with other documents released under this +License, under the terms defined in section 4 above for modified +versions, provided that you include in the combination all of the +Invariant Sections of all of the original documents, unmodified, and +list them all as Invariant Sections of your combined work in its +license notice, and that you preserve all their Warranty Disclaimers. + +The combined work need only contain one copy of this License, and +multiple identical Invariant Sections may be replaced with a single +copy. If there are multiple Invariant Sections with the same name but +different contents, make the title of each such section unique by +adding at the end of it, in parentheses, the name of the original +author or publisher of that section if known, or else a unique number. +Make the same adjustment to the section titles in the list of +Invariant Sections in the license notice of the combined work. + +In the combination, you must combine any sections Entitled "History" +in the various original documents, forming one section Entitled +"History"; likewise combine any sections Entitled "Acknowledgements", +and any sections Entitled "Dedications". You must delete all sections +Entitled "Endorsements". + + +6. COLLECTIONS OF DOCUMENTS + +You may make a collection consisting of the Document and other documents +released under this License, and replace the individual copies of this +License in the various documents with a single copy that is included in +the collection, provided that you follow the rules of this License for +verbatim copying of each of the documents in all other respects. + +You may extract a single document from such a collection, and distribute +it individually under this License, provided you insert a copy of this +License into the extracted document, and follow this License in all +other respects regarding verbatim copying of that document. + + +7. AGGREGATION WITH INDEPENDENT WORKS + +A compilation of the Document or its derivatives with other separate +and independent documents or works, in or on a volume of a storage or +distribution medium, is called an "aggregate" if the copyright +resulting from the compilation is not used to limit the legal rights +of the compilation's users beyond what the individual works permit. +When the Document is included in an aggregate, this License does not +apply to the other works in the aggregate which are not themselves +derivative works of the Document. + +If the Cover Text requirement of section 3 is applicable to these +copies of the Document, then if the Document is less than one half of +the entire aggregate, the Document's Cover Texts may be placed on +covers that bracket the Document within the aggregate, or the +electronic equivalent of covers if the Document is in electronic form. +Otherwise they must appear on printed covers that bracket the whole +aggregate. + + +8. TRANSLATION + +Translation is considered a kind of modification, so you may +distribute translations of the Document under the terms of section 4. +Replacing Invariant Sections with translations requires special +permission from their copyright holders, but you may include +translations of some or all Invariant Sections in addition to the +original versions of these Invariant Sections. You may include a +translation of this License, and all the license notices in the +Document, and any Warranty Disclaimers, provided that you also include +the original English version of this License and the original versions +of those notices and disclaimers. In case of a disagreement between +the translation and the original version of this License or a notice +or disclaimer, the original version will prevail. + +If a section in the Document is Entitled "Acknowledgements", +"Dedications", or "History", the requirement (section 4) to Preserve +its Title (section 1) will typically require changing the actual +title. + + +9. TERMINATION + +You may not copy, modify, sublicense, or distribute the Document except +as expressly provided for under this License. Any other attempt to +copy, modify, sublicense or distribute the Document is void, and will +automatically terminate your rights under this License. However, +parties who have received copies, or rights, from you under this +License will not have their licenses terminated so long as such +parties remain in full compliance. + + +10. FUTURE REVISIONS OF THIS LICENSE + +The Free Software Foundation may publish new, revised versions +of the GNU Free Documentation License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. See +http://www.gnu.org/copyleft/. + +Each version of the License is given a distinguishing version number. +If the Document specifies that a particular numbered version of this +License "or any later version" applies to it, you have the option of +following the terms and conditions either of that specified version or +of any later version that has been published (not as a draft) by the +Free Software Foundation. If the Document does not specify a version +number of this License, you may choose any version ever published (not +as a draft) by the Free Software Foundation. + + +ADDENDUM: How to use this License for your documents + +To use this License in a document you have written, include a copy of +the License in the document and put the following copyright and +license notices just after the title page: + + Copyright (c) YEAR YOUR NAME. + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.2 + or any later version published by the Free Software Foundation; + with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. + A copy of the license is included in the section entitled "GNU + Free Documentation License". + +If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, +replace the "with...Texts." line with this: + + with the Invariant Sections being LIST THEIR TITLES, with the + Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. + +If you have Invariant Sections without Cover Texts, or some other +combination of the three, merge those two alternatives to suit the +situation. + +If your document contains nontrivial examples of program code, we +recommend releasing these examples in parallel under your choice of +free software license, such as the GNU General Public License, +to permit their use in free software. diff --git a/src/Doxyfile b/src/Doxyfile new file mode 100644 index 0000000..c09648d --- /dev/null +++ b/src/Doxyfile @@ -0,0 +1,266 @@ +# Doxyfile 1.3.7-KDevelop + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = knetstats.kdevelop +PROJECT_NUMBER = 0.1 +OUTPUT_DIRECTORY = +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +USE_WINDOWS_ENCODING = NO +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = YES +STRIP_FROM_PATH = /home/hugo/ +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = NO +INHERIT_DOCS = YES +DISTRIBUTE_GROUP_DOC = NO +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +SUBGROUPING = YES +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = NO +EXTRACT_PRIVATE = NO +EXTRACT_STATIC = NO +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = /home/hugo/src/knetstats +FILE_PATTERNS = *.c \ + *.cc \ + *.cxx \ + *.cpp \ + *.c++ \ + *.java \ + *.ii \ + *.ixx \ + *.ipp \ + *.i++ \ + *.inl \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ \ + *.idl \ + *.odl \ + *.cs \ + *.php \ + *.php3 \ + *.inc \ + *.m \ + *.mm \ + *.C \ + *.CC \ + *.C++ \ + *.II \ + *.I++ \ + *.H \ + *.HH \ + *.H++ \ + *.CS \ + *.PHP \ + *.PHP3 \ + *.M \ + *.MM \ + *.C \ + *.H \ + *.tlh \ + *.diff \ + *.patch \ + *.moc \ + *.xpm \ + *.dox +RECURSIVE = yes +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = * +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_SOURCE_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = NO +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = YES +REFERENCES_RELATION = YES +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = NO +TREEVIEW_WIDTH = 250 +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = YES +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = NO +USE_PDFLATEX = NO +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = yes +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = knetstats.tag +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +UML_LOOK = NO +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 1024 +MAX_DOT_GRAPH_HEIGHT = 1024 +MAX_DOT_GRAPH_DEPTH = 1000 +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = NO diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..66b3066 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,5 @@ +SUBDIRS = src doc + +xdg_apps_DATA = knetstats.desktop + +KDE_ICON = knetstats diff --git a/src/doc/Makefile.am b/src/doc/Makefile.am new file mode 100644 index 0000000..81fee21 --- /dev/null +++ b/src/doc/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = en diff --git a/src/doc/en/Makefile.am b/src/doc/en/Makefile.am new file mode 100644 index 0000000..8f050ec --- /dev/null +++ b/src/doc/en/Makefile.am @@ -0,0 +1,2 @@ +KDE_LANG = en +KDE_DOCS = knetstats diff --git a/src/doc/en/index.docbook b/src/doc/en/index.docbook new file mode 100644 index 0000000..36815bb --- /dev/null +++ b/src/doc/en/index.docbook @@ -0,0 +1,130 @@ + +KNetStats 1.5"> + + + + + + + +]> + + + + + + + + + + +The &knetstats; Handbook + + + +Hugo Parente Lima + + + +
hugo_pl@users.sourceforge.net
+
+
+
+ + + + +2004-2005 +Hugo Parente Lima + + + +&FDLNotice; + + + +2005-11-14 +1.1 + + + + + +&knetstats; Is a simple KDE network monitor that show rx/tx LEDs of any network interface on a system tray icon. + + + + + + +KDE +knetstats +network +monitor +leds + + +
+ + + + +Using &knetstats; + +Choose a interface and see the leds :-). + + + + + + + + +Credits and License + + +&knetstats; + +Hugo Parente Lima - original author. +Thomas Windheuser - SCons help, Debian packages, etc. +KNemo - Icon themes +Ilyas Bakirov, Roberto Leandrini, Carlos Ortiz, Henrik Gebauer, Edward Romantsov, Wiktor Wandachowicz, Guillaume Savaton, Petar Toushkov, Liu Di - KNetStats translation to other languages + +You can find more info on KNetStats website. + + + +&underFDL; +&underGPL; + + + +&documentation.index; +
diff --git a/src/doc/man/Makefile.am b/src/doc/man/Makefile.am new file mode 100644 index 0000000..514c585 --- /dev/null +++ b/src/doc/man/Makefile.am @@ -0,0 +1,4 @@ +man_MANS = manpage.xml + +EXTRA_DIST = $(man_MANS) + diff --git a/src/doc/man/manpage.xml b/src/doc/man/manpage.xml new file mode 100644 index 0000000..52d305e --- /dev/null +++ b/src/doc/man/manpage.xml @@ -0,0 +1,142 @@ + +.
will be generated. You may view the +manual page with: nroff -man .
| less'. A +typical entry in a Makefile or Makefile.am is: + +DB2MAN=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/\ +manpages/docbook.xsl +XP=xsltproc -''-nonet + +manpage.1: manpage.dbk + $(XP) $(DB2MAN) $< + +The xsltproc binary is found in the xsltproc package. The +XSL files are in docbook-xsl. Please remember that if you +create the nroff version in one of the debian/rules file +targets (such as build), you will need to include xsltproc +and docbook-xsl in your Build-Depends control field. + +--> + + + Thomas"> + Windheuser"> + + 16 Oct 2005"> + + 1"> + thomas@0x5c.net"> + + knetstats"> + + + Debian"> + GNU"> + GPL"> +]> + + + +
+ &dhemail; +
+ + &dhfirstname; + &dhsurname; + + + 2005 + &dhusername; + + &dhdate; +
+ + &dhucpackage; + + &dhsection; + + + &dhpackage; + + A system tray icon, which indicates network activity + + + + &dhpackage; + + + + + + + DESCRIPTION + + This manual page documents briefly the + &dhpackage; + commands. + + This manual page was written for the &debian; distribution. + Instead, it has documentation in the &gnu; + Info format; see below. + + &dhpackage; is a program that provides a system tray icon. This icon provides two + LED's, which begin to blink if there is network traffic. + + + + OPTIONS + + These programs follow the usual &gnu; command line syntax, + with long options starting with two dashes (`-'). A summary of + options is included below. For a complete description, see the + Info files. + + + + + + + + Show summary of options. + + + + + + + + Show version of program. + + + + + + SEE ALSO + + + + AUTHOR + + This manual page was written by &dhusername; &dhemail; for + the &debian; system (but may be used by others). Permission is + granted to copy, distribute and/or modify this document under + the terms of the &gnu; General Public License, Version 2 any + later version published by the Free Software Foundation. + + + On Debian systems, the complete text of the GNU General Public + License can be found in /usr/share/common-licenses/GPL. + + + +
+ diff --git a/src/hi16-app-knetstats.png b/src/hi16-app-knetstats.png new file mode 100644 index 0000000..6e7e576 Binary files /dev/null and b/src/hi16-app-knetstats.png differ diff --git a/src/hi32-app-knetstats.png b/src/hi32-app-knetstats.png new file mode 100644 index 0000000..3328106 Binary files /dev/null and b/src/hi32-app-knetstats.png differ diff --git a/src/hi48-app-knetstats.png b/src/hi48-app-knetstats.png new file mode 100644 index 0000000..869cd7b Binary files /dev/null and b/src/hi48-app-knetstats.png differ diff --git a/src/knetstats.desktop b/src/knetstats.desktop new file mode 100644 index 0000000..69cab53 --- /dev/null +++ b/src/knetstats.desktop @@ -0,0 +1,32 @@ +[Desktop Entry] +Name=KNetStats +Name[pa]=ਕੇ-ਨੈੱਟ-ਹਾਲਤ +GenericName=Network monitor +GenericName[bg]=Наблюдение на мрежа +GenericName[cs]=Síťový monitor +GenericName[da]=Netværksovervåger +GenericName[de]=Netzwerkmonitor +GenericName[el]=Επόπτης δικτύου +GenericName[es]=Monitor de red +GenericName[et]=Võrgumonitor +GenericName[fr]=Surveillance réseau +GenericName[ga]=Monatóir líonra +GenericName[gl]=Monitor da rede +GenericName[it]=Monitor di rete +GenericName[ja]=ネットワークモニター +GenericName[ka]=ქსელის მეთვალყურე +GenericName[nl]=Netwerkmonitor +GenericName[pa]=ਨੈੱਟਵਰਕ ਨਿਗਰਾਨ +GenericName[pt]=Monitor da rede +GenericName[pt_BR]=Monitor de rede +GenericName[sk]=Monitor siete +GenericName[sv]=Nätverksövervakare +GenericName[tr]=Ağ izleyici +GenericName[uk]=Монітор мережі +Exec=knetstats +Icon=knetstats +Terminal=false +Type=Application +Categories=Qt;KDE;Network; +X-KDE-StartupNotify=true + diff --git a/src/src/Makefile.am b/src/src/Makefile.am new file mode 100644 index 0000000..fc9c70b --- /dev/null +++ b/src/src/Makefile.am @@ -0,0 +1,22 @@ +INCLUDES = $(all_includes) + +SUBDIRS = pics + +bin_PROGRAMS = knetstats + +knetstats_SOURCES = configurebase.ui configure.cpp statisticsbase.ui main.cpp \ + knetstats.cpp knetstatsview.cpp statistics.cpp chart.cpp interface.cpp +knetstats_LDADD = $(LIB_KDEUI) +knetstats_LDFLAGS = $(all_libraries) $(KDE_RPATH) +METASOURCES = configure.moc knetstats.moc knetstatsview.moc statistics.moc + +# these are the headers for your project +noinst_HEADERS = chart.h configure.h knetstats.h knetstatsview.h statistics.h \ + interface.h + +messages: rc.cpp + $(EXTRACTRC) *.ui >> rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/knetstats.pot + +KDE_OPTIONS = nofinal + diff --git a/src/src/chart.cpp b/src/src/chart.cpp new file mode 100644 index 0000000..9f48f14 --- /dev/null +++ b/src/src/chart.cpp @@ -0,0 +1,65 @@ +/*************************************************************************** +* Copyright (C) 2005 by Hugo Parente Lima * +* hugo_pl@users.sourceforge.net * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ + +#include "chart.h" +#include +#include + +Chart::Chart(QWidget* parent, const double* uploadBuffer, const double* downloadBuffer, int bufferSize, const int* ptr, const double* maxspeed) : QWidget(parent), mUplBuffer(uploadBuffer), mDldBuffer(downloadBuffer), mBufferSize(bufferSize), mPtr(ptr), mMaxSpeed(maxspeed) { + setWFlags(Qt::WNoAutoErase); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); +} + +void Chart::paintEvent(QPaintEvent*) { + QPainter paint(this); + paint.setBackgroundColor(Qt::black); + paint.setBackgroundMode(Qt::OpaqueMode); + QBrush brush(QColor(0x33, 0x33, 0x33), CrossPattern); + paint.fillRect(0, 0, width(), height(), brush); + + const double step = width()/double(mBufferSize); + const int HEIGHT = height() - 1; + + int x; + int lastX = x = width(); + int lastRxY = HEIGHT - int(HEIGHT * (mDldBuffer[*mPtr]/(*mMaxSpeed))); + int lastTxY = HEIGHT - int(HEIGHT * (mUplBuffer[*mPtr]/(*mMaxSpeed))); + + int count = 0; + for (int i = *mPtr; count < mBufferSize; i--) { + if (i < 0) + i = mBufferSize-1; + int rxY = HEIGHT - int(HEIGHT * (mDldBuffer[i]/(*mMaxSpeed))); + int txY = HEIGHT - int(HEIGHT * (mUplBuffer[i]/(*mMaxSpeed))); + paint.setPen(Qt::green); + paint.drawLine(lastX, lastRxY, x, rxY); + paint.setPen(Qt::red); + paint.drawLine(lastX, lastTxY, x, txY); + //qDebug("%d => %d", i, int(mSpeedHistoryRx[i])); + lastX = x; + lastRxY = rxY; + lastTxY = txY; + + count++; + x = width() - int(step*(count+1)); + + } +} + diff --git a/src/src/chart.h b/src/src/chart.h new file mode 100644 index 0000000..2e89540 --- /dev/null +++ b/src/src/chart.h @@ -0,0 +1,43 @@ +/*************************************************************************** +* Copyright (C) 2005 by Hugo Parente Lima * +* hugo_pl@users.sourceforge.net * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ + +#ifndef CHART_H +#define CHART_H + +#include + +class QPaintEvent; + +class Chart : public QWidget { +public: + Chart(QWidget* parent, const double* uploadBuffer, const double* downloadBuffer, int bufferSize, const int* ptr, const double* maxspeed); + QSize sizeHint() { return QSize(200, 100); } +protected: + void paintEvent( QPaintEvent* ev ); + +private: + const double* mUplBuffer; + const double* mDldBuffer; + const int mBufferSize; + const int* mPtr; + const double* mMaxSpeed; +}; + +#endif diff --git a/src/src/configure.cpp b/src/src/configure.cpp new file mode 100644 index 0000000..4e10636 --- /dev/null +++ b/src/src/configure.cpp @@ -0,0 +1,161 @@ +/*************************************************************************** + * Copyright (C) 2004 by Hugo Parente Lima * + * hugo_pl@users.sourceforge.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "configure.h" +#include "knetstats.h" + +// Qt includes +#include +#include +#include +#include +#include +#include +// Kde includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +Configure::Configure(KNetStats* parent, const InterfaceMap& ifs) : ConfigureBase(parent) { + // Load configuration + KIconLoader* loader = kapp->iconLoader(); + + QPixmap iconPCI = loader->loadIcon("icon_pci.png", KIcon::Small, 16); + + // Clone the configuration. + for (InterfaceMap::ConstIterator it = ifs.begin(); it != ifs.end(); ++it) { + mInterfaces->insertItem(iconPCI, it.key()); + mConfig[it.key()] = it.data()->options(); + +// parent->readInterfaceOptions(*it, &mConfig[*it]); + } + + mInterfaces->setCurrentItem(0); + changeInterface(mInterfaces->selectedItem()); + + connect(mInterfaces, SIGNAL(selectionChanged(QListBoxItem*)), this, SLOT(changeInterface(QListBoxItem*))); + connect(mTheme, SIGNAL(activated(int)), this, SLOT(changeTheme(int))); + //connect(mInterfaces, SIGNAL(contextMenuRequested(QListBoxItem*, const QPoint&)), this, SLOT(showInterfaceContextMenu(QListBoxItem*, const QPoint&))); +} + +void Configure::changeInterface(QListBoxItem* item) { + QString interface = item->text(); + + if (!mCurrentItem.isEmpty()) + { + // Salvas as modificações passadas + KNetStatsView::Options& oldview = mConfig[mCurrentItem]; + // general options + oldview.mMonitoring = mMonitoring->isChecked(); + oldview.mUpdateInterval = mUpdateInterval->value(); + oldview.mViewMode = (KNetStatsView::Mode) mViewMode->currentItem(); + // txt view options + oldview.mTxtUplColor = mTxtUplColor->color(); + oldview.mTxtDldColor = mTxtDldColor->color(); + oldview.mTxtFont = mTxtFont->font(); + // icon view + oldview.mTheme = mTheme->currentItem(); + // chart view + oldview.mChartUplColor = mChartUplColor->color(); + oldview.mChartDldColor = mChartDldColor->color(); + oldview.mChartBgColor = mChartBgColor->color(); + oldview.mChartTransparentBackground = mChartTransparentBackground->isChecked(); + } + + if (interface == mCurrentItem) + return; + // Carrega as opt. da nova interface + KNetStatsView::Options& view = mConfig[interface]; + // general + mMonitoring->setChecked(view.mMonitoring); + mUpdateInterval->setValue(view.mUpdateInterval); + mViewMode->setCurrentItem(view.mViewMode); + mWdgStack->raiseWidget(view.mViewMode); + // txt options + mTxtUplColor->setColor(view.mTxtUplColor); + mTxtDldColor->setColor(view.mTxtDldColor); + mTxtFont->setFont( view.mTxtFont ); + // icon options + mTheme->setCurrentItem(view.mTheme); + changeTheme(view.mTheme); + // chart options + mChartUplColor->setColor(view.mChartUplColor); + mChartDldColor->setColor(view.mChartDldColor); + mChartBgColor->setColor(view.mChartBgColor); + mChartTransparentBackground->setChecked(view.mChartTransparentBackground); + + mCurrentItem = interface; +} + +bool Configure::canSaveConfig() +{ + // update the options + changeInterface(mInterfaces->item( mInterfaces->currentItem() )); + + bool ok = false; + for(OptionsMap::ConstIterator i = mConfig.begin(); i != mConfig.end(); ++i) + if (i.data().mMonitoring) { + ok = true; + break; + } + + if (!ok) + KMessageBox::error(this, i18n("You need to select at least one interface to monitor.")); + return ok; +} + +void Configure::changeTheme(int theme) +{ + KIconLoader* loader = kapp->iconLoader(); + mIconError->setPixmap(loader->loadIcon("theme"+QString::number(theme)+"_error.png", + KIcon::Panel, ICONSIZE)); + mIconNone->setPixmap(loader->loadIcon("theme"+QString::number(theme)+"_none.png", + KIcon::Panel, ICONSIZE)); + mIconTx->setPixmap(loader->loadIcon("theme"+QString::number(theme)+"_tx.png", + KIcon::Panel, ICONSIZE)); + mIconRx->setPixmap(loader->loadIcon("theme"+QString::number(theme)+"_rx.png", + KIcon::Panel, ICONSIZE)); + mIconBoth->setPixmap(loader->loadIcon("theme"+QString::number(theme)+"_both.png", + KIcon::Panel, ICONSIZE)); +} +/* +void Configure::showInterfaceContextMenu(QListBoxItem* item, const QPoint& point) { + if (!item && mConfig.size() == 1) + return; + QPixmap icon = kapp->iconLoader()->loadIcon("editdelete", KIcon::Small, 16); + QPopupMenu* menu = new QPopupMenu(this); + menu->insertItem(icon, i18n("Renomve Interface"), this, SLOT(removeInterface())); + menu->exec(point); +} + +void Configure::removeInterface() { + mConfig.erase(mInterfaces->currentText()); + mInterfaces->removeItem(mInterfaces->currentItem()); +} +*/ +#include "configure.moc" diff --git a/src/src/configure.h b/src/src/configure.h new file mode 100644 index 0000000..a0098f7 --- /dev/null +++ b/src/src/configure.h @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (C) 2004 by Hugo Parente Lima * + * hugo_pl@users.sourceforge.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef CONFIGURE_H +#define CONFIGURE_H + +#include "configurebase.h" +#include "interface.h" +#include +#include +#include +#include +#include +#include + +static const int ICONSIZE = 22; + +class KNetStats; +class QListBoxItem; + + +typedef QMap OptionsMap; + + +/** +* Configure dialog +*/ +class Configure : public ConfigureBase +{ + Q_OBJECT +public: + Configure(KNetStats* parent, const InterfaceMap& ifs); + + const OptionsMap& currentConfig() const { return mConfig; } + bool canSaveConfig(); + const OptionsMap& options() const { return mConfig; } +private: + QString mCurrentItem; + OptionsMap mConfig; + +protected slots: + void changeInterface(QListBoxItem* item); + void changeTheme(int theme); + //void showInterfaceContextMenu(QListBoxItem* item, const QPoint& point); + //void removeInterface(); +}; + +#endif diff --git a/src/src/configurebase.ui b/src/src/configurebase.ui new file mode 100644 index 0000000..4444be0 --- /dev/null +++ b/src/src/configurebase.ui @@ -0,0 +1,684 @@ + +ConfigureBase + + + ConfigureBase + + + + 0 + 0 + 355 + 307 + + + + + 4 + 4 + 0 + 0 + + + + Configure KNetStats + + + + unnamed + + + Minimum + + + + layout7 + + + + unnamed + + + + mSpacer + + + Horizontal + + + Expanding + + + + 120 + 20 + + + + + + mOk + + + Ok + + + true + + + + + mApply + + + Apply + + + + + mCancel + + + Cancel + + + + + + + mInterfaces + + + + 5 + 7 + 0 + 0 + + + + + + mAppearanceGroup + + + + 5 + 7 + 0 + 0 + + + + Appearance + + + + unnamed + + + + mWdgStack + + + + mIconPage + + + 0 + + + + unnamed + + + 0 + + + + layout5 + + + + unnamed + + + + mLabel4 + + + Theme: + + + + + + Classic + + + + + Modem + + + + + Network + + + + + Wireless + + + + + Kppp + + + + mTheme + + + + + spacer2 + + + Horizontal + + + Expanding + + + + 21 + 20 + + + + + + + + layout7_2 + + + + unnamed + + + + mIconError + + + + 0 + 0 + 0 + 0 + + + + + 22 + 22 + + + + true + + + + + spacer3 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + mIconNone + + + + 0 + 0 + 0 + 0 + + + + + 22 + 22 + + + + true + + + + + spacer4 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + mIconTx + + + + 0 + 0 + 0 + 0 + + + + + 22 + 22 + + + + true + + + + + spacer5 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + mIconRx + + + + 0 + 0 + 0 + 0 + + + + + 22 + 22 + + + + true + + + + + spacer6 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + mIconBoth + + + + 0 + 0 + 0 + 0 + + + + + 22 + 22 + + + + true + + + + + + + spacer11 + + + Vertical + + + Expanding + + + + 20 + 20 + + + + + + + + mTextPage + + + 1 + + + + unnamed + + + 0 + + + + mTxtUplColor + + + + + + + + mLabel5 + + + Download color: + + + + + mTxtDldColor + + + + + + + + mTxtFont + + + + 5 + 0 + 0 + 0 + + + + + + mLabel6 + + + Upload color: + + + + + + + mBarsPage + + + 2 + + + + unnamed + + + 0 + + + + mChartBgLabel + + + Background: + + + + + mChartUplColor + + + + + + + + mLabel7 + + + Upload color: + + + + + mLabel8 + + + Download color: + + + + + mChartDldColor + + + + + + + + mChartBgColor + + + + + + + + mChartTransparentBackground + + + Transparent background + + + + + + + + + + mConfigurationGroup + + + + 5 + 7 + 0 + 0 + + + + Configuration + + + + unnamed + + + + + Icon + + + + + Text + + + + + Chart + + + + mViewMode + + + + + mLabel3 + + + View mode: + + + + + mLabel2 + + + Update interval: + + + WordBreak|AlignVCenter + + + + + mUpdateInterval + + + 300 + + + 100 + + + 2000 + + + ms + + + + + mMonitoring + + + To monitor this interface + + + + + + + + + mViewMode + activated(int) + mWdgStack + raiseWidget(int) + + + mChartTransparentBackground + toggled(bool) + mChartBgColor + setDisabled(bool) + + + mChartTransparentBackground + toggled(bool) + mChartBgLabel + setDisabled(bool) + + + + mOk + mApply + mCancel + mInterfaces + mMonitoring + mUpdateInterval + mViewMode + mTheme + mTxtUplColor + mTxtDldColor + mTxtFont + mChartUplColor + mChartDldColor + mChartBgColor + mChartTransparentBackground + + + + kpushbutton.h + kpushbutton.h + kpushbutton.h + kcolorbutton.h + kcolorbutton.h + kfontrequester.h + kcolorbutton.h + kcolorbutton.h + kcolorbutton.h + kcombobox.h + knuminput.h + knuminput.h + + diff --git a/src/src/interface.cpp b/src/src/interface.cpp new file mode 100644 index 0000000..26a02a5 --- /dev/null +++ b/src/src/interface.cpp @@ -0,0 +1,57 @@ +// +// C++ Implementation: interface +// +// Description: +// +// +// Author: Hugo Parente Lima , (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "interface.h" +#include +#include +#include + +Interface::Interface(KNetStats* parent, const QString& name) : mName(name), mView(0), mParent(parent) { + update(); +} + +void Interface::update() { + bool defaultVisibility = !(mName == "lo" || mName == "sit0"); + + KConfig* cfg = kapp->config(); + KConfigGroupSaver groupSaver(cfg, mName); + bool visible = cfg->readBoolEntry("Monitoring", defaultVisibility); + if (!visible) + setVisible(false); + else if (visible && !mView) + setVisible(true); + else if (visible && mView) + mView->updateViewOptions(); +} + +void Interface::setVisible(bool visible) { + if (!visible) { + delete mView; + mView = 0; + } else if (visible && !mView) + mView = new KNetStatsView(mParent, mName); +} + +KNetStatsView::Options Interface::options() { + if (mView) + return mView->options(); + else { + KNetStatsView::Options opt; + KNetStatsView::readOptions(mName, &opt, false); + return opt; + } +} + +void Interface::say(const QString& message) { + if (mView) + mView->say(message); +} + diff --git a/src/src/interface.h b/src/src/interface.h new file mode 100644 index 0000000..71b29f8 --- /dev/null +++ b/src/src/interface.h @@ -0,0 +1,51 @@ +// +// C++ Interface: interface +// +// Description: +// +// +// Author: Hugo Parente Lima , (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#ifndef INTERFACE_H +#define INTERFACE_H + +#include +#include "knetstatsview.h" +class KNetStats; + +class Interface { + QString mName; + KNetStatsView* mView; + KNetStats* mParent; + + Interface(const Interface&); +public: + /** + * Constructs a new interface. + * \param parent parent of the view of this interface. + * \param name name of this interface (not the QObject name!!) + */ + Interface(KNetStats* parent, const QString& name); + + /** + * Set this interface visible to the user via a KNetStatsView. + */ + void setVisible(bool visible); + bool isVisible() { return mView; } + + void update(); + + void say(const QString& message); + + KNetStatsView::Options options(); +}; + +#include +typedef QMap InterfaceMap; + + +#endif diff --git a/src/src/knetstats.cpp b/src/src/knetstats.cpp new file mode 100644 index 0000000..e02e3f6 --- /dev/null +++ b/src/src/knetstats.cpp @@ -0,0 +1,191 @@ +/*************************************************************************** + * Copyright (C) 2004 by Hugo Parente Lima * + * hugo_pl@users.sourceforge.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "knetstats.h" +#include "knetstatsview.h" +#include "configure.h" +#include "interface.h" + +// Qt includes +#include +#include +#include +// KDE includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +KNetStats::KNetStats() : QWidget(0, "knetstats"), mConfigure(0), mBoot(true) { + setupUi(); + int count; + detectNewInterfaces(&count); + if (!count && numInterfaces()) // caos!!! All interfaces are invisible! turn all visible... + for(InterfaceMap::Iterator i = mInterfaces.begin(); i != mInterfaces.end(); ++i) + i.data()->setVisible(true); + + + mBoot = false; + QTimer* timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(detectNewInterfaces())); + timer->start(IF_DETECTION_INTERVAL); +} + +KNetStats::~KNetStats() { + for (InterfaceMap::Iterator it = mInterfaces.begin(); it != mInterfaces.end(); ++it) + delete it.data(); +} + + +void KNetStats::setupUi() { + setIcon(kapp->icon()); + // Cria o contextMenu + mActionCollection = new KActionCollection(this); + mContextMenu = new KPopupMenu(this); + mContextMenu->insertTitle( kapp->miniIcon(), kapp->caption() ); + KAction* configure = KStdAction::preferences(this, SLOT(configure()), mActionCollection, "configure"); + configure->plug(mContextMenu); + mContextMenu->insertSeparator(); + KHelpMenu* helpmenu = new KHelpMenu(this, QString::null, false); + mContextMenu->insertItem( i18n("&Help"), helpmenu->menu() ); + + mContextMenu->insertSeparator(); + KAction* quitAction = KStdAction::quit(kapp, SLOT(quit()), mActionCollection); + quitAction->plug(mContextMenu); + + connect(helpmenu, SIGNAL(showAboutApplication()), this, SLOT(about())); +} + +QStringList KNetStats::scanInterfaces() { + QDir dir("/sys/class/net"); + if (!dir.exists()) { + KMessageBox::error(0, i18n("You need kernel 2.6.x with support to the /sys filesystem.")); + return QStringList(); + } else { + QStringList list = dir.entryList(QDir::Dirs); + list.pop_front(); // removes "." and ".." entries + list.pop_front(); + return list; + } +} + +bool KNetStats::configure() { + if (mConfigure) + mConfigure->show(); + else { +/* if (!mInterfaces.size()) { + KMessageBox::error(this, i18n("You don't have any network interface.\nKNetStats will quit now.")); + return false; + }*/ + + mConfigure = new Configure(this, mInterfaces); + connect(mConfigure->mOk, SIGNAL(clicked()), this, SLOT(configOk())); + connect(mConfigure->mApply, SIGNAL(clicked()), this, SLOT(configApply())); + connect(mConfigure->mCancel, SIGNAL(clicked()), this, SLOT(configCancel())); + mConfigure->show(); + } + return true; +} + +void KNetStats::configOk() { + if (mConfigure->canSaveConfig()) { + saveConfig( mConfigure->options() ); + delete mConfigure; + mConfigure = 0; + } +} + +void KNetStats::configApply() { + if (mConfigure->canSaveConfig()) + saveConfig( mConfigure->options() ); +} + +void KNetStats::configCancel() { + delete mConfigure; + mConfigure = 0; +} + +void KNetStats::saveConfig(const OptionsMap& options) { + KConfig* cfg = kapp->config(); + + for(OptionsMap::ConstIterator i = options.begin(); i != options.end(); ++i) { + KConfigGroupSaver groupSaver(cfg, i.key()); + const KNetStatsView::Options& opt = i.data(); + // general + cfg->writeEntry("UpdateInterval", opt.mUpdateInterval); + cfg->writeEntry("ViewMode", opt.mViewMode); + cfg->writeEntry("Monitoring", opt.mMonitoring); + // txt view + cfg->writeEntry("TxtFont", opt.mTxtFont); + cfg->writeEntry("TxtUplColor", opt.mTxtUplColor); + cfg->writeEntry("TxtDldColor", opt.mTxtDldColor); + // IconView + cfg->writeEntry("Theme", opt.mTheme); + // Graphic view + cfg->writeEntry("ChartUplColor", opt.mChartUplColor); + cfg->writeEntry("ChartDldColor", opt.mChartDldColor); + cfg->writeEntry("ChartBgColor", opt.mChartBgColor); + cfg->writeEntry("ChartUseTransparentBackground", opt.mChartTransparentBackground); + } + + for (InterfaceMap::ConstIterator i = mInterfaces.begin(); i != mInterfaces.end(); ++i) + i.data()->update(); +} + +void KNetStats::about() { + KAboutApplication dlg(this); + dlg.exec(); +} + + +void KNetStats::detectNewInterfaces(int* count_ptr) { + int count = 0; + const QStringList& interfaces = KNetStats::scanInterfaces(); + QStringList::ConstIterator i = interfaces.begin(); + for(; i != interfaces.end(); ++i) { + InterfaceMap::Iterator elem = mInterfaces.find(*i); + if (elem == mInterfaces.end()) + if (createInterface(*i)) + count++; + } + if (count && count_ptr) + *count_ptr = count; +} + +bool KNetStats::createInterface(const QString& name) { + // Cria a interface e adiciona em mInterfaces. + Interface* interface = new Interface(this, name); + mInterfaces.insert(name, interface); + if (!mBoot) + interface->say(i18n("New interface detected: %1").arg(name)); + return interface->isVisible(); +} + +#include "knetstats.moc" diff --git a/src/src/knetstats.h b/src/src/knetstats.h new file mode 100644 index 0000000..4282890 --- /dev/null +++ b/src/src/knetstats.h @@ -0,0 +1,93 @@ +/*************************************************************************** + * Copyright (C) 2004 by Hugo Parente Lima * + * hugo_pl@users.sourceforge.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef KNETSTATS_H +#define KNETSTATS_H + +#include +#include +#include +#include "configure.h" + +class KNetStatsView; +class KConfig; +class KPopupMenu; +class KActionCollection; + +class Interface; + + +class KNetStats : public QWidget +{ + Q_OBJECT + + enum { + IF_DETECTION_INTERVAL = 5000 + }; + +public: + /// Constructor + KNetStats(); + ~KNetStats(); + + KPopupMenu* const contextMenu() const { return mContextMenu; } + /** + * \brief Search for network interfaces parsing /proc/net/dev + * \return A StringList with the network interface names + */ + static QStringList scanInterfaces(); + int numInterfaces() const { return mInterfaces.size(); } + + +public slots: + /// Display configure the dialog box + bool configure(); + /// Configure dialog OK button + void configOk(); + /// Configure dialog Apply button + void configApply(); + /// Configure dialog Cancel button + void configCancel(); + + /// Diaplay the about box + void about(); + /** + * Search for new interfaces + * \param count_ptr Interface count, store the number of new visible interfaces found. + */ + void detectNewInterfaces(int* count_ptr = 0); +private: + KPopupMenu* mContextMenu; // help menu usado por todos os tray icons + Configure* mConfigure; + KActionCollection* mActionCollection; + bool mBoot; + InterfaceMap mInterfaces; + + + void readOptions(); + void saveConfig(const OptionsMap& options); + void clearOptions(OptionsMap* options); + void setupUi(); + // Creates a new interface, returns true or false if the new interface is visible or not. + bool createInterface(const QString& interface); + +}; + +#endif diff --git a/src/src/knetstatsview.cpp b/src/src/knetstatsview.cpp new file mode 100644 index 0000000..ea480ab --- /dev/null +++ b/src/src/knetstatsview.cpp @@ -0,0 +1,402 @@ +/*************************************************************************** + * Copyright (C) 2004-2005 by Hugo Parente Lima * + * hugo_pl@users.sourceforge.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "knetstatsview.h" +#include "knetstats.h" + +// KDE headers +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +// Qt headers +#include +#include +#include +#include +#include +#include +#include +#include + +// C headers +#include +#include + +// Linux headers +extern "C" { +#include +#include +#include +#include +} + +#include "configure.h" +#include "statistics.h" + +extern const char* programName; + +KNetStatsView::KNetStatsView(KNetStats* parent, const QString& interface) +: KSystemTray(parent, 0), mSysDevPath("/sys/class/net/"+interface+"/"), mInterface(interface) { + mFdSock = 0; + mFirstUpdate = true; + mMaxSpeedAge = 0; + mMaxSpeed = 0.0; + mBRx = mBTx = mPRx = mPTx = 0; + mConnected = mCarrier = true; + mTotalBytesRx = mTotalBytesTx = mTotalPktRx = mTotalPktTx = 0; + mSpeedBufferPtr = mSpeedHistoryPtr = 0; + mStatistics = 0; + + readOptions(interface, &mOptions, true); + resetBuffers(); + openFdSocket(); + memset(&mDevInfo, 0, sizeof(mDevInfo)); + strcpy(mDevInfo.ifr_name, mInterface.latin1()); + + setTextFormat(Qt::PlainText); + mContextMenu = parent->contextMenu(); + show(); + + // Timer + mTimer = new QTimer(this, "timer"); + connect(mTimer, SIGNAL(timeout()), this, SLOT(updateStats(void))); + + QToolTip::add(this, i18n("Monitoring %1").arg(mInterface)); + setup(); + mStatistics = new Statistics(this); +} + +KNetStatsView::~KNetStatsView() { + if (mFdSock != -1) + shutdown(mFdSock, SHUT_RDWR); + +} + +void KNetStatsView::setup() { + if (mOptions.mViewMode == Text) + setFont(mOptions.mTxtFont); + else if (mOptions.mViewMode == Icon) { + // Load Icons + KIconLoader* loader = kapp->iconLoader(); + mIconError = loader->loadIcon("theme"+QString::number(mOptions.mTheme)+"_error.png", + KIcon::Panel, ICONSIZE); + mIconNone = loader->loadIcon("theme"+QString::number(mOptions.mTheme)+"_none.png", + KIcon::Panel, ICONSIZE); + mIconTx = loader->loadIcon("theme"+QString::number(mOptions.mTheme)+"_tx.png", + KIcon::Panel, ICONSIZE); + mIconRx =loader->loadIcon("theme"+QString::number(mOptions.mTheme)+"_rx.png", + KIcon::Panel, ICONSIZE); + mIconBoth = loader->loadIcon("theme"+QString::number(mOptions.mTheme)+"_both.png", + KIcon::Panel, ICONSIZE); + mCurrentIcon = &mIconNone; + } + mTimer->start(mOptions.mUpdateInterval); + updateStats(); + QWidget::update(); + mFirstUpdate = false; +} + +void KNetStatsView::say(const QString& message) { + KPassivePopup::message(programName, message, kapp->miniIcon(), this); +} + +void KNetStatsView::updateViewOptions() { + readOptions(mInterface, &mOptions); + setup(); +} + +void KNetStatsView::updateStats() { + FILE* flags_fp = fopen((mSysDevPath+"flags").latin1(), "r"); + bool currentStatus; + if (!flags_fp) + currentStatus = false; + else { + int flags; + fscanf(flags_fp, "%Xu", &flags); + fclose(flags_fp); + currentStatus = IFF_UP & flags; + } + + if (!currentStatus && mConnected) { // interface down... + mConnected = false; + resetBuffers(); + QWidget::update(); + say(i18n("%1 is inactive").arg(mInterface)); + } else if (currentStatus && !mConnected) { + mConnected = true; + say(i18n("%1 is active").arg(mInterface)); + } + + // kernel < 2.6.9 (I think) does not have carrier info, considering carrier ever on. + FILE* carrier_fp = fopen((mSysDevPath+"carrier").latin1(), "r"); + char carrierFlag = '1'; + if (carrier_fp) { + carrierFlag = fgetc(carrier_fp); + fclose(carrier_fp); + } + + if (!mConnected) + return; + if (carrierFlag == '0') { // carrier down + if (mCarrier) { + mCarrier = false; + QWidget::update(); + say(i18n("%1 is disconnected").arg(mInterface)); + } + return; + } else if (!mCarrier) { // carrier up + mCarrier = true; + say(i18n("%1 is connected").arg(mInterface)); + } + + unsigned int brx = readInterfaceNumValue("rx_bytes"); + unsigned int btx = readInterfaceNumValue("tx_bytes"); + unsigned int prx = readInterfaceNumValue("rx_packets"); + unsigned int ptx = readInterfaceNumValue("tx_packets"); + + + if (!mFirstUpdate) { // a primeira velocidade sempre eh absurda, para evitar isso temos o mFirstUpdate + if (++mSpeedBufferPtr >= SPEED_BUFFER_SIZE) + mSpeedBufferPtr = 0; + + // Calcula as velocidades + mSpeedBufferTx[mSpeedBufferPtr] = ((btx - mBTx)*(1000.0f/mOptions.mUpdateInterval)); + mSpeedBufferRx[mSpeedBufferPtr] = ((brx - mBRx)*(1000.0f/mOptions.mUpdateInterval)); + mSpeedBufferPTx[mSpeedBufferPtr] = ((ptx - mPTx)*(1000.0f/mOptions.mUpdateInterval)); + mSpeedBufferPRx[mSpeedBufferPtr] = ((prx - mPRx)*(1000.0f/mOptions.mUpdateInterval)); + + if (++mSpeedHistoryPtr >= HISTORY_SIZE) + mSpeedHistoryPtr = 0; + mSpeedHistoryRx[mSpeedHistoryPtr] = calcSpeed(mSpeedBufferRx); + mSpeedHistoryTx[mSpeedHistoryPtr] = calcSpeed(mSpeedBufferTx); + + mMaxSpeedAge--; + + if (mSpeedHistoryTx[mSpeedHistoryPtr] > mMaxSpeed) { + mMaxSpeed = mSpeedHistoryTx[mSpeedHistoryPtr]; + mMaxSpeedAge = HISTORY_SIZE; + } + if (mSpeedHistoryRx[mSpeedHistoryPtr] > mMaxSpeed) { + mMaxSpeed = mSpeedHistoryRx[mSpeedHistoryPtr]; + mMaxSpeedAge = HISTORY_SIZE; + } + if (mMaxSpeedAge < 1) + calcMaxSpeed(); + } + + if (mOptions.mViewMode == Icon) { + QPixmap* newIcon; + if (brx == mBRx) { + if (btx == mBTx ) + newIcon = &mIconNone; + else + newIcon = &mIconTx; + } else { + if (btx == mBTx ) + newIcon = &mIconRx; + else + newIcon = &mIconBoth; + } + + if (newIcon != mCurrentIcon) { + mCurrentIcon = newIcon; + QWidget::update(); + } + } else if (mOptions.mViewMode == Graphic || (btx != mBTx && brx != mBRx)) + QWidget::update(); + + // Update stats + mTotalBytesRx += brx - mBRx; + mTotalBytesTx += btx - mBTx; + mTotalPktRx += prx - mPRx; + mTotalPktTx += ptx - mPTx; + + mBRx = brx; + mBTx = btx; + mPRx = prx; + mPTx = ptx; +} + +unsigned long KNetStatsView::readInterfaceNumValue(const char* name) { + // stdio functions appear to be more fast than QFile? + FILE* fp = fopen((mSysDevPath+"statistics/"+name).latin1(), "r"); + long retval; + fscanf(fp, "%lu", &retval); + fclose(fp); + return retval; +} + +QString KNetStatsView::readInterfaceStringValue(const char* name, int maxlength) { + QFile macFile(mSysDevPath+name); + macFile.open(IO_ReadOnly); + QString value; + macFile.readLine(value, maxlength); + return value; +} + +void KNetStatsView::resetBuffers() { + memset(mSpeedHistoryRx, 0, sizeof(double)*HISTORY_SIZE); + memset(mSpeedHistoryTx, 0, sizeof(double)*HISTORY_SIZE); + memset(mSpeedBufferRx, 0, sizeof(double)*SPEED_BUFFER_SIZE); + memset(mSpeedBufferTx, 0, sizeof(double)*SPEED_BUFFER_SIZE); + memset(mSpeedBufferPRx, 0, sizeof(double)*SPEED_BUFFER_SIZE); + memset(mSpeedBufferPTx, 0, sizeof(double)*SPEED_BUFFER_SIZE); +} + +void KNetStatsView::paintEvent( QPaintEvent* ) { + QPainter paint(this); + switch(mOptions.mViewMode) { + case Icon: + if (!mCarrier || !mConnected) + mCurrentIcon = &mIconError; + paint.drawPixmap(0, 0, *mCurrentIcon); + break; + case Text: + drawText(paint); + break; + case Graphic: + drawGraphic(paint); + break; + } +} + +void KNetStatsView::drawText(QPainter& paint) { + if (!mCarrier || !mConnected) { + paint.drawText(rect(), Qt::AlignCenter, "?"); + } else { + paint.setFont( mOptions.mTxtFont ); + paint.setPen( mOptions.mTxtUplColor ); + paint.drawText( rect(), Qt::AlignTop, Statistics::byteFormat(byteSpeedTx(), "KB", "MB")); + paint.setPen( mOptions.mTxtDldColor ); + paint.drawText( rect(), Qt::AlignBottom, Statistics::byteFormat(byteSpeedRx(), "KB", "MB")); + } +} + +void KNetStatsView::drawGraphic(QPainter& paint) { + if (!mCarrier || !mConnected) { + paint.drawText(rect(), Qt::AlignCenter, "X"); + return; + } + + QSize size = this->size(); + + if (!mOptions.mChartTransparentBackground) + paint.fillRect(0, 0, size.width(), size.height(), mOptions.mChartBgColor); + + const int HEIGHT = size.height()-1; + + // qDebug("MaxSpeed: %d, age: %d", int(mMaxSpeed), mMaxSpeedAge); + int lastX; + int lastRxY = HEIGHT - int(HEIGHT * (mSpeedHistoryRx[mSpeedHistoryPtr]/mMaxSpeed)); + int lastTxY = HEIGHT - int(HEIGHT * (mSpeedHistoryTx[mSpeedHistoryPtr]/mMaxSpeed)); + int x = lastX = size.width(); + int count = 0; + for (int i = mSpeedHistoryPtr; count < width(); i--) { + if (i < 0) + i = HISTORY_SIZE-1; + + int rxY = HEIGHT - int(HEIGHT * (mSpeedHistoryRx[i]/mMaxSpeed)); + int txY = HEIGHT - int(HEIGHT * (mSpeedHistoryTx[i]/mMaxSpeed)); + paint.setPen(mOptions.mChartDldColor); + paint.drawLine(lastX, lastRxY, x, rxY); + paint.setPen(mOptions.mChartUplColor); + paint.drawLine(lastX, lastTxY, x, txY); + //qDebug("%d => %d", i, int(mSpeedHistoryRx[i])); + lastX = x; + lastRxY = rxY; + lastTxY = txY; + + count++; + x = width()-int(count+1); + } +} + +void KNetStatsView::mousePressEvent(QMouseEvent* ev) { + if (ev->button() == Qt::RightButton ) + mContextMenu->exec(QCursor::pos()); + else if (ev->button() == Qt::LeftButton) + if (mStatistics->isShown()) + mStatistics->accept(); + else + mStatistics->show(); +} + +bool KNetStatsView::openFdSocket() { + if (mFdSock > 0) + return true; + if ((mFdSock = socket(AF_INET, SOCK_DGRAM, 0)) > 0) + return true; + return false; +} + +QString KNetStatsView::getIp() { + if (mFdSock == -1 && !openFdSocket()) + return ""; + + ioctl(mFdSock, SIOCGIFADDR, &mDevInfo); + sockaddr_in sin = ((sockaddr_in&)mDevInfo.ifr_addr); + return inet_ntoa(sin.sin_addr); +} + +QString KNetStatsView::getNetmask() { + if (mFdSock == -1 && !openFdSocket()) + return ""; + ioctl(mFdSock, SIOCGIFNETMASK, &mDevInfo); + sockaddr_in mask = ((sockaddr_in&)mDevInfo.ifr_netmask); + return inet_ntoa(mask.sin_addr); +} + +void KNetStatsView::readOptions( const QString& name, KNetStatsView::Options* opts, bool defaultVisibility ) { + KConfig* cfg = kapp->config(); + KConfigGroupSaver groupSaver(cfg, name); + + // general + opts->mUpdateInterval = cfg->readNumEntry("UpdateInterval", 300); + opts->mViewMode = (Mode)cfg->readNumEntry("ViewMode", 0); + opts->mMonitoring = cfg->readBoolEntry("Monitoring", defaultVisibility); + // txt view + opts->mTxtFont = cfg->readFontEntry("TxtFont"); + opts->mTxtUplColor = cfg->readColorEntry("TxtUplColor", &Qt::red); + opts->mTxtDldColor = cfg->readColorEntry("TxtDldColor", &Qt::green); + // IconView + int defaultTheme = 0; + if (name.startsWith("wlan")) + defaultTheme = 3; // three... is a magic number... a magic number.... + opts->mTheme = cfg->readNumEntry("Theme", defaultTheme); + // Graphic + opts->mChartUplColor = cfg->readColorEntry("ChartUplColor", &Qt::red); + opts->mChartDldColor = cfg->readColorEntry("ChartDldColor", &Qt::blue); + opts->mChartBgColor = cfg->readColorEntry("ChartBgColor", &Qt::white); + opts->mChartTransparentBackground = cfg->readBoolEntry("ChartUseTransparentBackground", true); +} + + +#include "knetstatsview.moc" diff --git a/src/src/knetstatsview.h b/src/src/knetstatsview.h new file mode 100644 index 0000000..4e97392 --- /dev/null +++ b/src/src/knetstatsview.h @@ -0,0 +1,258 @@ +/*************************************************************************** +* Copyright (C) 2004-2005 by Hugo Parente Lima * +* hugo_pl@users.sourceforge.net * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ + +#ifndef KNETSTATSVIEW_H +#define KNETSTATSVIEW_H + +#include +#include +#include +#include + +#include +#include + +class QTimer; +class QMouseEvent; +class QPainter; +class QPaintEvent; +class Statistics; +class KNetStats; + +/** +* Main class +*/ +class KNetStatsView : public KSystemTray +{ + Q_OBJECT + + enum { + HISTORY_SIZE = 50, // Speed history buffer size + SPEED_BUFFER_SIZE = 10 // Speed normalization buffer size + }; + +public: + /** + * KNetstats view mode on system tray. + */ + enum Mode { + Icon, Text, Graphic + }; + + /** + * Visualization options. + */ + struct Options { + // general + int mUpdateInterval; + Mode mViewMode; + bool mMonitoring; + // txt view + QFont mTxtFont; + QColor mTxtUplColor; + QColor mTxtDldColor; + // icon view + int mTheme; + // chart view + QColor mChartUplColor; + QColor mChartDldColor; + QColor mChartBgColor; + bool mChartTransparentBackground; + }; + + KNetStatsView(KNetStats* parent, const QString& interface); + ~KNetStatsView(); + + void say(const QString& message); + void updateViewOptions(); + // read a value from /sys/class/net/interface/name + unsigned long readInterfaceNumValue(const char* name); + // read a value from /sys/class/net/interface/name + QString readInterfaceStringValue(const char* name, int maxlength); + QString getIp(); + QString getNetmask(); + + const double* speedHistoryRx() const { return mSpeedHistoryRx; } + const double* speedHistoryTx() const { return mSpeedHistoryTx; } + const int historyBufferSize() const { return HISTORY_SIZE; } + const int* historyPointer() const { return &mSpeedHistoryPtr; } + const double* maxSpeed() const { return &mMaxSpeed; } + + /// Return a copy of the current view options. + Options options() const { return mOptions; } + /// read the interface view options + static void readOptions( const QString& name, Options* opts, bool defaultVisibility = false ); + + /// The current monitored network interface + inline const QString& interface() const; + /// The current Update Interval in miliseconds + inline int updateInterval() const; + /// We are in textmode? + inline Mode viewMode() const; + + /// Total of bytes receiveds + inline unsigned int totalBytesRx() const; + /// Total of bytes transmitted + inline unsigned int totalBytesTx() const; + /// Total of packets receiveds + inline unsigned int totalPktRx() const; + /// Total of packets transmitted + inline unsigned int totalPktTx() const; + /// RX Speed in bytes per second + inline double byteSpeedRx() const; + /// TX Speed in bytes per second + inline double byteSpeedTx() const; + /// RX Speed in packets per second + inline double pktSpeedRx() const; + /// TX Speed in packets per second + inline double pktSpeedTx() const; + +protected: + void mousePressEvent( QMouseEvent* ev ); + void paintEvent( QPaintEvent* ev ); + +private: + + int mFdSock; // Kernel-knetstats socket + struct ifreq mDevInfo; // info struct about our interface + + + QString mSysDevPath; // Path to the device. + bool mCarrier; // Interface carrier is on? + bool mConnected; // Interface exists? + + KPopupMenu* mContextMenu; // Global ContextMenu + Statistics* mStatistics; // Statistics window + QString mInterface; // Current interface + Options mOptions; // View options + + // Icons + QPixmap mIconError, mIconNone, mIconTx, mIconRx, mIconBoth; + QPixmap* mCurrentIcon; // Current state + QTimer* mTimer; // Timer + + // Rx e Tx to bytes and packets + unsigned long mBRx, mBTx, mPRx, mPTx; + // Statistics + unsigned long mTotalBytesRx, mTotalBytesTx, mTotalPktRx, mTotalPktTx; + // Speed buffers + double mSpeedBufferRx[SPEED_BUFFER_SIZE], mSpeedBufferTx[SPEED_BUFFER_SIZE]; + double mSpeedBufferPRx[SPEED_BUFFER_SIZE], mSpeedBufferPTx[SPEED_BUFFER_SIZE]; + // pointer to current speed buffer position + int mSpeedBufferPtr; + + bool mFirstUpdate; + + // History buffer TODO: Make it configurable! + double mSpeedHistoryRx[HISTORY_SIZE]; + double mSpeedHistoryTx[HISTORY_SIZE]; + int mSpeedHistoryPtr; + double mMaxSpeed; + int mMaxSpeedAge; + + + // setup the view. + void setup(); + void drawText(QPainter& paint); + void drawGraphic(QPainter& paint); + // Reset speed and history buffers + void resetBuffers(); + // calc tha max. speed stored in the history buffer + inline void calcMaxSpeed(); + // calc the speed using a speed buffer + inline double calcSpeed(const double* buffer) const; + + bool openFdSocket(); + +private slots: + // Called by the timer to update statistics + void updateStats(); + +}; + +void KNetStatsView::calcMaxSpeed() { + double max = 0.0; + int ptr = mSpeedHistoryPtr; + for (int i = 0; i < HISTORY_SIZE; ++i) { + if (mSpeedHistoryRx[i] > max) { + max = mSpeedHistoryRx[i]; + ptr = i; + } + if (mSpeedHistoryTx[i] > max) { + max = mSpeedHistoryTx[i]; + ptr = i; + } + } + mMaxSpeed = max; + mMaxSpeedAge = (mSpeedHistoryPtr > ptr) ? (mSpeedHistoryPtr - ptr) : (mSpeedHistoryPtr + HISTORY_SIZE - ptr); +} + +double KNetStatsView::calcSpeed(const double* buffer) const { + double total = 0.0; + for (int i = 0; i < SPEED_BUFFER_SIZE; ++i) + total += buffer[i]; + return total/SPEED_BUFFER_SIZE; +} + +const QString& KNetStatsView::interface() const { + return mInterface; +} + +int KNetStatsView::updateInterval() const { + return mOptions.mUpdateInterval; +} + +KNetStatsView::Mode KNetStatsView::viewMode() const { + return mOptions.mViewMode; +} + +unsigned int KNetStatsView::totalBytesRx() const { + return mTotalBytesRx; +} + +unsigned int KNetStatsView::totalBytesTx() const { + return mTotalBytesTx; +} + +unsigned int KNetStatsView::totalPktRx() const { + return mTotalPktRx; +} + +unsigned int KNetStatsView::totalPktTx() const { + return mTotalPktTx; +} + +double KNetStatsView::byteSpeedRx() const { + return mSpeedHistoryRx[mSpeedHistoryPtr]; +} + +double KNetStatsView::byteSpeedTx() const { + return mSpeedHistoryTx[mSpeedHistoryPtr]; +} + +double KNetStatsView::pktSpeedRx() const { + return calcSpeed(mSpeedBufferPRx); +} + +double KNetStatsView::pktSpeedTx() const { + return calcSpeed(mSpeedBufferPTx); +} + +#endif diff --git a/src/src/main.cpp b/src/src/main.cpp new file mode 100644 index 0000000..6c00834 --- /dev/null +++ b/src/src/main.cpp @@ -0,0 +1,66 @@ +/*************************************************************************** + * Copyright (C) 2004-2006 by Hugo Parente Lima * + * hugo_pl@users.sourceforge.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "knetstats.h" + +const char* programName = I18N_NOOP( "KNetStats" ); + +int main( int argc, char** argv ) +{ + KAboutData aboutData( "knetstats", programName, + "v1.6.1", // version + I18N_NOOP( "A network device monitor." ), // description + KAboutData::License_GPL, // license + "(C) 2004-2005 Hugo Parente Lima", // copyright + 0, + "http://knetstats.sourceforge.net", // homepage + "hugo_pl@users.sourceforge.net"); // bug email address + aboutData.setTranslator(I18N_NOOP("_: NAME OF TRANSLATORS"), I18N_NOOP("_: EMAIL OF TRANSLATORS")); + aboutData.addAuthor( "Hugo Parente Lima", 0, "hugo_pl@users.sourceforge.net" ); + + // Credits + aboutData.addCredit( "Thomas Windheuser", I18N_NOOP("SCons help, Debian packages, etc."), 0); + aboutData.addCredit( "KNemo", I18N_NOOP("Icon themes"), 0, + "http://kde-apps.org/content/show.php?content=12956" ); + // translators + aboutData.addCredit( "Ilyas Bakirov, Roberto Leandrini, Carlos Ortiz, Henrik Gebauer, Edward Romantsov, Wiktor Wandachowicz, Guillaume Savaton, Petar Toushkov, Liu Di", I18N_NOOP("KNetStats translation to other languages"), 0); + + KCmdLineArgs::init( argc, argv, &aboutData ); + KApplication::disableAutoDcopRegistration(); + + KApplication app; + KNetStats knetstats; + if (!knetstats.numInterfaces()) { + KMessageBox::error(0, i18n("You don't have any network interface.\nKNetStats will quit now.")); + return 1; + } + return app.exec(); +} + diff --git a/src/src/pics/Makefile.am b/src/src/pics/Makefile.am new file mode 100644 index 0000000..fab68d0 --- /dev/null +++ b/src/src/pics/Makefile.am @@ -0,0 +1,5 @@ +knetstats_DATA = theme0_none.png theme1_error.png theme2_both.png theme2_tx.png theme3_rx.png theme4_none.png \ + icon_pci.png theme0_rx.png theme1_none.png theme2_error.png theme3_both.png theme3_tx.png theme4_rx.png \ + theme0_both.png theme0_tx.png theme1_rx.png theme2_none.png theme3_error.png theme4_both.png theme4_tx.png \ + theme0_error.png theme1_both.png theme1_tx.png theme2_rx.png theme3_none.png theme4_error.png +knetstatsdir = $(kde_datadir)/knetstats/pics diff --git a/src/src/pics/icon_pci.png b/src/src/pics/icon_pci.png new file mode 100644 index 0000000..07059cc Binary files /dev/null and b/src/src/pics/icon_pci.png differ diff --git a/src/src/pics/theme0_both.png b/src/src/pics/theme0_both.png new file mode 100644 index 0000000..b81da44 Binary files /dev/null and b/src/src/pics/theme0_both.png differ diff --git a/src/src/pics/theme0_error.png b/src/src/pics/theme0_error.png new file mode 100644 index 0000000..803c077 Binary files /dev/null and b/src/src/pics/theme0_error.png differ diff --git a/src/src/pics/theme0_none.png b/src/src/pics/theme0_none.png new file mode 100644 index 0000000..a8f7c89 Binary files /dev/null and b/src/src/pics/theme0_none.png differ diff --git a/src/src/pics/theme0_rx.png b/src/src/pics/theme0_rx.png new file mode 100644 index 0000000..c0a49e1 Binary files /dev/null and b/src/src/pics/theme0_rx.png differ diff --git a/src/src/pics/theme0_tx.png b/src/src/pics/theme0_tx.png new file mode 100644 index 0000000..ba442ed Binary files /dev/null and b/src/src/pics/theme0_tx.png differ diff --git a/src/src/pics/theme1_both.png b/src/src/pics/theme1_both.png new file mode 100644 index 0000000..0dce305 Binary files /dev/null and b/src/src/pics/theme1_both.png differ diff --git a/src/src/pics/theme1_error.png b/src/src/pics/theme1_error.png new file mode 100644 index 0000000..729f1f9 Binary files /dev/null and b/src/src/pics/theme1_error.png differ diff --git a/src/src/pics/theme1_none.png b/src/src/pics/theme1_none.png new file mode 100644 index 0000000..6abcd43 Binary files /dev/null and b/src/src/pics/theme1_none.png differ diff --git a/src/src/pics/theme1_rx.png b/src/src/pics/theme1_rx.png new file mode 100644 index 0000000..51d144d Binary files /dev/null and b/src/src/pics/theme1_rx.png differ diff --git a/src/src/pics/theme1_tx.png b/src/src/pics/theme1_tx.png new file mode 100644 index 0000000..751b788 Binary files /dev/null and b/src/src/pics/theme1_tx.png differ diff --git a/src/src/pics/theme2_both.png b/src/src/pics/theme2_both.png new file mode 100644 index 0000000..f41a05a Binary files /dev/null and b/src/src/pics/theme2_both.png differ diff --git a/src/src/pics/theme2_error.png b/src/src/pics/theme2_error.png new file mode 100644 index 0000000..5aad370 Binary files /dev/null and b/src/src/pics/theme2_error.png differ diff --git a/src/src/pics/theme2_none.png b/src/src/pics/theme2_none.png new file mode 100644 index 0000000..a72c89f Binary files /dev/null and b/src/src/pics/theme2_none.png differ diff --git a/src/src/pics/theme2_rx.png b/src/src/pics/theme2_rx.png new file mode 100644 index 0000000..222d38d Binary files /dev/null and b/src/src/pics/theme2_rx.png differ diff --git a/src/src/pics/theme2_tx.png b/src/src/pics/theme2_tx.png new file mode 100644 index 0000000..fa3b0c5 Binary files /dev/null and b/src/src/pics/theme2_tx.png differ diff --git a/src/src/pics/theme3_both.png b/src/src/pics/theme3_both.png new file mode 100644 index 0000000..634b2d3 Binary files /dev/null and b/src/src/pics/theme3_both.png differ diff --git a/src/src/pics/theme3_error.png b/src/src/pics/theme3_error.png new file mode 100644 index 0000000..b1da123 Binary files /dev/null and b/src/src/pics/theme3_error.png differ diff --git a/src/src/pics/theme3_none.png b/src/src/pics/theme3_none.png new file mode 100644 index 0000000..b7395aa Binary files /dev/null and b/src/src/pics/theme3_none.png differ diff --git a/src/src/pics/theme3_rx.png b/src/src/pics/theme3_rx.png new file mode 100644 index 0000000..7cd6ef5 Binary files /dev/null and b/src/src/pics/theme3_rx.png differ diff --git a/src/src/pics/theme3_tx.png b/src/src/pics/theme3_tx.png new file mode 100644 index 0000000..b471965 Binary files /dev/null and b/src/src/pics/theme3_tx.png differ diff --git a/src/src/pics/theme4_both.png b/src/src/pics/theme4_both.png new file mode 100644 index 0000000..28e1f24 Binary files /dev/null and b/src/src/pics/theme4_both.png differ diff --git a/src/src/pics/theme4_error.png b/src/src/pics/theme4_error.png new file mode 100644 index 0000000..7a64e8a Binary files /dev/null and b/src/src/pics/theme4_error.png differ diff --git a/src/src/pics/theme4_none.png b/src/src/pics/theme4_none.png new file mode 100644 index 0000000..b41880c Binary files /dev/null and b/src/src/pics/theme4_none.png differ diff --git a/src/src/pics/theme4_rx.png b/src/src/pics/theme4_rx.png new file mode 100644 index 0000000..ee2ad1b Binary files /dev/null and b/src/src/pics/theme4_rx.png differ diff --git a/src/src/pics/theme4_tx.png b/src/src/pics/theme4_tx.png new file mode 100644 index 0000000..7851340 Binary files /dev/null and b/src/src/pics/theme4_tx.png differ diff --git a/src/src/statistics.cpp b/src/src/statistics.cpp new file mode 100644 index 0000000..efa571e --- /dev/null +++ b/src/src/statistics.cpp @@ -0,0 +1,79 @@ +/*************************************************************************** +* Copyright (C) 2004 by Hugo Parente Lima * +* hugo_pl@users.sourceforge.net * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ +#include "statistics.h" +#include "chart.h" +#include "knetstatsview.h" + +#include +#include +#include +#include +#include + + + +Statistics::Statistics( KNetStatsView* parent, const char *name ) +: StatisticsBase( parent, name ), mInterface(parent->interface()), mParent(parent) { + setCaption( i18n( "Details of %1" ).arg( mInterface ) ); + + QBoxLayout* l = new QHBoxLayout( mChart ); + l->setAutoAdd( true ); + Chart* chart = new Chart(mChart, parent->speedHistoryTx(), parent->speedHistoryRx(), parent->historyBufferSize(), parent->historyPointer(), parent->maxSpeed()); + mMAC->setText(mParent->readInterfaceStringValue("address", 18)); + mIP->setAlignment(Qt::AlignRight); + mMAC->setAlignment(Qt::AlignRight); + mNetmask->setAlignment(Qt::AlignRight); + update(); + + mTimer = new QTimer( this ); + connect( mTimer, SIGNAL( timeout() ), this, SLOT( update() ) ); + connect( mTimer, SIGNAL( timeout() ), chart, SLOT( update() ) ); +} + +void Statistics::update() { + mMaxSpeed->setText(byteFormat( *mParent->maxSpeed() )+"/s"); + mBRx->setText( byteFormat( mParent->totalBytesRx() ) ); + mBTx->setText( byteFormat( mParent->totalBytesTx() ) ); + mByteSpeedRx->setText( byteFormat( mParent->byteSpeedRx() )+"/s" ); + mByteSpeedTx->setText( byteFormat( mParent->byteSpeedTx() )+"/s" ); + + mPRx->setText( QString::number( mParent->totalPktRx() ) ); + mPTx->setText( QString::number( mParent->totalPktTx() ) ); + mPktSpeedRx->setText( QString::number( mParent->pktSpeedRx(), 'f', 1 )+"pkts/s" ); + mPktSpeedTx->setText( QString::number( mParent->pktSpeedTx(), 'f', 1 )+"pkts/s" ); +} + +void Statistics::show() { + // Update details... + mMTU->setText(mParent->readInterfaceStringValue("mtu", 6)); + mIP->setText( mParent->getIp() ); + mNetmask->setText( mParent->getNetmask() ); + + mTimer->start( mParent->updateInterval() ); + StatisticsBase::show(); +} + +void Statistics::accept() { + mTimer->stop(); + StatisticsBase::accept(); +} + + +#include "statistics.moc" diff --git a/src/src/statistics.h b/src/src/statistics.h new file mode 100644 index 0000000..40ba1a0 --- /dev/null +++ b/src/src/statistics.h @@ -0,0 +1,66 @@ +/*************************************************************************** +* Copyright (C) 2004 by Hugo Parente Lima * +* hugo_pl@users.sourceforge.net * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ +#ifndef STATISTICS_H +#define STATISTICS_H + +#include "statisticsbase.h" +#include + +class KNetStatsView; + +class Statistics : public StatisticsBase +{ + Q_OBJECT + +public: + Statistics( KNetStatsView* parent = 0, const char *name = 0 ); + + /** + * Formats a numberic byte representation + * \param num The numeric representation + * \param decimal Decimal digits + * \param bytesufix Sufix for bytes + * \param ksufix Sufix for kilobytes + * \param msufix Sufix for megabytes + */ + static inline QString byteFormat( double num, const char* ksufix = " KB", const char* msufix = " MB"); + + void show(); +private: + QTimer* mTimer; + const QString& mInterface; + KNetStatsView* mParent; +public slots: + void accept(); + +private slots: + void update(); +}; + +QString Statistics::byteFormat( double num, const char* ksufix, const char* msufix ) { + const double ONE_KB = 1024.0; + const double ONE_MB = ONE_KB*ONE_KB; + if ( num >= ONE_MB ) // MB + return QString::number( num/(ONE_MB), 'f', 1 ) + msufix; + else // Kb + return QString::number( num/ONE_KB, 'f', 1 ) + ksufix; +} + +#endif diff --git a/src/src/statisticsbase.ui b/src/src/statisticsbase.ui new file mode 100644 index 0000000..d8f0662 --- /dev/null +++ b/src/src/statisticsbase.ui @@ -0,0 +1,480 @@ + +StatisticsBase + + + StatisticsBase + + + + 0 + 0 + 261 + 303 + + + + + 5 + 5 + 0 + 0 + + + + KNetStats + + + + unnamed + + + Minimum + + + + layout3 + + + + unnamed + + + + mChart + + + + 7 + 5 + 0 + 0 + + + + Panel + + + Sunken + + + + + spacer4_2 + + + Vertical + + + Expanding + + + + 20 + 41 + + + + + + mMaxSpeed + + + + 7 + + + + ? KB/s + + + AlignVCenter|AlignRight + + + + + textLabel2_3 + + + + 7 + + + + 0 KB/s + + + AlignVCenter|AlignRight + + + + + + + tabWidget2 + + + + 7 + 4 + 0 + 0 + + + + + tab + + + &Statistics + + + + unnamed + + + + mLabel5 + + + Upload speed: + + + + + mLabel1 + + + Received: + + + + + mLabel6 + + + Download speed: + + + + + mLabel2 + + + Transmited: + + + + + spacer2_2 + + + Horizontal + + + Expanding + + + + 71 + 20 + + + + + + mPktSpeedRx + + + AlignVCenter|AlignRight + + + + + textLabel1 + + + Bytes + + + + + mPRx + + + AlignVCenter|AlignRight + + + + + mByteSpeedTx + + + AlignVCenter|AlignRight + + + + + mBTx + + + AlignVCenter|AlignRight + + + + + mPTx + + + AlignVCenter|AlignRight + + + + + mPktSpeedTx + + + AlignVCenter|AlignRight + + + + + mBRx + + + AlignVCenter|AlignRight + + + + + mByteSpeedRx + + + AlignVCenter|AlignRight + + + + + textLabel2 + + + Packets + + + + + + + tab + + + Deta&ils + + + + unnamed + + + + textLabel1_2 + + + IP: + + + + + textLabel2_2 + + + Netmask: + + + + + textLabel3 + + + MAC: + + + + + textLabel7 + + + MTU: + + + + + spacer4 + + + Vertical + + + Expanding + + + + 200 + 21 + + + + + + spacer5 + + + Horizontal + + + Expanding + + + + 51 + 80 + + + + + + mIP + + + + 5 + 7 + 0 + 0 + + + + NoWrap + + + + + mNetmask + + + + 5 + 7 + 0 + 0 + + + + NoWrap + + + + + mMAC + + + + 5 + 7 + 0 + 0 + + + + 1 + + + + + + NoWrap + + + + + mMTU + + + 1 + + + + + + AlignVCenter + + + + + + + + layout2 + + + + unnamed + + + + spacer2 + + + Horizontal + + + Expanding + + + + 91 + 20 + + + + + + mOk + + + + 1 + 4 + 0 + 0 + + + + O&k + + + true + + + + + + + + + mOk + clicked() + StatisticsBase + accept() + + + + tabWidget2 + mOk + + + + kactivelabel.h + kactivelabel.h + kactivelabel.h + kpushbutton.h + + -- cgit v1.2.1