Cherry-Picking upstream version 1.10.16+20150823.
							
								
								
									
										2
									
								
								.clang-format
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,2 @@
 | 
			
		||||
BreakBeforeBraces: Allman
 | 
			
		||||
IndentWidth: 4
 | 
			
		||||
							
								
								
									
										69
									
								
								CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,69 @@
 | 
			
		||||
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
 | 
			
		||||
set(PROJECT qps)
 | 
			
		||||
project(${PROJECT})
 | 
			
		||||
 | 
			
		||||
option(UPDATE_TRANSLATIONS "Update source translation translations/*.ts files" OFF)
 | 
			
		||||
 | 
			
		||||
# additional cmake files
 | 
			
		||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
 | 
			
		||||
 | 
			
		||||
if(NOT CMAKE_BUILD_TYPE)
 | 
			
		||||
    set(CMAKE_BUILD_TYPE Release)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
set(MAJOR_VERSION 1)
 | 
			
		||||
set(MINOR_VERSION 10)
 | 
			
		||||
set(PATCH_VERSION 16)
 | 
			
		||||
set(QPS_VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION})
 | 
			
		||||
add_definitions(-DQPS_VERSION="${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}")
 | 
			
		||||
 | 
			
		||||
# C++11 support
 | 
			
		||||
include(CheckCXXCompilerFlag)
 | 
			
		||||
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
 | 
			
		||||
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
 | 
			
		||||
if(COMPILER_SUPPORTS_CXX11)
 | 
			
		||||
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 | 
			
		||||
elseif(COMPILER_SUPPORTS_CXX0X)
 | 
			
		||||
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
 | 
			
		||||
else()
 | 
			
		||||
    message(FATAL "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. C++11 support is required")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
find_package(Qt5 REQUIRED COMPONENTS Widgets X11Extras DBus LinguistTools)
 | 
			
		||||
 | 
			
		||||
include(GNUInstallDirs)
 | 
			
		||||
include(LXQtTranslateTs) # Altough the name it doesn't depend on LXQt in any way
 | 
			
		||||
include(LXQtTranslateDesktop)
 | 
			
		||||
include(Qt5TranslationLoader)
 | 
			
		||||
 | 
			
		||||
# Must be defined after including GNUInstallDirs. Move with care.
 | 
			
		||||
set(QPS_TRANSLATIONS_DIR
 | 
			
		||||
    "${CMAKE_INSTALL_FULL_DATAROOTDIR}/${PROJECT_NAME}/translations"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
 | 
			
		||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 | 
			
		||||
set(CMAKE_AUTOMOC ON)
 | 
			
		||||
set(CMAKE_AUTOUIC ON)
 | 
			
		||||
set(CMAKE_AUTORCC ON)
 | 
			
		||||
 | 
			
		||||
add_subdirectory(src)
 | 
			
		||||
 | 
			
		||||
# install the man page
 | 
			
		||||
install(FILES qps.1 DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/man/man1")
 | 
			
		||||
 | 
			
		||||
# install the app icon
 | 
			
		||||
install(FILES
 | 
			
		||||
    icon/qps.png
 | 
			
		||||
    DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# building tarball with CPack
 | 
			
		||||
include(InstallRequiredSystemLibraries)
 | 
			
		||||
set(CPACK_PACKAGE_VERSION_MAJOR ${LXQT_MAJOR_VERSION})
 | 
			
		||||
set(CPACK_PACKAGE_VERSION_MINOR ${LXQT_MINOR_VERSION})
 | 
			
		||||
set(CPACK_PACKAGE_VERSION_PATCH ${LXQT_PATCH_VERSION})
 | 
			
		||||
set(CPACK_GENERATOR TBZ2)
 | 
			
		||||
set(CPACK_SOURCE_GENERATOR TBZ2)
 | 
			
		||||
set(CPACK_SOURCE_IGNORE_FILES /build/;.gitignore;.*~;.git;.kdev4;temp)
 | 
			
		||||
include(CPack)
 | 
			
		||||
							
								
								
									
										280
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,280 @@
 | 
			
		||||
                    GNU GENERAL PUBLIC LICENSE
 | 
			
		||||
                       Version 2, June 1991
 | 
			
		||||
 | 
			
		||||
 Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
 | 
			
		||||
 51 Franklin Street, 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.
 | 
			
		||||
 | 
			
		||||
                            Preamble
 | 
			
		||||
 | 
			
		||||
  The licenses for most software are designed to take away your
 | 
			
		||||
freedom to share and change it.  By contrast, the GNU General Public
 | 
			
		||||
License is intended to guarantee your freedom to share and change free
 | 
			
		||||
software--to make sure the software is free for all its users.  This
 | 
			
		||||
General Public License applies to most of the Free Software
 | 
			
		||||
Foundation's software and to any other program whose authors commit to
 | 
			
		||||
using it.  (Some other Free Software Foundation software is covered by
 | 
			
		||||
the GNU Lesser General Public License instead.)  You can apply it to
 | 
			
		||||
your programs, too.
 | 
			
		||||
 | 
			
		||||
  When we speak of free software, we are referring to freedom, not
 | 
			
		||||
price.  Our General Public Licenses are designed to make sure that you
 | 
			
		||||
have the freedom to distribute copies of free software (and charge for
 | 
			
		||||
this service if you wish), that you receive source code or can get it
 | 
			
		||||
if you want it, that you can change the software or use pieces of it
 | 
			
		||||
in new free programs; and that you know you can do these things.
 | 
			
		||||
 | 
			
		||||
  To protect your rights, we need to make restrictions that forbid
 | 
			
		||||
anyone to deny you these rights or to ask you to surrender the rights.
 | 
			
		||||
These restrictions translate to certain responsibilities for you if you
 | 
			
		||||
distribute copies of the software, or if you modify it.
 | 
			
		||||
 | 
			
		||||
  For example, if you distribute copies of such a program, whether
 | 
			
		||||
gratis or for a fee, you must give the recipients all the rights that
 | 
			
		||||
you have.  You must make sure that they, too, receive or can get the
 | 
			
		||||
source code.  And you must show them these terms so they know their
 | 
			
		||||
rights.
 | 
			
		||||
 | 
			
		||||
  We protect your rights with two steps: (1) copyright the software, and
 | 
			
		||||
(2) offer you this license which gives you legal permission to copy,
 | 
			
		||||
distribute and/or modify the software.
 | 
			
		||||
 | 
			
		||||
  Also, for each author's protection and ours, we want to make certain
 | 
			
		||||
that everyone understands that there is no warranty for this free
 | 
			
		||||
software.  If the software is modified by someone else and passed on, we
 | 
			
		||||
want its recipients to know that what they have is not the original, so
 | 
			
		||||
that any problems introduced by others will not reflect on the original
 | 
			
		||||
authors' reputations.
 | 
			
		||||
 | 
			
		||||
  Finally, any free program is threatened constantly by software
 | 
			
		||||
patents.  We wish to avoid the danger that redistributors of a free
 | 
			
		||||
program will individually obtain patent licenses, in effect making the
 | 
			
		||||
program proprietary.  To prevent this, we have made it clear that any
 | 
			
		||||
patent must be licensed for everyone's free use or not licensed at all.
 | 
			
		||||
 | 
			
		||||
  The precise terms and conditions for copying, distribution and
 | 
			
		||||
modification follow.
 | 
			
		||||
 | 
			
		||||
                    GNU GENERAL PUBLIC LICENSE
 | 
			
		||||
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 | 
			
		||||
 | 
			
		||||
  0. This License applies to any program or other work which contains
 | 
			
		||||
a notice placed by the copyright holder saying it may be distributed
 | 
			
		||||
under the terms of this General Public License.  The "Program", below,
 | 
			
		||||
refers to any such program or work, and a "work based on the Program"
 | 
			
		||||
means either the Program or any derivative work under copyright law:
 | 
			
		||||
that is to say, a work containing the Program or a portion of it,
 | 
			
		||||
either verbatim or with modifications and/or translated into another
 | 
			
		||||
language.  (Hereinafter, translation is included without limitation in
 | 
			
		||||
the term "modification".)  Each licensee is addressed as "you".
 | 
			
		||||
 | 
			
		||||
Activities other than copying, distribution and modification are not
 | 
			
		||||
covered by this License; they are outside its scope.  The act of
 | 
			
		||||
running the Program is not restricted, and the output from the Program
 | 
			
		||||
is covered only if its contents constitute a work based on the
 | 
			
		||||
Program (independent of having been made by running the Program).
 | 
			
		||||
Whether that is true depends on what the Program does.
 | 
			
		||||
 | 
			
		||||
  1. You may copy and distribute verbatim copies of the Program's
 | 
			
		||||
source code as you receive it, in any medium, provided that you
 | 
			
		||||
conspicuously and appropriately publish on each copy an appropriate
 | 
			
		||||
copyright notice and disclaimer of warranty; keep intact all the
 | 
			
		||||
notices that refer to this License and to the absence of any warranty;
 | 
			
		||||
and give any other recipients of the Program a copy of this License
 | 
			
		||||
along with the Program.
 | 
			
		||||
 | 
			
		||||
You may charge a fee for the physical act of transferring a copy, and
 | 
			
		||||
you may at your option offer warranty protection in exchange for a fee.
 | 
			
		||||
 | 
			
		||||
  2. You may modify your copy or copies of the Program or any portion
 | 
			
		||||
of it, thus forming a work based on the Program, and copy and
 | 
			
		||||
distribute such modifications or work under the terms of Section 1
 | 
			
		||||
above, provided that you also meet all of these conditions:
 | 
			
		||||
 | 
			
		||||
    a) You must cause the modified files to carry prominent notices
 | 
			
		||||
    stating that you changed the files and the date of any change.
 | 
			
		||||
 | 
			
		||||
    b) You must cause any work that you distribute or publish, that in
 | 
			
		||||
    whole or in part contains or is derived from the Program or any
 | 
			
		||||
    part thereof, to be licensed as a whole at no charge to all third
 | 
			
		||||
    parties under the terms of this License.
 | 
			
		||||
 | 
			
		||||
    c) If the modified program normally reads commands interactively
 | 
			
		||||
    when run, you must cause it, when started running for such
 | 
			
		||||
    interactive use in the most ordinary way, to print or display an
 | 
			
		||||
    announcement including an appropriate copyright notice and a
 | 
			
		||||
    notice that there is no warranty (or else, saying that you provide
 | 
			
		||||
    a warranty) and that users may redistribute the program under
 | 
			
		||||
    these conditions, and telling the user how to view a copy of this
 | 
			
		||||
    License.  (Exception: if the Program itself is interactive but
 | 
			
		||||
    does not normally print such an announcement, your work based on
 | 
			
		||||
    the Program is not required to print an announcement.)
 | 
			
		||||
 | 
			
		||||
These requirements apply to the modified work as a whole.  If
 | 
			
		||||
identifiable sections of that work are not derived from the Program,
 | 
			
		||||
and can be reasonably considered independent and separate works in
 | 
			
		||||
themselves, then this License, and its terms, do not apply to those
 | 
			
		||||
sections when you distribute them as separate works.  But when you
 | 
			
		||||
distribute the same sections as part of a whole which is a work based
 | 
			
		||||
on the Program, the distribution of the whole must be on the terms of
 | 
			
		||||
this License, whose permissions for other licensees extend to the
 | 
			
		||||
entire whole, and thus to each and every part regardless of who wrote it.
 | 
			
		||||
 | 
			
		||||
Thus, it is not the intent of this section to claim rights or contest
 | 
			
		||||
your rights to work written entirely by you; rather, the intent is to
 | 
			
		||||
exercise the right to control the distribution of derivative or
 | 
			
		||||
collective works based on the Program.
 | 
			
		||||
 | 
			
		||||
In addition, mere aggregation of another work not based on the Program
 | 
			
		||||
with the Program (or with a work based on the Program) on a volume of
 | 
			
		||||
a storage or distribution medium does not bring the other work under
 | 
			
		||||
the scope of this License.
 | 
			
		||||
 | 
			
		||||
  3. You may copy and distribute the Program (or a work based on it,
 | 
			
		||||
under Section 2) in object code or executable form under the terms of
 | 
			
		||||
Sections 1 and 2 above provided that you also do one of the following:
 | 
			
		||||
 | 
			
		||||
    a) Accompany it with the complete corresponding machine-readable
 | 
			
		||||
    source code, which must be distributed under the terms of Sections
 | 
			
		||||
    1 and 2 above on a medium customarily used for software interchange; or,
 | 
			
		||||
 | 
			
		||||
    b) Accompany it with a written offer, valid for at least three
 | 
			
		||||
    years, to give any third party, for a charge no more than your
 | 
			
		||||
    cost of physically performing source distribution, a complete
 | 
			
		||||
    machine-readable copy of the corresponding source code, to be
 | 
			
		||||
    distributed under the terms of Sections 1 and 2 above on a medium
 | 
			
		||||
    customarily used for software interchange; or,
 | 
			
		||||
 | 
			
		||||
    c) Accompany it with the information you received as to the offer
 | 
			
		||||
    to distribute corresponding source code.  (This alternative is
 | 
			
		||||
    allowed only for noncommercial distribution and only if you
 | 
			
		||||
    received the program in object code or executable form with such
 | 
			
		||||
    an offer, in accord with Subsection b above.)
 | 
			
		||||
 | 
			
		||||
The source code for a work means the preferred form of the work for
 | 
			
		||||
making modifications to it.  For an executable work, complete source
 | 
			
		||||
code means all the source code for all modules it contains, plus any
 | 
			
		||||
associated interface definition files, plus the scripts used to
 | 
			
		||||
control compilation and installation of the executable.  However, as a
 | 
			
		||||
special exception, the source code distributed need not include
 | 
			
		||||
anything that is normally distributed (in either source or binary
 | 
			
		||||
form) with the major components (compiler, kernel, and so on) of the
 | 
			
		||||
operating system on which the executable runs, unless that component
 | 
			
		||||
itself accompanies the executable.
 | 
			
		||||
 | 
			
		||||
If distribution of executable or object code is made by offering
 | 
			
		||||
access to copy from a designated place, then offering equivalent
 | 
			
		||||
access to copy the source code from the same place counts as
 | 
			
		||||
distribution of the source code, even though third parties are not
 | 
			
		||||
compelled to copy the source along with the object code.
 | 
			
		||||
 | 
			
		||||
  4. You may not copy, modify, sublicense, or distribute the Program
 | 
			
		||||
except as expressly provided under this License.  Any attempt
 | 
			
		||||
otherwise to copy, modify, sublicense or distribute the Program 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.
 | 
			
		||||
 | 
			
		||||
  5. You are not required to accept this License, since you have not
 | 
			
		||||
signed it.  However, nothing else grants you permission to modify or
 | 
			
		||||
distribute the Program or its derivative works.  These actions are
 | 
			
		||||
prohibited by law if you do not accept this License.  Therefore, by
 | 
			
		||||
modifying or distributing the Program (or any work based on the
 | 
			
		||||
Program), you indicate your acceptance of this License to do so, and
 | 
			
		||||
all its terms and conditions for copying, distributing or modifying
 | 
			
		||||
the Program or works based on it.
 | 
			
		||||
 | 
			
		||||
  6. Each time you redistribute the Program (or any work based on the
 | 
			
		||||
Program), the recipient automatically receives a license from the
 | 
			
		||||
original licensor to copy, distribute or modify the Program subject to
 | 
			
		||||
these terms and conditions.  You may not impose any further
 | 
			
		||||
restrictions on the recipients' exercise of the rights granted herein.
 | 
			
		||||
You are not responsible for enforcing compliance by third parties to
 | 
			
		||||
this License.
 | 
			
		||||
 | 
			
		||||
  7. If, as a consequence of a court judgment or allegation of patent
 | 
			
		||||
infringement or for any other reason (not limited to patent issues),
 | 
			
		||||
conditions are imposed on you (whether by court order, agreement or
 | 
			
		||||
otherwise) that contradict the conditions of this License, they do not
 | 
			
		||||
excuse you from the conditions of this License.  If you cannot
 | 
			
		||||
distribute so as to satisfy simultaneously your obligations under this
 | 
			
		||||
License and any other pertinent obligations, then as a consequence you
 | 
			
		||||
may not distribute the Program at all.  For example, if a patent
 | 
			
		||||
license would not permit royalty-free redistribution of the Program by
 | 
			
		||||
all those who receive copies directly or indirectly through you, then
 | 
			
		||||
the only way you could satisfy both it and this License would be to
 | 
			
		||||
refrain entirely from distribution of the Program.
 | 
			
		||||
 | 
			
		||||
If any portion of this section is held invalid or unenforceable under
 | 
			
		||||
any particular circumstance, the balance of the section is intended to
 | 
			
		||||
apply and the section as a whole is intended to apply in other
 | 
			
		||||
circumstances.
 | 
			
		||||
 | 
			
		||||
It is not the purpose of this section to induce you to infringe any
 | 
			
		||||
patents or other property right claims or to contest validity of any
 | 
			
		||||
such claims; this section has the sole purpose of protecting the
 | 
			
		||||
integrity of the free software distribution system, which is
 | 
			
		||||
implemented by public license practices.  Many people have made
 | 
			
		||||
generous contributions to the wide range of software distributed
 | 
			
		||||
through that system in reliance on consistent application of that
 | 
			
		||||
system; it is up to the author/donor to decide if he or she is willing
 | 
			
		||||
to distribute software through any other system and a licensee cannot
 | 
			
		||||
impose that choice.
 | 
			
		||||
 | 
			
		||||
This section is intended to make thoroughly clear what is believed to
 | 
			
		||||
be a consequence of the rest of this License.
 | 
			
		||||
 | 
			
		||||
  8. If the distribution and/or use of the Program is restricted in
 | 
			
		||||
certain countries either by patents or by copyrighted interfaces, the
 | 
			
		||||
original copyright holder who places the Program under this License
 | 
			
		||||
may add an explicit geographical distribution limitation excluding
 | 
			
		||||
those countries, so that distribution is permitted only in or among
 | 
			
		||||
countries not thus excluded.  In such case, this License incorporates
 | 
			
		||||
the limitation as if written in the body of this License.
 | 
			
		||||
 | 
			
		||||
  9. The Free Software Foundation may publish revised and/or new versions
 | 
			
		||||
of the General Public 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.
 | 
			
		||||
 | 
			
		||||
Each version is given a distinguishing version number.  If the Program
 | 
			
		||||
specifies a version number of this License which applies to it and "any
 | 
			
		||||
later version", you have the option of following the terms and conditions
 | 
			
		||||
either of that version or of any later version published by the Free
 | 
			
		||||
Software Foundation.  If the Program does not specify a version number of
 | 
			
		||||
this License, you may choose any version ever published by the Free Software
 | 
			
		||||
Foundation.
 | 
			
		||||
 | 
			
		||||
  10. If you wish to incorporate parts of the Program into other free
 | 
			
		||||
programs whose distribution conditions are different, write to the author
 | 
			
		||||
to ask for permission.  For software which is copyrighted by the Free
 | 
			
		||||
Software Foundation, write to the Free Software Foundation; we sometimes
 | 
			
		||||
make exceptions for this.  Our decision will be guided by the two goals
 | 
			
		||||
of preserving the free status of all derivatives of our free software and
 | 
			
		||||
of promoting the sharing and reuse of software generally.
 | 
			
		||||
 | 
			
		||||
                            NO WARRANTY
 | 
			
		||||
 | 
			
		||||
  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
 | 
			
		||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
 | 
			
		||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
 | 
			
		||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
 | 
			
		||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 | 
			
		||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
 | 
			
		||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
 | 
			
		||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
 | 
			
		||||
REPAIR OR CORRECTION.
 | 
			
		||||
 | 
			
		||||
  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
 | 
			
		||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
 | 
			
		||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
 | 
			
		||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
 | 
			
		||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
 | 
			
		||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
 | 
			
		||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
 | 
			
		||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
 | 
			
		||||
POSSIBILITY OF SUCH DAMAGES.
 | 
			
		||||
 | 
			
		||||
                     END OF TERMS AND CONDITIONS
 | 
			
		||||
							
								
								
									
										33
									
								
								Qt5TranslationLoader.cpp.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,33 @@
 | 
			
		||||
/* This file has been generated by the CMake qt_translation_loader().
 | 
			
		||||
 * It loads Qt application translations.
 | 
			
		||||
 *
 | 
			
		||||
 * Attention: All changes will be overwritten!!!
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <QCoreApplication>
 | 
			
		||||
#include <QLocale>
 | 
			
		||||
#include <QTranslator>
 | 
			
		||||
#include <QLibraryInfo>
 | 
			
		||||
 | 
			
		||||
static void loadQtTranslation()
 | 
			
		||||
{
 | 
			
		||||
    QString locale = QLocale::system().name();
 | 
			
		||||
    QTranslator *qtTranslator = new QTranslator(qApp);
 | 
			
		||||
 | 
			
		||||
    if (qtTranslator->load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
 | 
			
		||||
        qApp->installTranslator(qtTranslator);
 | 
			
		||||
    } else {
 | 
			
		||||
        delete qtTranslator;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QTranslator *appTranslator = new QTranslator(qApp);
 | 
			
		||||
    if (appTranslator->load(QString("@translations_dir@/@catalog_name@_%1.qm").arg(locale))) {
 | 
			
		||||
        QCoreApplication::installTranslator(appTranslator);
 | 
			
		||||
    } else if (locale == QLatin1String("C") ||
 | 
			
		||||
                locale.startsWith(QLatin1String("en"))) {
 | 
			
		||||
        // English is the default. It's translated anyway.
 | 
			
		||||
        delete appTranslator;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Q_COREAPP_STARTUP_FUNCTION(loadQtTranslation)
 | 
			
		||||
							
								
								
									
										10
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,10 @@
 | 
			
		||||
## Qt Process Manager
 | 
			
		||||
 | 
			
		||||
### Building
 | 
			
		||||
 | 
			
		||||
* Requires Qt 5
 | 
			
		||||
 | 
			
		||||
### License
 | 
			
		||||
 | 
			
		||||
Qps is licensed under the terms of the
 | 
			
		||||
[GPLv2](http://choosealicense.com/licenses/gpl-2.0/) or any later version.
 | 
			
		||||
							
								
								
									
										107
									
								
								cmake/LXQtTranslateDesktop.cmake
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,107 @@
 | 
			
		||||
#=============================================================================
 | 
			
		||||
# The lxqt_translate_desktop() function was copied from the
 | 
			
		||||
# LXQt LxQtTranslate.cmake
 | 
			
		||||
#
 | 
			
		||||
# Original Author: Alexander Sokolov <sokoloff.a@gmail.com>
 | 
			
		||||
#
 | 
			
		||||
# funtion lxqt_translate_desktop(_RESULT
 | 
			
		||||
#                           SOURCES <sources>
 | 
			
		||||
#                           [TRANSLATION_DIR] translation_directory
 | 
			
		||||
#                    )
 | 
			
		||||
#     Output:
 | 
			
		||||
#       _RESULT The generated .desktop (.desktop) files
 | 
			
		||||
#
 | 
			
		||||
#     Input:
 | 
			
		||||
#
 | 
			
		||||
#       SOURCES List of input desktop files (.destktop.in) to be translated
 | 
			
		||||
#               (merged), relative to the CMakeList.txt.
 | 
			
		||||
#
 | 
			
		||||
#       TRANSLATION_DIR Optional path to the directory with the .ts files,
 | 
			
		||||
#                        relative to the CMakeList.txt. Defaults to
 | 
			
		||||
#                        "translations".
 | 
			
		||||
#
 | 
			
		||||
#=============================================================================
 | 
			
		||||
 | 
			
		||||
function(lxqt_translate_desktop _RESULT)
 | 
			
		||||
    # Parse arguments ***************************************
 | 
			
		||||
    set(oneValueArgs TRANSLATION_DIR)
 | 
			
		||||
    set(multiValueArgs SOURCES)
 | 
			
		||||
 | 
			
		||||
    cmake_parse_arguments(_ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
 | 
			
		||||
 | 
			
		||||
    # check for unknown arguments
 | 
			
		||||
    set(_UNPARSED_ARGS ${_ARGS_UNPARSED_ARGUMENTS})
 | 
			
		||||
    if (NOT ${_UNPARSED_ARGS} STREQUAL "")
 | 
			
		||||
        MESSAGE(FATAL_ERROR
 | 
			
		||||
          "Unknown arguments '${_UNPARSED_ARGS}'.\n"
 | 
			
		||||
          "See lxqt_translate_desktop() documentation for more information.\n"
 | 
			
		||||
        )
 | 
			
		||||
    endif()
 | 
			
		||||
 | 
			
		||||
    if (NOT DEFINED _ARGS_SOURCES)
 | 
			
		||||
        set(${_RESULT} "" PARENT_SCOPE)
 | 
			
		||||
        return()
 | 
			
		||||
    else()
 | 
			
		||||
        set(_sources ${_ARGS_SOURCES})
 | 
			
		||||
    endif()
 | 
			
		||||
 | 
			
		||||
    if (NOT DEFINED _ARGS_TRANSLATION_DIR)
 | 
			
		||||
        set(_translationDir "translations")
 | 
			
		||||
    else()
 | 
			
		||||
        set(_translationDir ${_ARGS_TRANSLATION_DIR})
 | 
			
		||||
    endif()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    get_filename_component (_translationDir ${_translationDir} ABSOLUTE)
 | 
			
		||||
 | 
			
		||||
    foreach (_inFile ${_sources})
 | 
			
		||||
        get_filename_component(_inFile   ${_inFile} ABSOLUTE)
 | 
			
		||||
        get_filename_component(_fileName ${_inFile} NAME_WE)
 | 
			
		||||
        #Extract the real extension ............
 | 
			
		||||
        get_filename_component(_fileExt  ${_inFile} EXT)
 | 
			
		||||
        string(REPLACE ".in" "" _fileExt ${_fileExt})
 | 
			
		||||
        #.......................................
 | 
			
		||||
        set(_outFile "${CMAKE_CURRENT_BINARY_DIR}/${_fileName}${_fileExt}")
 | 
			
		||||
 | 
			
		||||
        file(GLOB _translations
 | 
			
		||||
            ${_translationDir}/${_fileName}_*${_fileExt}
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        set(_pattern "'\\[.*]\\s*='")
 | 
			
		||||
        if (_translations)
 | 
			
		||||
            list(SORT _translations)
 | 
			
		||||
            add_custom_command(OUTPUT ${_outFile}
 | 
			
		||||
                COMMAND grep -v "'#TRANSLATIONS_DIR='" ${_inFile} > ${_outFile}
 | 
			
		||||
                COMMAND grep -h ${_pattern} ${_translations} >> ${_outFile}
 | 
			
		||||
                COMMENT "Generating ${_fileName}${_fileExt}"
 | 
			
		||||
            )
 | 
			
		||||
        else()
 | 
			
		||||
            add_custom_command(OUTPUT ${_outFile}
 | 
			
		||||
                COMMAND grep -v "'#TRANSLATIONS_DIR='" ${_inFile} > ${_outFile}
 | 
			
		||||
                COMMENT "Generating ${_fileName}${_fileExt}"
 | 
			
		||||
            )
 | 
			
		||||
        endif()
 | 
			
		||||
 | 
			
		||||
        set(__result ${__result} ${_outFile})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        # TX file ***********************************************
 | 
			
		||||
        set(_txFile "${CMAKE_BINARY_DIR}/tx/${_fileName}${_fileExt}.tx.sh")
 | 
			
		||||
        string(REPLACE "${CMAKE_SOURCE_DIR}/" "" _tx_translationDir ${_translationDir})
 | 
			
		||||
        string(REPLACE "${CMAKE_SOURCE_DIR}/" "" _tx_inFile ${_inFile})
 | 
			
		||||
        string(REPLACE "." "" _fileType ${_fileExt})
 | 
			
		||||
 | 
			
		||||
        file(WRITE ${_txFile}
 | 
			
		||||
            "[ -f ${_inFile} ] || exit 0\n"
 | 
			
		||||
            "echo '[lxde-qt.${_fileName}_${_fileType}]'\n"
 | 
			
		||||
            "echo 'type = DESKTOP'\n"
 | 
			
		||||
            "echo 'source_lang = en'\n"
 | 
			
		||||
            "echo 'source_file = ${_tx_inFile}'\n"
 | 
			
		||||
            "echo 'file_filter = ${_tx_translationDir}/${_fileName}_<lang>${_fileExt}'\n"
 | 
			
		||||
            "echo ''\n"
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    endforeach()
 | 
			
		||||
 | 
			
		||||
    set(${_RESULT} ${__result} PARENT_SCOPE)
 | 
			
		||||
endfunction(lxqt_translate_desktop)
 | 
			
		||||
							
								
								
									
										140
									
								
								cmake/LXQtTranslateTs.cmake
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,140 @@
 | 
			
		||||
#=============================================================================
 | 
			
		||||
# Copyright 2014 Luís Pereira <luis.artur.pereira@gmail.com>
 | 
			
		||||
#
 | 
			
		||||
# Redistribution and use in source and binary forms, with or without
 | 
			
		||||
# modification, are permitted provided that the following conditions
 | 
			
		||||
# are met:
 | 
			
		||||
#
 | 
			
		||||
# 1. Redistributions of source code must retain the copyright
 | 
			
		||||
#    notice, this list of conditions and the following disclaimer.
 | 
			
		||||
# 2. Redistributions in binary form must reproduce the copyright
 | 
			
		||||
#    notice, this list of conditions and the following disclaimer in the
 | 
			
		||||
#    documentation and/or other materials provided with the distribution.
 | 
			
		||||
# 3. The name of the author may not be used to endorse or promote products
 | 
			
		||||
#    derived from this software without specific prior written permission.
 | 
			
		||||
#
 | 
			
		||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 | 
			
		||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 | 
			
		||||
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 | 
			
		||||
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 | 
			
		||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 | 
			
		||||
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 | 
			
		||||
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
#=============================================================================
 | 
			
		||||
#
 | 
			
		||||
# funtion lxqt_translate_ts(qmFiles
 | 
			
		||||
#                           [USE_QT5 [Yes | No]]
 | 
			
		||||
#                           [UPDATE_TRANSLATIONS [Yes | No]]
 | 
			
		||||
#                           SOURCES <sources>
 | 
			
		||||
#                           [TEMPLATE] translation_template
 | 
			
		||||
#                           [TRANSLATION_DIR] translation_directory
 | 
			
		||||
#                           [INSTALL_DIR] install_directory
 | 
			
		||||
#                           [COMPONENT] component
 | 
			
		||||
#                    )
 | 
			
		||||
#     Output:
 | 
			
		||||
#       qmFiles The generated compiled translations (.qm) files
 | 
			
		||||
#
 | 
			
		||||
#     Input:
 | 
			
		||||
#       USE_QT5 Optional flag to choose between Qt4 and Qt5. Defaults to Qt5
 | 
			
		||||
#
 | 
			
		||||
#       UPDATE_TRANSLATIONS Optional flag. Setting it to Yes, extracts and
 | 
			
		||||
#                           compiles the translations. Setting it No, only
 | 
			
		||||
#                           compiles them.
 | 
			
		||||
#
 | 
			
		||||
#       TEMPLATE Optional translations files base name. Defaults to
 | 
			
		||||
#                ${PROJECT_NAME}. An .ts extensions is added.
 | 
			
		||||
#
 | 
			
		||||
#       TRANSLATION_DIR Optional path to the directory with the .ts files,
 | 
			
		||||
#                        relative to the CMakeList.txt. Defaults to
 | 
			
		||||
#                        "translations".
 | 
			
		||||
#
 | 
			
		||||
#       INSTALL_DIR Optional destination of the file compiled files (qmFiles).
 | 
			
		||||
#                    If not present no installation is performed
 | 
			
		||||
#
 | 
			
		||||
#       COMPONENT Optional install component. Only effective if INSTALL_DIR
 | 
			
		||||
#                   present. Defaults to "Runtime".
 | 
			
		||||
 | 
			
		||||
# CMake v2.8.3 needed to use the CMakeParseArguments module
 | 
			
		||||
cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR)
 | 
			
		||||
 | 
			
		||||
# We use our patched version to round a annoying bug.
 | 
			
		||||
include(Qt5PatchedLinguistToolsMacros)
 | 
			
		||||
 | 
			
		||||
function(lxqt_translate_ts qmFiles)
 | 
			
		||||
    set(oneValueArgs USE_QT5 UPDATE_TRANSLATIONS TEMPLATE TRANSLATION_DIR INSTALL_DIR COMPONENT)
 | 
			
		||||
    set(multiValueArgs SOURCES)
 | 
			
		||||
    cmake_parse_arguments(TR "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
 | 
			
		||||
 | 
			
		||||
    if (NOT DEFINED TR_UPDATE_TRANSLATIONS)
 | 
			
		||||
        set(TR_UPDATE_TRANSLATIONS "No")
 | 
			
		||||
    endif()
 | 
			
		||||
 | 
			
		||||
    if (NOT DEFINED TR_USE_QT5)
 | 
			
		||||
        set(TR_USE_QT5 "Yes")
 | 
			
		||||
    endif()
 | 
			
		||||
 | 
			
		||||
    if(NOT DEFINED TR_TEMPLATE)
 | 
			
		||||
        set(TR_TEMPLATE "${PROJECT_NAME}")
 | 
			
		||||
    endif()
 | 
			
		||||
 | 
			
		||||
    if (NOT DEFINED TR_TRANSLATION_DIR)
 | 
			
		||||
        set(TR_TRANSLATION_DIR "translations")
 | 
			
		||||
    endif()
 | 
			
		||||
 | 
			
		||||
    file(GLOB tsFiles "${TR_TRANSLATION_DIR}/${TR_TEMPLATE}_*.ts")
 | 
			
		||||
    set(templateFile "${TR_TRANSLATION_DIR}/${TR_TEMPLATE}.ts")
 | 
			
		||||
 | 
			
		||||
    if(TR_USE_QT5)
 | 
			
		||||
        # Qt5
 | 
			
		||||
        if (TR_UPDATE_TRANSLATIONS)
 | 
			
		||||
            qt5_patched_create_translation(QMS
 | 
			
		||||
                ${TR_SOURCES}
 | 
			
		||||
                ${templateFile}
 | 
			
		||||
                OPTIONS -locations absolute
 | 
			
		||||
            )
 | 
			
		||||
            qt5_patched_create_translation(QM
 | 
			
		||||
                ${TR_SOURCES}
 | 
			
		||||
                ${tsFiles}
 | 
			
		||||
                OPTIONS -locations absolute
 | 
			
		||||
            )
 | 
			
		||||
        else()
 | 
			
		||||
            qt5_patched_add_translation(QM ${tsFiles})
 | 
			
		||||
        endif()
 | 
			
		||||
    else()
 | 
			
		||||
        # Qt4
 | 
			
		||||
        if(TR_UPDATE_TRANSLATIONS)
 | 
			
		||||
            qt4_create_translation(QMS
 | 
			
		||||
                ${TR_SOURCES}
 | 
			
		||||
                ${templateFile}
 | 
			
		||||
                OPTIONS -locations absolute
 | 
			
		||||
            )
 | 
			
		||||
            qt4_create_translation(QM
 | 
			
		||||
                ${TR_SOURCES}
 | 
			
		||||
                ${tsFiles}
 | 
			
		||||
                OPTIONS -locations absolute
 | 
			
		||||
            )
 | 
			
		||||
        else()
 | 
			
		||||
            qt4_add_translation(QM ${tsFiles})
 | 
			
		||||
        endif()
 | 
			
		||||
    endif()
 | 
			
		||||
 | 
			
		||||
    if(TR_UPDATE_TRANSLATIONS)
 | 
			
		||||
        add_custom_target("update_${TR_TEMPLATE}_ts" ALL DEPENDS ${QMS})
 | 
			
		||||
    endif()
 | 
			
		||||
 | 
			
		||||
    if(DEFINED TR_INSTALL_DIR)
 | 
			
		||||
        if(NOT DEFINED TR_COMPONENT)
 | 
			
		||||
            set(TR_COMPONENT "Runtime")
 | 
			
		||||
        endif()
 | 
			
		||||
 | 
			
		||||
        install(FILES ${QM}
 | 
			
		||||
            DESTINATION "${TR_INSTALL_DIR}"
 | 
			
		||||
            COMPONENT "${TR_COMPONENT}"
 | 
			
		||||
        )
 | 
			
		||||
    endif()
 | 
			
		||||
 | 
			
		||||
    set(${qmFiles} ${QM} PARENT_SCOPE)
 | 
			
		||||
endfunction()
 | 
			
		||||
							
								
								
									
										112
									
								
								cmake/Qt5PatchedLinguistToolsMacros.cmake
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,112 @@
 | 
			
		||||
#=============================================================================
 | 
			
		||||
# Copyright 2005-2011 Kitware, Inc.
 | 
			
		||||
# All rights reserved.
 | 
			
		||||
#
 | 
			
		||||
# Redistribution and use in source and binary forms, with or without
 | 
			
		||||
# modification, are permitted provided that the following conditions
 | 
			
		||||
# are met:
 | 
			
		||||
#
 | 
			
		||||
# * Redistributions of source code must retain the above copyright
 | 
			
		||||
#   notice, this list of conditions and the following disclaimer.
 | 
			
		||||
#
 | 
			
		||||
# * Redistributions in binary form must reproduce the above copyright
 | 
			
		||||
#   notice, this list of conditions and the following disclaimer in the
 | 
			
		||||
#   documentation and/or other materials provided with the distribution.
 | 
			
		||||
#
 | 
			
		||||
# * Neither the name of Kitware, Inc. nor the names of its
 | 
			
		||||
#   contributors may be used to endorse or promote products derived
 | 
			
		||||
#   from this software without specific prior written permission.
 | 
			
		||||
#
 | 
			
		||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
			
		||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
			
		||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
			
		||||
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
			
		||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
			
		||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
#=============================================================================
 | 
			
		||||
 | 
			
		||||
include(CMakeParseArguments)
 | 
			
		||||
 | 
			
		||||
function(QT5_PATCHED_CREATE_TRANSLATION _qm_files)
 | 
			
		||||
    set(options)
 | 
			
		||||
    set(oneValueArgs)
 | 
			
		||||
    set(multiValueArgs OPTIONS)
 | 
			
		||||
 | 
			
		||||
    cmake_parse_arguments(_LUPDATE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
 | 
			
		||||
    set(_lupdate_files ${_LUPDATE_UNPARSED_ARGUMENTS})
 | 
			
		||||
    set(_lupdate_options ${_LUPDATE_OPTIONS})
 | 
			
		||||
 | 
			
		||||
    set(_my_sources)
 | 
			
		||||
    set(_my_tsfiles)
 | 
			
		||||
    foreach(_file ${_lupdate_files})
 | 
			
		||||
        get_filename_component(_ext ${_file} EXT)
 | 
			
		||||
        get_filename_component(_abs_FILE ${_file} ABSOLUTE)
 | 
			
		||||
        if(_ext MATCHES "ts")
 | 
			
		||||
            list(APPEND _my_tsfiles ${_abs_FILE})
 | 
			
		||||
        else()
 | 
			
		||||
            list(APPEND _my_sources ${_abs_FILE})
 | 
			
		||||
        endif()
 | 
			
		||||
    endforeach()
 | 
			
		||||
    foreach(_ts_file ${_my_tsfiles})
 | 
			
		||||
        if(_my_sources)
 | 
			
		||||
          # make a list file to call lupdate on, so we don't make our commands too
 | 
			
		||||
          # long for some systems
 | 
			
		||||
#          get_filename_component(_ts_name ${_ts_file} NAME_WE)
 | 
			
		||||
 | 
			
		||||
          get_filename_component(_name ${_ts_file} NAME)
 | 
			
		||||
          string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" _ts_name ${_name})
 | 
			
		||||
 | 
			
		||||
          set(_ts_lst_file "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_ts_name}_lst_file")
 | 
			
		||||
          set(_lst_file_srcs)
 | 
			
		||||
          foreach(_lst_file_src ${_my_sources})
 | 
			
		||||
              set(_lst_file_srcs "${_lst_file_src}\n${_lst_file_srcs}")
 | 
			
		||||
          endforeach()
 | 
			
		||||
 | 
			
		||||
          get_directory_property(_inc_DIRS INCLUDE_DIRECTORIES)
 | 
			
		||||
          foreach(_pro_include ${_inc_DIRS})
 | 
			
		||||
              get_filename_component(_abs_include "${_pro_include}" ABSOLUTE)
 | 
			
		||||
              set(_lst_file_srcs "-I${_pro_include}\n${_lst_file_srcs}")
 | 
			
		||||
          endforeach()
 | 
			
		||||
 | 
			
		||||
          file(WRITE ${_ts_lst_file} "${_lst_file_srcs}")
 | 
			
		||||
        endif()
 | 
			
		||||
        add_custom_command(OUTPUT ${_ts_file}
 | 
			
		||||
            COMMAND ${Qt5_LUPDATE_EXECUTABLE}
 | 
			
		||||
            ARGS ${_lupdate_options} "@${_ts_lst_file}" -ts ${_ts_file}
 | 
			
		||||
            DEPENDS ${_my_sources} ${_ts_lst_file} VERBATIM)
 | 
			
		||||
    endforeach()
 | 
			
		||||
    qt5_patched_add_translation(${_qm_files} ${_my_tsfiles})
 | 
			
		||||
    set(${_qm_files} ${${_qm_files}} PARENT_SCOPE)
 | 
			
		||||
endfunction()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function(QT5_PATCHED_ADD_TRANSLATION _qm_files)
 | 
			
		||||
    foreach(_current_FILE ${ARGN})
 | 
			
		||||
        get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
 | 
			
		||||
#        get_filename_component(qm ${_abs_FILE} NAME_WE)
 | 
			
		||||
 | 
			
		||||
        get_filename_component(_name ${_abs_FILE} NAME)
 | 
			
		||||
        string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" qm ${_name})
 | 
			
		||||
 | 
			
		||||
        get_source_file_property(output_location ${_abs_FILE} OUTPUT_LOCATION)
 | 
			
		||||
        if(output_location)
 | 
			
		||||
            file(MAKE_DIRECTORY "${output_location}")
 | 
			
		||||
            set(qm "${output_location}/${qm}.qm")
 | 
			
		||||
        else()
 | 
			
		||||
            set(qm "${CMAKE_CURRENT_BINARY_DIR}/${qm}.qm")
 | 
			
		||||
        endif()
 | 
			
		||||
 | 
			
		||||
        add_custom_command(OUTPUT ${qm}
 | 
			
		||||
            COMMAND ${Qt5_LRELEASE_EXECUTABLE}
 | 
			
		||||
            ARGS ${_abs_FILE} -qm ${qm}
 | 
			
		||||
            DEPENDS ${_abs_FILE} VERBATIM
 | 
			
		||||
        )
 | 
			
		||||
        list(APPEND ${_qm_files} ${qm})
 | 
			
		||||
    endforeach()
 | 
			
		||||
    set(${_qm_files} ${${_qm_files}} PARENT_SCOPE)
 | 
			
		||||
endfunction()
 | 
			
		||||
							
								
								
									
										47
									
								
								cmake/Qt5TranslationLoader.cmake
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,47 @@
 | 
			
		||||
#=============================================================================
 | 
			
		||||
# Copyright 2014 Luís Pereira <luis.artur.pereira@gmail.com>
 | 
			
		||||
#
 | 
			
		||||
# Redistribution and use in source and binary forms, with or without
 | 
			
		||||
# modification, are permitted provided that the following conditions
 | 
			
		||||
# are met:
 | 
			
		||||
#
 | 
			
		||||
# 1. Redistributions of source code must retain the copyright
 | 
			
		||||
#    notice, this list of conditions and the following disclaimer.
 | 
			
		||||
# 2. Redistributions in binary form must reproduce the copyright
 | 
			
		||||
#    notice, this list of conditions and the following disclaimer in the
 | 
			
		||||
#    documentation and/or other materials provided with the distribution.
 | 
			
		||||
# 3. The name of the author may not be used to endorse or promote products
 | 
			
		||||
#    derived from this software without specific prior written permission.
 | 
			
		||||
#
 | 
			
		||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 | 
			
		||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 | 
			
		||||
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 | 
			
		||||
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 | 
			
		||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 | 
			
		||||
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 | 
			
		||||
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
#=============================================================================
 | 
			
		||||
#
 | 
			
		||||
# These functions enables "automatic" translation loading in Qt5 apps
 | 
			
		||||
#   and libs. They generate a .cpp file that takes care of everything. The
 | 
			
		||||
#   user doesn't have to do anything in the source code.
 | 
			
		||||
#
 | 
			
		||||
# qt5_translation_loader(<source_files> <translations_dir> <catalog_name>)
 | 
			
		||||
#
 | 
			
		||||
# Output:
 | 
			
		||||
#   <source_files> Appends the generated file to this variable.
 | 
			
		||||
#
 | 
			
		||||
# Input:
 | 
			
		||||
#   <translations_dir> Full path name to the translations dir.
 | 
			
		||||
#   <catalog_name> Translation catalog to be loaded.
 | 
			
		||||
 | 
			
		||||
function(qt5_translation_loader source_files translations_dir catalog_name)
 | 
			
		||||
    configure_file(
 | 
			
		||||
        "${CMAKE_SOURCE_DIR}/Qt5TranslationLoader.cpp.in"
 | 
			
		||||
        Qt5TranslationLoader.cpp @ONLY
 | 
			
		||||
    )
 | 
			
		||||
    set(${source_files} ${${source_files}} ${CMAKE_CURRENT_BINARY_DIR}/Qt5TranslationLoader.cpp PARENT_SCOPE)
 | 
			
		||||
endfunction()
 | 
			
		||||
							
								
								
									
										196
									
								
								icon/icon-small.xpm
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,196 @@
 | 
			
		||||
/* XPM */
 | 
			
		||||
static char * icon_small_xpm[] = {
 | 
			
		||||
"25 25 168 2",
 | 
			
		||||
"  	c None",
 | 
			
		||||
". 	c #181918",
 | 
			
		||||
"+ 	c #3F413F",
 | 
			
		||||
"@ 	c #242524",
 | 
			
		||||
"# 	c #008600",
 | 
			
		||||
"$ 	c #008000",
 | 
			
		||||
"% 	c #000300",
 | 
			
		||||
"& 	c #002000",
 | 
			
		||||
"* 	c #00AF00",
 | 
			
		||||
"= 	c #000000",
 | 
			
		||||
"- 	c #004500",
 | 
			
		||||
"; 	c #010101",
 | 
			
		||||
"> 	c #2D2E2D",
 | 
			
		||||
", 	c #139F13",
 | 
			
		||||
"' 	c #000400",
 | 
			
		||||
") 	c #007200",
 | 
			
		||||
"! 	c #005800",
 | 
			
		||||
"~ 	c #131313",
 | 
			
		||||
"{ 	c #2CAB2C",
 | 
			
		||||
"] 	c #033803",
 | 
			
		||||
"^ 	c #001800",
 | 
			
		||||
"/ 	c #00B200",
 | 
			
		||||
"( 	c #030303",
 | 
			
		||||
"_ 	c #2C2D2C",
 | 
			
		||||
": 	c #039603",
 | 
			
		||||
"< 	c #000700",
 | 
			
		||||
"[ 	c #007100",
 | 
			
		||||
"} 	c #005900",
 | 
			
		||||
"| 	c #005000",
 | 
			
		||||
"1 	c #007A00",
 | 
			
		||||
"2 	c #001300",
 | 
			
		||||
"3 	c #333433",
 | 
			
		||||
"4 	c #020202",
 | 
			
		||||
"5 	c #006C00",
 | 
			
		||||
"6 	c #001900",
 | 
			
		||||
"7 	c #008800",
 | 
			
		||||
"8 	c #016101",
 | 
			
		||||
"9 	c #2B2C2B",
 | 
			
		||||
"0 	c #9A9A9A",
 | 
			
		||||
"a 	c #494A49",
 | 
			
		||||
"b 	c #001500",
 | 
			
		||||
"c 	c #008900",
 | 
			
		||||
"d 	c #033703",
 | 
			
		||||
"e 	c #25CA25",
 | 
			
		||||
"f 	c #9E9D9E",
 | 
			
		||||
"g 	c #9E9A9E",
 | 
			
		||||
"h 	c #828282",
 | 
			
		||||
"i 	c #404240",
 | 
			
		||||
"j 	c #007000",
 | 
			
		||||
"k 	c #004200",
 | 
			
		||||
"l 	c #040404",
 | 
			
		||||
"m 	c #232423",
 | 
			
		||||
"n 	c #9E9E9E",
 | 
			
		||||
"o 	c #9B989B",
 | 
			
		||||
"p 	c #7A7A7A",
 | 
			
		||||
"q 	c #4F514F",
 | 
			
		||||
"r 	c #3F423F",
 | 
			
		||||
"s 	c #00B700",
 | 
			
		||||
"t 	c #232323",
 | 
			
		||||
"u 	c #9A979A",
 | 
			
		||||
"v 	c #3F3F3F",
 | 
			
		||||
"w 	c #8F8C8F",
 | 
			
		||||
"x 	c #5C5B5C",
 | 
			
		||||
"y 	c #696B69",
 | 
			
		||||
"z 	c #484948",
 | 
			
		||||
"A 	c #008500",
 | 
			
		||||
"B 	c #9D999D",
 | 
			
		||||
"C 	c #676567",
 | 
			
		||||
"D 	c #3D3E3D",
 | 
			
		||||
"E 	c #4E4C4E",
 | 
			
		||||
"F 	c #2A292A",
 | 
			
		||||
"G 	c #323132",
 | 
			
		||||
"H 	c #666466",
 | 
			
		||||
"I 	c #999699",
 | 
			
		||||
"J 	c #535253",
 | 
			
		||||
"K 	c #004A00",
 | 
			
		||||
"L 	c #010401",
 | 
			
		||||
"M 	c #252625",
 | 
			
		||||
"N 	c #484748",
 | 
			
		||||
"O 	c #4C4A4C",
 | 
			
		||||
"P 	c #979597",
 | 
			
		||||
"Q 	c #949294",
 | 
			
		||||
"R 	c #949394",
 | 
			
		||||
"S 	c #A1A3A1",
 | 
			
		||||
"T 	c #000500",
 | 
			
		||||
"U 	c #004800",
 | 
			
		||||
"V 	c #2B6E2B",
 | 
			
		||||
"W 	c #6D6A6D",
 | 
			
		||||
"X 	c #545254",
 | 
			
		||||
"Y 	c #9C989C",
 | 
			
		||||
"Z 	c #272627",
 | 
			
		||||
"` 	c #726F72",
 | 
			
		||||
" .	c #929192",
 | 
			
		||||
"..	c #BFC1BF",
 | 
			
		||||
"+.	c #A1C2A1",
 | 
			
		||||
"@.	c #003D00",
 | 
			
		||||
"#.	c #00C200",
 | 
			
		||||
"$.	c #1C1D1C",
 | 
			
		||||
"%.	c #8B8B8B",
 | 
			
		||||
"&.	c #878487",
 | 
			
		||||
"*.	c #373637",
 | 
			
		||||
"=.	c #9B979B",
 | 
			
		||||
"-.	c #787578",
 | 
			
		||||
";.	c #716E71",
 | 
			
		||||
">.	c #919091",
 | 
			
		||||
",.	c #BEC0BE",
 | 
			
		||||
"'.	c #9C9D9C",
 | 
			
		||||
").	c #494949",
 | 
			
		||||
"!.	c #292929",
 | 
			
		||||
"~.	c #8B8E8B",
 | 
			
		||||
"{.	c #7D7E7D",
 | 
			
		||||
"].	c #7E7B7E",
 | 
			
		||||
"^.	c #2E2C2E",
 | 
			
		||||
"/.	c #908F90",
 | 
			
		||||
"(.	c #BCBEBC",
 | 
			
		||||
"_.	c #999A99",
 | 
			
		||||
":.	c #4F4F4F",
 | 
			
		||||
"<.	c #001400",
 | 
			
		||||
"[.	c #00B600",
 | 
			
		||||
"}.	c #060606",
 | 
			
		||||
"|.	c #1D1D1D",
 | 
			
		||||
"1.	c #6B6F6B",
 | 
			
		||||
"2.	c #787978",
 | 
			
		||||
"3.	c #444244",
 | 
			
		||||
"4.	c #686668",
 | 
			
		||||
"5.	c #8F8F8F",
 | 
			
		||||
"6.	c #BABCBA",
 | 
			
		||||
"7.	c #969796",
 | 
			
		||||
"8.	c #555555",
 | 
			
		||||
"9.	c #004700",
 | 
			
		||||
"0.	c #151615",
 | 
			
		||||
"a.	c #8F8E8F",
 | 
			
		||||
"b.	c #B8BAB8",
 | 
			
		||||
"c.	c #949494",
 | 
			
		||||
"d.	c #5A5A5A",
 | 
			
		||||
"e.	c #001000",
 | 
			
		||||
"f.	c #6C6F6C",
 | 
			
		||||
"g.	c #8D8D8D",
 | 
			
		||||
"h.	c #B3B5B3",
 | 
			
		||||
"i.	c #929292",
 | 
			
		||||
"j.	c #608660",
 | 
			
		||||
"k.	c #001A00",
 | 
			
		||||
"l.	c #00B000",
 | 
			
		||||
"m.	c #141514",
 | 
			
		||||
"n.	c #6F726F",
 | 
			
		||||
"o.	c #8D8E8D",
 | 
			
		||||
"p.	c #646464",
 | 
			
		||||
"q.	c #007E00",
 | 
			
		||||
"r.	c #004C00",
 | 
			
		||||
"s.	c #153215",
 | 
			
		||||
"t.	c #656565",
 | 
			
		||||
"u.	c #005400",
 | 
			
		||||
"v.	c #007600",
 | 
			
		||||
"w.	c #000900",
 | 
			
		||||
"x.	c #009800",
 | 
			
		||||
"y.	c #004000",
 | 
			
		||||
"z.	c #004100",
 | 
			
		||||
"A.	c #038603",
 | 
			
		||||
"B.	c #03A003",
 | 
			
		||||
"C.	c #2C4D2C",
 | 
			
		||||
"D.	c #00AD00",
 | 
			
		||||
"E.	c #002800",
 | 
			
		||||
"F.	c #008700",
 | 
			
		||||
"G.	c #139113",
 | 
			
		||||
"H.	c #002500",
 | 
			
		||||
"I.	c #00BB00",
 | 
			
		||||
"J.	c #00A100",
 | 
			
		||||
"K.	c #007C00",
 | 
			
		||||
"                                                  ",
 | 
			
		||||
"  . + @ # $ % & * = = - = = = = = = = = = @ + .   ",
 | 
			
		||||
"  + ; > , ' = = ) ! = - = = = = = = = = ~ > ; +   ",
 | 
			
		||||
"  @ > { ] = = = ^ / = - = = = = = = = = ( _ > @   ",
 | 
			
		||||
"  = ~ : < = = = = [ } - = = = = = = = = = ( ~ =   ",
 | 
			
		||||
"  = | 1 = = = = = 2 [ - = 3 4 = = = = = = = = =   ",
 | 
			
		||||
"  = 5 6 = = = = = = 7 8 9 0 a ( = = = = = = = =   ",
 | 
			
		||||
"  b c = = = = = = = d e f g h i ( = = = = = = =   ",
 | 
			
		||||
"  j k = = = = = = l m n g o p q r ( = = = = = =   ",
 | 
			
		||||
"  s 2 = = = = = l t n g u v w x y z ( = = = = =   ",
 | 
			
		||||
"  A = = = = = ( m n B C D E F G H I J = = = = =   ",
 | 
			
		||||
"  K % % % % L M n g I F N O P Q g R S % % % % T   ",
 | 
			
		||||
"  U k k k k V f g W X Y Z ` g g  ...+.@.@.@.@.#.  ",
 | 
			
		||||
"  = = = = = $.%.&.*.=.-.Y ;.g >.,.'.).= = = = A   ",
 | 
			
		||||
"  = = = = = !.~.{.Z ].^.g g /.(._.:.= = = = <.[.  ",
 | 
			
		||||
"  = = = = = }.|.1.2.3.4.g 5.6.7.8.= = = = = 9.j   ",
 | 
			
		||||
"  = = = = = = = 0.1.%.g a.b.c.d.= = = = = = 7 e.  ",
 | 
			
		||||
"  = = = = = = = = 0.f.g.h.i.j.= = = = = = k.l.=   ",
 | 
			
		||||
"  = = = = = = = = = m.n.o.p.j <.= = = = = q.r.=   ",
 | 
			
		||||
"  = = = = = = = = = = s.t.= u.v.= = = = w.x.= =   ",
 | 
			
		||||
"  = ~ ( = = = = = = = y.= = = l.k.= = = z.A.~ =   ",
 | 
			
		||||
"  @ > _ ( = = = = = = y.= = = u.v.= = < B.C.> @   ",
 | 
			
		||||
"  + ; > ~ = = = = = = y.= = = = D.E.T F.G.> ; +   ",
 | 
			
		||||
"  . + @ = = = = = = = y.= = = = H.I.J.K.= @ + .   ",
 | 
			
		||||
"                                                  "};
 | 
			
		||||
							
								
								
									
										57
									
								
								icon/icon.xpm
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,57 @@
 | 
			
		||||
/* XPM */
 | 
			
		||||
static const char *icon_xpm[] = {
 | 
			
		||||
"48 48 6 1",
 | 
			
		||||
" 	c None",
 | 
			
		||||
".	c #000000",
 | 
			
		||||
"X	c #00FF00",
 | 
			
		||||
"o	c #7A7E7A",
 | 
			
		||||
"O	c #FFFFFF",
 | 
			
		||||
"+	c #9E9A9E",
 | 
			
		||||
"                                                ",
 | 
			
		||||
"   .......XX..XX.............................   ",
 | 
			
		||||
"  ..oo...XX....XX.....X...................oo..  ",
 | 
			
		||||
" ..o..o.XX......X........................o..o.. ",
 | 
			
		||||
" .o....oX.......XX....X.................o....o. ",
 | 
			
		||||
" .o....oX........X......................o....o. ",
 | 
			
		||||
" ..o..oX.........XX...X..................o..o.. ",
 | 
			
		||||
" ...ooXX..........X.......................oo... ",
 | 
			
		||||
" .....X...........XX..X........................ ",
 | 
			
		||||
" .....X............X........................... ",
 | 
			
		||||
" ....XX............X..X........................ ",
 | 
			
		||||
" ....X..............X....Oo.................... ",
 | 
			
		||||
" ....X..............X.X..o+o................... ",
 | 
			
		||||
" ...X...............XX.Oo+++o.................. ",
 | 
			
		||||
" ...X................XXo++++oo................. ",
 | 
			
		||||
" ..XX................Oo++++o.oo................ ",
 | 
			
		||||
" ..X.................o++++++o.oo............... ",
 | 
			
		||||
" ..X...............Oo++++o+++o.oo.............. ",
 | 
			
		||||
" .XX...............o+++++..+++.o+o............. ",
 | 
			
		||||
" .X..............Oo++++oo+..++..++o............ ",
 | 
			
		||||
" .X..............o++++....+....+++++........... ",
 | 
			
		||||
" XX............Oo++++..++.++oo++++oO........... ",
 | 
			
		||||
" X.............o++++++....++++++++oO........... ",
 | 
			
		||||
" XX.X.X.X.X.XOo++++++++..+++++++oOoOX.X.X.X.XXX ",
 | 
			
		||||
" ............o++++...+++..++++++oOoO.........X. ",
 | 
			
		||||
" ............o+++..++++++.++++oOoO.O.........X. ",
 | 
			
		||||
" ............oo++.++++.+++++++oOoO...........X. ",
 | 
			
		||||
" ............ooo+..+++.+++++oOoO.O..........XX. ",
 | 
			
		||||
" ............Oooo+..+..+++++oOoO............X.. ",
 | 
			
		||||
" ..............ooo+...++++oOoO.O............X.. ",
 | 
			
		||||
" ...............ooo+++++++oOoO.............XX.. ",
 | 
			
		||||
" ................ooo++++oOoO.O.............X... ",
 | 
			
		||||
" .................ooo+++oOoO...............X... ",
 | 
			
		||||
" ..................ooo+OoO.O..............XX... ",
 | 
			
		||||
" ...................oooOoO.X..............X.... ",
 | 
			
		||||
" ....................ooO.O..X............XX.... ",
 | 
			
		||||
" .....................oO....X............X..... ",
 | 
			
		||||
" ......................O....XX...........X..... ",
 | 
			
		||||
" .....................X......X..........XX..... ",
 | 
			
		||||
" ............................XX.........X...... ",
 | 
			
		||||
" ...oo................X.......X........XX.oo... ",
 | 
			
		||||
" ..o..o.......................XX.......X.o..o.. ",
 | 
			
		||||
" .o....o..............X........X......XXo....o. ",
 | 
			
		||||
" .o....o.......................XX....XX.o....o. ",
 | 
			
		||||
" ..o..o...............X.........XX..XX...o..o.. ",
 | 
			
		||||
"  ..oo...........................XXXX.....oo..  ",
 | 
			
		||||
"   ...................X......................   ",
 | 
			
		||||
"                                                "};
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								icon/letters.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 720 B  | 
							
								
								
									
										
											BIN
										
									
								
								icon/letters.xcf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										19
									
								
								icon/letters.xpm
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,19 @@
 | 
			
		||||
/* XPM */
 | 
			
		||||
static char * letters_xpm[] = {
 | 
			
		||||
"570 9 7 1",
 | 
			
		||||
" 	c None",
 | 
			
		||||
".	c #000000",
 | 
			
		||||
"+	c #00473E",
 | 
			
		||||
"@	c #007D71",
 | 
			
		||||
"#	c #51ECB7",
 | 
			
		||||
"$	c #FFFFFF",
 | 
			
		||||
"%	c #00A390",
 | 
			
		||||
"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ",
 | 
			
		||||
"  +++  @###@ @###@ @###@ @###  @@     +++   +#@   ###   ###    @    +@+   +++   +++   +++   +++   ###   +%+  @###@ @###@ @+++@ @###@ @###@ @###@ @###@ @###@  +++  @###@ @###@ @###@ @###@ @###@ @###@  ###  ###%  +###@ @###  @###@ @###@ @###@ @+++@  +#+   +++@ @+++@ @+++  #   # ####  @###@ ####@ @###@ %###  @###@ @###@ %+++% %+++% %+++% @+++@ %+++% @###@ @##+   +++   +++   ###   +++   +++   +++  %+++   +++   +++% @###@ @###@  ###@ @+++@  + +  @+++@ %+++@ %+++   +++   +++   +++  @###@ @###@ ####   ###@ %###% %+++% %+++% @+++% %+++% %+++% @###@  +++   +%+   +++   +++ ",
 | 
			
		||||
" +   + #   @ #   + +   # # #   @#  # +   + + @%+ #         # #   # + # + +   + +   + +   + +   # #   # + # + +   # +   # #   # #   + #   + +   # #   # #   # + # + #   # #   # #   # #   # #   # #   # #   # #   # #   + #   # #   + #   + #   + #   # + # + +   # #   # #   + ## ## #   # #   # #   # #   # #   # #   + + # + #   # #   # #   # #   # #   # +   # #   + #   + +   + %   % +   + +   + +   + #   + +   + +   # #   + #   + #   + #   # +   + +   # #   # #   + +   + +   + +   + #   # #   # #   # #   + + # + #   # #   # #   # #   # #   # +   # +   + + # + +   + +   +",
 | 
			
		||||
" +   + #   @ #   + +   # # # +    #  +   + +   + #         #  #%#  + # + +   + +   + +   + +  #+ #  ## + # + +   # +   # #   # #   + #   + +   # #   # #   # + @ + +   # +   # +   # +   # +   # #   # #   # #   # #   + #   # #   + #   + #   + #   # + # + +   # #  #+ #   + # # # #   # #   # #   # #   # #   # #   + + # + #   # #   # #   # +# #+ #+ +# +  #+ #   + +#  + +   + #   # +   + +   + +   % #   + +   + +   # #   + #   + #   + #   # + # + +   # #  #+ #   + +   + +   + +   + #   # #   # #   # #   + + # + #   # #   # #   # +# #+ #+ +# +  #+ +   + + # + +   + +   +",
 | 
			
		||||
"  +++  @###@ @###@  ###@  ###    #    +++   +++               %#%  ##@##  +++  ##@##  +++   +%+  %+#+%  +%+  @###@  ###@ @###@ @###@ @###@  +++@ @###@ @###@  +++   +@#@  +@#@  +@#@  +@#@  +@#@ @+##@ %###% %###  @+++  @+++@ @###  @###  @+##@ @###@  +@+   +++@ @##+  @+++  @+++@ @+++@ @+++@ %###@ @#++@ ###%  @###@  +@+  @+++@ @+++@ @+++@   #    ###   +#+  @+++   +%+  @+++@  +++   +++   +++   #### %###+ @###@ @###@ @###@ @###@ % ##@ @###@  +++   +++@ @##+@ @+++  %#+#% ##%+   ###  @###@ @#++@ ####   ###   +@+  @+++@ @+++@ @+++@   #    ###   +#+   +++   + +   +++   +++ ",
 | 
			
		||||
" +   + @   # #   # +   #   # #  #    +   + +   + #         #  #%#  + # + +   + +   + +   + +#  + ##  # + # + #   + +   # +   # +   # #   # +   # #   # +   # + @ + + # + + # + + # + + # + + # + # ##+ #   # #   # #   + #   # #   + #   + #   # #   # + # + +   # #  #+ #   + #   # #   # #   # #   + # # # #   # +   # + # + #   # #   # # # # +# #+ + # + +#  + #   + +  #+ +   + +   + +   + +   + #   # #   # #   + #   # #   + #   + #   # #   # + # + +   # # ##+ #   + # # # #  #+ #   # #   + # # # #   # +   # + # + #   # #   # # # # +# #+ + # + +#  + +   + + # + +   + +   +",
 | 
			
		||||
" +   + @   # #   # +   #   # # #  #@ +   + +   + #         # #   # + # + + @ + +   + +   + #   + #   # + # + #   + +   # +   # +   # #   # +   # #   # +   # + # + +   + +   + +   + +   + +   + #   + #   # #   # #   + #   # #   + #   + #   # #   # + # + +   # #   # #   + #   # #   # #   # #   + #  ## #   # +   # + # + #   # +# #+ ## ## #   # + # + #   + #   + +   # +   + +   + +   + +   + #   # #   # #   + #   # #   + #   + #   # #   # + # + +   # #   # #   + # # # #  #+ #   # #   + #  ## #   # +   # + # + #   # +# #+ ## ## #   # + # + #   + +   + + # + +   + +   +",
 | 
			
		||||
"  +++  %###@ @###@  ###@ @###@    @@  +++   +++   ###   ###    @    +@+   @#+   +++   +#+   +++   ###   +#+  @###@ @###@  +++@ @###@ @###@  +++@ @###@ @###@  +++   +#+   +#+   +#+   +#+   +#+  @###@ %+++% ###%  +###@ ####  @###@ #+++  @###@ @+++@  +#+  @###@ @+++@ @###+ %+++% #+++# @###@ %+++  @###@ %+++% @###@  +%+   ###    #   #+ +# %+++%  +#+  %###@ @##+   +++   +++   +++  @###@ @###@ @###% %###  @###@ +#### @###@ #+++   ###% @+++@  +#+  @###@ %+++@ @###+ # % # #++#   ###  %+++  @###@ %+++% %###   +%+  +###+   #   #+++# %+++%   #+  @###@  +++   +%+   +++   +++ ",
 | 
			
		||||
"                                                                           #                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              "};
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								icon/pause.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 502 B  | 
							
								
								
									
										
											BIN
										
									
								
								icon/preferences-system.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 2.8 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								icon/qps.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 623 B  | 
							
								
								
									
										
											BIN
										
									
								
								icon/rec.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 686 B  | 
							
								
								
									
										
											BIN
										
									
								
								icon/superman.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.4 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								icon/vcross.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 656 B  | 
							
								
								
									
										
											BIN
										
									
								
								icon/vista.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 3.1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								icon/vpointer.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 660 B  | 
							
								
								
									
										25
									
								
								icon/vpointer.xpm
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,25 @@
 | 
			
		||||
/* XPM */
 | 
			
		||||
static char * vpointer_xpm[] = {
 | 
			
		||||
"16 16 6 1",
 | 
			
		||||
" 	c None",
 | 
			
		||||
".	c #00A097",
 | 
			
		||||
"+	c #43A687",
 | 
			
		||||
"@	c #00DAA4",
 | 
			
		||||
"#	c #56C4A9",
 | 
			
		||||
"$	c #2FFDBB",
 | 
			
		||||
"                ",
 | 
			
		||||
"                ",
 | 
			
		||||
"       ..       ",
 | 
			
		||||
"       ..       ",
 | 
			
		||||
"                ",
 | 
			
		||||
"       ++       ",
 | 
			
		||||
"       ++       ",
 | 
			
		||||
"                ",
 | 
			
		||||
"   @@  ##  @@   ",
 | 
			
		||||
"   @@  ##  @@   ",
 | 
			
		||||
"     @@  @@     ",
 | 
			
		||||
"     @@  @@     ",
 | 
			
		||||
"       $$       ",
 | 
			
		||||
"       $$       ",
 | 
			
		||||
"                ",
 | 
			
		||||
"                "};
 | 
			
		||||
							
								
								
									
										46
									
								
								icon/warn.xpm
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,46 @@
 | 
			
		||||
/* XPM */
 | 
			
		||||
static const char *warn_xpm[] = {
 | 
			
		||||
/* width height num_colors chars_per_pixel */
 | 
			
		||||
"    39    35        4            1",
 | 
			
		||||
/* colors */
 | 
			
		||||
". c none",
 | 
			
		||||
"# c #000000",
 | 
			
		||||
"a c #ffff00",
 | 
			
		||||
"b c #ffffff",
 | 
			
		||||
/* pixels */
 | 
			
		||||
"..................###..................",
 | 
			
		||||
".................#####.................",
 | 
			
		||||
".................#####.................",
 | 
			
		||||
"................#######................",
 | 
			
		||||
"...............#########...............",
 | 
			
		||||
"...............#########...............",
 | 
			
		||||
"..............####aba####..............",
 | 
			
		||||
"..............####baa####..............",
 | 
			
		||||
".............####abaaa####.............",
 | 
			
		||||
"............####aba#aaa####............",
 | 
			
		||||
"............####ab###aa####............",
 | 
			
		||||
"...........####aba###aaa####...........",
 | 
			
		||||
"..........#####ab#####aa#####..........",
 | 
			
		||||
"..........####aba#####aaa####..........",
 | 
			
		||||
".........####abaa#####aaaa####.........",
 | 
			
		||||
".........####abaa#####aaaa####.........",
 | 
			
		||||
"........####abaaa#####aaaaa####........",
 | 
			
		||||
".......#####abaaa#####aaaaa#####.......",
 | 
			
		||||
".......####abaaaa#####aaaaaa####.......",
 | 
			
		||||
"......####abaaaaa#####aaaaaaa####......",
 | 
			
		||||
"......####abaaaaa#####aaaaaaa####......",
 | 
			
		||||
".....####abaaaaaa#####aaaaaaaa####.....",
 | 
			
		||||
"....####aabaaaaaaa###aaaaaaaaaa####....",
 | 
			
		||||
"....####abaaaaaaaa###aaaaaaaaaa####....",
 | 
			
		||||
"...####abaaaaaaaaaa#aaaaaaaaaaaa####...",
 | 
			
		||||
"..#####abaaaaaaaaaaaaaaaaaaaaaaa####...",
 | 
			
		||||
"..####abaaaaaaaaaaa#aaaaaaaaaaaaa####..",
 | 
			
		||||
".####aabaaaaaaaaaa###aaaaaaaaaaaaa####.",
 | 
			
		||||
".####abaaaaaaaaaa#####aaaaaaaaaaaa####.",
 | 
			
		||||
"####aabaaaaaaaaaaa###aaaaaaaaaaaaaa####",
 | 
			
		||||
"####abaaaaaaaaaaaaa#aaaaaaaaaaaaaaa####",
 | 
			
		||||
"#####aaaaaaaaaaaaaaaaaaaaaaaaaaaaa#####",
 | 
			
		||||
"#######################################",
 | 
			
		||||
".#####################################.",
 | 
			
		||||
"..###################################.."
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										98
									
								
								icon/x1.xpm
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,98 @@
 | 
			
		||||
/* XPM */
 | 
			
		||||
static const char * x1_xpm[] = {
 | 
			
		||||
"12 12 83 1",
 | 
			
		||||
" 	c None",
 | 
			
		||||
".	c #545454",
 | 
			
		||||
"+	c #333333",
 | 
			
		||||
"@	c #3D3D3D",
 | 
			
		||||
"#	c #373737",
 | 
			
		||||
"$	c #303030",
 | 
			
		||||
"%	c #353535",
 | 
			
		||||
"&	c #555555",
 | 
			
		||||
"*	c #585858",
 | 
			
		||||
"=	c #0B1D0A",
 | 
			
		||||
"-	c #184B17",
 | 
			
		||||
";	c #020202",
 | 
			
		||||
">	c #040404",
 | 
			
		||||
",	c #060606",
 | 
			
		||||
"'	c #0E0E0E",
 | 
			
		||||
")	c #101810",
 | 
			
		||||
"!	c #163C15",
 | 
			
		||||
"~	c #040E04",
 | 
			
		||||
"{	c #535653",
 | 
			
		||||
"]	c #123711",
 | 
			
		||||
"^	c #4BEF47",
 | 
			
		||||
"/	c #1E5F1C",
 | 
			
		||||
"(	c #040C04",
 | 
			
		||||
"_	c #020602",
 | 
			
		||||
":	c #010101",
 | 
			
		||||
"<	c #133C12",
 | 
			
		||||
"[	c #4EF94B",
 | 
			
		||||
"}	c #133D12",
 | 
			
		||||
"|	c #2E2E2E",
 | 
			
		||||
"1	c #030A03",
 | 
			
		||||
"2	c #10350F",
 | 
			
		||||
"3	c #43D840",
 | 
			
		||||
"4	c #0D2A0C",
 | 
			
		||||
"5	c #051105",
 | 
			
		||||
"6	c #010501",
 | 
			
		||||
"7	c #0B260B",
 | 
			
		||||
"8	c #44E444",
 | 
			
		||||
"9	c #123E12",
 | 
			
		||||
"0	c #000000",
 | 
			
		||||
"a	c #343434",
 | 
			
		||||
"b	c #48F548",
 | 
			
		||||
"c	c #061606",
 | 
			
		||||
"d	c #0C290C",
 | 
			
		||||
"e	c #45E645",
 | 
			
		||||
"f	c #051305",
 | 
			
		||||
"g	c #0A0A0A",
 | 
			
		||||
"h	c #323232",
 | 
			
		||||
"i	c #313131",
 | 
			
		||||
"j	c #4AFC4A",
 | 
			
		||||
"k	c #091F09",
 | 
			
		||||
"l	c #0C0C0C",
 | 
			
		||||
"m	c #2D2D2D",
 | 
			
		||||
"n	c #071907",
 | 
			
		||||
"o	c #4AFA4A",
 | 
			
		||||
"p	c #030D03",
 | 
			
		||||
"q	c #363636",
 | 
			
		||||
"r	c #061506",
 | 
			
		||||
"s	c #4CFE4C",
 | 
			
		||||
"t	c #051405",
 | 
			
		||||
"u	c #3FD23F",
 | 
			
		||||
"v	c #081D08",
 | 
			
		||||
"w	c #383838",
 | 
			
		||||
"x	c #103810",
 | 
			
		||||
"y	c #46EB46",
 | 
			
		||||
"z	c #144314",
 | 
			
		||||
"A	c #164715",
 | 
			
		||||
"B	c #4CFD4C",
 | 
			
		||||
"C	c #010401",
 | 
			
		||||
"D	c #0C280C",
 | 
			
		||||
"E	c #4FFC4B",
 | 
			
		||||
"F	c #164714",
 | 
			
		||||
"G	c #4D4D4D",
 | 
			
		||||
"H	c #113A11",
 | 
			
		||||
"I	c #154514",
 | 
			
		||||
"J	c #020402",
 | 
			
		||||
"K	c #525252",
 | 
			
		||||
"L	c #464646",
 | 
			
		||||
"M	c #202020",
 | 
			
		||||
"N	c #2A2A2A",
 | 
			
		||||
"O	c #242424",
 | 
			
		||||
"P	c #282828",
 | 
			
		||||
"Q	c #272727",
 | 
			
		||||
"R	c #515151",
 | 
			
		||||
" .+@#+$$#%& ",
 | 
			
		||||
"*=-;>,'')!~{",
 | 
			
		||||
"$]^/(_::<[}|",
 | 
			
		||||
"%1234567890a",
 | 
			
		||||
"%065bcdef0gh",
 | 
			
		||||
"i0065jbk60lh",
 | 
			
		||||
"m000noj7p6>q",
 | 
			
		||||
"h00rs6tuv56w",
 | 
			
		||||
"%0xyr065uz_w",
 | 
			
		||||
"%AB7000CDEFw",
 | 
			
		||||
"G;H000000IJK",
 | 
			
		||||
" LMNOPQQQ|R "};
 | 
			
		||||
							
								
								
									
										49
									
								
								icon/x2.xpm
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,49 @@
 | 
			
		||||
/* XPM */
 | 
			
		||||
static const char * x2_xpm[] = {
 | 
			
		||||
"12 12 34 1",
 | 
			
		||||
" 	c None",
 | 
			
		||||
".	c #565656",
 | 
			
		||||
"+	c #353535",
 | 
			
		||||
"@	c #3E3E3E",
 | 
			
		||||
"#	c #373737",
 | 
			
		||||
"$	c #333333",
 | 
			
		||||
"%	c #303030",
 | 
			
		||||
"&	c #555555",
 | 
			
		||||
"*	c #595959",
 | 
			
		||||
"=	c #030303",
 | 
			
		||||
"-	c #010101",
 | 
			
		||||
";	c #050505",
 | 
			
		||||
">	c #060606",
 | 
			
		||||
",	c #0E0E0E",
 | 
			
		||||
"'	c #000000",
 | 
			
		||||
")	c #545454",
 | 
			
		||||
"!	c #313131",
 | 
			
		||||
"~	c #383838",
 | 
			
		||||
"{	c #363636",
 | 
			
		||||
"]	c #0C0C0C",
 | 
			
		||||
"^	c #323232",
 | 
			
		||||
"/	c #2D2D2D",
 | 
			
		||||
"(	c #040404",
 | 
			
		||||
"_	c #4D4D4D",
 | 
			
		||||
":	c #020202",
 | 
			
		||||
"<	c #525252",
 | 
			
		||||
"[	c #464646",
 | 
			
		||||
"}	c #202020",
 | 
			
		||||
"|	c #2A2A2A",
 | 
			
		||||
"1	c #242424",
 | 
			
		||||
"2	c #282828",
 | 
			
		||||
"3	c #272727",
 | 
			
		||||
"4	c #2E2E2E",
 | 
			
		||||
"5	c #515151",
 | 
			
		||||
" .+@#$%%#+& ",
 | 
			
		||||
"*=-=;>,,,>')",
 | 
			
		||||
"!---------'~",
 | 
			
		||||
"{'''''''''-#",
 | 
			
		||||
"+''''''''']^",
 | 
			
		||||
"!''''''''']^",
 | 
			
		||||
"/'''''''''({",
 | 
			
		||||
"^''''''''''~",
 | 
			
		||||
"+'''''''''-~",
 | 
			
		||||
"+'''''''''-~",
 | 
			
		||||
"_:'''''''':<",
 | 
			
		||||
" [}|1233345 "};
 | 
			
		||||
							
								
								
									
										317
									
								
								qps.1
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,317 @@
 | 
			
		||||
.\" -*-nroff-*-
 | 
			
		||||
.TH QPS 1 "Sept 30 1999"
 | 
			
		||||
.UC 4
 | 
			
		||||
.SH NAME
 | 
			
		||||
qps \- Visual Process Manager
 | 
			
		||||
.SH SYNOPSIS
 | 
			
		||||
.B qps
 | 
			
		||||
[
 | 
			
		||||
.I options
 | 
			
		||||
]
 | 
			
		||||
.SH DESCRIPTION
 | 
			
		||||
.PP
 | 
			
		||||
.B qps
 | 
			
		||||
is a monitor that displays the status of the processes currently in existence,
 | 
			
		||||
much like top(1) or ps(1).
 | 
			
		||||
The user interface uses the Qt toolkit, and most operations should be
 | 
			
		||||
fairly intuitive.
 | 
			
		||||
.PP
 | 
			
		||||
The process list is sorted by the highlighted field. Click on another
 | 
			
		||||
title to change; click again to reverse the sorting order. Rearrange the
 | 
			
		||||
columns by dragging the titles.
 | 
			
		||||
.PP
 | 
			
		||||
Left-clicking on a process selects or deselects it. Shift-click to select
 | 
			
		||||
multiple processes. The PIDs of selected processes can be pasted into other
 | 
			
		||||
applications (this option can be disabled).
 | 
			
		||||
.PP
 | 
			
		||||
The right mouse button pops up a context menu, which duplicates some
 | 
			
		||||
functions from the main menu for convenience. It works both on processes and
 | 
			
		||||
on the column headings.
 | 
			
		||||
.PP
 | 
			
		||||
Control-clicking in the process table selects all processes with the same
 | 
			
		||||
displayed value in the particular column clicked in. For instance, to select
 | 
			
		||||
all processes owned by "joshua", keep Control pressed while clicking on
 | 
			
		||||
"joshua". Shift and Control together produces the expected result.
 | 
			
		||||
.PP
 | 
			
		||||
In Tree mode, the parent-child relations between processes is shown in a
 | 
			
		||||
more obvious way. Click on the triangles to show or hide an entire subtree.
 | 
			
		||||
Sorting only affects siblings; the tree structure imposes the global order.
 | 
			
		||||
.PP
 | 
			
		||||
To change the time-sharing priority of the selected processes, type the new
 | 
			
		||||
priority in the
 | 
			
		||||
.I Renice...
 | 
			
		||||
dialog. The new nice value should be in the range -20 to 20; 0 is the
 | 
			
		||||
default. A larger number means that the process gets less CPU time.
 | 
			
		||||
Only the super-user may decrease the nice value.
 | 
			
		||||
.PP
 | 
			
		||||
The
 | 
			
		||||
.I Change Scheduling...
 | 
			
		||||
dialog allows the super-user to change the scheduling policy of the
 | 
			
		||||
selected processes (using Posix.1b scheduling control).
 | 
			
		||||
Normal processes are set to SCHED_OTHER and have static priority 0;
 | 
			
		||||
(soft) real-time processes have the policy SCHED_FIFO or SCHED_RR and
 | 
			
		||||
a static priority in the range of 1 to 99. (See
 | 
			
		||||
sched_setscheduler(2).) Solaris has additional scheduling policies,
 | 
			
		||||
but right now qps doesn't allow setting these.
 | 
			
		||||
.PP
 | 
			
		||||
By default, the process display updates every 5 seconds. To change, type the
 | 
			
		||||
new update period in the
 | 
			
		||||
.I Update Period...
 | 
			
		||||
dialog. The units min, s and ms may be used (if none, seconds are
 | 
			
		||||
assumed). You can force an update by pressing the space bar or
 | 
			
		||||
clicking the
 | 
			
		||||
.I Update
 | 
			
		||||
button. qps will consume a lot of CPU time if the update period is
 | 
			
		||||
short or zero. If iconified, however, qps will use very little CPU.
 | 
			
		||||
.PP
 | 
			
		||||
The USER field shows the real user ID. If the effective user ID of a
 | 
			
		||||
process is different from its real user ID, a plus sign (+) is appended to
 | 
			
		||||
the user name; if it is the super-user, an asterisk (*) is appended.
 | 
			
		||||
.PP
 | 
			
		||||
The load, CPU, memory and swap displays in the status bar can be
 | 
			
		||||
toggled between graphic and text representations by clicking on them,
 | 
			
		||||
or by settings in the
 | 
			
		||||
.I Preferences...
 | 
			
		||||
dialog. The load numbers shown are the number of jobs in the run queue
 | 
			
		||||
averaged over 1, 5 and 15 minutes.
 | 
			
		||||
.PP
 | 
			
		||||
The swap bar will turn red if free swap space falls below a certain value,
 | 
			
		||||
which can be changed in the
 | 
			
		||||
.I Preferences...
 | 
			
		||||
dialog. The number can be entered in K, M (megabytes) or % (percent of total
 | 
			
		||||
swap space). The default is 10%.
 | 
			
		||||
.PP
 | 
			
		||||
On SMP (multi-CPU) machines running Solaris 2.6 or Linux 2.1.x or
 | 
			
		||||
later, the CPU stats will be shown for each processor in vertical
 | 
			
		||||
mode, and the average of all CPUs in horizontal mode.
 | 
			
		||||
.PP
 | 
			
		||||
For displaying the WCHAN field as symbols, the kernel symbol file
 | 
			
		||||
System.map is needed. qps will search for it in the following
 | 
			
		||||
locations:
 | 
			
		||||
.PP
 | 
			
		||||
.nf
 | 
			
		||||
	/boot/System.map-\c
 | 
			
		||||
.I RELEASE
 | 
			
		||||
	/boot/System.map
 | 
			
		||||
	/lib/modules/\c
 | 
			
		||||
.I RELEASE\c
 | 
			
		||||
/System.map
 | 
			
		||||
	/usr/src/linux-\c
 | 
			
		||||
.I RELEASE\c
 | 
			
		||||
/System.map
 | 
			
		||||
	/usr/src/linux/System.map
 | 
			
		||||
	/usr/local/src/linux-\c
 | 
			
		||||
.I RELEASE\c
 | 
			
		||||
/System.map
 | 
			
		||||
	/usr/local/src/linux/System.map
 | 
			
		||||
.fi
 | 
			
		||||
.PP
 | 
			
		||||
where
 | 
			
		||||
.I RELEASE
 | 
			
		||||
is the kernel release number, for instance "2.0.29". If the
 | 
			
		||||
System.map file isn't found or unreadable, hexadecimal addresses will be
 | 
			
		||||
displayed instead. The prefixes "sys_" and "do_" are stripped from the
 | 
			
		||||
symbols before they are displayed.
 | 
			
		||||
Under Solaris, symbolic names are currently not supported and hexadecimal
 | 
			
		||||
addresses will always be shown.
 | 
			
		||||
.PP
 | 
			
		||||
The
 | 
			
		||||
.I View Details
 | 
			
		||||
menu item opens a window that shows different aspects of the selected
 | 
			
		||||
processes. Double-clicking on a process has the same effect. All
 | 
			
		||||
information is only available to the owner of the process (and to the
 | 
			
		||||
super-user).
 | 
			
		||||
.PP
 | 
			
		||||
The
 | 
			
		||||
.I Sockets
 | 
			
		||||
table (Linux only) shows the currently used TCP and UDP sockets. If
 | 
			
		||||
.I Host Name Lookup
 | 
			
		||||
is checked in the
 | 
			
		||||
.I Preferences
 | 
			
		||||
dialog, a host name lookup will be done for each IP address. This is
 | 
			
		||||
done by a background process but can take a while for difficult cases
 | 
			
		||||
(but once looked up, addresses are cached).
 | 
			
		||||
.PP
 | 
			
		||||
The
 | 
			
		||||
.I Memory Maps
 | 
			
		||||
table shows the process's memory mappings. In Linux 2.0.x and Solaris,
 | 
			
		||||
the file names are not given. Anonymous mappings (allocated memory not
 | 
			
		||||
bound to a file or device) are marked (anonymous).
 | 
			
		||||
.PP
 | 
			
		||||
The
 | 
			
		||||
.I Files
 | 
			
		||||
table shows the process's open files. In Linux 2.0.x, the files
 | 
			
		||||
are given on the form [\c
 | 
			
		||||
.I AABB\c
 | 
			
		||||
]:\c
 | 
			
		||||
.I inode,
 | 
			
		||||
where
 | 
			
		||||
.I AA
 | 
			
		||||
and
 | 
			
		||||
.I BB
 | 
			
		||||
are the device major/minor numbers in hexadecimal.
 | 
			
		||||
.PP
 | 
			
		||||
The
 | 
			
		||||
.I Environment
 | 
			
		||||
table shows the process's environment variables. Note that this is the
 | 
			
		||||
environment with which the process was started, not necessarily
 | 
			
		||||
incorporating later changes. Some processes that modify their command
 | 
			
		||||
line, notably sendmail(8) and ftpd(8), may use the environment space
 | 
			
		||||
for this, showing nonsense in this table. Clicking on the field
 | 
			
		||||
headings changes sorting order as usual. (On Solaris, only the first
 | 
			
		||||
8K of the environment are shown. It will be fixed if it turns out to
 | 
			
		||||
be a limitation.)
 | 
			
		||||
.PP
 | 
			
		||||
.I Find Parent
 | 
			
		||||
and
 | 
			
		||||
.I Find Children
 | 
			
		||||
will select the parent/children of the selected processes, and center the
 | 
			
		||||
table on the first of them.
 | 
			
		||||
.I Find Descendants
 | 
			
		||||
will select the tree of all children of the selected processes.
 | 
			
		||||
.PP
 | 
			
		||||
If
 | 
			
		||||
.I Include Child Times
 | 
			
		||||
is selected in the
 | 
			
		||||
.I Options
 | 
			
		||||
menu, the TIME field will show the sum of the CPU times used by the process
 | 
			
		||||
and all of its children.
 | 
			
		||||
.PP
 | 
			
		||||
You can specify commands to be run on the selected processes by bringing
 | 
			
		||||
up the
 | 
			
		||||
.I Edit Commands...
 | 
			
		||||
dialog. The "Description" of each command is what appears in the menu;
 | 
			
		||||
the "Command Line" is a shell command (executed with /bin/sh). Before the
 | 
			
		||||
command is passed to the shell, the following substitutions are made:
 | 
			
		||||
.TP
 | 
			
		||||
.B %p
 | 
			
		||||
with the PID (Process ID) of the selected process
 | 
			
		||||
.TP
 | 
			
		||||
.B %c
 | 
			
		||||
with the short command name of the process
 | 
			
		||||
.TP
 | 
			
		||||
.B %C
 | 
			
		||||
with the complete command line of the process
 | 
			
		||||
.TP
 | 
			
		||||
.B %u
 | 
			
		||||
with the name of the (real) owner of the process
 | 
			
		||||
.TP
 | 
			
		||||
.B %%
 | 
			
		||||
with a literal '%'.
 | 
			
		||||
.PP
 | 
			
		||||
Any other % + letter combination is removed. The command line will be run
 | 
			
		||||
once for each selected process (in unspecified order).
 | 
			
		||||
.PP
 | 
			
		||||
.SH KEYBOARD ACCELERATORS
 | 
			
		||||
(valid in most contexts)
 | 
			
		||||
.TP
 | 
			
		||||
.B "Meta-W"
 | 
			
		||||
Close the active window (except the main window)
 | 
			
		||||
.TP
 | 
			
		||||
.B "Q, Meta-Q"
 | 
			
		||||
Quit qps.
 | 
			
		||||
.TP
 | 
			
		||||
.B "Space"
 | 
			
		||||
Force an update of the displayed tables.
 | 
			
		||||
.TP
 | 
			
		||||
.B "Control-Z"
 | 
			
		||||
Iconify qps.
 | 
			
		||||
.SH OPTIONS
 | 
			
		||||
.TP
 | 
			
		||||
.RI \-display \ display
 | 
			
		||||
sets the X display (default is $DISPLAY)
 | 
			
		||||
.TP
 | 
			
		||||
.RI \-geometry \ geometry
 | 
			
		||||
sets the geometry of the main window of qps
 | 
			
		||||
.TP
 | 
			
		||||
.RI \-background \ color
 | 
			
		||||
sets the default background color and an application palette (light and dark
 | 
			
		||||
shades are calculated). This doesn't work very well at the moment.
 | 
			
		||||
.TP
 | 
			
		||||
.RI \-foreground \ color
 | 
			
		||||
sets the default foreground color. This has limited use as well.
 | 
			
		||||
.TP
 | 
			
		||||
.RI \-title \ title
 | 
			
		||||
sets the application title (caption).
 | 
			
		||||
.TP
 | 
			
		||||
.RI \-style \ style
 | 
			
		||||
sets the application GUI style. Possible styles are
 | 
			
		||||
.I motif
 | 
			
		||||
and
 | 
			
		||||
.I windows.
 | 
			
		||||
(If you are using Qt 2.x, the styles
 | 
			
		||||
.I cde
 | 
			
		||||
and
 | 
			
		||||
.I platinum
 | 
			
		||||
are also available.)
 | 
			
		||||
.TP
 | 
			
		||||
.RI \-font \ font
 | 
			
		||||
sets the application font
 | 
			
		||||
.TP
 | 
			
		||||
.RI \-iconic
 | 
			
		||||
starts the application iconified.
 | 
			
		||||
.TP
 | 
			
		||||
.RI \-version
 | 
			
		||||
prints the version of qps and the Qt library, and exits.
 | 
			
		||||
.TP
 | 
			
		||||
.RI \-help
 | 
			
		||||
prints a summary of command-line options and exits.
 | 
			
		||||
.PP
 | 
			
		||||
.SH ENVIRONMENT
 | 
			
		||||
QPS_COLORS contains color specifications of comma-separated
 | 
			
		||||
.I name\c
 | 
			
		||||
:\c
 | 
			
		||||
.I value
 | 
			
		||||
pairs, where
 | 
			
		||||
.I name
 | 
			
		||||
is one of the following:
 | 
			
		||||
.PP
 | 
			
		||||
cpu-user, cpu-nice (Linux), cpu-sys, cpu-wait (Solaris), cpu-idle,
 | 
			
		||||
mem-used, mem-buff, mem-cache, mem-free,
 | 
			
		||||
swap-used, swap-free, swap-warn,
 | 
			
		||||
load-bg, load-fg, load-lines,
 | 
			
		||||
selection-bg, selection-fg
 | 
			
		||||
.PP
 | 
			
		||||
.I value
 | 
			
		||||
is an X11 color name, either a symbolic name like "salmon" or an RGB color
 | 
			
		||||
like #c5b769.
 | 
			
		||||
.PP
 | 
			
		||||
.SH FILES
 | 
			
		||||
.br
 | 
			
		||||
.DT
 | 
			
		||||
.ta \w'$HOME/.qps-settings\ \ \ 'u
 | 
			
		||||
/proc	kernel information pseudo-filesystem
 | 
			
		||||
.br
 | 
			
		||||
$HOME/.qps-settings	saved settings between invocations
 | 
			
		||||
.br
 | 
			
		||||
/etc/services	port number to service name mapping (Linux)
 | 
			
		||||
.br
 | 
			
		||||
System.map	kernel symbol map for WCHAN (Linux)
 | 
			
		||||
.br
 | 
			
		||||
.SH SEE ALSO
 | 
			
		||||
ps(1), top(1), kill(1), free(1), renice(8), proc(5), sched_setscheduler(2)
 | 
			
		||||
.SH AUTHOR
 | 
			
		||||
.PP
 | 
			
		||||
Mattias Engdegard (f91-men@nada.kth.se)
 | 
			
		||||
.SH LICENSE
 | 
			
		||||
qps is free software and may be redistributed under certain
 | 
			
		||||
conditions. See the GNU General Public License for details.
 | 
			
		||||
.PP
 | 
			
		||||
.SH BUGS
 | 
			
		||||
qps is too big and too slow.
 | 
			
		||||
 | 
			
		||||
The %CPU number isn't accurate at very short update intervals due to
 | 
			
		||||
timer granularity.
 | 
			
		||||
 | 
			
		||||
The %WCPU field isn't recalculated when qps is iconified, so it might take
 | 
			
		||||
a while to readjust when the window is deiconified again.
 | 
			
		||||
 | 
			
		||||
The WCHAN field doesn't show a function name if a process sleeps in a
 | 
			
		||||
location outside those in System.map (for instance, in a kernel
 | 
			
		||||
module), but a hex address instead. The function name can then be
 | 
			
		||||
found in /proc/ksyms but has to be found by hand right now.
 | 
			
		||||
 | 
			
		||||
The CPU indicator in the status bar will display nonsense in SMP systems
 | 
			
		||||
running Linux 2.0.x due to a kernel bug.
 | 
			
		||||
 | 
			
		||||
Adding/removing CPUs at runtime will probably confuse qps.
 | 
			
		||||
							
								
								
									
										13
									
								
								qps.desktop.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,13 @@
 | 
			
		||||
[Desktop Entry]
 | 
			
		||||
Type=Application
 | 
			
		||||
Name=qps
 | 
			
		||||
GenericName=Qt process manager
 | 
			
		||||
Comment=Qt application to display and manage running processes
 | 
			
		||||
Icon=qps
 | 
			
		||||
Categories=System;
 | 
			
		||||
TryExec=qps
 | 
			
		||||
Exec=qps
 | 
			
		||||
Terminal=false
 | 
			
		||||
StartupNotify=false
 | 
			
		||||
 | 
			
		||||
#TRANSLATIONS_DIR=src/translations
 | 
			
		||||
							
								
								
									
										91
									
								
								src/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,91 @@
 | 
			
		||||
 | 
			
		||||
set(SOURCES	
 | 
			
		||||
 	proc.cpp 
 | 
			
		||||
	qps.cpp
 | 
			
		||||
    screenshot.cpp
 | 
			
		||||
	pstable.cpp 
 | 
			
		||||
	uidstr.cpp 
 | 
			
		||||
	ttystr.cpp 
 | 
			
		||||
	dialogs.cpp 
 | 
			
		||||
	infobar.cpp 
 | 
			
		||||
	fieldsel.cpp 
 | 
			
		||||
	wchan.cpp 
 | 
			
		||||
	prefs.cpp 
 | 
			
		||||
	lookup.cpp 
 | 
			
		||||
	details.cpp 
 | 
			
		||||
	command.cpp 
 | 
			
		||||
	misc.cpp 
 | 
			
		||||
	trayicon.cpp 
 | 
			
		||||
	htable.cpp
 | 
			
		||||
#	htable2.cpp
 | 
			
		||||
#	pstable2.cpp
 | 
			
		||||
	qttableview.cpp 
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
SET(HEADERS	
 | 
			
		||||
	qps.h 
 | 
			
		||||
	screenshot.h
 | 
			
		||||
	pstable.h 
 | 
			
		||||
	dialogs.h 
 | 
			
		||||
	fieldsel.h 
 | 
			
		||||
	prefs.h 
 | 
			
		||||
	infobar.h 
 | 
			
		||||
	lookup.h 
 | 
			
		||||
	details.h 
 | 
			
		||||
	command.h 
 | 
			
		||||
	misc.h  
 | 
			
		||||
	trayicon.h 
 | 
			
		||||
	htable.h 
 | 
			
		||||
#	htable2.h
 | 
			
		||||
#	pstable2.h
 | 
			
		||||
	qttableview.h 
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
set(UIS
 | 
			
		||||
    watchdog.ui
 | 
			
		||||
    message.ui
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
#-----------------------------------------------------------------------------
 | 
			
		||||
# Translations
 | 
			
		||||
#-----------------------------------------------------------------------------
 | 
			
		||||
lxqt_translate_ts(QM_FILES
 | 
			
		||||
    UPDATE_TRANSLATIONS ${UPDATE_TRANSLATIONS}
 | 
			
		||||
    SOURCES ${SOURCES} ${HEADERS} ${UIS}
 | 
			
		||||
    INSTALL_DIR "${QPS_TRANSLATIONS_DIR}/${PROJECT_NAME}"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
qt5_translation_loader(
 | 
			
		||||
    QM_LOADER
 | 
			
		||||
    "${QPS_TRANSLATIONS_DIR}"
 | 
			
		||||
    ${PROJECT_NAME}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
lxqt_translate_desktop(DESKTOP_FILES
 | 
			
		||||
    SOURCES "${CMAKE_SOURCE_DIR}/qps.desktop.in"
 | 
			
		||||
)
 | 
			
		||||
#-----------------------------------------------------------------------------
 | 
			
		||||
# End of translations
 | 
			
		||||
#-----------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
add_executable(${PROJECT}
 | 
			
		||||
    ${SOURCES}
 | 
			
		||||
    ${HEADERS}
 | 
			
		||||
    ${UIS}
 | 
			
		||||
    ${QM_FILES}
 | 
			
		||||
    ${QM_LOADER}
 | 
			
		||||
    ${DESKTOP_FILES}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
target_link_libraries(${PROJECT}
 | 
			
		||||
    Qt5::Widgets
 | 
			
		||||
    Qt5::X11Extras
 | 
			
		||||
    Qt5::DBus
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
install(TARGETS ${PROJECT} RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
 | 
			
		||||
install(FILES
 | 
			
		||||
    ${DESKTOP_FILES}
 | 
			
		||||
    DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications"
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										1197
									
								
								src/command.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										226
									
								
								src/command.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,226 @@
 | 
			
		||||
// command.h				emacs, this is written in -*-c++-*-
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#ifndef COMMAND_H
 | 
			
		||||
#define COMMAND_H
 | 
			
		||||
 | 
			
		||||
#ifndef USING_PCH
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
#include <QLineEdit>
 | 
			
		||||
#include <QCheckBox>
 | 
			
		||||
#include <QToolButton>
 | 
			
		||||
#include <QPushButton>
 | 
			
		||||
#include <QListView>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "proc.h"
 | 
			
		||||
#include "misc.h"
 | 
			
		||||
 | 
			
		||||
int find_command(QString s);
 | 
			
		||||
void add_default_command();
 | 
			
		||||
 | 
			
		||||
class Command
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Command(){};
 | 
			
		||||
    Command(QString n, QString cmd, bool toolbar = false);
 | 
			
		||||
    ~Command();
 | 
			
		||||
    void call(Procinfo *p);
 | 
			
		||||
    bool IsNeedProc();
 | 
			
		||||
    QString getString();
 | 
			
		||||
    void putString(QString str);
 | 
			
		||||
 | 
			
		||||
    // CommandButton *toolbutton;
 | 
			
		||||
 | 
			
		||||
    QString name;    // appears in the menu
 | 
			
		||||
    QString cmdline; // may contain variables (%p etc)
 | 
			
		||||
    int menu;        // index in menu
 | 
			
		||||
    bool toolbar;
 | 
			
		||||
    bool popup;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class CommandModel : public QAbstractItemModel
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    CommandModel(QObject *parent = 0);
 | 
			
		||||
    ~CommandModel();
 | 
			
		||||
    QModelIndex index(int row, int column, const QModelIndex &parent) const;
 | 
			
		||||
    QModelIndex parent(const QModelIndex &child) const;
 | 
			
		||||
    int rowCount(const QModelIndex &parent) const;
 | 
			
		||||
    int columnCount(const QModelIndex &parent) const { return 1; };
 | 
			
		||||
    QVariant data(const QModelIndex &index, int role) const;
 | 
			
		||||
    //  Qt::ItemFlags flags(const QModelIndex &index) const;
 | 
			
		||||
    void update(); // TEMP
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// class CommandDialog : public QWidget
 | 
			
		||||
class CommandDialog : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    CommandDialog();
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void command_change();
 | 
			
		||||
 | 
			
		||||
  protected slots:
 | 
			
		||||
    void new_cmd();
 | 
			
		||||
    void add_new();
 | 
			
		||||
    void del_current();
 | 
			
		||||
    void set_buttons(int);
 | 
			
		||||
    void reset();
 | 
			
		||||
    void set_select(const QModelIndex &);
 | 
			
		||||
    void event_name_midified(const QString &new_name);
 | 
			
		||||
    void event_cmd_modified();
 | 
			
		||||
    void event_toolbar_checked(bool);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    QListView *listview;
 | 
			
		||||
    QPushButton *new0, *add, *del, *edit, *button_ok;
 | 
			
		||||
    QLineEdit *name, *cmdline;
 | 
			
		||||
    QCheckBox *qcheck1;
 | 
			
		||||
    QCheckBox *qcheck2;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#include <QItemDelegate>
 | 
			
		||||
class checkBoxDelegate : public QItemDelegate
 | 
			
		||||
// class checkBoxDelegate : public QAbstractItemDelegate
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    checkBoxDelegate(QObject *parent = 0);
 | 
			
		||||
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
 | 
			
		||||
                          const QModelIndex &index) const;
 | 
			
		||||
    void setEditorData(QWidget *editor, const QModelIndex &index) const;
 | 
			
		||||
    void setModelData(QWidget *editor, QAbstractItemModel *model,
 | 
			
		||||
                      const QModelIndex &index) const;
 | 
			
		||||
    void updateEditorGeometry(QWidget *editor,
 | 
			
		||||
                              const QStyleOptionViewItem &option,
 | 
			
		||||
                              const QModelIndex &index) const;
 | 
			
		||||
 | 
			
		||||
    void paint(QPainter *painter, const QStyleOptionViewItem &option,
 | 
			
		||||
               const QModelIndex &index) const;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#include <QStandardItemModel>
 | 
			
		||||
// class ListModel : public QAbstractItemModel
 | 
			
		||||
class ListModel : public QAbstractTableModel
 | 
			
		||||
// class ListModel : public QStandardItemModel
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    ListModel(QObject *parent = 0){};
 | 
			
		||||
    ~ListModel(){};
 | 
			
		||||
    QModelIndex index(int row, int column,
 | 
			
		||||
                      const QModelIndex &parent = QModelIndex()) const; // pure
 | 
			
		||||
    QModelIndex parent(const QModelIndex &child) const; // pure virtual
 | 
			
		||||
    int rowCount(const QModelIndex &parent) const;
 | 
			
		||||
    int columnCount(const QModelIndex &parent) const { return 2; };
 | 
			
		||||
    QVariant data(const QModelIndex &index, int role) const;
 | 
			
		||||
    QVariant headerData(int section, Qt::Orientation o, int role) const;
 | 
			
		||||
    //	QMap<int, QVariant> itemData ( const QModelIndex & index ) const
 | 
			
		||||
    //;
 | 
			
		||||
    void update()
 | 
			
		||||
    { // reset();
 | 
			
		||||
    }
 | 
			
		||||
    void update(const QModelIndex &idx);
 | 
			
		||||
    void update(int row);
 | 
			
		||||
    //  Qt::ItemFlags flags(const QModelIndex &index) const;
 | 
			
		||||
    //	void update(); //TEMP
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#include "ui_watchdog.h"
 | 
			
		||||
class WatchdogDialog : public QDialog, private Ui_EventDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    WatchdogDialog();
 | 
			
		||||
    ListModel *listmodel;
 | 
			
		||||
    // signals:
 | 
			
		||||
    //    void command_change();
 | 
			
		||||
    void checkCombo();
 | 
			
		||||
  protected slots:
 | 
			
		||||
    void _new();
 | 
			
		||||
    void apply();
 | 
			
		||||
    void add();
 | 
			
		||||
    void del();
 | 
			
		||||
    void condChanged(const QString &str);
 | 
			
		||||
    void Changed(const QString &str);
 | 
			
		||||
 | 
			
		||||
    void comboChanged(int);
 | 
			
		||||
    void eventcat_slected(const QModelIndex &idx);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual void showEvent(QShowEvent *event);
 | 
			
		||||
 | 
			
		||||
    //  void set_select( const QModelIndex & );
 | 
			
		||||
    //  void event_name_midified(const QString &new_name);
 | 
			
		||||
    //  void event_cmd_modified();
 | 
			
		||||
    // void event_toolbar_checked(bool);
 | 
			
		||||
  private:
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define WATCH_PROCESS_START 0
 | 
			
		||||
#define WATCH_PROCESS_FINISH 1
 | 
			
		||||
#define WATCH_PROCESS_CPU_OVER 2
 | 
			
		||||
#define WATCH_SYS_CPU_OVER 3
 | 
			
		||||
#define WATCH_SYS_CPU_UNDER 4
 | 
			
		||||
 | 
			
		||||
// if process [name] start, exec [command], showmsg [xxx]
 | 
			
		||||
// if process [name] finish exec [command], showmsg [xxx]
 | 
			
		||||
// if system cpu over [90%], exec [command], msg [xxx]
 | 
			
		||||
// if system cpu under [10%], exec [command], msg [xxx]
 | 
			
		||||
// if process [name] cpu over [90%] exec [command] msg [xxx]
 | 
			
		||||
// if process [name] start, kill_it, msg [xxx]
 | 
			
		||||
// if process [name] start, soundplay [ ], msg [xxx]
 | 
			
		||||
 | 
			
		||||
class watchCond
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    int cond;
 | 
			
		||||
    int enable;
 | 
			
		||||
    int cpu;
 | 
			
		||||
    QString procname;
 | 
			
		||||
    QString command;
 | 
			
		||||
    QString message;
 | 
			
		||||
 | 
			
		||||
    watchCond()
 | 
			
		||||
    {
 | 
			
		||||
        enable = 0;
 | 
			
		||||
        //	procname[0]=0;		command[0]=0;
 | 
			
		||||
        // message[0]=0;
 | 
			
		||||
    }
 | 
			
		||||
    // key [txt]	[a]
 | 
			
		||||
    // QString getVal(QString &str, QString &key)
 | 
			
		||||
    QString getVal(QString &str, const char *key);
 | 
			
		||||
    QString getstring();
 | 
			
		||||
    void putstring(QString str);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#include <QProcess>
 | 
			
		||||
#include "ui_message.h"
 | 
			
		||||
class ExecWindow : public QWidget, private Ui_ExecWindow
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    ExecWindow();
 | 
			
		||||
    ExecWindow(QString str, QString exec_cmd, int pid = 0, QString cmd = "");
 | 
			
		||||
    ExecWindow(watchCond *wc, int pid = 0, QString cmd = "");
 | 
			
		||||
    ~ExecWindow();
 | 
			
		||||
    void setText(QString str);
 | 
			
		||||
    QProcess *pr;
 | 
			
		||||
    // QProcess 	proc;
 | 
			
		||||
    QString execmd;
 | 
			
		||||
    int flag_started;
 | 
			
		||||
    watchCond *wcond;
 | 
			
		||||
  protected slots:
 | 
			
		||||
    void cmd_started();
 | 
			
		||||
    void cmd_finished(int exitCode, QProcess::ExitStatus exitStatus);
 | 
			
		||||
    void cmd_error(QProcess::ProcessError error);
 | 
			
		||||
    void cmd_ok();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // COMMAND_H
 | 
			
		||||
							
								
								
									
										20
									
								
								src/config.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,20 @@
 | 
			
		||||
// config.h					-*-c++-*-
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#ifndef CONFIG_H
 | 
			
		||||
#define CONFIG_H
 | 
			
		||||
 | 
			
		||||
#if defined(__linux__)
 | 
			
		||||
#define LINUX
 | 
			
		||||
 | 
			
		||||
#elif defined(sun) && defined(__SVR4)
 | 
			
		||||
#define SOLARIS
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
#error Only Linux >= 2.0 and Solaris >= 2.6 supported, sorry
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif // CONFIG_H
 | 
			
		||||
							
								
								
									
										0
									
								
								src/ctrlbar.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										0
									
								
								src/ctrlbar.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										727
									
								
								src/details.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,727 @@
 | 
			
		||||
// details.C
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <netdb.h>
 | 
			
		||||
#include <netinet/in.h>
 | 
			
		||||
 | 
			
		||||
#include "details.h"
 | 
			
		||||
//#include "proc.h" // static flag
 | 
			
		||||
#include "qps.h" // static flag
 | 
			
		||||
Details::Details(Procinfo *p, Proc *proc) : QWidget(0)
 | 
			
		||||
{
 | 
			
		||||
    QString cap;
 | 
			
		||||
    pi = p;
 | 
			
		||||
    pi->detail = this;
 | 
			
		||||
    pr = proc;
 | 
			
		||||
    //	printf("pi=%x\n",pi);
 | 
			
		||||
    cap.sprintf("Process %d ( %s ) - details", pi->pid,
 | 
			
		||||
                qPrintable(pi->command));
 | 
			
		||||
    setWindowTitle(cap);
 | 
			
		||||
 | 
			
		||||
    tbar = new QTabWidget(this);
 | 
			
		||||
    // tbar->setMargin(5);
 | 
			
		||||
 | 
			
		||||
    // if(pi->fd_files) //if(pi->fd_files->size())
 | 
			
		||||
    if (pi->read_fds())
 | 
			
		||||
    {
 | 
			
		||||
        tbar->addTab(new Files(this), "&Files");
 | 
			
		||||
 | 
			
		||||
//	if(pi->read_fds()) // create sock_inodes
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
        // printf(" pi->socks.size=%d\n",  p->sock_inodes->size() );
 | 
			
		||||
        // this means if a process dont have socket then
 | 
			
		||||
        // no socket pane  show in Detail dialog.
 | 
			
		||||
        // Procinfo::read_sockets();
 | 
			
		||||
        if (pi->sock_inodes.size() != 0)
 | 
			
		||||
            tbar->addTab(new Sockets(this), "&Sockets");
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (pi->read_maps())
 | 
			
		||||
        tbar->addTab(new Maps(this), "&Memory Maps");
 | 
			
		||||
    if (pi->read_environ())
 | 
			
		||||
        tbar->addTab(new Environ(this), "&Environment");
 | 
			
		||||
    tbar->addTab(new AllFields(this), "&All Fields");
 | 
			
		||||
 | 
			
		||||
    tbar->adjustSize();
 | 
			
		||||
    QSize s0 = tbar->sizeHint();
 | 
			
		||||
    if (s0.width() > 800)
 | 
			
		||||
        s0.setWidth(800);
 | 
			
		||||
    resize(s0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Details::~Details()
 | 
			
		||||
{
 | 
			
		||||
    //	printf("~Details()\n");
 | 
			
		||||
    if (pi)
 | 
			
		||||
        pi->detail = 0;
 | 
			
		||||
    int i;
 | 
			
		||||
    /// for(i=0;i<tbar->count();i++)	delete tbar->page(i);
 | 
			
		||||
    delete tbar;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Details::set_procinfo(Procinfo *p)
 | 
			
		||||
{
 | 
			
		||||
    //	printf("p=%x, pi=%x\n",p,pi);
 | 
			
		||||
}
 | 
			
		||||
void Details::refresh()
 | 
			
		||||
{
 | 
			
		||||
    printf("Details::refresh()\n");
 | 
			
		||||
    QWidget *w = NULL; // tbar->currentPage ();
 | 
			
		||||
    // QWidget *w= tbar->currentPage ();
 | 
			
		||||
    if (w != NULL)
 | 
			
		||||
    {
 | 
			
		||||
        /// printf("refresh()\n");
 | 
			
		||||
        ((SimpleTable *)w)->refresh();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Details::process_gone()
 | 
			
		||||
{
 | 
			
		||||
    ///	printf("process_gone() *******************************\n");
 | 
			
		||||
    pi = 0;
 | 
			
		||||
    // for now, we just close the window. Another possibility would be
 | 
			
		||||
    // to leave it with a "process terminated" note.
 | 
			
		||||
    close();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// slot: react to changes in preferences
 | 
			
		||||
void Details::config_change() { return; }
 | 
			
		||||
 | 
			
		||||
void Details::resizeEvent(QResizeEvent *s)
 | 
			
		||||
{
 | 
			
		||||
    tbar->resize(s->size()); //**
 | 
			
		||||
    QWidget::resizeEvent(s);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// user closed the window (via window manager)
 | 
			
		||||
void Details::closeEvent(QCloseEvent *) { emit closed(this); }
 | 
			
		||||
 | 
			
		||||
SimpleTable::SimpleTable(QWidget *parent, int nfields, TableField *f,
 | 
			
		||||
                         int options)
 | 
			
		||||
    : HeadedTable(parent, options), fields(f)
 | 
			
		||||
{
 | 
			
		||||
    detail = (Details *)parent;
 | 
			
		||||
    setNumCols(nfields);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QSize SimpleTable::sizeHint() const
 | 
			
		||||
{
 | 
			
		||||
    /// return QSize(tableWidth(), 300);
 | 
			
		||||
    return QSize(480, 300);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString SimpleTable::title(int col) { return fields[col].name; }
 | 
			
		||||
 | 
			
		||||
int SimpleTable::colWidth(int col) { return fields[col].width; }
 | 
			
		||||
 | 
			
		||||
inline int SimpleTable::alignment(int col) { return fields[col].align; }
 | 
			
		||||
 | 
			
		||||
int SimpleTable::leftGap(int col) { return fields[col].gap; }
 | 
			
		||||
 | 
			
		||||
QString SimpleTable::tipText(int col) { return fields[col].tooltip; }
 | 
			
		||||
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
 | 
			
		||||
// declaration of static members
 | 
			
		||||
bool Sockets::have_services = false;
 | 
			
		||||
QHash<int, char *> Sockets::servdict;
 | 
			
		||||
Lookup *Sockets::lookup = 0;
 | 
			
		||||
 | 
			
		||||
TableField Sockets::fields[] = {
 | 
			
		||||
    {"Fd", 5, 8, Qt::AlignRight, "File descriptor"},
 | 
			
		||||
    {"Proto", 4, 8, Qt::AlignLeft, "Protocol (TCP or UDP)"},
 | 
			
		||||
    {"Recv-Q", 9, 8, Qt::AlignRight, "Bytes in receive queue"},
 | 
			
		||||
    {"Send-Q", 9, 8, Qt::AlignRight, "Bytes in send queue"},
 | 
			
		||||
    {"Local Addr", -1, 8, Qt::AlignLeft, "Local IP address"},
 | 
			
		||||
    {"Port", 6, 8, Qt::AlignLeft, "Local port"},
 | 
			
		||||
    {"Remote Addr", -1, 8, Qt::AlignLeft, "Remote IP address"},
 | 
			
		||||
    {"Port", 6, 8, Qt::AlignLeft, "Remote port"},
 | 
			
		||||
    {"State", 18, 8, Qt::AlignLeft, "Connection state"}};
 | 
			
		||||
 | 
			
		||||
Sockets::Sockets(QWidget *parent) : SimpleTable(parent, SOCKFIELDS, fields)
 | 
			
		||||
{
 | 
			
		||||
    if (!lookup)
 | 
			
		||||
        lookup = new Lookup();
 | 
			
		||||
    connect(lookup, SIGNAL(resolved(unsigned)),
 | 
			
		||||
            SLOT(update_hostname(unsigned)));
 | 
			
		||||
    doing_lookup = Qps::hostname_lookup;
 | 
			
		||||
    refresh();
 | 
			
		||||
    // compute total width = window width
 | 
			
		||||
    int totw = 400;
 | 
			
		||||
    // for(int i = 0; i < SOCKFIELDS; i++)
 | 
			
		||||
    //	totw += actualColWidth(i);
 | 
			
		||||
    resize(totw, 200);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Sockets::~Sockets()
 | 
			
		||||
{
 | 
			
		||||
    // why seg?
 | 
			
		||||
    // if(lookup)	delete lookup;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const char *tcp_states[] = {
 | 
			
		||||
    "ESTABLISHED", // 1
 | 
			
		||||
    "SYN_SENT",    "SYN_RECV",   "FIN_WAIT1", "FIN_WAIT2", "TIME_WAIT",
 | 
			
		||||
    "CLOSE",       "CLOSE_WAIT", "LAST_ACK",  "LISTEN",
 | 
			
		||||
    "CLOSING" // 11
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static inline const char *tcp_state_name(int st)
 | 
			
		||||
{
 | 
			
		||||
    return (st < 1 || st > 11) ? "UNKNOWN" : tcp_states[st - 1];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString Sockets::text(int row, int col)
 | 
			
		||||
{
 | 
			
		||||
    Procinfo *p = procinfo();
 | 
			
		||||
    if (p->sock_inodes.size() == 0)
 | 
			
		||||
        refresh_sockets();
 | 
			
		||||
    SockInode *sock_ino = p->sock_inodes[row];
 | 
			
		||||
    // SockInode *sock_ino = p->sock_inodes[row];
 | 
			
		||||
    Sockinfo *si = p->proc->socks.value(sock_ino->inode, NULL);
 | 
			
		||||
    if (!si)
 | 
			
		||||
        return ""; // process gone, return empty string
 | 
			
		||||
 | 
			
		||||
    QString s;
 | 
			
		||||
    switch (col)
 | 
			
		||||
    {
 | 
			
		||||
    case FD:
 | 
			
		||||
        s.setNum(sock_ino->fd);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case PROTO:
 | 
			
		||||
        s = (si->proto == Sockinfo::TCP) ? "tcp" : "udp";
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case RECVQ:
 | 
			
		||||
        s.setNum(si->rx_queue);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case SENDQ:
 | 
			
		||||
        s.setNum(si->tx_queue);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case LOCALADDR:
 | 
			
		||||
        s = ipAddr(si->local_addr);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case LOCALPORT:
 | 
			
		||||
        if (Qps::service_lookup)
 | 
			
		||||
        {
 | 
			
		||||
            const char *serv = servname(si->local_port);
 | 
			
		||||
            if (serv)
 | 
			
		||||
            {
 | 
			
		||||
                s = serv;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        s.setNum(si->local_port);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case REMOTEADDR:
 | 
			
		||||
        s = ipAddr(si->rem_addr);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case REMOTEPORT:
 | 
			
		||||
        if (Qps::service_lookup)
 | 
			
		||||
        {
 | 
			
		||||
            const char *serv = servname(si->rem_port);
 | 
			
		||||
            if (serv)
 | 
			
		||||
            {
 | 
			
		||||
                s = serv;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        s.setNum(si->rem_port);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case STATE:
 | 
			
		||||
        s = tcp_state_name(si->st);
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString Sockets::ipAddr(unsigned addr)
 | 
			
		||||
{
 | 
			
		||||
    unsigned a = htonl(addr);
 | 
			
		||||
    QString s;
 | 
			
		||||
    if (doing_lookup)
 | 
			
		||||
    {
 | 
			
		||||
        s = lookup->hostname(addr);
 | 
			
		||||
        if (s.isNull())
 | 
			
		||||
        {
 | 
			
		||||
            s.sprintf("(%d.%d.%d.%d)", (a >> 24) & 0xff, (a >> 16) & 0xff,
 | 
			
		||||
                      (a >> 8) & 0xff, a & 0xff);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        if (a == 0)
 | 
			
		||||
            s = "*";
 | 
			
		||||
        else
 | 
			
		||||
            s.sprintf("%d.%d.%d.%d", (a >> 24) & 0xff, (a >> 16) & 0xff,
 | 
			
		||||
                      (a >> 8) & 0xff, a & 0xff);
 | 
			
		||||
    }
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Sockets::refresh_window()
 | 
			
		||||
{
 | 
			
		||||
    Procinfo *p = procinfo();
 | 
			
		||||
    if (!p)
 | 
			
		||||
        return;
 | 
			
		||||
    int rows = p->sock_inodes.size();
 | 
			
		||||
    /// resetWidths();
 | 
			
		||||
    setNumRows(rows);
 | 
			
		||||
    setNumCols(SOCKFIELDS);
 | 
			
		||||
    /// repaint_changed();
 | 
			
		||||
    repaintAll();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Sockets::refresh()
 | 
			
		||||
{
 | 
			
		||||
    if (refresh_sockets())
 | 
			
		||||
        refresh_window();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// return true if sockets could be read successfully, false otherwise
 | 
			
		||||
bool Sockets::refresh_sockets()
 | 
			
		||||
{
 | 
			
		||||
    //	Procinfo::read_sockets();
 | 
			
		||||
    return procinfo()->read_fds();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// react to changes in preferences
 | 
			
		||||
void Sockets::config_change()
 | 
			
		||||
{
 | 
			
		||||
    if (doing_lookup != Qps::hostname_lookup)
 | 
			
		||||
    {
 | 
			
		||||
        doing_lookup = Qps::hostname_lookup;
 | 
			
		||||
        ////setNumCols(SOCKFIELDS);
 | 
			
		||||
        // for(int col = 0; col < SOCKFIELDS; col++)
 | 
			
		||||
        //	widthChanged(col);
 | 
			
		||||
        ////updateTableSize();
 | 
			
		||||
        ////repaintAll();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// slot: called when a host name has been looked up
 | 
			
		||||
void Sockets::update_hostname(unsigned addr)
 | 
			
		||||
{
 | 
			
		||||
    // if(widthChanged(REMOTEADDR) || widthChanged(LOCALADDR)) {
 | 
			
		||||
    if (1)
 | 
			
		||||
    {
 | 
			
		||||
        ////	updateTableSize();
 | 
			
		||||
        ///	repaintAll();
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        // just repaint some rows
 | 
			
		||||
        Procinfo *p = procinfo();
 | 
			
		||||
        if (!p->sock_inodes.size())
 | 
			
		||||
        {
 | 
			
		||||
            /// Procinfo::read_sockets();
 | 
			
		||||
            p->read_fds();
 | 
			
		||||
        }
 | 
			
		||||
        int rows = p->sock_inodes.size();
 | 
			
		||||
        for (int i = 0; i < rows; i++)
 | 
			
		||||
        {
 | 
			
		||||
            int inode = p->sock_inodes[i]->inode;
 | 
			
		||||
            /// Sockinfo *si = Procinfo::socks[inode];
 | 
			
		||||
            /// if(si->local_addr == addr) updateCell(i, LOCALADDR);
 | 
			
		||||
            /// if(si->rem_addr == addr)	updateCell(i,
 | 
			
		||||
            /// REMOTEADDR);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char *Sockets::servname(unsigned port)
 | 
			
		||||
{
 | 
			
		||||
    if (!have_services)
 | 
			
		||||
    {
 | 
			
		||||
        have_services = true;
 | 
			
		||||
        // fill servdict from /etc/services (just try once)
 | 
			
		||||
        setservent(1);
 | 
			
		||||
        struct servent *s;
 | 
			
		||||
        while ((s = getservent()) != 0)
 | 
			
		||||
        {
 | 
			
		||||
            unsigned short hport = ntohs((unsigned short)s->s_port);
 | 
			
		||||
            if (!servdict.value(hport, NULL))
 | 
			
		||||
            {
 | 
			
		||||
                servdict.insert(hport, strdup(s->s_name));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        endservent();
 | 
			
		||||
    }
 | 
			
		||||
    return servdict.value(port, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // LINUX
 | 
			
		||||
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
 | 
			
		||||
// Stupid code to make up for moc:s inability to grok preprocessor conditionals
 | 
			
		||||
void Sockets::refresh() {}
 | 
			
		||||
QString Sockets::text(int, int) { return 0; }
 | 
			
		||||
void Sockets::config_change() {}
 | 
			
		||||
Sockets::~Sockets() {}
 | 
			
		||||
void Sockets::update_hostname(unsigned int) {}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
TableField Maps::fields[] = {
 | 
			
		||||
    {"Address Range", -1, 8, Qt::AlignLeft, "Mapped addresses (hex)"},
 | 
			
		||||
    {"Size", 8, 8, Qt::AlignRight, "Kbytes mapped (dec)"},
 | 
			
		||||
    {"Perm", 5, 8, Qt::AlignLeft, "Permission flags"},
 | 
			
		||||
    {"Offset", -1, 8, Qt::AlignRight, "File offset at start of mapping (hex)"},
 | 
			
		||||
    {"Device", 8, 8, Qt::AlignLeft, "Major,Minor device numbers (dec)"},
 | 
			
		||||
    {"Inode", 10, 8, Qt::AlignRight, "Inode number (dec)"},
 | 
			
		||||
    {"File", -9, 8, Qt::AlignLeft, "File name (if available)"}};
 | 
			
		||||
 | 
			
		||||
// memory leak
 | 
			
		||||
Maps::Maps(QWidget *parent) : SimpleTable(parent, MAPSFIELDS, fields)
 | 
			
		||||
{
 | 
			
		||||
    // monospaced font looks best in the table body since it contains
 | 
			
		||||
    // hex numerals and flag fields. Pick Courier (why not)
 | 
			
		||||
    body->setFont(QFont("Courier", font().pointSize()));
 | 
			
		||||
    bool mono = true;
 | 
			
		||||
    QFont f = font();
 | 
			
		||||
    if (f.rawMode())
 | 
			
		||||
    {
 | 
			
		||||
        /* see if the font is monospaced enough for our needs */
 | 
			
		||||
        QFontMetrics fm(f);
 | 
			
		||||
        int zw = fm.width('0');
 | 
			
		||||
        const char *test = "abcdef";
 | 
			
		||||
        for (const char *p = test; *p; p++)
 | 
			
		||||
            if (fm.width(*p) != zw)
 | 
			
		||||
            {
 | 
			
		||||
                mono = false;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
        mono = f.fixedPitch();
 | 
			
		||||
    if (mono)
 | 
			
		||||
    {
 | 
			
		||||
        ////setBodyFont(f);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        int ps = f.pointSize();
 | 
			
		||||
        /// setBodyFont(QFont("Courier", ps ? ps : 10));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    refresh();
 | 
			
		||||
    // compute total width = window width
 | 
			
		||||
    int totw = 300;
 | 
			
		||||
    // for(int i = 0; i < MAPSFIELDS; i++)	totw += actualColWidth(i);
 | 
			
		||||
    resize(totw + 20, 200);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Maps::~Maps()
 | 
			
		||||
{
 | 
			
		||||
    //	if(maps)
 | 
			
		||||
    //		maps->clear();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString Maps::text(int row, int col)
 | 
			
		||||
{
 | 
			
		||||
    Procinfo *p = procinfo();
 | 
			
		||||
    if (p->maps.size() == 0)
 | 
			
		||||
    {
 | 
			
		||||
        refresh_maps();
 | 
			
		||||
        if (p->maps.size() == 0)
 | 
			
		||||
            return "";
 | 
			
		||||
    }
 | 
			
		||||
    Mapsinfo *mi = p->maps[row];
 | 
			
		||||
 | 
			
		||||
    QString s;
 | 
			
		||||
    char buf[80];
 | 
			
		||||
    switch (col)
 | 
			
		||||
    {
 | 
			
		||||
    case ADDRESS:
 | 
			
		||||
        sprintf(buf, (sizeof(void *) == 4) ? "%08lx-%08lx" : "%016lx-%016lx",
 | 
			
		||||
                mi->from, mi->to);
 | 
			
		||||
        s = buf;
 | 
			
		||||
        break;
 | 
			
		||||
    case SIZE:
 | 
			
		||||
        s.setNum((mi->to - mi->from) >> 10);
 | 
			
		||||
        s += "kb";
 | 
			
		||||
        break;
 | 
			
		||||
    case PERM:
 | 
			
		||||
        s = "    ";
 | 
			
		||||
        for (int i = 0; i < 4; i++)
 | 
			
		||||
            s[i] = mi->perm[i];
 | 
			
		||||
        break;
 | 
			
		||||
    case OFFSET:
 | 
			
		||||
        sprintf(buf, (sizeof(void *) == 4) ? "%08lx" : "%016lx", mi->offset);
 | 
			
		||||
        s = buf;
 | 
			
		||||
        break;
 | 
			
		||||
    case DEVICE:
 | 
			
		||||
        s.sprintf("%2u,%2u", mi->major, mi->minor);
 | 
			
		||||
        break;
 | 
			
		||||
    case INODE:
 | 
			
		||||
        s.setNum(mi->inode);
 | 
			
		||||
        break;
 | 
			
		||||
    case FILENAME:
 | 
			
		||||
        s = mi->filename;
 | 
			
		||||
        if (!Qps::show_file_path)
 | 
			
		||||
        {
 | 
			
		||||
            int i = s.lastIndexOf('/');
 | 
			
		||||
            if (i >= 0)
 | 
			
		||||
                s.remove(0, i + 1);
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Maps::refresh_window()
 | 
			
		||||
{
 | 
			
		||||
    if (!procinfo())
 | 
			
		||||
        return;
 | 
			
		||||
    int rows = procinfo()->maps.size();
 | 
			
		||||
    ////resetWidths();
 | 
			
		||||
    setNumRows(rows);
 | 
			
		||||
    setNumCols(MAPSFIELDS);
 | 
			
		||||
    repaintAll();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Maps::refresh()
 | 
			
		||||
{
 | 
			
		||||
    if (refresh_maps())
 | 
			
		||||
        refresh_window();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Maps::refresh_maps() { return procinfo()->read_maps(); }
 | 
			
		||||
 | 
			
		||||
TableField Files::fields[] = {
 | 
			
		||||
    {"Fd", 5, 8, Qt::AlignRight, "File descriptor"},
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    {"Mode", 3, 8, Qt::AlignLeft, "Open mode"},
 | 
			
		||||
#endif
 | 
			
		||||
    {"Name", -1, 8, Qt::AlignLeft, "File name (if available)"}};
 | 
			
		||||
 | 
			
		||||
Files::Files(QWidget *parent) : SimpleTable(parent, FILEFIELDS, fields)
 | 
			
		||||
{
 | 
			
		||||
    // compute total width = window width
 | 
			
		||||
    refresh_window();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Files::~Files() {}
 | 
			
		||||
 | 
			
		||||
void Files::refresh()
 | 
			
		||||
{
 | 
			
		||||
    printf("Files::refresh()\n");
 | 
			
		||||
    // return true if fds could be read successfully, false otherwise
 | 
			
		||||
    if (procinfo()->read_fds())
 | 
			
		||||
        refresh_window();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Files::refresh_fds() { return false; }
 | 
			
		||||
 | 
			
		||||
void Files::refresh_window()
 | 
			
		||||
{
 | 
			
		||||
    Procinfo *p = procinfo();
 | 
			
		||||
    if (!p)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    // if(p->fd_files==NULL) printf("qps :dddds\n");
 | 
			
		||||
 | 
			
		||||
    int rows = p->fd_files.size();
 | 
			
		||||
 | 
			
		||||
    resetWidths();
 | 
			
		||||
    // printf("size=%d\n",rows);
 | 
			
		||||
    setNumRows(rows);
 | 
			
		||||
    setNumCols(FILEFIELDS);
 | 
			
		||||
    repaintAll(); // useless ?
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString Files::text(int row, int col)
 | 
			
		||||
{
 | 
			
		||||
    Procinfo *p = procinfo(); // alot!!
 | 
			
		||||
    if (p == 0)
 | 
			
		||||
        return "zero";
 | 
			
		||||
    //	printf("p=%x px=%x\n",p,px);
 | 
			
		||||
    if (p->fd_files.size() == 0)
 | 
			
		||||
    { //???????????///////
 | 
			
		||||
        refresh_fds();
 | 
			
		||||
        if (p->fd_files.size() == 0)
 | 
			
		||||
            return "";
 | 
			
		||||
    }
 | 
			
		||||
    if (row >= p->fd_files.size())
 | 
			
		||||
        return "";
 | 
			
		||||
 | 
			
		||||
    Fileinfo *fi = p->fd_files[row];
 | 
			
		||||
    QString s;
 | 
			
		||||
    switch (col)
 | 
			
		||||
    {
 | 
			
		||||
    case FILEDESC:
 | 
			
		||||
        s.setNum(fi->fd);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    case FILEMODE:
 | 
			
		||||
        if (fi->mode & OPEN_READ)
 | 
			
		||||
            s.append("R");
 | 
			
		||||
        if (fi->mode & OPEN_WRITE)
 | 
			
		||||
            s.append("W");
 | 
			
		||||
        break;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    case FILENAME:
 | 
			
		||||
        s = fi->filename;
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TableField Environ::fields[] = {
 | 
			
		||||
    {"Variable", -1, 8, Qt::AlignLeft, "Variable name"},
 | 
			
		||||
    {"Value", -1, 8, Qt::AlignLeft, "Variable value"}};
 | 
			
		||||
 | 
			
		||||
Environ *Environ::static_env = 0;
 | 
			
		||||
Environ::Environ(QWidget *parent)
 | 
			
		||||
    : SimpleTable(parent, ENVFIELDS, fields), rev(false)
 | 
			
		||||
{
 | 
			
		||||
    connect(this, SIGNAL(titleClicked(int)), SLOT(sort_change(int)));
 | 
			
		||||
    refresh();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Environ::~Environ() {}
 | 
			
		||||
 | 
			
		||||
QString Environ::text(int row, int col)
 | 
			
		||||
{
 | 
			
		||||
    Procinfo *p = procinfo(); // if dead process then
 | 
			
		||||
    if (row >= p->environ.size())
 | 
			
		||||
        printf("size dddd=row=%d\n", row);
 | 
			
		||||
    NameValue nv = p->environ[row]; // Segfault !!
 | 
			
		||||
    return (col == ENVNAME) ? nv.name : nv.value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Environ::refresh_window()
 | 
			
		||||
{
 | 
			
		||||
    if (!procinfo())
 | 
			
		||||
        return;
 | 
			
		||||
    /// resetWidths();
 | 
			
		||||
    int rows = procinfo()->environ.size();
 | 
			
		||||
    setNumRows(rows);
 | 
			
		||||
    setNumCols(ENVFIELDS);
 | 
			
		||||
    repaintAll();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Environ::refresh()
 | 
			
		||||
{
 | 
			
		||||
    if (procinfo()->read_environ())
 | 
			
		||||
    {
 | 
			
		||||
        // sort();
 | 
			
		||||
        refresh_window();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Environ::sort_change(int col)
 | 
			
		||||
{
 | 
			
		||||
    Procinfo *p = procinfo();
 | 
			
		||||
    /*
 | 
			
		||||
    if(!p->environ) {
 | 
			
		||||
            refresh_environ();
 | 
			
		||||
            if(!p->environ)
 | 
			
		||||
                    return;
 | 
			
		||||
    }*/
 | 
			
		||||
    ////rev = (col == sortedCol()) ? !rev : false;
 | 
			
		||||
    setSortedCol(col);
 | 
			
		||||
    sort();
 | 
			
		||||
    refresh_window();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// sort table according to current settings
 | 
			
		||||
void Environ::sort()
 | 
			
		||||
{
 | 
			
		||||
    /////if(sortedCol() >= 0)
 | 
			
		||||
    {
 | 
			
		||||
        static_env = this;
 | 
			
		||||
        //	if(procinfo()->environ==NULL)
 | 
			
		||||
        //		printf("qps : Environ::sort() error ???\n");
 | 
			
		||||
        //	else
 | 
			
		||||
        //	procinfo()->environ.sort(compare);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Environ::compare(const NameValue *a, const NameValue *b)
 | 
			
		||||
{
 | 
			
		||||
    Environ *e = Environ::static_env;
 | 
			
		||||
    int r;
 | 
			
		||||
    /*
 | 
			
		||||
    if(e->sortedCol() == ENVNAME)
 | 
			
		||||
            r = strcmp(a->name, b->name);
 | 
			
		||||
    else
 | 
			
		||||
            r = strcmp(a->value, b->value);  SimpleTable(QWidget *parent,
 | 
			
		||||
    int
 | 
			
		||||
    nfields, TableField *f, int options = 0);
 | 
			
		||||
  */
 | 
			
		||||
    return e->rev ? -r : r;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TableField AllFields::fields[] = {
 | 
			
		||||
    {"Field", -1, 8, Qt::AlignLeft, "Field name"},
 | 
			
		||||
    {"Description", -1, 8, Qt::AlignLeft, "Field description"},
 | 
			
		||||
    {"Value", -1, 8, Qt::AlignLeft, "Field value"}};
 | 
			
		||||
 | 
			
		||||
AllFields::AllFields(QWidget *parent)
 | 
			
		||||
    : SimpleTable(parent, FIELDSFIELDS, fields)
 | 
			
		||||
{
 | 
			
		||||
    refresh();
 | 
			
		||||
    // compute total width = window width
 | 
			
		||||
    int totw = 0;
 | 
			
		||||
    //	for(int i = 0; i < FIELDSFIELDS; i++) totw += actualColWidth(i);
 | 
			
		||||
    resize(totw + 20, 200);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
AllFields::~AllFields() {}
 | 
			
		||||
 | 
			
		||||
// Proc not changed ?
 | 
			
		||||
QString AllFields::text(int row, int col)
 | 
			
		||||
{
 | 
			
		||||
    QString s;
 | 
			
		||||
    // printf("text start r=%d , c=%d\n",row,col);
 | 
			
		||||
    // if( ((Details *)parent())->proc()==NULL)
 | 
			
		||||
    // printf("size=%d\n", ((Details *)parent())->proc()->allcats.size() );
 | 
			
		||||
    // printf("size=%d\n", proc()->allcats.size() );
 | 
			
		||||
 | 
			
		||||
    Category *cat = proc()->categories.values()[row];
 | 
			
		||||
    //	Category *cat = proc()->allcats[row];
 | 
			
		||||
    switch (col)
 | 
			
		||||
    {
 | 
			
		||||
    case FIELDNAME:
 | 
			
		||||
        s = cat->name;
 | 
			
		||||
        break;
 | 
			
		||||
    case FIELDDESC:
 | 
			
		||||
        s = cat->help;
 | 
			
		||||
        break;
 | 
			
		||||
    case FIELDVALUE:
 | 
			
		||||
        s = cat->string(procinfo());
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    // printf("text end\n");
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// parent will be  tbar(TabWidget) !!!
 | 
			
		||||
void AllFields::refresh_window()
 | 
			
		||||
{
 | 
			
		||||
    // printf("refresh_window\n");
 | 
			
		||||
    if (!procinfo())
 | 
			
		||||
        return;
 | 
			
		||||
    setNumRows(proc()->categories.size());
 | 
			
		||||
    setNumCols(FIELDSFIELDS);
 | 
			
		||||
    // DEL resetWidths();
 | 
			
		||||
    // repaint_changed();
 | 
			
		||||
    repaintAll();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AllFields::refresh() { refresh_window(); }
 | 
			
		||||
							
								
								
									
										236
									
								
								src/details.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,236 @@
 | 
			
		||||
// details.h				emacs, this is written in -*-c++-*-
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#ifndef DETAILS_H
 | 
			
		||||
#define DETAILS_H
 | 
			
		||||
 | 
			
		||||
#ifndef USING_PCH
 | 
			
		||||
#include <QTabWidget>
 | 
			
		||||
#include <QFrame>
 | 
			
		||||
#include <QHash>
 | 
			
		||||
#include <QCloseEvent>
 | 
			
		||||
#include <QResizeEvent>
 | 
			
		||||
#include <QLayout>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "proc.h"
 | 
			
		||||
#include "lookup.h"
 | 
			
		||||
 | 
			
		||||
class Details : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    Details(Procinfo *p, Proc *proc);
 | 
			
		||||
    ~Details();
 | 
			
		||||
 | 
			
		||||
    void refresh();
 | 
			
		||||
    void config_change();
 | 
			
		||||
    void process_gone();
 | 
			
		||||
    Procinfo *get_procinfo() { return pi; }
 | 
			
		||||
    Proc *proc() { return pr; }
 | 
			
		||||
    void set_procinfo(Procinfo *p);
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void closed(Details *);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual void resizeEvent(QResizeEvent *);
 | 
			
		||||
    virtual void closeEvent(QCloseEvent *);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    QTabWidget *tbar;
 | 
			
		||||
    Procinfo *pi;
 | 
			
		||||
    Proc *pr;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct TableField
 | 
			
		||||
{
 | 
			
		||||
    const char *name;
 | 
			
		||||
    int width;
 | 
			
		||||
    int gap;
 | 
			
		||||
    int align;
 | 
			
		||||
    const char *tooltip;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// SimpleTable: a HeadedTable with fixed number of columns
 | 
			
		||||
#include "htable.h"
 | 
			
		||||
class SimpleTable : public HeadedTable
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    SimpleTable(QWidget *parent, int nfields, TableField *f, int options = 0);
 | 
			
		||||
    QSize sizeHint() const;
 | 
			
		||||
    virtual void refresh(){};
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual QString title(int col);
 | 
			
		||||
    virtual QString text(int row, int col) = 0;
 | 
			
		||||
    virtual int colWidth(int col);
 | 
			
		||||
    virtual int alignment(int col);
 | 
			
		||||
    virtual int leftGap(int col);
 | 
			
		||||
    virtual QString tipText(int col);
 | 
			
		||||
    //   Procinfo *procinfo() { return ((Details
 | 
			
		||||
    //   *)parentWidget())->procinfo(); }
 | 
			
		||||
    Procinfo *procinfo() { return detail->get_procinfo(); }
 | 
			
		||||
    Proc *proc() { return detail->proc(); }
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    const TableField *fields;
 | 
			
		||||
    Details *detail;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Sockets : public SimpleTable
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    Sockets(QWidget *parent);
 | 
			
		||||
    ~Sockets();
 | 
			
		||||
 | 
			
		||||
    void refresh();
 | 
			
		||||
    void refresh_window();
 | 
			
		||||
    bool refresh_sockets();
 | 
			
		||||
    const char *servname(unsigned port);
 | 
			
		||||
    QString ipAddr(unsigned addr);
 | 
			
		||||
    QString hostname(unsigned addr);
 | 
			
		||||
    void config_change();
 | 
			
		||||
 | 
			
		||||
  public slots:
 | 
			
		||||
    void update_hostname(unsigned addr);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual QString text(int row, int col);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    enum
 | 
			
		||||
    {
 | 
			
		||||
        FD,
 | 
			
		||||
        PROTO,
 | 
			
		||||
        RECVQ,
 | 
			
		||||
        SENDQ,
 | 
			
		||||
        LOCALADDR,
 | 
			
		||||
        LOCALPORT,
 | 
			
		||||
        REMOTEADDR,
 | 
			
		||||
        REMOTEPORT,
 | 
			
		||||
        STATE,
 | 
			
		||||
        SOCKFIELDS
 | 
			
		||||
    };
 | 
			
		||||
    static TableField fields[SOCKFIELDS];
 | 
			
		||||
 | 
			
		||||
    bool doing_lookup; // if table painted with host lookup
 | 
			
		||||
 | 
			
		||||
    static Lookup *lookup;
 | 
			
		||||
    static bool have_services; // true if we have tried reading services
 | 
			
		||||
    static QHash<int, char *> servdict;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Maps : public SimpleTable
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Maps(QWidget *parent);
 | 
			
		||||
    ~Maps();
 | 
			
		||||
 | 
			
		||||
    void refresh();
 | 
			
		||||
    void refresh_window();
 | 
			
		||||
    bool refresh_maps();
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual QString text(int row, int col);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    enum
 | 
			
		||||
    {
 | 
			
		||||
        ADDRESS,
 | 
			
		||||
        SIZE,
 | 
			
		||||
        PERM,
 | 
			
		||||
        OFFSET,
 | 
			
		||||
        DEVICE,
 | 
			
		||||
        INODE,
 | 
			
		||||
        FILENAME,
 | 
			
		||||
        MAPSFIELDS
 | 
			
		||||
    };
 | 
			
		||||
    static TableField fields[MAPSFIELDS];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Files : public SimpleTable
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Files(QWidget *parent);
 | 
			
		||||
    ~Files();
 | 
			
		||||
 | 
			
		||||
    void refresh();
 | 
			
		||||
    void refresh_window();
 | 
			
		||||
    bool refresh_fds();
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual QString text(int row, int col);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    enum
 | 
			
		||||
    {
 | 
			
		||||
        FILEDESC,
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
        FILEMODE,
 | 
			
		||||
#endif
 | 
			
		||||
        FILENAME,
 | 
			
		||||
        FILEFIELDS
 | 
			
		||||
    };
 | 
			
		||||
    static TableField fields[FILEFIELDS];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Environ : public SimpleTable
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    Environ(QWidget *parent);
 | 
			
		||||
    ~Environ();
 | 
			
		||||
 | 
			
		||||
    void refresh();
 | 
			
		||||
    void refresh_window();
 | 
			
		||||
 | 
			
		||||
  public slots:
 | 
			
		||||
    void sort_change(int);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual QString text(int row, int col);
 | 
			
		||||
 | 
			
		||||
    void sort();
 | 
			
		||||
    static int compare(const NameValue *a, const NameValue *b);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    enum
 | 
			
		||||
    {
 | 
			
		||||
        ENVNAME,
 | 
			
		||||
        ENVVALUE,
 | 
			
		||||
        ENVFIELDS
 | 
			
		||||
    };
 | 
			
		||||
    bool rev;                   // sorting reversed
 | 
			
		||||
    static Environ *static_env; // for sorting, must have static pointer
 | 
			
		||||
    static TableField fields[ENVFIELDS];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class AllFields : public SimpleTable
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    AllFields(QWidget *parent);
 | 
			
		||||
    ~AllFields();
 | 
			
		||||
 | 
			
		||||
    void refresh();
 | 
			
		||||
    void refresh_window();
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual QString text(int row, int col);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    enum
 | 
			
		||||
    {
 | 
			
		||||
        FIELDNAME,
 | 
			
		||||
        FIELDDESC,
 | 
			
		||||
        FIELDVALUE,
 | 
			
		||||
        FIELDSFIELDS
 | 
			
		||||
    };
 | 
			
		||||
    static TableField fields[FIELDSFIELDS];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // DETAILS_H
 | 
			
		||||
							
								
								
									
										397
									
								
								src/dialogs.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,397 @@
 | 
			
		||||
// dialogs.C
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#include "qps.h"
 | 
			
		||||
#include "dialogs.h"
 | 
			
		||||
#include <sched.h>
 | 
			
		||||
 | 
			
		||||
extern Qps *qps;
 | 
			
		||||
 | 
			
		||||
// center window a with respect to main application window
 | 
			
		||||
static void center_window(QWidget *a)
 | 
			
		||||
{
 | 
			
		||||
    QWidget *b = QApplication::activeWindow();
 | 
			
		||||
    // QWidget *b = qApp->mainWidget();
 | 
			
		||||
    a->move(b->x() + (b->width() - a->width()) / 2,
 | 
			
		||||
            b->y() + (b->height() - a->height()) / 2);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void move_mouse_window(QWidget *a)
 | 
			
		||||
{
 | 
			
		||||
    // QWidget *b = qApp->mainWidget();
 | 
			
		||||
    QWidget *b = QApplication::activeWindow();
 | 
			
		||||
    a->move(b->x() + (b->width() - a->width()) / 2,
 | 
			
		||||
            b->y() + (b->height() - a->height()) / 2);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void fix_size(QWidget *w) { w->setFixedSize(w->sizeHint()); }
 | 
			
		||||
 | 
			
		||||
// Modal dialog
 | 
			
		||||
IntervalDialog::IntervalDialog(const char *ed_txt, bool enabled) : QDialog()
 | 
			
		||||
{
 | 
			
		||||
    setWindowTitle("Change Update Period");
 | 
			
		||||
    QVBoxLayout *tl = new QVBoxLayout;
 | 
			
		||||
    QHBoxLayout *h1 = new QHBoxLayout;
 | 
			
		||||
    setLayout(tl);
 | 
			
		||||
    tl->addLayout(h1);
 | 
			
		||||
 | 
			
		||||
    QLabel *label1 = new QLabel("New Update Period", this);
 | 
			
		||||
    h1->addWidget(label1);
 | 
			
		||||
    h1->addStretch(1);
 | 
			
		||||
 | 
			
		||||
    lined = new QLineEdit(this);
 | 
			
		||||
    QFont f = font();
 | 
			
		||||
    lined->setMaxLength(7);
 | 
			
		||||
    lined->setText(ed_txt);
 | 
			
		||||
    if (enabled)
 | 
			
		||||
    {
 | 
			
		||||
        lined->selectAll();
 | 
			
		||||
        lined->setFocus();
 | 
			
		||||
    }
 | 
			
		||||
    // lined->setEnabled(enabled);
 | 
			
		||||
    lined->setEnabled(true);
 | 
			
		||||
    fix_size(lined);
 | 
			
		||||
    lined->setFixedWidth(64);
 | 
			
		||||
    h1->addWidget(lined);
 | 
			
		||||
 | 
			
		||||
    label = new QLabel(this);
 | 
			
		||||
    label->setFrameStyle(QFrame::Panel);
 | 
			
		||||
    label->setFrameShadow(QFrame::Sunken);
 | 
			
		||||
    label->setText("");
 | 
			
		||||
    label->setAlignment(Qt::AlignRight);
 | 
			
		||||
    tl->addWidget(label);
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
  toggle = new CrossBox("Dynamic Update (under devel)", this);
 | 
			
		||||
  fix_size(toggle);
 | 
			
		||||
  toggle->setChecked(enabled);
 | 
			
		||||
  //toggle->setChecked(false);
 | 
			
		||||
  toggle->setChecked(true);
 | 
			
		||||
  toggle->setEnabled(false);
 | 
			
		||||
  tl->addWidget(toggle);
 | 
			
		||||
    */
 | 
			
		||||
    QHBoxLayout *h2 = new QHBoxLayout;
 | 
			
		||||
    // h2->addStretch(1);
 | 
			
		||||
    cancel = new QPushButton("Cancel", this);
 | 
			
		||||
    h2->addWidget(cancel);
 | 
			
		||||
    ok = new QPushButton("OK", this);
 | 
			
		||||
    // ok->setFocus();
 | 
			
		||||
    h2->addWidget(ok);
 | 
			
		||||
    tl->addLayout(h2);
 | 
			
		||||
 | 
			
		||||
    connect(ok, SIGNAL(clicked()), SLOT(done_dialog()));
 | 
			
		||||
    connect(cancel, SIGNAL(clicked()), SLOT(reject()));
 | 
			
		||||
    connect(lined, SIGNAL(returnPressed()), SLOT(done_dialog()));
 | 
			
		||||
    connect(lined, SIGNAL(textChanged(const QString &)),
 | 
			
		||||
            SLOT(event_label_changed()));
 | 
			
		||||
    //    connect(toggle, SIGNAL(toggled(bool)), lined,
 | 
			
		||||
    //    SLOT(setEnabled(bool)));
 | 
			
		||||
 | 
			
		||||
    ok->setDefault(true);
 | 
			
		||||
 | 
			
		||||
    ///   Q3Accel *acc = new Q3Accel(this);
 | 
			
		||||
    /// acc->connectItem(acc->insertItem(Qt::Key_Escape), this,
 | 
			
		||||
    /// SLOT(reject()));
 | 
			
		||||
    //  tl->setSizeConstraint(QLayout::SetFixedSize);
 | 
			
		||||
    //    center_window(this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void IntervalDialog::event_label_changed()
 | 
			
		||||
{
 | 
			
		||||
    QString txt;
 | 
			
		||||
    int i = 0;
 | 
			
		||||
    ed_result = lined->text();
 | 
			
		||||
    ed_result = ed_result.simplified();
 | 
			
		||||
 | 
			
		||||
    // if(toggle->isChecked())
 | 
			
		||||
 | 
			
		||||
    QString s = ed_result;
 | 
			
		||||
    if (s.length() == 0)
 | 
			
		||||
    {
 | 
			
		||||
        label->setText("No UPDATE");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    while ((s[i] >= '0' && s[i] <= '9') || s[i] == '.')
 | 
			
		||||
        i++;
 | 
			
		||||
 | 
			
		||||
    float period = (i > 0) ? s.left(i).toFloat() : -1;
 | 
			
		||||
 | 
			
		||||
    s = s.mid(i, 3).simplified();
 | 
			
		||||
    if (s.length() == 0 || s == "s")
 | 
			
		||||
        period *= 1000;
 | 
			
		||||
    else if (s == "min")
 | 
			
		||||
        period *= 60000;
 | 
			
		||||
    else if (s != "ms")
 | 
			
		||||
        period = -1;
 | 
			
		||||
    if (period <= 0)
 | 
			
		||||
    {
 | 
			
		||||
        label->setText("Invalid value");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    txt.sprintf("%d ms", (int)period);
 | 
			
		||||
    label->setText(txt);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void IntervalDialog::done_dialog()
 | 
			
		||||
{
 | 
			
		||||
    int i = 0;
 | 
			
		||||
 | 
			
		||||
    ed_result = lined->text();
 | 
			
		||||
    ed_result = ed_result.simplified();
 | 
			
		||||
 | 
			
		||||
    // if(toggle->isChecked())
 | 
			
		||||
    QString s = ed_result;
 | 
			
		||||
    while ((s[i] >= '0' && s[i] <= '9') || s[i] == '.')
 | 
			
		||||
        i++;
 | 
			
		||||
 | 
			
		||||
    float period = (i > 0) ? s.left(i).toFloat() : -1;
 | 
			
		||||
 | 
			
		||||
    s = s.mid(i, 3).simplified();
 | 
			
		||||
    if (s.length() == 0 || s == "s")
 | 
			
		||||
        period *= 1000;
 | 
			
		||||
    else if (s == "min")
 | 
			
		||||
        period *= 60000;
 | 
			
		||||
    else if (s != "ms")
 | 
			
		||||
        period = -1;
 | 
			
		||||
    if (period < 0)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    qps->set_update_period((int)period);
 | 
			
		||||
    qps->update_timer();
 | 
			
		||||
 | 
			
		||||
    accept();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SliderDialog::SliderDialog(int defaultval, int minval, int maxval) : QDialog()
 | 
			
		||||
{
 | 
			
		||||
    setWindowTitle("Renice Process");
 | 
			
		||||
    QVBoxLayout *tl = new QVBoxLayout;
 | 
			
		||||
    QHBoxLayout *h1 = new QHBoxLayout;
 | 
			
		||||
    setLayout(tl);
 | 
			
		||||
    tl->addLayout(h1);
 | 
			
		||||
 | 
			
		||||
    label = new QLabel("New nice value:", this);
 | 
			
		||||
    h1->addWidget(label);
 | 
			
		||||
 | 
			
		||||
    h1->addStretch(1);
 | 
			
		||||
 | 
			
		||||
    lined = new QLineEdit(this);
 | 
			
		||||
    lined->setMaxLength(3);
 | 
			
		||||
    lined->setText(QString::number(defaultval));
 | 
			
		||||
    lined->setFocus();
 | 
			
		||||
    lined->setFixedWidth(64);
 | 
			
		||||
    h1->addWidget(lined);
 | 
			
		||||
 | 
			
		||||
    slider = new QSlider(Qt::Horizontal, this);
 | 
			
		||||
    slider->setMaximum(maxval);
 | 
			
		||||
    slider->setMinimum(minval);
 | 
			
		||||
    slider->setTickInterval(10);
 | 
			
		||||
    slider->setTickPosition(QSlider::TicksBelow);
 | 
			
		||||
    slider->setValue(defaultval);
 | 
			
		||||
    tl->addWidget(slider);
 | 
			
		||||
 | 
			
		||||
    QHBoxLayout *h2 = new QHBoxLayout;
 | 
			
		||||
    tl->addLayout(h2);
 | 
			
		||||
 | 
			
		||||
    // decorate slider
 | 
			
		||||
    QLabel *left = new QLabel(this);
 | 
			
		||||
    QLabel *mid = new QLabel(this);
 | 
			
		||||
    QLabel *right = new QLabel(this);
 | 
			
		||||
    left->setNum(minval);
 | 
			
		||||
    mid->setNum((minval + maxval) / 2);
 | 
			
		||||
    right->setNum(maxval);
 | 
			
		||||
    h2->addWidget(left);
 | 
			
		||||
    h2->addStretch(1);
 | 
			
		||||
    h2->addWidget(mid);
 | 
			
		||||
    h2->addStretch(1);
 | 
			
		||||
    h2->addWidget(right);
 | 
			
		||||
 | 
			
		||||
    QHBoxLayout *h3 = new QHBoxLayout;
 | 
			
		||||
    tl->addLayout(h3);
 | 
			
		||||
 | 
			
		||||
    h3->addStretch(1);
 | 
			
		||||
    cancel = new QPushButton("Cancel", this);
 | 
			
		||||
    // fix_size(cancel);
 | 
			
		||||
    h3->addWidget(cancel);
 | 
			
		||||
 | 
			
		||||
    ok = new QPushButton("OK", this);
 | 
			
		||||
    ok->setFixedSize(cancel->sizeHint());
 | 
			
		||||
    h3->addWidget(ok);
 | 
			
		||||
 | 
			
		||||
    connect(ok, SIGNAL(clicked()), SLOT(done_dialog()));
 | 
			
		||||
    ok->setDefault(true);
 | 
			
		||||
    connect(cancel, SIGNAL(clicked()), SLOT(reject()));
 | 
			
		||||
    connect(lined, SIGNAL(returnPressed()), SLOT(done_dialog()));
 | 
			
		||||
    connect(slider, SIGNAL(valueChanged(int)), this, SLOT(slider_change(int)));
 | 
			
		||||
    // Q3Accel *acc = new Q3Accel(this);
 | 
			
		||||
    // acc->connectItem(acc->insertItem(Qt::Key_Escape), this,
 | 
			
		||||
    // SLOT(reject()));
 | 
			
		||||
    // tl->freeze();
 | 
			
		||||
 | 
			
		||||
    center_window(this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SliderDialog::done_dialog()
 | 
			
		||||
{
 | 
			
		||||
    ed_result = lined->text();
 | 
			
		||||
    ed_result = ed_result.simplified();
 | 
			
		||||
    accept();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SliderDialog::slider_change(int val)
 | 
			
		||||
{
 | 
			
		||||
    QString s;
 | 
			
		||||
    s.setNum(val);
 | 
			
		||||
    lined->setText(s);
 | 
			
		||||
    lined->selectAll();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DRAFT CODE,
 | 
			
		||||
PermissionDialog::PermissionDialog(QString msg, QString passwd) : QDialog()
 | 
			
		||||
{
 | 
			
		||||
    setWindowTitle("Permission");
 | 
			
		||||
    QVBoxLayout *vbox = new QVBoxLayout;
 | 
			
		||||
    label = new QLabel(msg, this);
 | 
			
		||||
    vbox->addWidget(label);
 | 
			
		||||
 | 
			
		||||
    setLayout(vbox);
 | 
			
		||||
 | 
			
		||||
    QHBoxLayout *hbox = new QHBoxLayout;
 | 
			
		||||
    vbox->addLayout(hbox);
 | 
			
		||||
    label = new QLabel("root password", this);
 | 
			
		||||
    hbox->addWidget(label);
 | 
			
		||||
    lined = new QLineEdit(this);
 | 
			
		||||
    hbox->addWidget(lined);
 | 
			
		||||
 | 
			
		||||
    hbox = new QHBoxLayout;
 | 
			
		||||
    vbox->addLayout(hbox);
 | 
			
		||||
    QPushButton *cancel = new QPushButton("Cancel", this);
 | 
			
		||||
    hbox->addWidget(cancel);
 | 
			
		||||
 | 
			
		||||
    QPushButton *ok = new QPushButton("OK", this);
 | 
			
		||||
    hbox->addWidget(ok);
 | 
			
		||||
 | 
			
		||||
    connect(ok, SIGNAL(clicked()), SLOT(accept()));
 | 
			
		||||
    connect(cancel, SIGNAL(clicked()), SLOT(reject()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SchedDialog::SchedDialog(int policy, int prio) : QDialog()
 | 
			
		||||
{
 | 
			
		||||
    setWindowTitle("Change scheduling");
 | 
			
		||||
    QVBoxLayout *vl = new QVBoxLayout;
 | 
			
		||||
    setLayout(vl);
 | 
			
		||||
 | 
			
		||||
    bgrp = new QGroupBox("Scheduling Policy", this);
 | 
			
		||||
    vl->addWidget(bgrp); // bgrp->setCheckable(1);
 | 
			
		||||
    rb_other = new QRadioButton("SCHED_OTHER (time-sharing)", bgrp);
 | 
			
		||||
    rb_fifo = new QRadioButton("SCHED_FIFO (real-time)", bgrp);
 | 
			
		||||
    rb_rr = new QRadioButton("SCHED_RR (real-time)", bgrp);
 | 
			
		||||
 | 
			
		||||
    QVBoxLayout *vbox = new QVBoxLayout;
 | 
			
		||||
    vbox->addWidget(rb_other);
 | 
			
		||||
    vbox->addWidget(rb_fifo);
 | 
			
		||||
    vbox->addWidget(rb_rr);
 | 
			
		||||
    bgrp->setLayout(vbox);
 | 
			
		||||
 | 
			
		||||
    connect(rb_other, SIGNAL(clicked(bool)), SLOT(button_clicked(bool)));
 | 
			
		||||
    connect(rb_fifo, SIGNAL(clicked(bool)), SLOT(button_clicked(bool)));
 | 
			
		||||
    connect(rb_rr, SIGNAL(clicked(bool)), SLOT(button_clicked(bool)));
 | 
			
		||||
 | 
			
		||||
    QHBoxLayout *hbox1 = new QHBoxLayout;
 | 
			
		||||
    QPushButton *ok, *cancel;
 | 
			
		||||
    ok = new QPushButton("OK", this);
 | 
			
		||||
    ok->setDefault(true);
 | 
			
		||||
    cancel = new QPushButton("Cancel", this);
 | 
			
		||||
    hbox1->addWidget(ok);
 | 
			
		||||
    hbox1->addWidget(cancel);
 | 
			
		||||
    vl->addLayout(hbox1);
 | 
			
		||||
 | 
			
		||||
    connect(ok, SIGNAL(clicked()), SLOT(done_dialog()));
 | 
			
		||||
    connect(cancel, SIGNAL(clicked()), SLOT(reject()));
 | 
			
		||||
 | 
			
		||||
    int active = 0;
 | 
			
		||||
    QRadioButton *rb;
 | 
			
		||||
    switch (policy)
 | 
			
		||||
    {
 | 
			
		||||
    case SCHED_OTHER:
 | 
			
		||||
        active = 0;
 | 
			
		||||
        rb = rb_other;
 | 
			
		||||
        break;
 | 
			
		||||
    case SCHED_FIFO:
 | 
			
		||||
        active = 1;
 | 
			
		||||
        rb = rb_fifo;
 | 
			
		||||
        break;
 | 
			
		||||
    case SCHED_RR:
 | 
			
		||||
        active = 2;
 | 
			
		||||
        rb = rb_rr;
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    rb->setChecked(true);
 | 
			
		||||
    out_policy = policy;
 | 
			
		||||
    out_prio = prio;
 | 
			
		||||
 | 
			
		||||
    QHBoxLayout *hbox = new QHBoxLayout;
 | 
			
		||||
    lbl = new QLabel("Priority (1-99):", this);
 | 
			
		||||
    lined = new QLineEdit(this);
 | 
			
		||||
    hbox->addWidget(lbl);
 | 
			
		||||
    hbox->addWidget(lined);
 | 
			
		||||
    vbox->addLayout(hbox);
 | 
			
		||||
    QFont f = font();
 | 
			
		||||
    f.setBold(false);
 | 
			
		||||
    lined->setFont(f);
 | 
			
		||||
    lined->resize(60, lined->sizeHint().height());
 | 
			
		||||
    lined->setMaxLength(4);
 | 
			
		||||
    QString s;
 | 
			
		||||
    s.setNum(prio);
 | 
			
		||||
    lined->setText(s);
 | 
			
		||||
    button_clicked(active);
 | 
			
		||||
 | 
			
		||||
    // make sure return and escape work as accelerators
 | 
			
		||||
    connect(lined, SIGNAL(returnPressed()), SLOT(done_dialog()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SchedDialog::done_dialog()
 | 
			
		||||
{
 | 
			
		||||
    if (rb_rr->isChecked())
 | 
			
		||||
        out_policy = SCHED_RR;
 | 
			
		||||
    else if (rb_fifo->isChecked())
 | 
			
		||||
        out_policy = SCHED_FIFO;
 | 
			
		||||
    else
 | 
			
		||||
        out_policy = SCHED_OTHER;
 | 
			
		||||
    QString s(lined->text());
 | 
			
		||||
    bool ok;
 | 
			
		||||
    out_prio = s.toInt(&ok);
 | 
			
		||||
    if (out_policy != SCHED_OTHER && (!ok || out_prio < 1 || out_prio > 99))
 | 
			
		||||
    {
 | 
			
		||||
        QMessageBox::warning(this, "Invalid Input",
 | 
			
		||||
                             "The priority must be in the range 1..99");
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
        accept();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SchedDialog::button_clicked(bool val)
 | 
			
		||||
{
 | 
			
		||||
    //	printf("SchedDialog::checked()\n");
 | 
			
		||||
    if (rb_other->isChecked())
 | 
			
		||||
    {
 | 
			
		||||
        lbl->setEnabled(false);
 | 
			
		||||
        lined->setEnabled(false);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        QString s(lined->text());
 | 
			
		||||
        bool ok;
 | 
			
		||||
        int n = s.toInt(&ok);
 | 
			
		||||
        if (ok && n == 0)
 | 
			
		||||
            lined->setText("1");
 | 
			
		||||
        lbl->setEnabled(true);
 | 
			
		||||
        lined->setEnabled(true);
 | 
			
		||||
        lined->setFocus();
 | 
			
		||||
        lined->selectAll();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										105
									
								
								src/dialogs.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,105 @@
 | 
			
		||||
// dialogs.h			emacs, this is a -*-c++-*- file
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
// misc. handy dialogs for use everywhere
 | 
			
		||||
 | 
			
		||||
#ifndef DIALOGS_H
 | 
			
		||||
#define DIALOGS_H
 | 
			
		||||
 | 
			
		||||
#ifndef USING_PCH
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
#include <QSlider>
 | 
			
		||||
#include <QGroupBox>
 | 
			
		||||
#include <QLineEdit>
 | 
			
		||||
#include <QPixmap>
 | 
			
		||||
 | 
			
		||||
#include <QMessageBox>
 | 
			
		||||
#include <QApplication>
 | 
			
		||||
#include <QHBoxLayout>
 | 
			
		||||
#include <QVBoxLayout>
 | 
			
		||||
#include <QLabel>
 | 
			
		||||
#include <QFrame>
 | 
			
		||||
#include <QPushButton>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "misc.h"
 | 
			
		||||
 | 
			
		||||
class IntervalDialog : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    IntervalDialog(const char *ed_txt, bool toggle_state);
 | 
			
		||||
 | 
			
		||||
  protected slots:
 | 
			
		||||
    void done_dialog();
 | 
			
		||||
    void event_label_changed();
 | 
			
		||||
 | 
			
		||||
  public:
 | 
			
		||||
    QString ed_result;
 | 
			
		||||
    CrossBox *toggle;
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    QPushButton *ok, *cancel;
 | 
			
		||||
    QLabel *label;
 | 
			
		||||
    QLineEdit *lined;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class SliderDialog : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    SliderDialog(int defaultval, int minval, int maxval);
 | 
			
		||||
 | 
			
		||||
    QString ed_result;
 | 
			
		||||
 | 
			
		||||
  protected slots:
 | 
			
		||||
    void slider_change(int val);
 | 
			
		||||
    void done_dialog();
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    QPushButton *ok, *cancel;
 | 
			
		||||
    QLabel *label;
 | 
			
		||||
    QLineEdit *lined;
 | 
			
		||||
    QSlider *slider;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class PermissionDialog : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    PermissionDialog(QString msg, QString passwd);
 | 
			
		||||
    QLineEdit *lined;
 | 
			
		||||
    QLabel *label;
 | 
			
		||||
 | 
			
		||||
    // protected slots:
 | 
			
		||||
    //    void slider_change(int val);
 | 
			
		||||
    //  void done_dialog();
 | 
			
		||||
    /*
 | 
			
		||||
    protected:
 | 
			
		||||
        QPushButton *ok, *cancel;
 | 
			
		||||
        QLabel *label;
 | 
			
		||||
        QSlider *slider; */
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class SchedDialog : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    SchedDialog(int policy, int prio);
 | 
			
		||||
 | 
			
		||||
    int out_prio;
 | 
			
		||||
    int out_policy;
 | 
			
		||||
 | 
			
		||||
  protected slots:
 | 
			
		||||
    void done_dialog();
 | 
			
		||||
    void button_clicked(bool);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    QGroupBox *bgrp;
 | 
			
		||||
    QRadioButton *rb_other, *rb_fifo, *rb_rr;
 | 
			
		||||
    QLabel *lbl;
 | 
			
		||||
    QLineEdit *lined;
 | 
			
		||||
};
 | 
			
		||||
#endif // DIALOGS_H
 | 
			
		||||
							
								
								
									
										107
									
								
								src/fieldsel.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,107 @@
 | 
			
		||||
// indent by VIM
 | 
			
		||||
// fieldsel.cpp
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#include "fieldsel.h"
 | 
			
		||||
 | 
			
		||||
FieldSelect::FieldSelect(Procview *pv)
 | 
			
		||||
{
 | 
			
		||||
    nbuttons = pv->categories.size();
 | 
			
		||||
    disp_fields.resize(64);
 | 
			
		||||
    procview = pv;
 | 
			
		||||
 | 
			
		||||
    int half = (nbuttons + 1) / 2;
 | 
			
		||||
    updating = false;
 | 
			
		||||
 | 
			
		||||
    setWindowTitle("Select Custom Fields ");
 | 
			
		||||
    QBoxLayout *v_layout = new QVBoxLayout;
 | 
			
		||||
    setLayout(v_layout);
 | 
			
		||||
 | 
			
		||||
    QGridLayout *grid = new QGridLayout;
 | 
			
		||||
    grid->setSpacing(0);
 | 
			
		||||
    grid->setColumnMinimumWidth(2, 17);
 | 
			
		||||
    v_layout->addLayout(grid);
 | 
			
		||||
 | 
			
		||||
    buts = new QCheckBox *[nbuttons];
 | 
			
		||||
 | 
			
		||||
    QList<int> keys = pv->categories.keys();
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < nbuttons; i++)
 | 
			
		||||
    {
 | 
			
		||||
        Category *cat = pv->categories[keys.takeFirst()]; // fieldlist
 | 
			
		||||
 | 
			
		||||
        QCheckBox *but = new QCheckBox(cat->name, this);
 | 
			
		||||
        QLabel *desc = new QLabel(cat->help, this);
 | 
			
		||||
        if (i < half)
 | 
			
		||||
        {
 | 
			
		||||
            grid->addWidget(but, i, 0);
 | 
			
		||||
            grid->addWidget(desc, i, 1);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            grid->addWidget(but, i - half, 3);
 | 
			
		||||
            grid->addWidget(desc, i - half, 4);
 | 
			
		||||
        }
 | 
			
		||||
        buts[i] = but;
 | 
			
		||||
        connect(but, SIGNAL(toggled(bool)), this, SLOT(field_toggled(bool)));
 | 
			
		||||
    }
 | 
			
		||||
    update_boxes();
 | 
			
		||||
 | 
			
		||||
    QPushButton *closebut = new QPushButton("Close", this);
 | 
			
		||||
    connect(closebut, SIGNAL(clicked()), SLOT(closed()));
 | 
			
		||||
    closebut->setFocus();
 | 
			
		||||
 | 
			
		||||
    v_layout->addWidget(closebut);
 | 
			
		||||
    //	v_layout->freeze(); ///!!!
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CALLBACK : one of the fields was toggled (we don't know which one yet)
 | 
			
		||||
void FieldSelect::field_toggled(bool)
 | 
			
		||||
{
 | 
			
		||||
    if (updating)
 | 
			
		||||
        return;
 | 
			
		||||
    set_disp_fields();
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < nbuttons; i++)
 | 
			
		||||
    {
 | 
			
		||||
        Category *cat = procview->cat_by_name(buts[i]->text().toLatin1());
 | 
			
		||||
 | 
			
		||||
        if (buts[i]->isChecked() != disp_fields.testBit(cat->id))
 | 
			
		||||
        {
 | 
			
		||||
            if (buts[i]->isChecked())
 | 
			
		||||
                emit added_field(cat->id); // send cat_index
 | 
			
		||||
            else
 | 
			
		||||
                emit removed_field(cat->id);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FieldSelect::closed() { hide(); }
 | 
			
		||||
 | 
			
		||||
void FieldSelect::closeEvent(QCloseEvent *) { closed(); }
 | 
			
		||||
 | 
			
		||||
void FieldSelect::set_disp_fields()
 | 
			
		||||
{
 | 
			
		||||
    disp_fields.fill(false);
 | 
			
		||||
    int n = procview->cats.size();
 | 
			
		||||
    for (int i = 0; i < n; i++)
 | 
			
		||||
        disp_fields.setBit(procview->cats[i]->id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FieldSelect::showEvent(QShowEvent *) { update_boxes(); }
 | 
			
		||||
 | 
			
		||||
// init check button ?
 | 
			
		||||
void FieldSelect::update_boxes()
 | 
			
		||||
{
 | 
			
		||||
    set_disp_fields();
 | 
			
		||||
 | 
			
		||||
    updating = true;
 | 
			
		||||
    for (int i = 0; i < nbuttons; i++)
 | 
			
		||||
    {
 | 
			
		||||
        Category *cat = procview->cat_by_name(buts[i]->text().toLatin1());
 | 
			
		||||
        buts[i]->setChecked(disp_fields.testBit(cat->id));
 | 
			
		||||
    }
 | 
			
		||||
    updating = false;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										49
									
								
								src/fieldsel.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,49 @@
 | 
			
		||||
// fieldsel.h				emacs, this is written in -*-c++-*-
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#ifndef FIELDSEL_H
 | 
			
		||||
#define FIELDSEL_H
 | 
			
		||||
 | 
			
		||||
#include <QBitArray>
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
#include <QCheckBox>
 | 
			
		||||
 | 
			
		||||
#include <QLabel>
 | 
			
		||||
#include <QPushButton>
 | 
			
		||||
#include <QGridLayout>
 | 
			
		||||
#include <QVBoxLayout>
 | 
			
		||||
#include <QCloseEvent>
 | 
			
		||||
 | 
			
		||||
#include "proc.h"
 | 
			
		||||
 | 
			
		||||
class FieldSelect : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    FieldSelect(Procview *pv);
 | 
			
		||||
 | 
			
		||||
    void update_boxes();
 | 
			
		||||
 | 
			
		||||
  public slots:
 | 
			
		||||
    void field_toggled(bool);
 | 
			
		||||
    void closed();
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void added_field(int);
 | 
			
		||||
    void removed_field(int);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    QCheckBox **buts;
 | 
			
		||||
    int nbuttons;
 | 
			
		||||
    QBitArray disp_fields;
 | 
			
		||||
    bool updating;
 | 
			
		||||
    Procview *procview;
 | 
			
		||||
 | 
			
		||||
    void set_disp_fields();
 | 
			
		||||
    void closeEvent(QCloseEvent *);
 | 
			
		||||
    virtual void showEvent(QShowEvent *);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // FIELDSEL_H
 | 
			
		||||
							
								
								
									
										19
									
								
								src/global.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,19 @@
 | 
			
		||||
#ifndef GLOBAL_H
 | 
			
		||||
#define GLOBAL_H
 | 
			
		||||
 | 
			
		||||
#include "qps.h"
 | 
			
		||||
#include "misc.h"
 | 
			
		||||
 | 
			
		||||
extern QList<Command *> commands;
 | 
			
		||||
extern ControlBar *controlbar;
 | 
			
		||||
extern int default_font_height;
 | 
			
		||||
extern bool flag_show_thread;
 | 
			
		||||
extern int flag_thread_ok;
 | 
			
		||||
extern bool previous_flag_show_thread;
 | 
			
		||||
extern int num_opened_files;
 | 
			
		||||
 | 
			
		||||
extern Qps *qps;
 | 
			
		||||
extern SearchBox *search_box;
 | 
			
		||||
extern TFrame *infobox;
 | 
			
		||||
 | 
			
		||||
#endif // GLOBAL_H
 | 
			
		||||
							
								
								
									
										1269
									
								
								src/htable.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										362
									
								
								src/htable.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,362 @@
 | 
			
		||||
// htable.h				emacs, this is written in -*-c++-*-
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdeg?rd, 1997-1999
 | 
			
		||||
 | 
			
		||||
// This file defines the HeadedTable class.
 | 
			
		||||
// A HeadedTable is a QTableView with one line of headers over each column.
 | 
			
		||||
 | 
			
		||||
#ifndef HTABLE_H
 | 
			
		||||
#define HTABLE_H
 | 
			
		||||
 | 
			
		||||
#include "qttableview.h"
 | 
			
		||||
 | 
			
		||||
#ifndef USING_PCH
 | 
			
		||||
#include <QHash>
 | 
			
		||||
#include <QToolTip>
 | 
			
		||||
#include <QVBoxLayout>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// table options (bits to be ORed together)
 | 
			
		||||
#define HTBL_ROW_SELECTION 1         // rows are selectable
 | 
			
		||||
#define HTBL_ROW_DOUBLE_CLICK 2      // rows can be double-clicked
 | 
			
		||||
#define HTBL_ROW_CONTEXT_MENU 4      // right button menu on rows
 | 
			
		||||
#define HTBL_HEADING_TOOLTIPS 8      // tooltips on headings
 | 
			
		||||
#define HTBL_HEADING_CONTEXT_MENU 16 // right button menu on headings
 | 
			
		||||
#define HTBL_HEADING_CLICK 32 // able to click on heading (change sort order)
 | 
			
		||||
#define HTBL_REORDER_COLS 64  // able to reorder columns
 | 
			
		||||
 | 
			
		||||
class HeadedTable;
 | 
			
		||||
 | 
			
		||||
class CellAttribute
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    QString text;
 | 
			
		||||
    bool selected;
 | 
			
		||||
    bool sorted;
 | 
			
		||||
    QSize size;
 | 
			
		||||
    QColor backColor; // table share
 | 
			
		||||
    QColor foreColor; // rows share
 | 
			
		||||
    int xpos;         // cols share
 | 
			
		||||
    int ypos;         // rows share
 | 
			
		||||
    int w;            // cols share
 | 
			
		||||
    int depth;        // rows share
 | 
			
		||||
    int folded;       //
 | 
			
		||||
    int lastchild;    //
 | 
			
		||||
    CellAttribute()
 | 
			
		||||
    {
 | 
			
		||||
        text = "";
 | 
			
		||||
        sorted = selected = false;
 | 
			
		||||
        xpos = -1, ypos = -1, w = 0, depth = -1, folded = -1;
 | 
			
		||||
        lastchild = 0;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct TableRow
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    CellAttribute cells[64]; // enough
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TableCache
 | 
			
		||||
{
 | 
			
		||||
    int nrow, ncol;
 | 
			
		||||
    QList<TableRow *> rows;
 | 
			
		||||
 | 
			
		||||
  public:
 | 
			
		||||
    TableCache()
 | 
			
		||||
    {
 | 
			
		||||
        // for(int i=0;i<1;i++) // tmp
 | 
			
		||||
        rows.append(new TableRow);
 | 
			
		||||
        nrow = 0;
 | 
			
		||||
        ncol = 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset() {} // clear cache
 | 
			
		||||
    void setSize(int row, int col);
 | 
			
		||||
    void setRow(int row);
 | 
			
		||||
    void setCol(int col);
 | 
			
		||||
 | 
			
		||||
    CellAttribute *value(int row, int col)
 | 
			
		||||
    {
 | 
			
		||||
        if (row < 0)
 | 
			
		||||
            qFatal("Qps: Error ! TableCache() under size !! row=%d \n", row);
 | 
			
		||||
 | 
			
		||||
        if (row >= rows.size())
 | 
			
		||||
        {
 | 
			
		||||
            row = rows.size();
 | 
			
		||||
            rows.append(new TableRow);
 | 
			
		||||
        }
 | 
			
		||||
        // if(row<0 or row>rows.size())
 | 
			
		||||
        return &(rows[row]->cells[col]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void cutUp(int n)
 | 
			
		||||
    {
 | 
			
		||||
        for (int i = 0; i < n; i++)
 | 
			
		||||
        {
 | 
			
		||||
            rows.append(rows.takeFirst());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    void cutDown(int n)
 | 
			
		||||
    {
 | 
			
		||||
        for (int i = 0; i < n; i++)
 | 
			
		||||
        {
 | 
			
		||||
            TableRow *row = rows.takeLast();
 | 
			
		||||
            rows.prepend(row);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class VPointer : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    VPointer(QWidget *parent);
 | 
			
		||||
    QPixmap *pix;
 | 
			
		||||
    QPixmap *pix_vcross;
 | 
			
		||||
    void setMovable(bool b) { flag_movable = b; }
 | 
			
		||||
    bool flag_movable;
 | 
			
		||||
  protected slots:
 | 
			
		||||
    //		void event_cursor_moved(QMouseEvent *e);
 | 
			
		||||
  protected:
 | 
			
		||||
    // virtual void drawButton 3( QPainter * ) ;
 | 
			
		||||
    virtual void paintEvent(QPaintEvent *event);
 | 
			
		||||
    //	void resizeEvent(QResizeEvent *p);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class FloatingHead : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    FloatingHead(QWidget *parent);
 | 
			
		||||
    QPixmap *pix;
 | 
			
		||||
    void setTitle(QString str, int w, int h);
 | 
			
		||||
    QString title;
 | 
			
		||||
  protected slots:
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual void paintEvent(QPaintEvent *event);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TableHead : public QtTableView
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    TableCache tablecache;
 | 
			
		||||
    TableHead(HeadedTable *parent = 0);
 | 
			
		||||
    virtual bool isCellChanged(int row, int col);
 | 
			
		||||
    virtual void checkProfile();
 | 
			
		||||
 | 
			
		||||
  protected slots:
 | 
			
		||||
    void scrollSideways(int);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual void paintCell(QPainter *p, int row, int col, bool update);
 | 
			
		||||
    virtual int cellWidth(int col);
 | 
			
		||||
    virtual void mousePressEvent(QMouseEvent *e);
 | 
			
		||||
    virtual void mouseReleaseEvent(QMouseEvent *e);
 | 
			
		||||
    virtual void mouseMoveEvent(QMouseEvent *e);
 | 
			
		||||
    virtual void eraseRight(QPainter *, QRect &r);
 | 
			
		||||
 | 
			
		||||
    virtual void dragEnterEvent(QDragEnterEvent *event);
 | 
			
		||||
    virtual void dragLeaveEvent(QDragLeaveEvent *event);
 | 
			
		||||
 | 
			
		||||
    FloatingHead *floatHead;
 | 
			
		||||
 | 
			
		||||
    HeadedTable *htable; // to access parent class
 | 
			
		||||
    QPoint press;
 | 
			
		||||
    int click_col; // physical column clicked in
 | 
			
		||||
    bool dragging;
 | 
			
		||||
    int drag_pos; // previous dragging position
 | 
			
		||||
    int drag_offset;
 | 
			
		||||
signals:
 | 
			
		||||
    void rightClicked(QPoint where, int col);
 | 
			
		||||
    void toolTip(QPoint where, int col);
 | 
			
		||||
 | 
			
		||||
    friend class HeadedTable;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TableBody : public QtTableView
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    TableCache tablecache;
 | 
			
		||||
    TableBody(HeadedTable *parent = 0);
 | 
			
		||||
    void drawGhostCol(int x, int w);
 | 
			
		||||
    // int zerowidth;		// width of the digit 0
 | 
			
		||||
 | 
			
		||||
    virtual bool isCellChanged(int row, int col);
 | 
			
		||||
    virtual void checkProfile();
 | 
			
		||||
  protected slots:
 | 
			
		||||
    // for keyboard accelerators
 | 
			
		||||
    void jumpTop();
 | 
			
		||||
    void jumpBottom();
 | 
			
		||||
    void centerVertically(int row);
 | 
			
		||||
    void showRange(int from, int to);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual void scrollTrigger(int x, int y); // tmp
 | 
			
		||||
 | 
			
		||||
    virtual void paintCell(QPainter *p, int row, int col, bool forced);
 | 
			
		||||
    virtual int cellWidth(int col);
 | 
			
		||||
    void mousePressEvent(QMouseEvent *e);
 | 
			
		||||
    void mouseDoubleClickEvent(QMouseEvent *e);
 | 
			
		||||
    void mouseMoveEvent(QMouseEvent *e);
 | 
			
		||||
    void mouseReleaseEvent(QMouseEvent *);
 | 
			
		||||
    void leaveEvent(QEvent *);
 | 
			
		||||
 | 
			
		||||
    void timerEvent(QTimerEvent *);
 | 
			
		||||
    void updateRow(int row);
 | 
			
		||||
    void dragSelectTo(int row);
 | 
			
		||||
    QColor getXorColor();
 | 
			
		||||
    HeadedTable *htable; // to access parent class
 | 
			
		||||
    int first_drag_row;  // row where drag started
 | 
			
		||||
    int prev_drag_row;   // row where drag was at last event
 | 
			
		||||
    bool autoscrolling;  // true if we are autoscrolling right now
 | 
			
		||||
    enum
 | 
			
		||||
    {
 | 
			
		||||
        UP,
 | 
			
		||||
        DOWN
 | 
			
		||||
    } scrolldir;
 | 
			
		||||
    static const int scroll_delay = 10; // time delay when autoscrolling, in ms
 | 
			
		||||
    bool gadget_click; // whether mouse press was on folding gadget
 | 
			
		||||
  private:
 | 
			
		||||
    QColor background;
 | 
			
		||||
    QColor color_text;
 | 
			
		||||
    friend class HeadedTable;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class HeadedTable : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    HeadedTable(QWidget *parent, int opts = 0);
 | 
			
		||||
    ~HeadedTable();
 | 
			
		||||
    TableHead *header() { return head; } // interface
 | 
			
		||||
 | 
			
		||||
    TableHead *head;
 | 
			
		||||
    TableBody *body;
 | 
			
		||||
 | 
			
		||||
    CellAttribute *attr; // DEL temporarily buffer
 | 
			
		||||
    enum NodeState
 | 
			
		||||
    {
 | 
			
		||||
        Leaf,
 | 
			
		||||
        Open,
 | 
			
		||||
        Closed
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    void repaint_changed();
 | 
			
		||||
    int updateColWidth(int col);
 | 
			
		||||
 | 
			
		||||
    void resetWidths();
 | 
			
		||||
    void resetWidth(int col) { max_widths[col] = -1; } // dont use ?
 | 
			
		||||
    void setProxy(QWidget *w) { body->setFocusProxy(w); }
 | 
			
		||||
    void setSortedCol(int col);
 | 
			
		||||
    int sortedCol() { return sorted_col; }
 | 
			
		||||
    int numRows() { return nrows; }
 | 
			
		||||
    int numCols() { return ncols; }
 | 
			
		||||
    void setNumRows(int rows);
 | 
			
		||||
    void setNumCols(int cols);
 | 
			
		||||
    int clickedColumn() { return head->click_col; }
 | 
			
		||||
    void deleteCol(int col, bool update = true);
 | 
			
		||||
    int leftCell() { return body->leftCell(); };
 | 
			
		||||
    int lastColVisible() { return body->lastColVisible(); };
 | 
			
		||||
    int topCell() { return body->topCell(); };
 | 
			
		||||
    int lastRowVisible() { return body->lastRowVisible(); };
 | 
			
		||||
    void updateCell(int row, int col, bool erase = false);
 | 
			
		||||
    void updateHeading(int col){/* head->updateCell(0, col); */};
 | 
			
		||||
    void setAutoUpdate(bool update)
 | 
			
		||||
    {
 | 
			
		||||
        head->setAutoUpdate(update);
 | 
			
		||||
        body->setAutoUpdate(update);
 | 
			
		||||
    };
 | 
			
		||||
    void centerVertically(int row) { body->centerVertically(row); };
 | 
			
		||||
    void showRange(int from, int to) { body->showRange(from, to); };
 | 
			
		||||
    void repaintColumns(int col0, int col1 = -1);
 | 
			
		||||
    void setTreeMode(bool tm);
 | 
			
		||||
    bool treeMode() { return treemode; };
 | 
			
		||||
    int tableWidth() const
 | 
			
		||||
    {
 | 
			
		||||
        return body->totalWidth() + body->verticalScrollBar()->width();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void selectOnlyOne(int row);
 | 
			
		||||
    int numSelected() { return 0; }
 | 
			
		||||
    void clearAllSelections();
 | 
			
		||||
 | 
			
		||||
    virtual void setSelected(int row, bool sel){};
 | 
			
		||||
    virtual bool isSelected(int row) { return false; }
 | 
			
		||||
    virtual void checkTableModel(){};
 | 
			
		||||
signals:
 | 
			
		||||
    void titleClicked(int col);
 | 
			
		||||
    void selectionChanged();
 | 
			
		||||
    void doubleClicked(int row);
 | 
			
		||||
    void rightClicked(QPoint where);
 | 
			
		||||
    void foldSubTree(int row);
 | 
			
		||||
    void colMoved(int col, int place);
 | 
			
		||||
    void flyOnCell(int row, int col);
 | 
			
		||||
    void flyOnHCell(int col);
 | 
			
		||||
    void outOfCell();
 | 
			
		||||
    void outOfHCell();
 | 
			
		||||
 | 
			
		||||
  public slots:
 | 
			
		||||
    void selectAll();
 | 
			
		||||
    void repaintAll();
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    void fontChange(const QFont &oldFont);
 | 
			
		||||
    // These must be implemented in subclasses
 | 
			
		||||
    virtual QString title(int col) = 0;
 | 
			
		||||
    virtual QString text(int row, int col) = 0;
 | 
			
		||||
    virtual char *total_selectedRow(int col);
 | 
			
		||||
    // colWidth returns width in digit units; negative means variable width.
 | 
			
		||||
    virtual int colWidth(int col) = 0; // head_width
 | 
			
		||||
    virtual int alignment(int col) { return 0; }
 | 
			
		||||
    virtual int sizeHintForColumn(int col) const { return -1; }
 | 
			
		||||
    virtual void paintEvent(QPaintEvent *);
 | 
			
		||||
    virtual void hideEvent(QHideEvent *event);
 | 
			
		||||
    virtual void showEvent(QShowEvent *event);
 | 
			
		||||
 | 
			
		||||
    // may be reimplemented (default exists)
 | 
			
		||||
    virtual void moveCol(int col, int place);
 | 
			
		||||
 | 
			
		||||
    virtual QString tipText(int col);
 | 
			
		||||
    virtual int rowDepth(int row) { return 0; };
 | 
			
		||||
    virtual NodeState folded(int row) { return Leaf; };
 | 
			
		||||
    virtual int parentRow(int row) { return 0; };
 | 
			
		||||
    virtual bool lastChild(int row) { return false; };
 | 
			
		||||
    virtual bool columnMovable(int col) { return true; };
 | 
			
		||||
    // virtual bool modified(int row){return true;};
 | 
			
		||||
    virtual void overpaintCell(QPainter *p, int row, int col, int xpos){};
 | 
			
		||||
 | 
			
		||||
    void resizeEvent(QResizeEvent *);
 | 
			
		||||
 | 
			
		||||
    bool treemode;
 | 
			
		||||
    int treestep; // indentation for each tree level
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    inline int computedWidth(int col);
 | 
			
		||||
    int colOffset(int col);
 | 
			
		||||
    inline int colXPos(int col);
 | 
			
		||||
    void updateCols(int deltacols, int place, bool update);
 | 
			
		||||
 | 
			
		||||
    int alignment_col[64];
 | 
			
		||||
    int headwidth_col[64];
 | 
			
		||||
    int max_widths[64]; // row widths, indexed by columns
 | 
			
		||||
    // Svec<int> widths;		// row widths, indexed by columns
 | 
			
		||||
 | 
			
		||||
    int sorted_col;    // column to emphasize
 | 
			
		||||
    int reversed_sort; // true if sorting backwards
 | 
			
		||||
    int options;
 | 
			
		||||
    int nrows;
 | 
			
		||||
    int ncols;
 | 
			
		||||
 | 
			
		||||
    // text cache is in logical columns (reorder causes no flush)
 | 
			
		||||
    bool folding;     // true if folding gadgets are used
 | 
			
		||||
    bool lines;       // true if tree lines are drawn
 | 
			
		||||
    int gadget_space; // horizontal space for show/hide tree gadget
 | 
			
		||||
 | 
			
		||||
    friend class TableHead;
 | 
			
		||||
    friend class TableBody;
 | 
			
		||||
};
 | 
			
		||||
#endif // HTABLE_H
 | 
			
		||||
							
								
								
									
										210
									
								
								src/htable2.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,210 @@
 | 
			
		||||
 | 
			
		||||
#include "htable2.h"
 | 
			
		||||
HtableModel::HtableModel(QObject *parent) : QAbstractItemModel(parent)
 | 
			
		||||
{
 | 
			
		||||
    htable = (HeadedTable2 *)parent;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QModelIndex HtableModel::index(int row, int column,
 | 
			
		||||
                               const QModelIndex &parent) const
 | 
			
		||||
{
 | 
			
		||||
    // printf("index %d %d\n",row,column);
 | 
			
		||||
    if (row >= 0 and column >= 0 and row < htable->nrows)
 | 
			
		||||
    {
 | 
			
		||||
        // if( column <2)
 | 
			
		||||
        {
 | 
			
		||||
            //	watchCond *item=watchlist[row];
 | 
			
		||||
            return createIndex(row, column, NULL);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return QModelIndex();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Pure Virtual
 | 
			
		||||
QModelIndex HtableModel::parent(const QModelIndex &child) const
 | 
			
		||||
{
 | 
			
		||||
    int row, col;
 | 
			
		||||
    row = child.row();
 | 
			
		||||
    col = child.column();
 | 
			
		||||
    if (row >= 0 and col >= 0 and row < htable->nrows)
 | 
			
		||||
        return createIndex(htable->parentRow(row), col, NULL);
 | 
			
		||||
    return QModelIndex(); // no parent!
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// return chilren count
 | 
			
		||||
int HtableModel::rowCount(const QModelIndex &parent) const
 | 
			
		||||
{
 | 
			
		||||
    return htable->nrows;
 | 
			
		||||
}
 | 
			
		||||
// why segfault?
 | 
			
		||||
int HtableModel::columnCount(const QModelIndex &parent) const
 | 
			
		||||
{
 | 
			
		||||
    return htable->ncols;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
QVariant HtableModel::headerData(int section, Qt::Orientation orientation,
 | 
			
		||||
                                 int role) const
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    //	printf("headerData\n");
 | 
			
		||||
    if (role == Qt::DisplayRole)
 | 
			
		||||
    {
 | 
			
		||||
        return htable->title(section);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
 | 
			
		||||
        if (role == Qt::TextAlignmentRole)
 | 
			
		||||
        return htable->alignment(section);
 | 
			
		||||
    // return Qt::AlignCenter;
 | 
			
		||||
    else if (role == Qt::ToolTipRole)
 | 
			
		||||
        return htable->tipText(section);
 | 
			
		||||
    else
 | 
			
		||||
        /*
 | 
			
		||||
        if (role == Qt::FontRole)
 | 
			
		||||
        {
 | 
			
		||||
                QFont f=QFont();
 | 
			
		||||
                f.setBold(false);
 | 
			
		||||
                return f;
 | 
			
		||||
        } */
 | 
			
		||||
        if (role == Qt::SizeHintRole)
 | 
			
		||||
    {
 | 
			
		||||
        //	return QSize(18,18);
 | 
			
		||||
    }
 | 
			
		||||
    return QVariant();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QVariant HtableModel::data(const QModelIndex &index, int role) const
 | 
			
		||||
{
 | 
			
		||||
    //	printf("data\n");
 | 
			
		||||
    //	watchCond *item=
 | 
			
		||||
    // static_cast<watchCond*>(index.internalPointer());
 | 
			
		||||
    if (role == Qt::DisplayRole)
 | 
			
		||||
    {
 | 
			
		||||
        return htable->text(index.row(), index.column());
 | 
			
		||||
    }
 | 
			
		||||
    else if (role == Qt::DecorationRole)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    if (role == Qt::EditRole)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    if (role == Qt::CheckStateRole)
 | 
			
		||||
    {
 | 
			
		||||
        //	if(item->enable)
 | 
			
		||||
        //		return Qt::Checked;
 | 
			
		||||
        //	else
 | 
			
		||||
        //		return Qt::Unchecked;
 | 
			
		||||
    }
 | 
			
		||||
    if (role == Qt::TextAlignmentRole)
 | 
			
		||||
        return Qt::AlignRight;
 | 
			
		||||
    if (role == Qt::EditRole)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    if (role == Qt::SizeHintRole)
 | 
			
		||||
    {
 | 
			
		||||
        //	return QSize(18,18);
 | 
			
		||||
    }
 | 
			
		||||
    return QVariant();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Qt::ItemFlags HtableModel::flags(const QModelIndex &index) const
 | 
			
		||||
{
 | 
			
		||||
    return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// HtableHeader //////////////////////////
 | 
			
		||||
 | 
			
		||||
HtableHeader::HtableHeader(QWidget *parent)
 | 
			
		||||
    : QHeaderView(Qt::Horizontal, parent)
 | 
			
		||||
{
 | 
			
		||||
    htable = (HeadedTable2 *)parent;
 | 
			
		||||
    setMovable(true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void HtableHeader::mousePressEvent(QMouseEvent *e)
 | 
			
		||||
{
 | 
			
		||||
    QHeaderView::mousePressEvent(e);
 | 
			
		||||
    int col = logicalIndexAt(e->pos());
 | 
			
		||||
    // printf("col=%d\n",col);
 | 
			
		||||
    if (e->button() == Qt::RightButton)
 | 
			
		||||
    {
 | 
			
		||||
        // printf("pressed col=%d\n",col); //ok
 | 
			
		||||
        emit rightClicked(e->globalPos(), col);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
HeadedTable2::HeadedTable2(QWidget *parent, int opts) : QTreeView(parent)
 | 
			
		||||
//	:QTreeWidget(parent)
 | 
			
		||||
{
 | 
			
		||||
    nrows = ncols = 0;
 | 
			
		||||
    model = new HtableModel(this);
 | 
			
		||||
    HtableHeader *header = new HtableHeader(this);
 | 
			
		||||
    setHeader(header);
 | 
			
		||||
    setModel(model);
 | 
			
		||||
    //	setEditTriggers (QAbstractItemView::SelectedClicked );
 | 
			
		||||
    //	tableView->setItemDelegateForColumn(1,&delegate);
 | 
			
		||||
    //	tableView->setItemDelegate(&delegate);
 | 
			
		||||
    setSelectionBehavior(QAbstractItemView::SelectRows);
 | 
			
		||||
    setSelectionMode(QAbstractItemView::SingleSelection);
 | 
			
		||||
    //	setSelectionMode (QAbstractItemView::ExtendedSelection);
 | 
			
		||||
    // setSelectionMode (QAbstractItemView::MultiSelection);
 | 
			
		||||
 | 
			
		||||
    setUniformRowHeights(true);
 | 
			
		||||
    setAllColumnsShowFocus(true);
 | 
			
		||||
    setFrameShape(QFrame::NoFrame);
 | 
			
		||||
    setAlternatingRowColors(true);
 | 
			
		||||
 | 
			
		||||
    //	v->setResizeMode (0,QHeaderView::Stretch);
 | 
			
		||||
    // QHeaderView *h=header ();
 | 
			
		||||
    header->setResizeMode(
 | 
			
		||||
        QHeaderView::ResizeToContents); // use sizeHintForColumn()
 | 
			
		||||
    header->setClickable(true);
 | 
			
		||||
    //	header->setVisible(false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void HeadedTable2::setTreeMode(bool mode) {}
 | 
			
		||||
 | 
			
		||||
void HeadedTable2::setSortedCol(int c) {}
 | 
			
		||||
 | 
			
		||||
void HeadedTable2::setNumCols(int c) { ncols = c; }
 | 
			
		||||
void HeadedTable2::setNumRows(int row) { nrows = row; }
 | 
			
		||||
void HeadedTable2::selectAll() {}
 | 
			
		||||
void HeadedTable2::repaintAll() {}
 | 
			
		||||
void HeadedTable2::repaint_changed() {}
 | 
			
		||||
 | 
			
		||||
extern int flag_x;
 | 
			
		||||
void HeadedTable2::mousePressEvent(QMouseEvent *e)
 | 
			
		||||
{
 | 
			
		||||
    printf("mousePressEvent() \n");
 | 
			
		||||
    QTreeView::mousePressEvent(e);
 | 
			
		||||
    // falg_x=1;
 | 
			
		||||
    flag_x = !flag_x;
 | 
			
		||||
    if (e->button() == Qt::RightButton)
 | 
			
		||||
    {
 | 
			
		||||
        emit rightClicked(e->globalPos());
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TEST & DRAFT: loop ..
 | 
			
		||||
void HeadedTable2::modelIterate(const QModelIndex &parent)
 | 
			
		||||
{
 | 
			
		||||
    int rows = model->rowCount(parent);
 | 
			
		||||
    // printf("rows=%d\n",rows);
 | 
			
		||||
    // expand(parent);
 | 
			
		||||
    setExpanded(parent, true); //				expand(ci);
 | 
			
		||||
    for (int i = 0; i < rows; i++)
 | 
			
		||||
    {
 | 
			
		||||
        QModelIndex ci = model->index(i, 0, parent);
 | 
			
		||||
        // Procinfo *pi= static_cast<Procinfo*>(ci.internalPointer());
 | 
			
		||||
        // if(!pi->hidekids)//	setExpanded(ci,true); //
 | 
			
		||||
        // expand(ci);
 | 
			
		||||
        // if(!pi->hidekids and !isExpanded(ci)) 	expand(ci);
 | 
			
		||||
        // if(!folded(ci) and !isExpanded(ci)) 	expand(ci);
 | 
			
		||||
        // if(!folded(ci) and !isExpanded(ci))
 | 
			
		||||
 | 
			
		||||
        if (model->rowCount(ci) > 0)
 | 
			
		||||
            modelIterate(ci);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										186
									
								
								src/htable2.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,186 @@
 | 
			
		||||
 | 
			
		||||
#include <QTreeView>
 | 
			
		||||
#include <QMouseEvent>
 | 
			
		||||
#include <QStandardItemModel>
 | 
			
		||||
#include <QHeaderView>
 | 
			
		||||
 | 
			
		||||
#include <QTreeWidget>
 | 
			
		||||
 | 
			
		||||
class HeadedTable2;
 | 
			
		||||
class CellAttribute2
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    QString text;
 | 
			
		||||
    bool selected;
 | 
			
		||||
    bool sorted;
 | 
			
		||||
 | 
			
		||||
    QColor backColor; // table share
 | 
			
		||||
    QColor foreColor; // rows share
 | 
			
		||||
    int xpos;         // cols share
 | 
			
		||||
    int ypos;         // rows share
 | 
			
		||||
    int w;            // cols share
 | 
			
		||||
    int depth;        // rows share
 | 
			
		||||
    int folded;       //
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class HtableModel : public QAbstractItemModel
 | 
			
		||||
// class HtableModel : public QAbstractTableModel
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    HtableModel(QObject *parent = 0);
 | 
			
		||||
    ~HtableModel(){};
 | 
			
		||||
    virtual QModelIndex
 | 
			
		||||
    index(int row, int column,
 | 
			
		||||
          const QModelIndex &parent = QModelIndex()) const;     // pure
 | 
			
		||||
    virtual QModelIndex parent(const QModelIndex &child) const; // pure virtual
 | 
			
		||||
    virtual int rowCount(const QModelIndex &parent) const;
 | 
			
		||||
    virtual QVariant data(const QModelIndex &index, int role) const;
 | 
			
		||||
    int columnCount(const QModelIndex &parent) const;
 | 
			
		||||
    QVariant headerData(int section, Qt::Orientation o, int role) const;
 | 
			
		||||
    virtual Qt::ItemFlags flags(const QModelIndex &index) const;
 | 
			
		||||
    //  Qt::ItemFlags flags(const QModelIndex &index) const;
 | 
			
		||||
    //	QMap<int, QVariant> itemData ( const QModelIndex & index ) const
 | 
			
		||||
    //;
 | 
			
		||||
    //	void update(){ reset();}
 | 
			
		||||
    void update() { emit layoutChanged(); }
 | 
			
		||||
    //	void update(const QModelIndex &idx);
 | 
			
		||||
    //	void update(int row);
 | 
			
		||||
    //	void update(); //TEMP
 | 
			
		||||
    HeadedTable2 *htable;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class HtableHeader : public QHeaderView
 | 
			
		||||
// QHeaderView ( Qt::Orientation orientation, QWidget * parent = 0 )
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    HtableHeader(QWidget *parent = 0);
 | 
			
		||||
    ~HtableHeader(){};
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual void mousePressEvent(QMouseEvent *e);
 | 
			
		||||
signals:
 | 
			
		||||
    void rightClicked(QPoint where, int col);
 | 
			
		||||
    void toolTip(QPoint where, int col);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    HeadedTable2 *htable;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class HeadedTable2 : public QTreeView
 | 
			
		||||
// class HeadedTable2 : public QTreeWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    HeadedTable2(QWidget *parent, int opts = 0);
 | 
			
		||||
    ~HeadedTable2(){};
 | 
			
		||||
 | 
			
		||||
    friend class HtableModel;
 | 
			
		||||
    HtableModel *model;
 | 
			
		||||
 | 
			
		||||
    enum NodeState
 | 
			
		||||
    {
 | 
			
		||||
        Leaf,
 | 
			
		||||
        Open,
 | 
			
		||||
        Closed
 | 
			
		||||
    };
 | 
			
		||||
    void repaint_changed();
 | 
			
		||||
    int clickedColumn() { return 0; };     // need imp
 | 
			
		||||
    int sortedCol() { return sorted_col; } // ok
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
                    void deleteCol(int col, bool update = TRUE);
 | 
			
		||||
                    void topAndRepaint();
 | 
			
		||||
                    int lastRowVisible() { return body->lastRowVisible(); };
 | 
			
		||||
                    void updateCell(int row, int col, bool erase=false);
 | 
			
		||||
                    void updateHeading(int col) {  };
 | 
			
		||||
                    void selectionNotify();
 | 
			
		||||
                    void repaintColumns(int col0, int col1 = -1);
 | 
			
		||||
                    bool treeMode() { return treemode; };
 | 
			
		||||
                    int	tableWidth() const { return body->totalWidth()+
 | 
			
		||||
       body->verticalScrollBar()->width(); }
 | 
			
		||||
            bool isCellContentsChanged(int row,int col,bool head);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                    void selectOnly(int row);
 | 
			
		||||
                    void clearAllSelections();
 | 
			
		||||
                    */
 | 
			
		||||
 | 
			
		||||
    int numRows() { return nrows; }
 | 
			
		||||
    int numCols() { return ncols; }
 | 
			
		||||
    int numSelected() { return 0; }
 | 
			
		||||
    void setTreeMode(bool mode);
 | 
			
		||||
    void setSortedCol(int col);
 | 
			
		||||
    void setNumRows(int rows);
 | 
			
		||||
    void setNumCols(int cols);
 | 
			
		||||
    virtual bool isSelected(int row) { return false; }
 | 
			
		||||
    virtual void setSelected(int row, bool sel){};
 | 
			
		||||
    void modelIterate(const QModelIndex &idx);
 | 
			
		||||
signals:
 | 
			
		||||
    void titleClicked(int col);
 | 
			
		||||
    void doubleClicked(int row);
 | 
			
		||||
    void rightClicked(QPoint where);
 | 
			
		||||
    void foldSubTree(int row);
 | 
			
		||||
    void colMoved(int col, int place);
 | 
			
		||||
 | 
			
		||||
  public slots:
 | 
			
		||||
    void selectAll();
 | 
			
		||||
    void repaintAll();
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual void mousePressEvent(QMouseEvent *e);
 | 
			
		||||
    virtual int rowDepth(int row) { return 0; };
 | 
			
		||||
    virtual NodeState folded(int row) { return Leaf; };
 | 
			
		||||
    virtual bool folded(QModelIndex &idx) { return false; };
 | 
			
		||||
    virtual int parentRow(int row) { return 0; };
 | 
			
		||||
    virtual bool lastChild(int row) { return false; };
 | 
			
		||||
    virtual bool columnMovable(int col) { return true; };
 | 
			
		||||
    virtual int colWidth(int col) = 0; // head_width
 | 
			
		||||
    virtual void moveCol(int col, int place){};
 | 
			
		||||
    virtual QString title(int col) = 0;
 | 
			
		||||
    virtual QString text(int row, int col) = 0;
 | 
			
		||||
 | 
			
		||||
    virtual QString tipText(int col) { return ""; };
 | 
			
		||||
    virtual int alignment(int col) { return 0; };
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
            virtual char *total_selectedRow(int col);
 | 
			
		||||
            virtual int sizeHintForColumn(int col) const;
 | 
			
		||||
            virtual void hideEvent ( QHideEvent * event );
 | 
			
		||||
            virtual void showEvent ( QShowEvent * event );
 | 
			
		||||
            virtual void resizeEvent(QResizeEvent *);
 | 
			
		||||
    */
 | 
			
		||||
    // colWidth returns width in digit units; negative means variable width.
 | 
			
		||||
 | 
			
		||||
    //		virtual void drawCellContents(int row, int col, int w, int
 | 
			
		||||
    // h,
 | 
			
		||||
    // QPainter *painter);
 | 
			
		||||
    // virtual bool modified(int row){return true;};
 | 
			
		||||
    bool treemode;
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    // to make signals originate from the right object
 | 
			
		||||
    /*		void emit_click_signal(int col);
 | 
			
		||||
                    void emit_double_click_signal(int row);
 | 
			
		||||
                    void emit_right_click_signal(QPoint where);
 | 
			
		||||
                    void emit_fold(int row);
 | 
			
		||||
 | 
			
		||||
                    inline int computedWidth(int col);
 | 
			
		||||
                    int colOffset(int col);
 | 
			
		||||
                    inline int colXPos(int col);
 | 
			
		||||
                    void updateCols(int deltacols, int place, bool update);
 | 
			
		||||
    */
 | 
			
		||||
    int sorted_col;    // column to emphasize
 | 
			
		||||
    int reversed_sort; // true if sorting backwards
 | 
			
		||||
    int options;
 | 
			
		||||
 | 
			
		||||
    int nrows;
 | 
			
		||||
    int ncols;
 | 
			
		||||
 | 
			
		||||
    // text cache is in logical columns (reorder causes no flush)
 | 
			
		||||
    QHash<int, CellAttribute2 *>
 | 
			
		||||
        cached_attr; // indexed by (row << 16) + log_col
 | 
			
		||||
    QHash<int, CellAttribute2 *>
 | 
			
		||||
        cached_attr_h; // indexed by (row << 16) + log_col
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										1367
									
								
								src/infobar.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										215
									
								
								src/infobar.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,215 @@
 | 
			
		||||
// infobar.h				emacs, this is written in -*-c++-*-
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdeg?rd, 1997-1999
 | 
			
		||||
 | 
			
		||||
#ifndef INFOBAR_H
 | 
			
		||||
#define INFOBAR_H
 | 
			
		||||
 | 
			
		||||
#include "proc.h"
 | 
			
		||||
 | 
			
		||||
#ifndef USING_PCH
 | 
			
		||||
#include <QString>
 | 
			
		||||
#include <QPixmap>
 | 
			
		||||
#include <QResizeEvent>
 | 
			
		||||
#include <QFrame>
 | 
			
		||||
#include <QEvent>
 | 
			
		||||
#include <QMouseEvent>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
class subcpuRack : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    subcpuRack(QWidget *parent, Procview *p);
 | 
			
		||||
    void refresh();
 | 
			
		||||
    //   void update_load();
 | 
			
		||||
    //   void show_and_hide(bool, QWidget *, QWidget *);
 | 
			
		||||
    // signals:  void config_change();
 | 
			
		||||
  protected:
 | 
			
		||||
    void paintEvent(QPaintEvent *);
 | 
			
		||||
    void mousePressEvent(QMouseEvent *);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    //	List<gwidget*>  wlist;
 | 
			
		||||
    QWidget *parent;
 | 
			
		||||
    Procview *procview; // temp
 | 
			
		||||
    bool is_vertical;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class gwidget
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    gwidget() { x = 0, y = 0, width = 0, height = 0; };
 | 
			
		||||
    gwidget(QWidget *p) { parent = p; };
 | 
			
		||||
    virtual void draw(QPainter *p) { printf("gwidget\n"); };
 | 
			
		||||
    virtual void setPosition(int parent_width, int parent_height){};
 | 
			
		||||
    virtual const char *info() { return NULL; };
 | 
			
		||||
    void setParent(QWidget *p, Procview *procv)
 | 
			
		||||
    {
 | 
			
		||||
        parent = p;
 | 
			
		||||
        procview = procv;
 | 
			
		||||
    };
 | 
			
		||||
    void resize(int x_, int y_, int w, int h)
 | 
			
		||||
    {
 | 
			
		||||
        x = x_;
 | 
			
		||||
        y = y_;
 | 
			
		||||
        width = w;
 | 
			
		||||
        height = h;
 | 
			
		||||
    };
 | 
			
		||||
    bool intersect(int cx, int cy)
 | 
			
		||||
    {
 | 
			
		||||
        cx = cx - x;
 | 
			
		||||
        cy = cy - y;
 | 
			
		||||
        if (cx > 0 and cx < width)
 | 
			
		||||
            if (cy > 0 and cy < height)
 | 
			
		||||
                return true;
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int xpluswidth() { return x + width; };
 | 
			
		||||
    Procview *procview; // temp
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    int x;
 | 
			
		||||
    int y;
 | 
			
		||||
    int width;
 | 
			
		||||
    int height;
 | 
			
		||||
    QRect rect;
 | 
			
		||||
    QWidget *parent;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Infobar : public QFrame
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    Infobar(){};
 | 
			
		||||
 | 
			
		||||
    Infobar(QWidget *parent, Procview *);
 | 
			
		||||
    ~Infobar();
 | 
			
		||||
 | 
			
		||||
    void configure(); // respond to configuration change
 | 
			
		||||
 | 
			
		||||
    QPixmap *make_icon(int w, int h);
 | 
			
		||||
    // DEL QPixmap *load_icon(int w, int h) { return make_icon(w, h); }
 | 
			
		||||
    void refresh(); // update();
 | 
			
		||||
    void update_load();
 | 
			
		||||
    void drawGraphOnPixmap();
 | 
			
		||||
    bool swaplim_exceeded();
 | 
			
		||||
    void show_and_hide(bool, QWidget *, QWidget *);
 | 
			
		||||
    void showup();
 | 
			
		||||
signals:
 | 
			
		||||
    void clicked();
 | 
			
		||||
    void config_change();
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    void paintEvent(QPaintEvent *);
 | 
			
		||||
    void mousePressEvent(QMouseEvent *);
 | 
			
		||||
    void mouseMoveEvent(QMouseEvent *);
 | 
			
		||||
    void leaveEvent(QEvent *);
 | 
			
		||||
    virtual void enterEvent(QEvent *event);
 | 
			
		||||
    void hideEvent(QHideEvent *event);
 | 
			
		||||
    void resizeEvent(QResizeEvent *e);
 | 
			
		||||
 | 
			
		||||
    void add_history_point(unsigned value);
 | 
			
		||||
    void add_history_point2(float value);
 | 
			
		||||
    void make_graph(int w, int h, QPainter *p, bool test = false);
 | 
			
		||||
    Procview *procview;
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    // history points are stored in fixed point, scaled by history_scale
 | 
			
		||||
    static const unsigned int history_scale = 256;
 | 
			
		||||
    static const int time_dist = 60; // time between vertical lines (seconds)
 | 
			
		||||
 | 
			
		||||
    QList<gwidget *> wlist;
 | 
			
		||||
    int hist_size;  // history buffer size DEL
 | 
			
		||||
    int npoints;    // nr of history points currently remembered
 | 
			
		||||
    float *history; // (circular) history buffer DEL
 | 
			
		||||
    int h_index;    // next history index to use
 | 
			
		||||
    float peak;     // largest value in history
 | 
			
		||||
 | 
			
		||||
    bool dirty; // history changed since pixmap was drawn
 | 
			
		||||
    QPixmap pixmap;
 | 
			
		||||
    QPixmap icon_pm;
 | 
			
		||||
 | 
			
		||||
    int px, py; //	pointer position
 | 
			
		||||
 | 
			
		||||
    bool is_vertical;
 | 
			
		||||
    int official_height;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class GraphBase : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    GraphBase(QWidget *parent, Procview *);
 | 
			
		||||
    void drawGraphOnPixmap();
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    void paintEvent(QPaintEvent *);
 | 
			
		||||
    virtual void mousePressEvent(QMouseEvent *);
 | 
			
		||||
    virtual void mouseMoveEvent(QMouseEvent *);
 | 
			
		||||
    virtual void leaveEvent(QEvent *);
 | 
			
		||||
    //	virtual	void enterEvent ( QEvent * event ) ;
 | 
			
		||||
    //	void resizeEvent ( QResizeEvent * e );
 | 
			
		||||
 | 
			
		||||
    virtual void make_graph(int w, int h, QPainter *p);
 | 
			
		||||
    virtual QString doHistoryTXT(SysHistory *sysh);
 | 
			
		||||
 | 
			
		||||
    Procview *procview;
 | 
			
		||||
    int official_height;
 | 
			
		||||
    int npoints; // nr of history points currently remembered
 | 
			
		||||
  private:
 | 
			
		||||
    // history points are stored in fixed point, scaled by history_scale
 | 
			
		||||
    static const unsigned int history_scale = 256;
 | 
			
		||||
 | 
			
		||||
    int hist_size;  // history buffer size DEL
 | 
			
		||||
    float *history; // (circular) history buffer DEL
 | 
			
		||||
    int h_index;    // next history index to use
 | 
			
		||||
    float peak;     // largest value in history
 | 
			
		||||
 | 
			
		||||
    bool dirty; // history changed since pixmap was drawn
 | 
			
		||||
    QPixmap pixmap;
 | 
			
		||||
    QPixmap icon_pm;
 | 
			
		||||
 | 
			
		||||
    int px, py; //	pointer position
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class IO_Graph : public GraphBase
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    IO_Graph(QWidget *parent, Procview *);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    void make_graph(int w, int h, QPainter *p);
 | 
			
		||||
    QString doHistoryTXT(SysHistory *sysh);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// class Infobar2 : public Infobar
 | 
			
		||||
class Infobar2 : public QFrame
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    Infobar2(QWidget *parent, Procview *);
 | 
			
		||||
    void updatePixmap(); // TEMP
 | 
			
		||||
    QPixmap *load_icon(int w, int h) { return basic->make_icon(w, h); }
 | 
			
		||||
    void refresh(); // update();
 | 
			
		||||
    Infobar *basic;
 | 
			
		||||
    IO_Graph *io_graph;
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    int official_height;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class PDisplay : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    PDisplay(QWidget *parent);
 | 
			
		||||
    Infobar2 *addSystem(Procview *p);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // INFOBAR_H
 | 
			
		||||
							
								
								
									
										267
									
								
								src/lookup.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,267 @@
 | 
			
		||||
// lookup.C
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
// This module implements asynchronous address->hostname lookup.
 | 
			
		||||
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <sys/socket.h>
 | 
			
		||||
#include <signal.h>
 | 
			
		||||
#include <netinet/in.h>
 | 
			
		||||
#include <netdb.h>
 | 
			
		||||
 | 
			
		||||
#include "lookup.h"
 | 
			
		||||
#include "svec.cpp"
 | 
			
		||||
 | 
			
		||||
// declarations of static members
 | 
			
		||||
char *Lookup::argv0;
 | 
			
		||||
int Lookup::maxtitlelen;
 | 
			
		||||
 | 
			
		||||
UintQueue::UintQueue() { first = last = 0; };
 | 
			
		||||
 | 
			
		||||
void UintQueue::enqueue(unsigned x)
 | 
			
		||||
{
 | 
			
		||||
    if (last < 0)
 | 
			
		||||
    {
 | 
			
		||||
        // make room for inserting more elements
 | 
			
		||||
        int step = qMax(first + 1, 8);
 | 
			
		||||
        queue.setSize(first + step + 1);
 | 
			
		||||
        for (int i = first; i > last; i--)
 | 
			
		||||
            queue[i + step] = queue[i];
 | 
			
		||||
        first += step;
 | 
			
		||||
        last += step;
 | 
			
		||||
    }
 | 
			
		||||
    queue.set(last--, x);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
unsigned UintQueue::dequeue()
 | 
			
		||||
{
 | 
			
		||||
    if (isEmpty())
 | 
			
		||||
        fatal("UintQueue: queue empty");
 | 
			
		||||
    return queue[first--];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// constructor for node head
 | 
			
		||||
Hostnode::Hostnode() : next(this), prev(this) {}
 | 
			
		||||
 | 
			
		||||
// create a new cache node, initialized with null string
 | 
			
		||||
Hostnode::Hostnode(unsigned addr) : ipaddr(addr), next(0), prev(0) {}
 | 
			
		||||
 | 
			
		||||
// must be called on the head of the list
 | 
			
		||||
void Hostnode::moveToFront(Hostnode *node)
 | 
			
		||||
{
 | 
			
		||||
    if (next != node)
 | 
			
		||||
    {
 | 
			
		||||
        Hostnode *p = node->prev, *n = node->next;
 | 
			
		||||
        p->next = n;
 | 
			
		||||
        n->prev = p;
 | 
			
		||||
        node->next = next;
 | 
			
		||||
        node->prev = this;
 | 
			
		||||
        next->prev = node;
 | 
			
		||||
        next = node;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// must be called on the head of the list
 | 
			
		||||
void Hostnode::deleteLast()
 | 
			
		||||
{
 | 
			
		||||
    Hostnode *nuke = prev;
 | 
			
		||||
    prev = nuke->prev;
 | 
			
		||||
    prev->next = this;
 | 
			
		||||
    delete nuke;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// must be called on the head of the list
 | 
			
		||||
void Hostnode::insertFirst(Hostnode *node)
 | 
			
		||||
{
 | 
			
		||||
    node->prev = this;
 | 
			
		||||
    node->next = next;
 | 
			
		||||
    next->prev = node;
 | 
			
		||||
    next = node;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Lookup::Lookup() // : hostdict(17)
 | 
			
		||||
{
 | 
			
		||||
    sockfd = -1; // no lookup helper is running
 | 
			
		||||
    readsn = writesn = 0;
 | 
			
		||||
    outstanding = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// empty destructor, workaround for gcc bug
 | 
			
		||||
Lookup::~Lookup() {}
 | 
			
		||||
 | 
			
		||||
// look up host name (addr is in host byte order)
 | 
			
		||||
// a null name means it is been looked up (signal will be sent when done)
 | 
			
		||||
QString Lookup::hostname(unsigned addr)
 | 
			
		||||
{
 | 
			
		||||
    // first look in our cache
 | 
			
		||||
    Hostnode *hn = hostdict.value(addr, NULL);
 | 
			
		||||
    if (hn)
 | 
			
		||||
    {
 | 
			
		||||
        hostlru.moveToFront(hn);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        hn = new Hostnode(addr);
 | 
			
		||||
        if (hostdict.count() >= hostname_cache_size)
 | 
			
		||||
        {
 | 
			
		||||
            // remove least recently used item
 | 
			
		||||
            hostdict.remove(hostlru.last()->ipaddr);
 | 
			
		||||
            hostlru.deleteLast();
 | 
			
		||||
        }
 | 
			
		||||
        hostlru.insertFirst(hn);
 | 
			
		||||
        hostdict.insert(addr, hn);
 | 
			
		||||
        // if(hostdict.count() > hostdict.size() * 3)
 | 
			
		||||
        // hostdict.resize(hostdict.count());
 | 
			
		||||
        if (addr == 0)
 | 
			
		||||
            hn->name = "*";
 | 
			
		||||
        else
 | 
			
		||||
            request(addr);
 | 
			
		||||
    }
 | 
			
		||||
    return hn->name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Lookup::request(unsigned addr)
 | 
			
		||||
{
 | 
			
		||||
    addrqueue.enqueue(addr);
 | 
			
		||||
    if (sockfd < 0)
 | 
			
		||||
    {
 | 
			
		||||
        int socks[2];
 | 
			
		||||
        socketpair(AF_UNIX, SOCK_STREAM, 0, socks);
 | 
			
		||||
        // launch a new helper
 | 
			
		||||
        signal(SIGCHLD, SIG_IGN); // Linux does automatic child reaping, nice
 | 
			
		||||
        switch (fork())
 | 
			
		||||
        {
 | 
			
		||||
        case -1:    // error
 | 
			
		||||
            return; // don't bother, we'll try again next time
 | 
			
		||||
        case 0:     // child
 | 
			
		||||
            close(socks[0]);
 | 
			
		||||
            do_child(socks[1]);
 | 
			
		||||
            break;
 | 
			
		||||
        default: // parent
 | 
			
		||||
            close(socks[1]);
 | 
			
		||||
            sockfd = socks[0];
 | 
			
		||||
            readsn = new QSocketNotifier(sockfd, QSocketNotifier::Read, this);
 | 
			
		||||
            connect(readsn, SIGNAL(activated(int)), SLOT(receive_result(int)));
 | 
			
		||||
            writesn = new QSocketNotifier(sockfd, QSocketNotifier::Write, this);
 | 
			
		||||
            connect(writesn, SIGNAL(activated(int)), SLOT(send_request(int)));
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    writesn->setEnabled(true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// the child helper process loop
 | 
			
		||||
void Lookup::do_child(int fd)
 | 
			
		||||
{
 | 
			
		||||
    setproctitle("qps-dns-helper");
 | 
			
		||||
    // close unused fds
 | 
			
		||||
    for (int i = 0; i < fd; i++)
 | 
			
		||||
        close(i);
 | 
			
		||||
    for (;;)
 | 
			
		||||
    {
 | 
			
		||||
        unsigned addr;
 | 
			
		||||
        int ret = read(fd, &addr, sizeof(addr));
 | 
			
		||||
        if (ret <= 0)
 | 
			
		||||
        {
 | 
			
		||||
            _exit(0); // connection closed
 | 
			
		||||
        }
 | 
			
		||||
        struct hostent *h = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET);
 | 
			
		||||
        char buf[256];
 | 
			
		||||
        if (!h)
 | 
			
		||||
        {
 | 
			
		||||
            unsigned a = htonl(addr);
 | 
			
		||||
            sprintf(buf, "%d.%d.%d.%d", (a >> 24) & 0xff, (a >> 16) & 0xff,
 | 
			
		||||
                    (a >> 8) & 0xff, a & 0xff);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            strncpy(buf, h->h_name, sizeof(buf));
 | 
			
		||||
        }
 | 
			
		||||
        // if parent died, we'll get SIGPIPE here and terminate
 | 
			
		||||
        // automatically
 | 
			
		||||
        write(fd, &addr, sizeof(addr));
 | 
			
		||||
        int len = strlen(buf);
 | 
			
		||||
        write(fd, &len, sizeof(len));
 | 
			
		||||
        write(fd, buf, len);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// slot: receive result from helper
 | 
			
		||||
void Lookup::receive_result(int)
 | 
			
		||||
{
 | 
			
		||||
    unsigned addr;
 | 
			
		||||
    int len;
 | 
			
		||||
    char buf[256];
 | 
			
		||||
 | 
			
		||||
    if (read(sockfd, &addr, sizeof(addr)) <= 0 ||
 | 
			
		||||
        read(sockfd, &len, sizeof(len)) <= 0 || read(sockfd, buf, len) <= 0)
 | 
			
		||||
    {
 | 
			
		||||
        // helper has died
 | 
			
		||||
        delete readsn;
 | 
			
		||||
        delete writesn;
 | 
			
		||||
        close(sockfd);
 | 
			
		||||
        sockfd = -1;
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    buf[len] = '\0';
 | 
			
		||||
    Hostnode *hn = hostdict.value(addr, NULL);
 | 
			
		||||
    if (!hn)
 | 
			
		||||
        return; // gone from cache
 | 
			
		||||
    hn->name = buf;
 | 
			
		||||
    emit resolved(addr);
 | 
			
		||||
 | 
			
		||||
    outstanding--;
 | 
			
		||||
    // if there is nothing more in the queue, kill the helper
 | 
			
		||||
    if (addrqueue.isEmpty() && outstanding == 0)
 | 
			
		||||
    {
 | 
			
		||||
        close(sockfd);
 | 
			
		||||
        sockfd = -1;
 | 
			
		||||
        delete readsn;
 | 
			
		||||
        delete writesn;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// slot: send request to the helper
 | 
			
		||||
void Lookup::send_request(int)
 | 
			
		||||
{
 | 
			
		||||
    if (addrqueue.isEmpty())
 | 
			
		||||
    {
 | 
			
		||||
        writesn->setEnabled(false);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    unsigned addr = addrqueue.dequeue();
 | 
			
		||||
    if (write(sockfd, &addr, sizeof(addr)) < 0)
 | 
			
		||||
    {
 | 
			
		||||
        // This shouldn't happen, try to repair it anyway
 | 
			
		||||
        addrqueue.enqueue(addr);
 | 
			
		||||
        delete readsn;
 | 
			
		||||
        delete writesn;
 | 
			
		||||
        close(sockfd);
 | 
			
		||||
        sockfd = -1;
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    outstanding++;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// register and measure the space for modifying the visible command line
 | 
			
		||||
void Lookup::initproctitle(char **argv, char **envp)
 | 
			
		||||
{
 | 
			
		||||
    argv0 = argv[0];
 | 
			
		||||
    while (*envp)
 | 
			
		||||
        envp++;
 | 
			
		||||
    maxtitlelen = envp[-1] + strlen(envp[-1]) - argv0 - 2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// set the process title (idea snarfed from sysvinit (thanks Miquel) and
 | 
			
		||||
// refined by peeking into wu-ftpd)
 | 
			
		||||
void Lookup::setproctitle(const char *txt)
 | 
			
		||||
{
 | 
			
		||||
    memset(argv0, 0, maxtitlelen);
 | 
			
		||||
    strncpy(argv0, txt, maxtitlelen - 1);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										88
									
								
								src/lookup.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,88 @@
 | 
			
		||||
// lookup.h				emacs, this is written in -*-c++-*-
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#ifndef LOOKUP_H
 | 
			
		||||
#define LOOKUP_H
 | 
			
		||||
 | 
			
		||||
#include <qstring.h>
 | 
			
		||||
#include <qsocketnotifier.h>
 | 
			
		||||
#include "svec.h"
 | 
			
		||||
#include <QHash>
 | 
			
		||||
 | 
			
		||||
// queue (fifo) of unsigned ints (inet addresses)
 | 
			
		||||
class UintQueue
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    UintQueue();
 | 
			
		||||
 | 
			
		||||
    bool isEmpty() { return first == last; };
 | 
			
		||||
    void enqueue(unsigned x);
 | 
			
		||||
    unsigned dequeue();
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    Svec<unsigned> queue;
 | 
			
		||||
    int first; // index of first item in queue
 | 
			
		||||
    int last;  // index where next item will be put (< first)
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// list node for LRU cache of hostnames:
 | 
			
		||||
// This list is doubly-linked circular (to reduce the amount of special cases),
 | 
			
		||||
// with a head node that carries no data. In addition, each node is
 | 
			
		||||
// entered into a hash table for rapid lookup
 | 
			
		||||
class Hostnode
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Hostnode();
 | 
			
		||||
    Hostnode(unsigned addr);
 | 
			
		||||
 | 
			
		||||
    // these must be called on the head of the list
 | 
			
		||||
    void moveToFront(Hostnode *node);
 | 
			
		||||
    void deleteLast();
 | 
			
		||||
    void insertFirst(Hostnode *node);
 | 
			
		||||
    Hostnode *last() { return prev; };
 | 
			
		||||
 | 
			
		||||
    QString name;
 | 
			
		||||
    unsigned ipaddr; // hash key
 | 
			
		||||
    Hostnode *next, *prev;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Lookup : public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    Lookup();
 | 
			
		||||
    ~Lookup();
 | 
			
		||||
    QString hostname(unsigned addr);
 | 
			
		||||
 | 
			
		||||
    static void initproctitle(char **argv, char **envp);
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void resolved(unsigned addr);
 | 
			
		||||
 | 
			
		||||
  protected slots:
 | 
			
		||||
    void receive_result(int);
 | 
			
		||||
    void send_request(int);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    void request(unsigned addr);
 | 
			
		||||
    void do_child(int fd);
 | 
			
		||||
 | 
			
		||||
    static void setproctitle(const char *txt);
 | 
			
		||||
 | 
			
		||||
    static char *argv0;
 | 
			
		||||
    static int maxtitlelen;
 | 
			
		||||
 | 
			
		||||
    QHash<int, Hostnode *> hostdict;
 | 
			
		||||
    Hostnode hostlru;    // head of circular list
 | 
			
		||||
    UintQueue addrqueue; // queue of addresses to lookup
 | 
			
		||||
    int outstanding;     // number of outstanding requests
 | 
			
		||||
    int sockfd;          // -1 if no helper process is running
 | 
			
		||||
 | 
			
		||||
    QSocketNotifier *readsn, *writesn;
 | 
			
		||||
 | 
			
		||||
    static const unsigned hostname_cache_size = 400; // max names to cache
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // LOOKUP_H
 | 
			
		||||
							
								
								
									
										37
									
								
								src/message.ui
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,37 @@
 | 
			
		||||
<ui version="4.0" >
 | 
			
		||||
 <class>ExecWindow</class>
 | 
			
		||||
 <widget class="QWidget" name="ExecWindow" >
 | 
			
		||||
  <property name="geometry" >
 | 
			
		||||
   <rect>
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
    <y>0</y>
 | 
			
		||||
    <width>309</width>
 | 
			
		||||
    <height>162</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowTitle" >
 | 
			
		||||
   <string>Qps</string>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowIcon" >
 | 
			
		||||
   <iconset>
 | 
			
		||||
    <normaloff/>
 | 
			
		||||
   </iconset>
 | 
			
		||||
  </property>
 | 
			
		||||
  <layout class="QVBoxLayout" >
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QTextEdit" name="textEdit" />
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QPushButton" name="okButton" >
 | 
			
		||||
     <property name="text" >
 | 
			
		||||
      <string>Ok</string>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
  </layout>
 | 
			
		||||
 </widget>
 | 
			
		||||
 <resources>
 | 
			
		||||
  <include location="qps.qrc" />
 | 
			
		||||
 </resources>
 | 
			
		||||
 <connections/>
 | 
			
		||||
</ui>
 | 
			
		||||
							
								
								
									
										1215
									
								
								src/misc.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										296
									
								
								src/misc.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,296 @@
 | 
			
		||||
#ifndef MISC_H
 | 
			
		||||
#define MISC_H
 | 
			
		||||
 | 
			
		||||
#ifndef USING_PCH
 | 
			
		||||
#include <QAbstractButton>
 | 
			
		||||
#include <QCheckBox>
 | 
			
		||||
#include <QRadioButton>
 | 
			
		||||
#include <QStatusBar>
 | 
			
		||||
#include <QPainter>
 | 
			
		||||
 | 
			
		||||
#include <QLineEdit>
 | 
			
		||||
#include <QComboBox>
 | 
			
		||||
#include <QTextEdit>
 | 
			
		||||
#include <QToolButton>
 | 
			
		||||
 | 
			
		||||
#include <QTimerEvent>
 | 
			
		||||
#include <QKeyEvent>
 | 
			
		||||
#include <QBoxLayout>
 | 
			
		||||
#include <QHBoxLayout>
 | 
			
		||||
#include <QAbstractButton>
 | 
			
		||||
#include <QTimerEvent>
 | 
			
		||||
#include <QKeyEvent>
 | 
			
		||||
#include <QLabel>
 | 
			
		||||
#include <QPixmap>
 | 
			
		||||
#include <QFrame>
 | 
			
		||||
#include <QResizeEvent>
 | 
			
		||||
#include <QMenu>
 | 
			
		||||
#include <QMouseEvent>
 | 
			
		||||
#include <QTimeLine>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "qticonloader.h"
 | 
			
		||||
 | 
			
		||||
char *userName(int uid, int euid);
 | 
			
		||||
char *groupName(int gid, int egid);
 | 
			
		||||
 | 
			
		||||
void setQpsTheme();
 | 
			
		||||
 | 
			
		||||
int fsize(char *fname);
 | 
			
		||||
void msleep(long msec);
 | 
			
		||||
void mem_string(int kbytes, char *buf);
 | 
			
		||||
void mem_string_k(int kbytes, char *buf);
 | 
			
		||||
 | 
			
		||||
void init_xpm();
 | 
			
		||||
void init_misc(QWidget *main);
 | 
			
		||||
int pf_write(QPainter *p, int x, int y, const char *str);
 | 
			
		||||
int pf_str_width(char *str);
 | 
			
		||||
int pf_char_height();
 | 
			
		||||
void check_qps_running();
 | 
			
		||||
 | 
			
		||||
int QPS_PROCVIEW_CPU_NUM();
 | 
			
		||||
void AddLog(QString str);
 | 
			
		||||
 | 
			
		||||
class CrossBox : public QCheckBox
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    CrossBox(const char *text, QWidget *parent);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual void drawButton(QPainter *paint);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class CheckMenu : public QMenu
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    CheckMenu(QWidget *parent = 0);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TFrame : public QLabel
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    TFrame(QWidget *parent);
 | 
			
		||||
    void setText(QString str);
 | 
			
		||||
    void draw(QPainter &p);
 | 
			
		||||
    void showText(QPoint pos, QString str);
 | 
			
		||||
    void setPos(int x, int y);
 | 
			
		||||
    void setPos();
 | 
			
		||||
 | 
			
		||||
  protected slots:
 | 
			
		||||
    //    		void refresh();
 | 
			
		||||
    //  		void update(int n);
 | 
			
		||||
    //		QToolButton *button,*button2,*button3;
 | 
			
		||||
    //		void event_cursor_moved(QMouseEvent *e);
 | 
			
		||||
    void setValue(int val);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual void paintEvent(QPaintEvent *event);
 | 
			
		||||
    virtual void moveEvent(QMoveEvent *event);
 | 
			
		||||
    virtual void showEvent(QShowEvent *event);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    QString text;
 | 
			
		||||
    QTimeLine *timeLine;
 | 
			
		||||
    float opacity;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TBloon : public QLabel
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    TBloon(QWidget *parent);
 | 
			
		||||
    //	void setText(QString str);
 | 
			
		||||
    //	void draw( QPainter &p );
 | 
			
		||||
    //	void showText(QPoint pos,QString str);
 | 
			
		||||
 | 
			
		||||
    virtual bool eventFilter(QObject *watched, QEvent *event);
 | 
			
		||||
  protected slots:
 | 
			
		||||
    void update(int val);
 | 
			
		||||
    //    		void refresh();
 | 
			
		||||
    //  		void update(int n);
 | 
			
		||||
    //		QToolButton *button,*button2,*button3;
 | 
			
		||||
    //		void event_cursor_moved(QMouseEvent *e);
 | 
			
		||||
  protected:
 | 
			
		||||
    //	virtual void paintEvent(  QPaintEvent * event );
 | 
			
		||||
    //	virtual void moveEvent (QMoveEvent * event );
 | 
			
		||||
  private:
 | 
			
		||||
    QWidget *paren;
 | 
			
		||||
    QString text;
 | 
			
		||||
    QTimeLine *timeLine;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class FaderWidget : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
    Q_PROPERTY(QBrush fadeBrush READ fadeBrush WRITE setFadeBrush)
 | 
			
		||||
    Q_PROPERTY(int fadeDuration READ fadeDuration WRITE setFadeDuration)
 | 
			
		||||
  public:
 | 
			
		||||
    FaderWidget(QWidget *parent);
 | 
			
		||||
 | 
			
		||||
    QBrush fadeBrush() const { return startBrush; }
 | 
			
		||||
    void setFadeBrush(const QBrush &newColor) { startBrush = newColor; }
 | 
			
		||||
 | 
			
		||||
    int fadeDuration() const { return timeLine->duration(); }
 | 
			
		||||
    void setFadeDuration(int milliseconds)
 | 
			
		||||
    {
 | 
			
		||||
        timeLine->setDuration(milliseconds);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void start();
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    void paintEvent(QPaintEvent *event);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    QTimeLine *timeLine;
 | 
			
		||||
    QBrush startBrush;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class UFrame : public QFrame
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    UFrame(QWidget *parent);
 | 
			
		||||
    void setTitle(QString str);
 | 
			
		||||
  protected slots:
 | 
			
		||||
    //    		void refresh();
 | 
			
		||||
    //  		void update(int n);
 | 
			
		||||
    //		QToolButton *button,*button2,*button3;
 | 
			
		||||
    //		void event_cursor_moved(QMouseEvent *e);
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual void paintEvent(QPaintEvent *event);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    QString title;
 | 
			
		||||
    QString stylesheet;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class XButton : public QAbstractButton
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    XButton(QWidget *parent);
 | 
			
		||||
  protected slots:
 | 
			
		||||
    //    		void refresh();
 | 
			
		||||
    //  		void update(int n);
 | 
			
		||||
    //		QToolButton *button,*button2,*button3;
 | 
			
		||||
    //		void event_cursor_moved(QMouseEvent *e);
 | 
			
		||||
  protected:
 | 
			
		||||
    // virtual void drawButton 3( QPainter * ) ;
 | 
			
		||||
    virtual void paintEvent(QPaintEvent *event);
 | 
			
		||||
    void resizeEvent(QResizeEvent *p);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class SearchBox : public QLineEdit
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    SearchBox(QWidget *parent);
 | 
			
		||||
    void event_cursor_moved(QMouseEvent *e);
 | 
			
		||||
    void keyPressEvent(QKeyEvent *e);
 | 
			
		||||
  protected slots:
 | 
			
		||||
    void event_xbutton_clicked();
 | 
			
		||||
    //    		void refresh();
 | 
			
		||||
    //  		void update(int n);
 | 
			
		||||
    //		QToolButton *button,*button2,*button3;
 | 
			
		||||
  protected:
 | 
			
		||||
    void resizeEvent(QResizeEvent *);
 | 
			
		||||
    void timerEvent(QTimerEvent *);
 | 
			
		||||
    int left_time;
 | 
			
		||||
    //	XButton *xb;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class LogBox : public QLabel
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    LogBox(QWidget *w);
 | 
			
		||||
    QTextEdit *text;
 | 
			
		||||
    // QLabel *label,*label2,*label3;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class StatusBar : public QStatusBar
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    StatusBar(QWidget *parent);
 | 
			
		||||
    void refresh();
 | 
			
		||||
    void update(int n);
 | 
			
		||||
    QLabel *label, *label2, *label3;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class ControlBar : public QFrame
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    QComboBox *view;
 | 
			
		||||
    ControlBar(QWidget *parent);
 | 
			
		||||
    void setMode(bool treemode);
 | 
			
		||||
    void update_bar();
 | 
			
		||||
    QToolButton *pauseButton;
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void modeChange(bool treemode);
 | 
			
		||||
    void viewChange(QAction *);
 | 
			
		||||
    void need_refresh();
 | 
			
		||||
 | 
			
		||||
  public slots:
 | 
			
		||||
    void linear_clicked();
 | 
			
		||||
    void view_changed(int idx);
 | 
			
		||||
    void tree_clicked();
 | 
			
		||||
    void show_thread_clicked();
 | 
			
		||||
    void event_search_box_changed();
 | 
			
		||||
    void event_command_pressed();
 | 
			
		||||
    void setPaused(bool);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    void resizeEvent(QResizeEvent *);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    QRadioButton *b_tree, *b_linear, *b_treeT;
 | 
			
		||||
    QCheckBox *check_thread;
 | 
			
		||||
    QBoxLayout *layout;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#include <QTabWidget>
 | 
			
		||||
 | 
			
		||||
class QTabWidgetX : public QTabWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    QTabWidgetX(QWidget *parent);
 | 
			
		||||
    void showTab(bool);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#include <QtCore/QObject>
 | 
			
		||||
#include <QtDBus/QtDBus>
 | 
			
		||||
 | 
			
		||||
// class ServerAdaptor: public QDBusAbstractAdaptor
 | 
			
		||||
class ServerAdaptor : public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
    Q_CLASSINFO("D-Bus Interface", "com.trolltech.Examples.CarInterface")
 | 
			
		||||
    Q_CLASSINFO("D-Bus Introspection",
 | 
			
		||||
                ""
 | 
			
		||||
                "  <interface name=\"com.trolltech.Examples.CarInterface\" >\n"
 | 
			
		||||
                "    <method name=\"accelerate\" />\n"
 | 
			
		||||
                "    <method name=\"decelerate\" />\n"
 | 
			
		||||
                "    <method name=\"turnLeft\" />\n"
 | 
			
		||||
                "    <method name=\"turnRight\" />\n"
 | 
			
		||||
                "    <signal name=\"crashed\" />\n"
 | 
			
		||||
                "  </interface>\n"
 | 
			
		||||
                "")
 | 
			
		||||
  public:
 | 
			
		||||
    //    ServerAdaptor(QObject *parent);
 | 
			
		||||
    ServerAdaptor(){};
 | 
			
		||||
    virtual ~ServerAdaptor(){};
 | 
			
		||||
 | 
			
		||||
  public:         // PROPERTIES
 | 
			
		||||
  public Q_SLOTS: // METHODS
 | 
			
		||||
    void accelerate();
 | 
			
		||||
Q_SIGNALS: // SIGNALS
 | 
			
		||||
    void crashed();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // MISC_H
 | 
			
		||||
							
								
								
									
										352
									
								
								src/prefs.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,352 @@
 | 
			
		||||
// prefs.C
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdeg?rd, 1997-1999
 | 
			
		||||
 | 
			
		||||
#include "prefs.h"
 | 
			
		||||
#include "proc.h"
 | 
			
		||||
#include "qps.h"
 | 
			
		||||
#include <QLabel>
 | 
			
		||||
#include <QVBoxLayout>
 | 
			
		||||
#include <QGroupBox>
 | 
			
		||||
#include <qstring.h>
 | 
			
		||||
#include <QtGui>
 | 
			
		||||
#include <QApplication>
 | 
			
		||||
#include <QFontComboBox>
 | 
			
		||||
 | 
			
		||||
//#include <qstylefactory.h>
 | 
			
		||||
#include "qps.h"
 | 
			
		||||
extern Qps *qps;
 | 
			
		||||
 | 
			
		||||
extern QFontComboBox *font_cb;
 | 
			
		||||
// class that validates input for the "swap warning limit" field
 | 
			
		||||
class Swapvalid : public QValidator
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Swapvalid(QWidget *parent) : QValidator(parent) {}
 | 
			
		||||
    virtual State validate(QString &s, int &) const;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct Boxvar
 | 
			
		||||
{
 | 
			
		||||
    const char *text;
 | 
			
		||||
    bool *variable;
 | 
			
		||||
    // CrossBox *cb;
 | 
			
		||||
    QCheckBox *cb;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static Boxvar general_boxes[] = {
 | 
			
		||||
    // {"Graphic Load Display", &Qps::show_load_graph, 0},
 | 
			
		||||
    // {"Graphic CPU Display", &Qps::show_cpu_bar, 0},
 | 
			
		||||
    //{"Minimized on Close Button", &Qps::flag_systray, 0},
 | 
			
		||||
    {"Exit On Close Button", &Qps::flag_exit, 0},
 | 
			
		||||
 | 
			
		||||
    // TEMPO
 | 
			
		||||
    //  {"Use Tab-View", &Qps::flag_useTabView, 0},
 | 
			
		||||
    //   {"Hide qps in Linear mode", &Qps::flag_qps_hide, 0},
 | 
			
		||||
    //  {"Load Graph in Icon", &Qps::load_in_icon, 0},
 | 
			
		||||
    //  {"Selection: Copy PIDs to Clipboard", &Qps::pids_to_selection, 0},
 | 
			
		||||
    //   {"show underdevelopment ", &Qps::flag_devel, 0},
 | 
			
		||||
    //   {"Vertical CPU Bar (under development)", &Qps::vertical_cpu_bar, 0},
 | 
			
		||||
    {0, 0, 0}};
 | 
			
		||||
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
static Boxvar sockinfo_boxes[] = {
 | 
			
		||||
    {"Host Name Lookup", &Qps::hostname_lookup, 0},
 | 
			
		||||
    {"Service Name Lookup", &Qps::service_lookup, 0},
 | 
			
		||||
    {0, 0, 0}};
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static Boxvar tree_boxes[] = {{"Disclosure Triangles", &Qps::tree_gadgets, 0},
 | 
			
		||||
                              {"Branch Lines", &Qps::tree_lines, 0},
 | 
			
		||||
                              {0, 0, 0}};
 | 
			
		||||
 | 
			
		||||
static Boxvar misc_boxes[] = {
 | 
			
		||||
    {"Auto Save Settings on Exit", &Qps::auto_save_options, 0},
 | 
			
		||||
    {"Selection: Copy PIDs to Clipboard", &Qps::pids_to_selection, 0},
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
    {"Normalize NICE", &Qps::normalize_nice, 0},
 | 
			
		||||
    {"Use pmap for Map Names", &Qps::use_pmap, 0},
 | 
			
		||||
#endif
 | 
			
		||||
    {0, 0, 0}};
 | 
			
		||||
 | 
			
		||||
struct Cbgroup
 | 
			
		||||
{
 | 
			
		||||
    const char *caption;
 | 
			
		||||
    Boxvar *boxvar;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static Cbgroup groups[] = {{"General", general_boxes},
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
//    {"Socket Info Window", sockinfo_boxes},
 | 
			
		||||
#endif
 | 
			
		||||
                           //   {"Tree View", tree_boxes},
 | 
			
		||||
                           //    {"Miscellaneous", misc_boxes},
 | 
			
		||||
                           {0, 0}};
 | 
			
		||||
 | 
			
		||||
void find_fontsets();
 | 
			
		||||
// dual use function: both validate and apply changes
 | 
			
		||||
QValidator::State Swapvalid::validate(QString &s, int &) const
 | 
			
		||||
{
 | 
			
		||||
    // only accept /^[0-9]*[%kKmM]?$/
 | 
			
		||||
    int len = s.length();
 | 
			
		||||
    int i = 0;
 | 
			
		||||
    while (i < len && s[i] >= '0' && s[i] <= '9')
 | 
			
		||||
        i++;
 | 
			
		||||
    if ((i < len && QString("kKmM%").contains(s[i]) == 0) || i < len - 1)
 | 
			
		||||
        return Invalid;
 | 
			
		||||
    if (s[i] == 'k')
 | 
			
		||||
        s[i] = 'K';
 | 
			
		||||
    if (s[i] == 'm')
 | 
			
		||||
        s[i] = 'M';
 | 
			
		||||
    // int val = atoi((const char *)s);
 | 
			
		||||
    int val = s.toInt();
 | 
			
		||||
    bool percent;
 | 
			
		||||
    if (s[i] == '%')
 | 
			
		||||
    {
 | 
			
		||||
        percent = true;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        percent = false;
 | 
			
		||||
        if (s[i] == 'M')
 | 
			
		||||
            val <<= 10;
 | 
			
		||||
    }
 | 
			
		||||
    Qps::swaplimit = val;
 | 
			
		||||
    Qps::swaplim_percent = percent;
 | 
			
		||||
    return Acceptable;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Preferences::Preferences() : QDialog()
 | 
			
		||||
{
 | 
			
		||||
    int flag_test = 0;
 | 
			
		||||
    setWindowTitle("Preferences");
 | 
			
		||||
    QVBoxLayout *v_layout = new QVBoxLayout;
 | 
			
		||||
 | 
			
		||||
    if (flag_test)
 | 
			
		||||
    {
 | 
			
		||||
        QTabWidget *tbar = new QTabWidget(this);
 | 
			
		||||
        QWidget *w = new QWidget(this);
 | 
			
		||||
        tbar->addTab(w, "&Setting");
 | 
			
		||||
        w->setLayout(v_layout);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
        setLayout(v_layout);
 | 
			
		||||
 | 
			
		||||
    v_layout->setSpacing(1);
 | 
			
		||||
    // v_layout->setSpacing(1);
 | 
			
		||||
    const int border_x = 10;
 | 
			
		||||
    int min_x = 0;
 | 
			
		||||
 | 
			
		||||
    for (Cbgroup *g = groups; g->caption; g++)
 | 
			
		||||
    {
 | 
			
		||||
        QGroupBox *grp = new QGroupBox(g->caption, this);
 | 
			
		||||
        QVBoxLayout *vbox = new QVBoxLayout;
 | 
			
		||||
        for (Boxvar *b = g->boxvar; b->text; b++)
 | 
			
		||||
        {
 | 
			
		||||
            b->cb = new QCheckBox(b->text, grp);
 | 
			
		||||
            vbox->addWidget(b->cb);
 | 
			
		||||
            connect(b->cb, SIGNAL(clicked()), SLOT(update_reality()));
 | 
			
		||||
            // -> EMIT prefs_change()
 | 
			
		||||
        }
 | 
			
		||||
        grp->setLayout(vbox);
 | 
			
		||||
        v_layout->addWidget(grp);
 | 
			
		||||
    }
 | 
			
		||||
    update_boxes();
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
    QGroupBox *wgrp = new QGroupBox("Swap Warning", this);
 | 
			
		||||
  QHBoxLayout *hl = new QHBoxLayout;
 | 
			
		||||
    wgrp->setLayout(hl);
 | 
			
		||||
    QLabel *lbl = new QLabel("Warn when free swap below", wgrp);
 | 
			
		||||
    QLineEdit *swaped = new QLineEdit(wgrp);
 | 
			
		||||
  hl->addWidget(lbl);
 | 
			
		||||
  hl->addWidget(swaped);
 | 
			
		||||
    //swaped->setAlignment (  Qt::AlignRight );
 | 
			
		||||
    QString s;
 | 
			
		||||
    if(Qps::swaplim_percent) {
 | 
			
		||||
            s.sprintf("%d%%", Qps::swaplimit);
 | 
			
		||||
    } else {
 | 
			
		||||
            if(Qps::swaplimit >= 1024 && (Qps::swaplimit & 0x7ff) == 0)
 | 
			
		||||
                    s.sprintf("%dM", Qps::swaplimit >> 10);
 | 
			
		||||
            else
 | 
			
		||||
                    s.sprintf("%dK", Qps::swaplimit);
 | 
			
		||||
    }
 | 
			
		||||
    swaped->setText(s);
 | 
			
		||||
    swaped->setValidator(new Swapvalid(this));
 | 
			
		||||
    connect(swaped, SIGNAL(textChanged(const QString &)),
 | 
			
		||||
  SIGNAL(prefs_change()));
 | 
			
		||||
    v_layout->addWidget(wgrp);
 | 
			
		||||
    */
 | 
			
		||||
 | 
			
		||||
    rb_totalcpu = NULL; // tmp
 | 
			
		||||
 | 
			
		||||
    if (QPS_PROCVIEW_CPU_NUM() > 1)
 | 
			
		||||
    {
 | 
			
		||||
        QGroupBox *grp_cpu = new QGroupBox("%CPU divided by", this);
 | 
			
		||||
        QVBoxLayout *vboxlayout = new QVBoxLayout;
 | 
			
		||||
        QHBoxLayout *hbox = new QHBoxLayout;
 | 
			
		||||
        vboxlayout->addLayout(hbox);
 | 
			
		||||
 | 
			
		||||
        // num_cpus
 | 
			
		||||
        QString str;
 | 
			
		||||
        str.sprintf("Total cpu: %d", QPS_PROCVIEW_CPU_NUM());
 | 
			
		||||
        rb_totalcpu = new QRadioButton(str, grp_cpu);
 | 
			
		||||
        QRadioButton *rb2 = new QRadioButton("Single cpu: 1", grp_cpu);
 | 
			
		||||
        if (!Procview::flag_pcpu_single)
 | 
			
		||||
            rb_totalcpu->setChecked(true);
 | 
			
		||||
        else
 | 
			
		||||
            rb2->setChecked(true);
 | 
			
		||||
 | 
			
		||||
        rb_totalcpu->setToolTip("default");
 | 
			
		||||
        rb2->setToolTip("for developer");
 | 
			
		||||
        hbox->addWidget(rb_totalcpu);
 | 
			
		||||
        hbox->addWidget(rb2);
 | 
			
		||||
        grp_cpu->setLayout(vboxlayout);
 | 
			
		||||
        v_layout->addWidget(grp_cpu);
 | 
			
		||||
 | 
			
		||||
        connect(rb_totalcpu, SIGNAL(clicked()), this, SLOT(update_config()));
 | 
			
		||||
        connect(rb2, SIGNAL(clicked()), this, SLOT(update_config()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Appearance ====================================
 | 
			
		||||
    if (font_cb == NULL)
 | 
			
		||||
    {
 | 
			
		||||
        font_cb = new QFontComboBox(this); // preload
 | 
			
		||||
        font_cb->setWritingSystem(QFontDatabase::Latin);
 | 
			
		||||
        font_cb->setCurrentFont(QApplication::font());
 | 
			
		||||
 | 
			
		||||
        // remove Some Ugly Font : hershey...
 | 
			
		||||
        // printf("size=%d\n",font_cb->count());
 | 
			
		||||
        for (int i = 0; i < font_cb->count();)
 | 
			
		||||
        {
 | 
			
		||||
            QString name = font_cb->itemText(i);
 | 
			
		||||
            if (name.contains("hershey", Qt::CaseInsensitive) == true)
 | 
			
		||||
            {
 | 
			
		||||
                //		printf("%s\n",qPrintable(name));
 | 
			
		||||
                font_cb->removeItem(i);
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
                i++;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (font_cb)
 | 
			
		||||
    {
 | 
			
		||||
        font_cb->show();
 | 
			
		||||
 | 
			
		||||
        QGroupBox *gbox = new QGroupBox("Appearance", this);
 | 
			
		||||
        QVBoxLayout *vbox = new QVBoxLayout;
 | 
			
		||||
        QHBoxLayout *hbox = new QHBoxLayout();
 | 
			
		||||
 | 
			
		||||
        psizecombo = new QComboBox(this);
 | 
			
		||||
        hbox->addWidget(font_cb);
 | 
			
		||||
        hbox->addWidget(psizecombo);
 | 
			
		||||
        vbox->addLayout(hbox);
 | 
			
		||||
        gbox->setLayout(vbox);
 | 
			
		||||
        v_layout->addWidget(gbox);
 | 
			
		||||
 | 
			
		||||
        // connect(font_cb, SIGNAL(activated( int)),this,
 | 
			
		||||
        // SLOT(font_changed(int)));
 | 
			
		||||
        connect(font_cb, SIGNAL(activated(int)), this, SLOT(font_changed(int)));
 | 
			
		||||
        connect(psizecombo, SIGNAL(activated(int)), SLOT(font_changed(int)));
 | 
			
		||||
 | 
			
		||||
        // add to font size
 | 
			
		||||
        init_font_size();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
    // Style, Themes ==================================
 | 
			
		||||
    QLabel *label3 = new QLabel("Themes", font_grp);
 | 
			
		||||
    QComboBox *theme_combo = new QComboBox(font_grp);
 | 
			
		||||
 | 
			
		||||
    QStringList styles = QStyleFactory::keys();
 | 
			
		||||
  styles.sort();
 | 
			
		||||
  theme_combo->insertStringList(styles);
 | 
			
		||||
 | 
			
		||||
    QString currentstyle;
 | 
			
		||||
    currentstyle = QApplication::style().className();
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
    QPushButton *saveButton = new QPushButton("OK", this);
 | 
			
		||||
    // saveButton->setFocusPolicy(QWidget::NoFocus);
 | 
			
		||||
    saveButton->setFocus();
 | 
			
		||||
    saveButton->setDefault(true);
 | 
			
		||||
    v_layout->addWidget(saveButton);
 | 
			
		||||
    // v_layout->freeze();
 | 
			
		||||
 | 
			
		||||
    connect(saveButton, SIGNAL(clicked()), SLOT(closed()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
void Preferences::init_font_size()
 | 
			
		||||
{
 | 
			
		||||
    // 	QFontDatabase db;
 | 
			
		||||
    //	QStringList families ( WritingSystem writingSystem = Any ) const
 | 
			
		||||
    //	QStringList families = db.families(QFontDatabase::Latin);
 | 
			
		||||
    //	QStringList extra;
 | 
			
		||||
    psizecombo->clear();
 | 
			
		||||
    int i, idx = 0;
 | 
			
		||||
    for (i = 5; i < 24; i++)
 | 
			
		||||
        psizecombo->insertItem(idx++, QString::number(i));
 | 
			
		||||
 | 
			
		||||
    // find current font size
 | 
			
		||||
    i = 0;
 | 
			
		||||
    for (int psize = QApplication::font().pointSize(); i < psizecombo->count();
 | 
			
		||||
         ++i)
 | 
			
		||||
    {
 | 
			
		||||
        const int sz = psizecombo->itemText(i).toInt();
 | 
			
		||||
        if (sz == psize)
 | 
			
		||||
        {
 | 
			
		||||
            psizecombo->setCurrentIndex(i);
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// slot: update check boxes to reflect current status
 | 
			
		||||
void Preferences::update_boxes()
 | 
			
		||||
{
 | 
			
		||||
    for (Cbgroup *g = groups; g->caption; g++)
 | 
			
		||||
        for (Boxvar *b = g->boxvar; b->text; b++)
 | 
			
		||||
            b->cb->setChecked(*b->variable);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// slot: update flags and repaint to reflect state of check boxes
 | 
			
		||||
void Preferences::update_reality()
 | 
			
		||||
{
 | 
			
		||||
    for (Cbgroup *g = groups; g->caption; g++)
 | 
			
		||||
        for (Boxvar *b = g->boxvar; b->text; b++)
 | 
			
		||||
            *b->variable = b->cb->isChecked();
 | 
			
		||||
    emit prefs_change();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Preferences::update_config()
 | 
			
		||||
{
 | 
			
		||||
    if (rb_totalcpu and rb_totalcpu->isChecked() == true)
 | 
			
		||||
        Procview::flag_pcpu_single = false;
 | 
			
		||||
    else
 | 
			
		||||
        Procview::flag_pcpu_single = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Preferences::closed()
 | 
			
		||||
{
 | 
			
		||||
    //	delete font_cb;	font_cb==NULL;
 | 
			
		||||
    //	font_cb->clear();
 | 
			
		||||
    update_config();
 | 
			
		||||
    hide();
 | 
			
		||||
    emit prefs_change();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// work
 | 
			
		||||
void Preferences::font_changed(int i)
 | 
			
		||||
{
 | 
			
		||||
    int size = psizecombo->currentText().toInt();
 | 
			
		||||
    QFont font = font_cb->currentFont();
 | 
			
		||||
    font.setPointSize(size);
 | 
			
		||||
 | 
			
		||||
    QApplication::setFont(font);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DRAFT CODE:
 | 
			
		||||
void Preferences::fontset_changed(int i) {}
 | 
			
		||||
							
								
								
									
										37
									
								
								src/prefs.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,37 @@
 | 
			
		||||
// prefs.h				emacs, this is written in -*-c++-*-
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#ifndef PREFS_H
 | 
			
		||||
#define PREFS_H
 | 
			
		||||
 | 
			
		||||
#include <qdialog.h>
 | 
			
		||||
#include <qradiobutton.h>
 | 
			
		||||
#include <qlabel.h>
 | 
			
		||||
//#include <q3buttongroup.h>
 | 
			
		||||
#include <QtGui>
 | 
			
		||||
#include "misc.h"
 | 
			
		||||
 | 
			
		||||
class Preferences : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    Preferences();
 | 
			
		||||
    QComboBox *psizecombo;
 | 
			
		||||
    //    QFontComboBox *font_cb;
 | 
			
		||||
    QRadioButton *rb_totalcpu;
 | 
			
		||||
    void init_font_size();
 | 
			
		||||
 | 
			
		||||
  public slots:
 | 
			
		||||
    void update_boxes();
 | 
			
		||||
    void update_reality();
 | 
			
		||||
    void update_config();
 | 
			
		||||
    void closed();
 | 
			
		||||
    void font_changed(int);
 | 
			
		||||
    void fontset_changed(int);
 | 
			
		||||
signals:
 | 
			
		||||
    void prefs_change();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // PREFS_H
 | 
			
		||||
							
								
								
									
										2255
									
								
								src/proc.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										873
									
								
								src/proc.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,873 @@
 | 
			
		||||
// proc.h
 | 
			
		||||
// emacs, this is written in -*-c++-*- (who?)
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdeg?rd, 1997-1999
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#ifndef PROC_H
 | 
			
		||||
#define PROC_H
 | 
			
		||||
 | 
			
		||||
#include "config.h"
 | 
			
		||||
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
#include <kstat.h> // kstat_ctl_t
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef USING_PCH
 | 
			
		||||
#include <QHash>
 | 
			
		||||
#include <QVector>
 | 
			
		||||
#include <QString>
 | 
			
		||||
#include <QStringList>
 | 
			
		||||
#include <QDir>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
class Procinfo;
 | 
			
		||||
int read_file(char *name, char *buf, int max);
 | 
			
		||||
int read_file_addNULL(char *name, void *buf, int max);
 | 
			
		||||
void check_system_requirement();
 | 
			
		||||
int get_kernel_version();
 | 
			
		||||
 | 
			
		||||
//#define F_PID 0x00000000
 | 
			
		||||
enum fields
 | 
			
		||||
{
 | 
			
		||||
    F_PID = 0,
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    F_TGID,
 | 
			
		||||
#endif
 | 
			
		||||
    F_PPID,
 | 
			
		||||
    F_PGID,
 | 
			
		||||
    F_SID,
 | 
			
		||||
    F_TTY,
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    F_TPGID,
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef MOSIX
 | 
			
		||||
    F_MIGR,
 | 
			
		||||
    F_LOCKED,
 | 
			
		||||
    F_NMIGS,
 | 
			
		||||
    F_NOMOVE,
 | 
			
		||||
    F_RPID,
 | 
			
		||||
#endif
 | 
			
		||||
    F_USER,
 | 
			
		||||
    F_GROUP,
 | 
			
		||||
    F_UID,
 | 
			
		||||
    F_EUID,
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    F_SUID,
 | 
			
		||||
    F_FSUID,
 | 
			
		||||
#endif
 | 
			
		||||
    F_GID,
 | 
			
		||||
    F_EGID,
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    F_SGID,
 | 
			
		||||
    F_FSGID,
 | 
			
		||||
#endif
 | 
			
		||||
    F_PRI,
 | 
			
		||||
    F_NICE,
 | 
			
		||||
    F_PLCY,
 | 
			
		||||
    F_RPRI,
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    F_TMS,
 | 
			
		||||
    F_AFFCPU,
 | 
			
		||||
    F_SLPAVG,
 | 
			
		||||
#endif
 | 
			
		||||
    F_NLWP,
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
    F_ARCH,
 | 
			
		||||
#endif
 | 
			
		||||
    F_MAJFLT,
 | 
			
		||||
    F_MINFLT,
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    F_TRS,
 | 
			
		||||
    F_DRS,
 | 
			
		||||
    F_STACK,
 | 
			
		||||
#endif
 | 
			
		||||
    F_SIZE, // VSIZE
 | 
			
		||||
    F_SWAP, // Linux not correct
 | 
			
		||||
    F_MEM,
 | 
			
		||||
    F_RSS,
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    F_SHARE,
 | 
			
		||||
    F_DT,
 | 
			
		||||
    F_IOW,
 | 
			
		||||
    F_IOR,
 | 
			
		||||
#endif
 | 
			
		||||
    F_STAT,
 | 
			
		||||
    F_FLAGS,
 | 
			
		||||
    F_WCHAN,
 | 
			
		||||
    F_WCPU,
 | 
			
		||||
    F_CPU,  /* %CPU */
 | 
			
		||||
    F_PMEM, // F_PMEM: %MEM
 | 
			
		||||
    F_START,
 | 
			
		||||
    F_TIME,
 | 
			
		||||
    F_CPUNUM,
 | 
			
		||||
    F_CMD,
 | 
			
		||||
    F_PROCESSNAME, // NEW
 | 
			
		||||
    F_CWD,
 | 
			
		||||
    F_ROOT, //?
 | 
			
		||||
    F_CMDLINE,
 | 
			
		||||
    F_END = -1
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Details;
 | 
			
		||||
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
 | 
			
		||||
class Sockinfo
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    enum proto_t
 | 
			
		||||
    {
 | 
			
		||||
        TCP,
 | 
			
		||||
        UDP
 | 
			
		||||
    };
 | 
			
		||||
    proto_t proto;
 | 
			
		||||
    unsigned char st;
 | 
			
		||||
    unsigned char tr;
 | 
			
		||||
    unsigned local_addr;
 | 
			
		||||
    unsigned rem_addr;
 | 
			
		||||
    unsigned short local_port;
 | 
			
		||||
    unsigned short rem_port;
 | 
			
		||||
    unsigned tx_queue;
 | 
			
		||||
    unsigned rx_queue;
 | 
			
		||||
    unsigned tm_when;
 | 
			
		||||
    unsigned rexmits;
 | 
			
		||||
    int uid; //??
 | 
			
		||||
    int pid;
 | 
			
		||||
    int timeout;
 | 
			
		||||
    int inode;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class SockInode
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    SockInode(int descr, unsigned long ino) : fd(descr), inode(ino){};
 | 
			
		||||
    int fd;
 | 
			
		||||
    unsigned long inode;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class UnixSocket
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    unsigned long inode;
 | 
			
		||||
    QString name;
 | 
			
		||||
    unsigned flags;
 | 
			
		||||
    unsigned char type;  // SOCK_STREAM or SOCK_DGRAM
 | 
			
		||||
    unsigned char state; // SS_FREE, SS_UNCONNECTED, SS_CONNECTING,
 | 
			
		||||
                         // SS_CONNECTED, SS_DISCONNECTING
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // LINUX
 | 
			
		||||
 | 
			
		||||
// COMMON
 | 
			
		||||
class Mapsinfo
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    unsigned long from, to;
 | 
			
		||||
    unsigned long offset;
 | 
			
		||||
    unsigned long inode;
 | 
			
		||||
    QString filename; // null if name unknown
 | 
			
		||||
    char perm[4];     // "rwx[ps]"; last is private/shared flag
 | 
			
		||||
    unsigned minor, major;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define OPEN_READ 1
 | 
			
		||||
#define OPEN_WRITE 2
 | 
			
		||||
 | 
			
		||||
class Fileinfo
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Fileinfo(int descr, QString name, int open_mode = 0)
 | 
			
		||||
        : fd(descr), filename(name), mode(open_mode){};
 | 
			
		||||
    int fd;
 | 
			
		||||
    QString filename; // "major:minor inode" in Linux 2.0,
 | 
			
		||||
    // texual description in Solaris 2.6
 | 
			
		||||
    unsigned mode; // bits from OPEN_* above (Linux only)
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class NameValue
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    NameValue(){};
 | 
			
		||||
    // NameValue(const NameValue &nv){ name=nv.name; value=nv.value; };
 | 
			
		||||
    NameValue(const char *n, const char *val) : name(n), value(val){};
 | 
			
		||||
    QString name;
 | 
			
		||||
    QString value;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Category
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Category(const char *heading, const char *explain)
 | 
			
		||||
        : name(heading), help(explain), reversed(false),
 | 
			
		||||
          flag_int_value(false){};
 | 
			
		||||
    virtual ~Category();
 | 
			
		||||
 | 
			
		||||
    virtual int alignment() = 0;
 | 
			
		||||
    virtual QString string(Procinfo *p) = 0;
 | 
			
		||||
    virtual int width() = 0;
 | 
			
		||||
    virtual int compare(Procinfo *a, Procinfo *b);
 | 
			
		||||
 | 
			
		||||
    const char *name;
 | 
			
		||||
    const char *help;
 | 
			
		||||
    int index;
 | 
			
		||||
    int id;
 | 
			
		||||
    bool reversed;       // testing
 | 
			
		||||
    bool flag_int_value; // testing: for total sum , cat_memory , cat_int
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// COMMON
 | 
			
		||||
class Cat_int : public Category
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_int(const char *heading, const char *explain, int w,
 | 
			
		||||
            int Procinfo::*member);
 | 
			
		||||
    virtual int alignment() { return Qt::AlignRight; };
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
    virtual int width() { return field_width; };
 | 
			
		||||
    virtual int compare(Procinfo *a, Procinfo *b);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    int Procinfo::*int_member;
 | 
			
		||||
    int field_width;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// COMMON  for memory usage
 | 
			
		||||
class Cat_memory : public Category
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_memory(const char *heading, const char *explain, int w,
 | 
			
		||||
               unsigned long Procinfo::*member);
 | 
			
		||||
    virtual int alignment() { return Qt::AlignRight; };
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
    virtual int width() { return field_width; };
 | 
			
		||||
    virtual int compare(Procinfo *a, Procinfo *b);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    unsigned long Procinfo::*uintl_member;
 | 
			
		||||
    int field_width;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_uintl : public Category
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_uintl(const char *heading, const char *explain, int w,
 | 
			
		||||
              unsigned long Procinfo::*member);
 | 
			
		||||
    virtual int alignment() { return Qt::AlignRight; };
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
    virtual int width() { return field_width; };
 | 
			
		||||
    virtual int compare(Procinfo *a, Procinfo *b);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    unsigned long Procinfo::*uintl_member;
 | 
			
		||||
    int field_width;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_hex : public Cat_uintl
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_hex(const char *heading, const char *explain, int w,
 | 
			
		||||
            unsigned long Procinfo::*member);
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_swap : public Category
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_swap(const char *heading, const char *explain);
 | 
			
		||||
    virtual int alignment() { return Qt::AlignRight; };
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
    virtual int width() { return 8; };
 | 
			
		||||
    virtual int compare(Procinfo *a, Procinfo *b);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_string : public Category
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_string(const char *heading, const char *explain,
 | 
			
		||||
               QString Procinfo::*member = 0);
 | 
			
		||||
    virtual int alignment() { return Qt::AlignLeft; };
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
    virtual int width() { return -9; };
 | 
			
		||||
    virtual int gap() { return 8; };
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    QString Procinfo::*str_member;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_user : public Cat_string
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_user(const char *heading, const char *explain);
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_group : public Cat_string
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_group(const char *heading, const char *explain);
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_wchan : public Cat_string
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_wchan(const char *heading, const char *explain);
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_dir : public Cat_string
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_dir(const char *heading, const char *explain, const char *dirname,
 | 
			
		||||
            QString Procinfo::*member);
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    const char *dir;
 | 
			
		||||
    QString Procinfo::*cache;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_cmdline : public Cat_string
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_cmdline(const char *heading, const char *explain);
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_state : public Category
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_state(const char *heading, const char *explain);
 | 
			
		||||
    virtual int alignment() { return Qt::AlignLeft; };
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
    virtual int width() { return 6; };
 | 
			
		||||
    virtual int gap() { return 8; };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_policy : public Category
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_policy(const char *heading, const char *explain);
 | 
			
		||||
    virtual int alignment() { return Qt::AlignLeft; };
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
    virtual int width() { return 3; };
 | 
			
		||||
    virtual int gap() { return 8; };
 | 
			
		||||
    virtual int compare(Procinfo *a, Procinfo *b);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_rtprio : public Category
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_rtprio(const char *heading, const char *explain);
 | 
			
		||||
    virtual int alignment() { return Qt::AlignRight; };
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
    virtual int width() { return 5; };
 | 
			
		||||
    virtual int compare(Procinfo *a, Procinfo *b);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
class Cat_tms : public Category
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_tms(const char *heading, const char *explain);
 | 
			
		||||
    virtual int alignment() { return Qt::AlignRight; };
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
    virtual int width() { return 5; };
 | 
			
		||||
    virtual int compare(Procinfo *a, Procinfo *b);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_affcpu : public Category
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_affcpu(const char *heading, const char *explain);
 | 
			
		||||
    virtual int alignment() { return Qt::AlignRight; };
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
    virtual int width() { return 8; };
 | 
			
		||||
    // virtual int compare(Procinfo *a, Procinfo *b);
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
class Cat_time : public Category
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_time(const char *heading, const char *explain);
 | 
			
		||||
    virtual int alignment() { return Qt::AlignRight; };
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
    virtual int width() { return 7; };
 | 
			
		||||
    virtual int compare(Procinfo *a, Procinfo *b);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_start : public Category
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_start(const char *heading, const char *explain);
 | 
			
		||||
    virtual int alignment() { return Qt::AlignRight; };
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
    virtual int width() { return 8; };
 | 
			
		||||
    virtual int compare(Procinfo *a, Procinfo *b);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_percent : public Category
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_percent(const char *heading, const char *explain, int w,
 | 
			
		||||
                float Procinfo::*member);
 | 
			
		||||
    virtual int alignment() { return Qt::AlignRight; };
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
    virtual int width() { return field_width; };
 | 
			
		||||
    virtual int compare(Procinfo *a, Procinfo *b);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    float Procinfo::*float_member;
 | 
			
		||||
    int field_width;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Cat_tty : public Cat_string
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Cat_tty(const char *heading, const char *explain);
 | 
			
		||||
    virtual QString string(Procinfo *p);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define CPU_TIMES(cpu, kind) cpu_times_vec[cpu * CPUTIMES + kind]
 | 
			
		||||
class Proc;
 | 
			
		||||
 | 
			
		||||
class Procinfo // Process Infomation
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Procinfo(Proc *system_proc, int pid, int thread_id = -1);
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
    //	Procinfo(int pid);  //solaris !
 | 
			
		||||
    //	Procinfo(int pid, int thread);  //solaris !
 | 
			
		||||
    int readproc(int pid, int lwp);
 | 
			
		||||
#endif
 | 
			
		||||
    ~Procinfo();
 | 
			
		||||
    Procinfo *ref()
 | 
			
		||||
    {
 | 
			
		||||
        refcnt++;
 | 
			
		||||
        return this;
 | 
			
		||||
    };
 | 
			
		||||
    void deref()
 | 
			
		||||
    {
 | 
			
		||||
        if (!--refcnt)
 | 
			
		||||
            delete this;
 | 
			
		||||
    };
 | 
			
		||||
    Proc *proc;
 | 
			
		||||
 | 
			
		||||
    inline void calculate_cpu();
 | 
			
		||||
 | 
			
		||||
    int readproc();
 | 
			
		||||
 | 
			
		||||
    bool isThread();
 | 
			
		||||
    void read_fd(int fdnum, char *path);
 | 
			
		||||
    bool read_fds();
 | 
			
		||||
    bool read_maps();
 | 
			
		||||
    bool read_environ();
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
    void read_pmap_maps();
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef MOSIX
 | 
			
		||||
    static void check_for_mosix();
 | 
			
		||||
    static Svec<int> mosix_nodes();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    int get_policy();
 | 
			
		||||
    int get_rtprio();
 | 
			
		||||
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    double get_tms();
 | 
			
		||||
    unsigned long get_affcpu();
 | 
			
		||||
 | 
			
		||||
    QVector<SockInode *> sock_inodes; // socket inodes or NULL if not read
 | 
			
		||||
#endif
 | 
			
		||||
    int pid;
 | 
			
		||||
    bool clone;
 | 
			
		||||
 | 
			
		||||
    bool first_run;        // for optimization
 | 
			
		||||
    char hashstr[128 * 8]; // cache
 | 
			
		||||
    int hashlen;
 | 
			
		||||
    int hashcmp(char *str);
 | 
			
		||||
 | 
			
		||||
    QString command;   // COMMAND
 | 
			
		||||
    QString cmdline;   // COMMAND_LINE
 | 
			
		||||
    QString username;  //
 | 
			
		||||
    QString groupname; //
 | 
			
		||||
    QString cwd;       // null if not read
 | 
			
		||||
    QString root;      // null if not read
 | 
			
		||||
 | 
			
		||||
    bool accepted;
 | 
			
		||||
    int test_stop; // for test
 | 
			
		||||
    int session;   //	???
 | 
			
		||||
 | 
			
		||||
    int uid, euid;
 | 
			
		||||
    int gid, egid;
 | 
			
		||||
 | 
			
		||||
    char state;
 | 
			
		||||
    int ppid; // Parent's PID
 | 
			
		||||
    int pgrp;
 | 
			
		||||
    dev_t tty; // tty major:minor device
 | 
			
		||||
    int type;  // TESTING X,NETWORK,FILE_OPEN,TERMINAL(tty),THREAD,
 | 
			
		||||
 | 
			
		||||
    int nthreads; // number of threads : LWP(Solaris), task(Linux)
 | 
			
		||||
    int tgid;     // thread leader's id
 | 
			
		||||
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    double tms; // slice time
 | 
			
		||||
    int slpavg;
 | 
			
		||||
    unsigned long affcpu;
 | 
			
		||||
 | 
			
		||||
    int suid, fsuid;
 | 
			
		||||
    int sgid, fsgid;
 | 
			
		||||
    int tpgid;
 | 
			
		||||
 | 
			
		||||
    unsigned long cminflt;
 | 
			
		||||
    unsigned long cmajflt;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    unsigned long io_read;       // byte, testing
 | 
			
		||||
    unsigned long io_write;      // testing
 | 
			
		||||
    unsigned long io_read_KBps;  // K byte/sec
 | 
			
		||||
    unsigned long io_write_KBps; // K byte/sec
 | 
			
		||||
    unsigned long io_read_prev, io_write_prev;
 | 
			
		||||
 | 
			
		||||
    unsigned long flags; //?
 | 
			
		||||
    unsigned long minflt;
 | 
			
		||||
    unsigned long majflt;
 | 
			
		||||
 | 
			
		||||
    long utime;
 | 
			
		||||
    long old_utime; // initial value = -1 ;
 | 
			
		||||
    long cutime;
 | 
			
		||||
    int priority;
 | 
			
		||||
    int nice;
 | 
			
		||||
    unsigned long starttime; // start time since run in epoch? Linux : jiffies
 | 
			
		||||
                             // since boot , solaris
 | 
			
		||||
    unsigned long wchan;
 | 
			
		||||
    QString wchan_str;
 | 
			
		||||
 | 
			
		||||
    // Memory
 | 
			
		||||
    unsigned long mem;      // user Memory define
 | 
			
		||||
    unsigned long size;     // SIZE: total memory (K)
 | 
			
		||||
    unsigned long resident; // RSS: pages in resident set (non-swapped) (K)
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    unsigned long share; // shared memory pages (mmaped) (K)
 | 
			
		||||
    unsigned long trs;   // text resident set size (K)
 | 
			
		||||
    unsigned long lrs;   // shared-lib resident set size (K)
 | 
			
		||||
    unsigned long drs;   // data resident set size (K)
 | 
			
		||||
    unsigned long
 | 
			
		||||
        dt; // dirty pages (number of pages, not K), obsolute in Kernel 2.6
 | 
			
		||||
    unsigned long stack; // stack size (K)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
    int addr_bits; // address bits (32 or 64)
 | 
			
		||||
 | 
			
		||||
    char policy_name[2]; // two first letters of scheduling class
 | 
			
		||||
#endif
 | 
			
		||||
    struct timeval tv;     // time when the snapshot was taken
 | 
			
		||||
    struct timeval old_tv; //
 | 
			
		||||
 | 
			
		||||
    // Posix.1b scheduling
 | 
			
		||||
    int policy; // -1 = uninitialized
 | 
			
		||||
    int rtprio; // 0-99, higher can pre-empt lower (-1 = uninitialized)
 | 
			
		||||
 | 
			
		||||
    // Linux: the cpu used most of the time of the process
 | 
			
		||||
    // Solaris: the cpu on which the process last ran
 | 
			
		||||
    int which_cpu;
 | 
			
		||||
 | 
			
		||||
    // computed %cpu and %mem since last update
 | 
			
		||||
    float wcpu, old_wcpu; // %WCPUwheight cpu
 | 
			
		||||
    float pcpu;           // %CPU: percent cpu after last update
 | 
			
		||||
    float pmem;           // %MEM
 | 
			
		||||
 | 
			
		||||
    QVector<Fileinfo *> fd_files; // file names list
 | 
			
		||||
    QVector<Mapsinfo *> maps;     // maps list
 | 
			
		||||
    QVector<NameValue> environ;   // environment
 | 
			
		||||
    char *envblock;               // malloc()ed environment data block
 | 
			
		||||
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
    unsigned long env_ofs;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    Details *detail; // details window or NULL (backlink)
 | 
			
		||||
 | 
			
		||||
    unsigned int generation; // timestamp
 | 
			
		||||
 | 
			
		||||
    bool selected : 1;  // true if selected in current view
 | 
			
		||||
    bool hidekids : 1;  // true if children are hidden in tree view
 | 
			
		||||
    bool lastchild : 1; // true if last (visible) child in tree view
 | 
			
		||||
 | 
			
		||||
    short level;                  // distance from process root
 | 
			
		||||
    QVector<Procinfo *> children; // real child processes
 | 
			
		||||
    static const int MAX_CMD_LEN = 512;
 | 
			
		||||
 | 
			
		||||
    char refcnt;
 | 
			
		||||
 | 
			
		||||
    // virtual child for Table_Tree
 | 
			
		||||
    QVector<Procinfo *> table_children;
 | 
			
		||||
    int table_child_seq;
 | 
			
		||||
    int clear_gen;
 | 
			
		||||
    int child_seq_prev;
 | 
			
		||||
    int parent_row; // virtual parent for tree table
 | 
			
		||||
 | 
			
		||||
#ifdef MOSIX
 | 
			
		||||
    bool isremote;
 | 
			
		||||
    int from;
 | 
			
		||||
    int where;
 | 
			
		||||
    int remotepid;
 | 
			
		||||
    QString migr; // String explaining migration "node>" or ">node"
 | 
			
		||||
    int nmigs;
 | 
			
		||||
    int locked;
 | 
			
		||||
    QString cantmove;
 | 
			
		||||
    static bool mosix_running; // true if MOSIX is running
 | 
			
		||||
#endif
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef QHash<int, Procinfo *> Proclist;
 | 
			
		||||
 | 
			
		||||
class SysHistory
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    int idx;
 | 
			
		||||
    time_t time; // saved time, epoch...
 | 
			
		||||
    int current_gen;
 | 
			
		||||
    float load_cpu; // %CPU total ; green
 | 
			
		||||
    float load_mem; // %mem 	; yellow?
 | 
			
		||||
    float load_io;  // %SYS_IO 	; BLUE
 | 
			
		||||
    float load_net; //	;blue?	orange?
 | 
			
		||||
    Proclist procs;
 | 
			
		||||
    ~SysHistory();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// for A System
 | 
			
		||||
// cf. Procinfo is for a Process
 | 
			
		||||
//
 | 
			
		||||
class Proc
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Proc();
 | 
			
		||||
    ~Proc();
 | 
			
		||||
    void commonPostInit(); // COMMON
 | 
			
		||||
    void read_proc_all();  // test
 | 
			
		||||
    void refresh();
 | 
			
		||||
 | 
			
		||||
    static void init_static();
 | 
			
		||||
    int read_system();
 | 
			
		||||
    int countCpu();
 | 
			
		||||
    void read_loadavg();
 | 
			
		||||
 | 
			
		||||
    int read_pid_tasks(int pid);
 | 
			
		||||
 | 
			
		||||
    Category *cat_by_name(const char *s);
 | 
			
		||||
    int field_id_by_name(const char *s);
 | 
			
		||||
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    /* 	from /proc/net/{tcp,udp,unix}  */
 | 
			
		||||
    QHash<int, Sockinfo *> socks;    // tcp/udp sockets
 | 
			
		||||
    QHash<int, UnixSocket *> usocks; // unix domain sockets
 | 
			
		||||
    bool socks_current;              // true if the socks list is current
 | 
			
		||||
    bool usocks_current;             // true if the usocks list is current
 | 
			
		||||
 | 
			
		||||
    bool read_socket_list(Sockinfo::proto_t proto, const char *pseudofile);
 | 
			
		||||
    void read_sockets();
 | 
			
		||||
    bool read_usocket_list();
 | 
			
		||||
    void read_usockets();
 | 
			
		||||
    void invalidate_sockets();
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
    static kstat_ctl_t *kc; // NULL if kstat not opened
 | 
			
		||||
#endif
 | 
			
		||||
    QHash<int, Category *> categories;
 | 
			
		||||
 | 
			
		||||
    Proclist procs; // processes indexed by pid
 | 
			
		||||
 | 
			
		||||
    // TESTING
 | 
			
		||||
    QString supasswd; // test
 | 
			
		||||
    int syshistoryMAX;
 | 
			
		||||
    Proclist *hprocs; // temp_hprocs list
 | 
			
		||||
    Proclist *mprocs; //
 | 
			
		||||
    QList<SysHistory *> history;
 | 
			
		||||
 | 
			
		||||
    void setHistory(int tick);
 | 
			
		||||
    Proclist getHistory(int pos);
 | 
			
		||||
 | 
			
		||||
    int qps_pid;   // test
 | 
			
		||||
    float loadQps; // TEST
 | 
			
		||||
    static int update_msec;
 | 
			
		||||
 | 
			
		||||
    // class
 | 
			
		||||
    int num_cpus;     // current number of CPUs
 | 
			
		||||
    int old_num_cpus; // previous number of CPUs
 | 
			
		||||
 | 
			
		||||
    long num_network_process; //  number of network(socket) process
 | 
			
		||||
    long num_opened_files;    //  number of opened normal(not socket) files
 | 
			
		||||
    int num_process;          //  number of process
 | 
			
		||||
 | 
			
		||||
    long dt_total; //
 | 
			
		||||
    long dt_used;  //  cpu used time in clktick
 | 
			
		||||
 | 
			
		||||
    long read_byte;  //  test
 | 
			
		||||
    long write_byte; // test
 | 
			
		||||
    long io_byte;    // test file_io
 | 
			
		||||
 | 
			
		||||
    float load_cpu;   // %CPU total
 | 
			
		||||
    float loadavg[3]; // 1,5,15 minutes load avgs
 | 
			
		||||
 | 
			
		||||
    unsigned int clk_tick;  // the  number  of  clock ticks per second.
 | 
			
		||||
    unsigned int boot_time; // boot time in seconds since the Epoch
 | 
			
		||||
 | 
			
		||||
    int mem_total, mem_free;   // (Kb)
 | 
			
		||||
    int swap_total, swap_free; // in kB
 | 
			
		||||
 | 
			
		||||
    int mem_shared, mem_buffers, mem_cached; // Linux
 | 
			
		||||
 | 
			
		||||
    // the following are pointers to matrices indexed by kind (above) and
 | 
			
		||||
    // cpu
 | 
			
		||||
    unsigned *cpu_times_vec;
 | 
			
		||||
    unsigned *old_cpu_times_vec;
 | 
			
		||||
 | 
			
		||||
    // accessors for (old_)cpu_times_vec
 | 
			
		||||
    unsigned &cpu_times(int cpu, int kind)
 | 
			
		||||
    {
 | 
			
		||||
        return cpu_times_vec[cpu * CPUTIMES + kind];
 | 
			
		||||
    }
 | 
			
		||||
    unsigned &old_cpu_times(int cpu, int kind)
 | 
			
		||||
    {
 | 
			
		||||
        return old_cpu_times_vec[cpu * CPUTIMES + kind];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    // from /proc/stat
 | 
			
		||||
    unsigned long *per_cpu_times;     // vector of num_cpus times
 | 
			
		||||
    unsigned long *old_per_cpu_times; // vector of num_cpus times
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    // Solaris <sys/sysinfo.h> #defines CPU_xxx so we must avoid them
 | 
			
		||||
    enum
 | 
			
		||||
    {
 | 
			
		||||
        CPUTIME_USER,
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
        CPUTIME_NICE,
 | 
			
		||||
#endif
 | 
			
		||||
        CPUTIME_SYSTEM,
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
        CPUTIME_WAIT,
 | 
			
		||||
#endif
 | 
			
		||||
        CPUTIME_IDLE,
 | 
			
		||||
        CPUTIMES
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    //#define CPU_TIMES(cpu, kind) cpu_times_vec[cpu * CPUTIMES + kind]
 | 
			
		||||
 | 
			
		||||
    unsigned int current_gen;
 | 
			
		||||
    int maxSizeHistory;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Procview : public Proc
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Procview();
 | 
			
		||||
    QString filterstr;
 | 
			
		||||
 | 
			
		||||
    static bool flag_show_file_path;
 | 
			
		||||
    static bool flag_pcpu_single;
 | 
			
		||||
    static bool flag_cumulative;
 | 
			
		||||
 | 
			
		||||
    static int compare(Procinfo *const *a, Procinfo *const *b);
 | 
			
		||||
    static int compare_backwards(Procinfo *const *a, Procinfo *const *b);
 | 
			
		||||
    void refresh();
 | 
			
		||||
    bool accept_proc(Procinfo *p); // COMMON
 | 
			
		||||
    void linearize_tree(QVector<Procinfo *> *ps, int level, int prow,
 | 
			
		||||
                        bool flag_hide = false);
 | 
			
		||||
    void build_tree(Proclist &);
 | 
			
		||||
    void rebuild();
 | 
			
		||||
 | 
			
		||||
    void set_fields();
 | 
			
		||||
    void set_fields_list(int fields[]);
 | 
			
		||||
    void addField(char *name);                   // interface
 | 
			
		||||
    void addField(int FIELD_ID, int where = -1); // base interface
 | 
			
		||||
    void removeField(int FIELD_ID);
 | 
			
		||||
    int findCol(int FIELD_ID);
 | 
			
		||||
    void moveColumn(int col, int place);
 | 
			
		||||
    void deduce_fields();
 | 
			
		||||
    void fieldArrange();
 | 
			
		||||
    void update_customfield();
 | 
			
		||||
    //
 | 
			
		||||
    void setSortColumn(int col, bool r = false);
 | 
			
		||||
    void setTreeMode(bool b);
 | 
			
		||||
    void saveCOMMANDFIELD();
 | 
			
		||||
 | 
			
		||||
#ifndef GTK
 | 
			
		||||
    Procinfo *getProcinfoByPID(int pid) { return procs.value(pid, NULL); };
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    QVector<Procinfo *> linear_procs; // this is linear_proc_list for viewer
 | 
			
		||||
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    QVector<Sockinfo *> linear_socks; // Linux Testing
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    // QList<> tags_kernel;
 | 
			
		||||
 | 
			
		||||
    // root_procs contains processes without parent; normally only init, but
 | 
			
		||||
    // we cannot rely on this (Solaris has several parentless processes).
 | 
			
		||||
    // Also, if the view is restricted, all processes whose parent isn't in
 | 
			
		||||
    // the table.
 | 
			
		||||
    QVector<Procinfo *> root_procs; // table_root_procs; for viewer
 | 
			
		||||
    QVector<Category *> cats;       // for table
 | 
			
		||||
 | 
			
		||||
    Category *sortcat;
 | 
			
		||||
    Category *sortcat_linear; // testing
 | 
			
		||||
    int sort_column;          // index of
 | 
			
		||||
    bool reversed;            // true if sorted backwards
 | 
			
		||||
    static bool treeview;     // true if viewed in tree form
 | 
			
		||||
    bool enable;              // tmp
 | 
			
		||||
 | 
			
		||||
    enum procstates
 | 
			
		||||
    {
 | 
			
		||||
        ALL,
 | 
			
		||||
        OWNED,
 | 
			
		||||
        NROOT,
 | 
			
		||||
        RUNNING,
 | 
			
		||||
        HIDDEN,
 | 
			
		||||
        NETWORK
 | 
			
		||||
    };
 | 
			
		||||
    enum fieldstates
 | 
			
		||||
    {
 | 
			
		||||
        USER = HIDDEN + 1,
 | 
			
		||||
        JOBS,
 | 
			
		||||
        MEM,
 | 
			
		||||
        SCHED,
 | 
			
		||||
        CUSTOM
 | 
			
		||||
    };
 | 
			
		||||
    int viewproc;
 | 
			
		||||
    int viewfields;
 | 
			
		||||
 | 
			
		||||
    int idxF_CMD; ////Test
 | 
			
		||||
    QStringList customfields;
 | 
			
		||||
    static int custom_fields[64];
 | 
			
		||||
    // lists of fields to be used for different views, terminated by -1:
 | 
			
		||||
    static int mini_fields[]; // for mobile
 | 
			
		||||
    static int basic_fields[];
 | 
			
		||||
    static int jobs_fields[];
 | 
			
		||||
    static int mem_fields[];
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    static int sched_fields[];
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef MOSIX
 | 
			
		||||
    static int user_fields_mosix[];
 | 
			
		||||
    static int jobs_fields_mosix[];
 | 
			
		||||
    static int mem_fields_mosix[];
 | 
			
		||||
#endif
 | 
			
		||||
    static float avg_factor; // exponential factor for averaging
 | 
			
		||||
    static const int cpu_avg_time = 30 * 1000; // averaging time for WCPU (ms)
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    static Category *static_sortcat; // kludge: to be used by compare
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // PROC_H
 | 
			
		||||
							
								
								
									
										1100
									
								
								src/proc_common.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										2255
									
								
								src/proc_linux.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										2463
									
								
								src/proc_mosix.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										1328
									
								
								src/proc_solaris.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										586
									
								
								src/pstable.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,586 @@
 | 
			
		||||
// pstable.cpp
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdeg?rd, 1997-1999
 | 
			
		||||
 | 
			
		||||
// ** toooo complex,so need new Design ... should be more simple.. (by
 | 
			
		||||
// fasthyun@magicn.com)
 | 
			
		||||
 | 
			
		||||
#include "proc.h"
 | 
			
		||||
#include "pstable.h"
 | 
			
		||||
#include "misc.h"
 | 
			
		||||
 | 
			
		||||
///#include <limits.h>
 | 
			
		||||
#include <QApplication>
 | 
			
		||||
#include <QClipboard>
 | 
			
		||||
#include <QToolTip>
 | 
			
		||||
 | 
			
		||||
// When a subtree is folded away, selections inside it disappear to prevent
 | 
			
		||||
// unexpected behaviour
 | 
			
		||||
static void clear_subtree_selections(Procinfo *p)
 | 
			
		||||
{
 | 
			
		||||
    for (int i = 0; i < p->table_children.size(); i++)
 | 
			
		||||
    {
 | 
			
		||||
        Procinfo *c = p->table_children[i];
 | 
			
		||||
        c->selected = false;
 | 
			
		||||
        clear_subtree_selections(c);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SLOT :
 | 
			
		||||
// connect(this, SIGNAL(titleClicked(int)), SLOT(setSortColumn(int)));
 | 
			
		||||
void Pstable::setSortColumn(int col)
 | 
			
		||||
{
 | 
			
		||||
    procview->setSortColumn(col, false);
 | 
			
		||||
    setSortedCol(col); // void HeadedTable::setSortedCol(int col)
 | 
			
		||||
    refresh();         // rebuild table
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AWKWARD
 | 
			
		||||
// sync Procview and HeadedTable set sorted column of table to procview->sortcol
 | 
			
		||||
// called by 1. Pstable::moveCol(int col, int place)
 | 
			
		||||
void Pstable::set_sortcol()
 | 
			
		||||
{
 | 
			
		||||
    for (int i = 0; i < procview->cats.size(); i++)
 | 
			
		||||
    {
 | 
			
		||||
        if (procview->cats[i] == procview->sortcat)
 | 
			
		||||
        {
 | 
			
		||||
            HeadedTable::setSortedCol(i); // HeadedTable
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    setSortedCol(-1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// for Optimization
 | 
			
		||||
int Pstable::sizeHintForColumn(int col) const
 | 
			
		||||
{
 | 
			
		||||
    // int aw=fontMetrics().averageCharWidth();
 | 
			
		||||
    int aw = fontMetrics().width("0");
 | 
			
		||||
    int cat_idx = procview->cats[col]->index;
 | 
			
		||||
    // if(col==0) printf("col.idx=%d
 | 
			
		||||
    // %s\n",cat_idx,procview->cats[col]->name);
 | 
			
		||||
    switch (cat_idx)
 | 
			
		||||
    {
 | 
			
		||||
    // 	only COMMON Field
 | 
			
		||||
    //		case F_PID :
 | 
			
		||||
    case F_RSS:
 | 
			
		||||
    case F_SIZE:
 | 
			
		||||
    case F_TTY:
 | 
			
		||||
        return aw * 6;
 | 
			
		||||
    case F_MEM:
 | 
			
		||||
    case F_START:
 | 
			
		||||
    case F_CPU: // PCPU
 | 
			
		||||
        return aw * 6 + 2;
 | 
			
		||||
    case F_TIME:
 | 
			
		||||
        return aw * 5;
 | 
			
		||||
    case F_WCPU:
 | 
			
		||||
    case F_NICE:
 | 
			
		||||
        return aw * 5;
 | 
			
		||||
    case F_CMD:
 | 
			
		||||
        return -(aw * 20);
 | 
			
		||||
 | 
			
		||||
    case F_USER:
 | 
			
		||||
    //		case F_USER : return aw*10;
 | 
			
		||||
    case F_CMDLINE:
 | 
			
		||||
    default:
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// inner
 | 
			
		||||
QString Pstable::title(int col)
 | 
			
		||||
{
 | 
			
		||||
    if (col >= procview->cats.size())
 | 
			
		||||
    {
 | 
			
		||||
        qDebug("Qps Bug!: title() over col !! %d\n", col);
 | 
			
		||||
        return "";
 | 
			
		||||
    }
 | 
			
		||||
    return procview->cats[col]->name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TESTING
 | 
			
		||||
void Pstable::overpaintCell(QPainter *p, int row, int col, int xpos)
 | 
			
		||||
{
 | 
			
		||||
    if (col != 0)
 | 
			
		||||
        return;
 | 
			
		||||
    if (procview->cats[col]->id != F_CMD)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    int w;
 | 
			
		||||
 | 
			
		||||
    Procinfo *pi = procview->linear_procs[row];
 | 
			
		||||
 | 
			
		||||
    int n = pi->nthreads;
 | 
			
		||||
    if (n == 1)
 | 
			
		||||
        return;
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    if (pi->pid != pi->tgid)
 | 
			
		||||
        return; // LINUX
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
    w = p->fontMetrics().width(text(row, col));
 | 
			
		||||
 | 
			
		||||
    QFont font = p->font();
 | 
			
		||||
    int size = font.pointSize(); // point size
 | 
			
		||||
 | 
			
		||||
    if (size <= 0)
 | 
			
		||||
        return; // saver!
 | 
			
		||||
 | 
			
		||||
    int h = body->cellHeight();
 | 
			
		||||
    h = p->fontMetrics().height(); // return pixel
 | 
			
		||||
 | 
			
		||||
    int msize = h * 3.0 / 8.0;
 | 
			
		||||
    // printf("DEBUG: height=%d, msize=%d\n",h,msize);
 | 
			
		||||
 | 
			
		||||
    if (h <= 11)
 | 
			
		||||
        return; // saver!
 | 
			
		||||
 | 
			
		||||
    if (msize < 6)
 | 
			
		||||
        msize = 6;
 | 
			
		||||
 | 
			
		||||
    // font.setPointSize(msize); // not pixel!
 | 
			
		||||
    font.setPixelSize(msize); // not pixel!
 | 
			
		||||
    p->setFont(font);
 | 
			
		||||
    p->drawText(xpos + w + 2, msize + msize / 3, QString::number(n));
 | 
			
		||||
    font.setPointSize(size);
 | 
			
		||||
    p->setFont(font);
 | 
			
		||||
}
 | 
			
		||||
//
 | 
			
		||||
QString Pstable::text(int row, int col)
 | 
			
		||||
{
 | 
			
		||||
    if (col >= procview->cats.size())
 | 
			
		||||
    {
 | 
			
		||||
        qDebug("Qps Bug!: text() over col !! %d\n", col);
 | 
			
		||||
        return "";
 | 
			
		||||
    }
 | 
			
		||||
    return procview->cats[col]->string(procview->linear_procs[row]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Pstable::totalRow() //???
 | 
			
		||||
{
 | 
			
		||||
    return procview->linear_procs.size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Pstable::colWidth(int col)
 | 
			
		||||
{
 | 
			
		||||
    // this is -1 for variable width fields, htable keeps track of it
 | 
			
		||||
    if (col >= procview->cats.size())
 | 
			
		||||
    {
 | 
			
		||||
        qDebug("Qps Bug!: colWidth() over col !! %d\n", col);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    return procview->cats[col]->width();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Pstable::alignment(int col)
 | 
			
		||||
{
 | 
			
		||||
    // qDebug("debug:alignment()\n");
 | 
			
		||||
    Category *cat = procview->cats[col];
 | 
			
		||||
    return cat->alignment();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// virtual of HeadedTable
 | 
			
		||||
void Pstable::setSelected(int row, bool flag)
 | 
			
		||||
{
 | 
			
		||||
    ///	qDebug("debug:Pstable::setSelected()\n");
 | 
			
		||||
    Procinfo *pi = procview->linear_procs[row];
 | 
			
		||||
    if (pi->selected != flag)
 | 
			
		||||
    {
 | 
			
		||||
        pi->selected = flag;
 | 
			
		||||
        //	body->repaintRow(row);  // TEMP trick..
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// virtual
 | 
			
		||||
bool Pstable::isSelected(int row)
 | 
			
		||||
{
 | 
			
		||||
    Procinfo *pi = procview->linear_procs[row];
 | 
			
		||||
    return pi->selected; // VALGRIND
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Pstable::rowDepth(int row)
 | 
			
		||||
{
 | 
			
		||||
    Procinfo *pi = procview->linear_procs[row];
 | 
			
		||||
    if (pi)
 | 
			
		||||
        return pi->level; // VALGRIND segfault
 | 
			
		||||
 | 
			
		||||
    qDebug("Qps bug: over row  %d!!!\n", row);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Pstable::lastChild(int row)
 | 
			
		||||
{
 | 
			
		||||
    Procinfo *pi = procview->linear_procs[row];
 | 
			
		||||
    if (pi)
 | 
			
		||||
        return pi->lastchild;
 | 
			
		||||
    qDebug("Qps bug: over row  %d!!!\n", row);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Segfault !!!!
 | 
			
		||||
// return  not PPID ! just virtual parent in tree
 | 
			
		||||
int Pstable::parentRow(int row)
 | 
			
		||||
{
 | 
			
		||||
    return procview->linear_procs[row]->parent_row;
 | 
			
		||||
    /* int ppid= procview->linear_procs[row]->ppid;
 | 
			
		||||
    Procinfo *pi= procview->getProcinfoByPID(ppid);
 | 
			
		||||
    if(pi) return ppid;
 | 
			
		||||
    else return -1; */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DRAFT tooltip
 | 
			
		||||
QString Pstable::tipText(int col)
 | 
			
		||||
{
 | 
			
		||||
    Category *cat = procview->cats[col];
 | 
			
		||||
    QString s(cat->help);
 | 
			
		||||
    // trick
 | 
			
		||||
    if (cat->index == F_STAT)
 | 
			
		||||
        s.append("\n(R =Running, S =Sleeping, T =sTopped, Z=Zombie)");
 | 
			
		||||
    if (cat->index == F_PLCY)
 | 
			
		||||
        s.append("\n(TS =Time Sharing)");
 | 
			
		||||
    // if(cat->index == F_RSS);
 | 
			
		||||
    // s.append("\nRSS = CODE + DATA + SHARE\n"
 | 
			
		||||
    //	   "RSS = TRS  + DRS  + SHARE\n");
 | 
			
		||||
    /// s.append("\n(RSS = TRS + DRS)");
 | 
			
		||||
    if (cat == procview->sortcat)
 | 
			
		||||
        s.append(procview->reversed ? "\n(sorted backwards)" : "\n(sorted)");
 | 
			
		||||
 | 
			
		||||
    //	printf("size=%d\n",s.capacity());
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Pstable::showTip(QPoint p, int idx)
 | 
			
		||||
{
 | 
			
		||||
    QToolTip::showText(p, tipText(idx));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern TFrame *infobox; // testing
 | 
			
		||||
 | 
			
		||||
// SLOT
 | 
			
		||||
void Pstable::mouseOutOfCell() { infobox->hide(); }
 | 
			
		||||
 | 
			
		||||
// TEST
 | 
			
		||||
void Pstable::mouseOnCell(int row, int col)
 | 
			
		||||
{
 | 
			
		||||
    // printf("cursor on (%d,%d)\n",row,col);
 | 
			
		||||
 | 
			
		||||
    Category *cat = procview->cats[col];
 | 
			
		||||
    QString s = "";
 | 
			
		||||
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
    // below TEST code!
 | 
			
		||||
    if (cat->index == F_USER)
 | 
			
		||||
    {
 | 
			
		||||
        Procinfo *pi = procview->linear_procs[row];
 | 
			
		||||
        s = pi->username;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        infobox->hide();
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (infobox != NULL)
 | 
			
		||||
    {
 | 
			
		||||
        // p.setY(p.y() + geometry().y());
 | 
			
		||||
        // p.setY(QCursor::pos().y() - geometry().y());
 | 
			
		||||
        // p.setY(QCursor::pos().y() - frameGeometry().y());
 | 
			
		||||
        // p.setX(QCursor::pos().x() - frameGeometry().x());
 | 
			
		||||
        // QPoint p=QCursor::pos();
 | 
			
		||||
        //	if(htable->numSelected()>=2)
 | 
			
		||||
 | 
			
		||||
        infobox->show();
 | 
			
		||||
        infobox->setPos();
 | 
			
		||||
        if (s > 0)
 | 
			
		||||
        {
 | 
			
		||||
            infobox->setText(s);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            infobox->hide();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // char *str=htable->total_selectedRow(col);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Pstable::leaveEvent(QEvent *) {}
 | 
			
		||||
 | 
			
		||||
// DRAFT  who call?
 | 
			
		||||
// void TableBody::mouseMoveEvent(QMouseEvent *e)
 | 
			
		||||
char *Pstable::total_selectedRow(int col)
 | 
			
		||||
{
 | 
			
		||||
    static char buff[48];
 | 
			
		||||
    char mem_str[48];
 | 
			
		||||
    std::string name;
 | 
			
		||||
    int index;
 | 
			
		||||
 | 
			
		||||
    if (procview->cats.size() <= col or col < 0)
 | 
			
		||||
        return 0; // col == -1
 | 
			
		||||
    index = procview->cats[col]->index;
 | 
			
		||||
 | 
			
		||||
    switch (index)
 | 
			
		||||
    {
 | 
			
		||||
    case F_SIZE:
 | 
			
		||||
        name = "total SIZE: ";
 | 
			
		||||
        break;
 | 
			
		||||
    case F_RSS:
 | 
			
		||||
        name = "total RSS: ";
 | 
			
		||||
        break;
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    case F_TRS:
 | 
			
		||||
        name = "total Text: ";
 | 
			
		||||
        break;
 | 
			
		||||
    case F_DRS:
 | 
			
		||||
        name = "total Data: ";
 | 
			
		||||
        break;
 | 
			
		||||
    case F_STACK:
 | 
			
		||||
        name = "total STACK: ";
 | 
			
		||||
        break;
 | 
			
		||||
#endif
 | 
			
		||||
    default:
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int total = 0;
 | 
			
		||||
    int rows = procview->linear_procs.size();
 | 
			
		||||
    for (int i = 0; i < rows; i++)
 | 
			
		||||
        if (procview->linear_procs[i]->selected)
 | 
			
		||||
        {
 | 
			
		||||
            switch (index)
 | 
			
		||||
            {
 | 
			
		||||
            case F_SIZE:
 | 
			
		||||
                total += procview->linear_procs[i]->size;
 | 
			
		||||
                break;
 | 
			
		||||
            case F_RSS:
 | 
			
		||||
                total += procview->linear_procs[i]->resident;
 | 
			
		||||
                break;
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
            case F_TRS:
 | 
			
		||||
                total += procview->linear_procs[i]->trs;
 | 
			
		||||
                break;
 | 
			
		||||
            case F_DRS:
 | 
			
		||||
                total += procview->linear_procs[i]->drs;
 | 
			
		||||
                break;
 | 
			
		||||
            case F_STACK:
 | 
			
		||||
                total += procview->linear_procs[i]->stack;
 | 
			
		||||
                break;
 | 
			
		||||
#endif
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    mem_string(total, mem_str); // misc.h
 | 
			
		||||
    strcpy(buff, name.c_str());
 | 
			
		||||
    strcat(buff, mem_str);
 | 
			
		||||
    // sqDebug(buff,"total:%s",total);
 | 
			
		||||
    return buff;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 	col
 | 
			
		||||
//	colMoved(col, place);
 | 
			
		||||
Pstable::Pstable(QWidget *parent, Procview *pv) : HeadedTable(parent, 0)
 | 
			
		||||
{
 | 
			
		||||
    procview = pv;
 | 
			
		||||
    //	connect(this, SIGNAL(selectionChanged(const Svec<int>
 | 
			
		||||
    //*)),SLOT(selection_update(const Svec<int> *))); //DEL?
 | 
			
		||||
    //	connect(this,
 | 
			
		||||
    // SIGNAL(selectionChanged()),SLOT(selection_update())); //
 | 
			
		||||
    // when procinfo clicked
 | 
			
		||||
    connect(this, SIGNAL(titleClicked(int)), SLOT(setSortColumn(int)));
 | 
			
		||||
    connect(this, SIGNAL(foldSubTree(int)), SLOT(subtree_folded(int)));
 | 
			
		||||
    connect(head, SIGNAL(toolTip(QPoint, int)), this,
 | 
			
		||||
            SLOT(showTip(QPoint, int)));
 | 
			
		||||
    connect(this, SIGNAL(flyOnCell(int, int)), SLOT(mouseOnCell(int, int)));
 | 
			
		||||
    connect(this, SIGNAL(outOfCell()), SLOT(mouseOutOfCell()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// who call this ? : from qps.cpp
 | 
			
		||||
void Pstable::setProcview(Procview *pv) { procview = pv; }
 | 
			
		||||
 | 
			
		||||
HeadedTable::NodeState Pstable::folded(int row)
 | 
			
		||||
{
 | 
			
		||||
    Procinfo *p = procview->linear_procs[row];
 | 
			
		||||
    return (p->table_children.size() > 0) ? (p->hidekids ? Closed : Open)
 | 
			
		||||
                                          : Leaf;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// slot: called when selection changes
 | 
			
		||||
//	called by
 | 
			
		||||
//		1.void HeadedTable::selectionNotify()
 | 
			
		||||
/*
 | 
			
		||||
void Pstable::selection_update(const Svec<int> *rows)
 | 
			
		||||
{
 | 
			
		||||
        //CLIPBOARD
 | 
			
		||||
        qDebug("debug:selection_update()\n");
 | 
			
		||||
        for(int i = 0; i < rows->size(); i++) {
 | 
			
		||||
                int row = (*rows)[i];
 | 
			
		||||
                procview->linear_procs[row]->selected = isSelected(row); //
 | 
			
		||||
WRONG !!!
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        qps->update_menu_selection_status();
 | 
			
		||||
 | 
			
		||||
        if(numSelected() > 0 && qps->pids_to_selection) {
 | 
			
		||||
                // set the X11 selection to "PID1 PID2 PID3 ..."
 | 
			
		||||
                QString s, num;
 | 
			
		||||
                int n = numRows();
 | 
			
		||||
                for(int i = 0; i < n; i++) {
 | 
			
		||||
                        if(isSelected(i)) {
 | 
			
		||||
                                num.setNum(procview->linear_procs[i]->pid);
 | 
			
		||||
                                s.append(num);
 | 
			
		||||
                                if(i < n - 1)
 | 
			
		||||
                                        s.append(" ");
 | 
			
		||||
                        }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // important: this mustn't be called non-interactively since Qt
 | 
			
		||||
uses
 | 
			
		||||
                // the selection time of the last mouse or keyboard event
 | 
			
		||||
////		QApplication::clipboard()->setText(s);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
} */
 | 
			
		||||
 | 
			
		||||
// call by
 | 
			
		||||
// 	1.void Qps::set_table_mode(bool treemode)
 | 
			
		||||
// 	slot: changes table mode
 | 
			
		||||
void Pstable::setTreeMode(bool treemode)
 | 
			
		||||
{
 | 
			
		||||
    // qDebug("Pstable::setTreeMode() %d , procview.treeview
 | 
			
		||||
    // =%d\n",treemode,procview->treeview);
 | 
			
		||||
    // no more HeadedTable::setTreeMode(treemode);
 | 
			
		||||
    HeadedTable::setTreeMode(treemode);
 | 
			
		||||
    procview->treeview = treemode;
 | 
			
		||||
    procview->fieldArrange();
 | 
			
		||||
    set_sortcol();
 | 
			
		||||
    refresh(); //==rebuild();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
bool Pstable::columnMovable(int col)
 | 
			
		||||
{
 | 
			
		||||
    if (treemode)
 | 
			
		||||
    {
 | 
			
		||||
        if (col == 0)
 | 
			
		||||
            return false;
 | 
			
		||||
    }
 | 
			
		||||
    if (procview->cats[col]->index == F_CMDLINE)
 | 
			
		||||
        return false;
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// called by HeadedTable
 | 
			
		||||
// Description : FIELD movement by mouse drag to place From col
 | 
			
		||||
//	virtual HeadedTable::moveCol(col,place);
 | 
			
		||||
void Pstable::moveCol(int col, int place)
 | 
			
		||||
{
 | 
			
		||||
    // qDebug("Pstable::moveCol\n");
 | 
			
		||||
    procview->moveColumn(col, place);
 | 
			
		||||
    set_sortcol(); //???
 | 
			
		||||
    procview->fieldArrange();
 | 
			
		||||
    //	update();
 | 
			
		||||
    refresh(); // width size changed ,...
 | 
			
		||||
    return;
 | 
			
		||||
    // updateColWidth(place); updateColWidth(col);// TEMP
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NEED Check !!
 | 
			
		||||
// Slot: called when a subtree is opened or closed
 | 
			
		||||
// row = row number of sheet
 | 
			
		||||
void Pstable::subtree_folded(int row)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    Procinfo *p = procview->linear_procs[row];
 | 
			
		||||
    p->hidekids = !p->hidekids;
 | 
			
		||||
 | 
			
		||||
    if (p->hidekids)
 | 
			
		||||
        clear_subtree_selections(p); // *** important
 | 
			
		||||
 | 
			
		||||
    refresh(); // tree rebuild only
 | 
			
		||||
    return;
 | 
			
		||||
    // ???
 | 
			
		||||
    Procinfo *nextp =
 | 
			
		||||
        (row < numRows() - 1) ? procview->linear_procs[row + 1] : 0;
 | 
			
		||||
    if (!p->hidekids)
 | 
			
		||||
    {
 | 
			
		||||
        // Show as much as possible of the opened subtree
 | 
			
		||||
        int r = row + 1;
 | 
			
		||||
        while (r < numRows() && procview->linear_procs[r] != nextp)
 | 
			
		||||
            r++;
 | 
			
		||||
        //	setAutoUpdate(FALSE);
 | 
			
		||||
        showRange(row, r - 1);
 | 
			
		||||
        // setAutoUpdate(TRUE);
 | 
			
		||||
    }
 | 
			
		||||
    // This is a stopgap solution; it would be better to have htable
 | 
			
		||||
    // take care of the hiding of subtrees and repaint only the rows under
 | 
			
		||||
    // the line hidden
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DRAFT CODE:
 | 
			
		||||
// 1.procview->refresh: proc.refresh, rebuild
 | 
			
		||||
// 2.resetwidth
 | 
			
		||||
// 3.repaint
 | 
			
		||||
 | 
			
		||||
// called by
 | 
			
		||||
// 	1.void Qps::refresh()
 | 
			
		||||
void STATUSBAR_SETCOUNT(int n);
 | 
			
		||||
 | 
			
		||||
static int kgen = 123;
 | 
			
		||||
void Pstable::checkTableModel()
 | 
			
		||||
{
 | 
			
		||||
    //	int size=procview->linear_procs.size();
 | 
			
		||||
    //	if(size!=numRows())
 | 
			
		||||
    {
 | 
			
		||||
        //	printf("Warnning: this is the bug.. wrong! %d
 | 
			
		||||
        //%d\n",size,numRows());
 | 
			
		||||
    }
 | 
			
		||||
    if (procview->current_gen != kgen)
 | 
			
		||||
    {
 | 
			
		||||
        //		printf("Warnning: maybe this is the bug.. wrong!
 | 
			
		||||
        //%d
 | 
			
		||||
        //%d\n",kgen,procview->current_gen);
 | 
			
		||||
        //		setAutoUpdate(false);  // ********** important for
 | 
			
		||||
        // GUI-thread
 | 
			
		||||
        //		HeadedTable::setTreeMode(procview->treeview);
 | 
			
		||||
        procview->rebuild();                       // for Table
 | 
			
		||||
        setNumRows(procview->linear_procs.size()); // 1.
 | 
			
		||||
        //	qDebug("Pstable setTreeMode =%d , procview.treeview
 | 
			
		||||
        //=%d\n",treemode,procview->treeview);
 | 
			
		||||
        setNumCols(procview->cats.size()); // 2. resetWidths()
 | 
			
		||||
        kgen = procview->current_gen;
 | 
			
		||||
        //		setAutoUpdate(true);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// paintEvent();
 | 
			
		||||
 | 
			
		||||
void Pstable::refresh()
 | 
			
		||||
{
 | 
			
		||||
    //    qDebug("Pstable:refresh()");
 | 
			
		||||
    //	procview->refresh(); -> move to Qps::refresh()
 | 
			
		||||
    //	qDebug("catsize=%d\n",procview->cats.size());
 | 
			
		||||
    procview->rebuild();                       // for Table
 | 
			
		||||
    setNumRows(procview->linear_procs.size()); // 1.
 | 
			
		||||
    setNumCols(procview->cats.size());         // 2. resetWidths()  UNINITIAL
 | 
			
		||||
    kgen = procview->current_gen;
 | 
			
		||||
    // checkTableModel();
 | 
			
		||||
    repaint_changed();
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
    if(true)
 | 
			
		||||
    {
 | 
			
		||||
            int count=0,trow=0;
 | 
			
		||||
            for(int row = 0; row < nrows; row++)
 | 
			
		||||
                    if(isSelected(row))
 | 
			
		||||
                    {
 | 
			
		||||
                            count++;
 | 
			
		||||
                            trow=row;
 | 
			
		||||
                    }
 | 
			
		||||
            if (count == 1)
 | 
			
		||||
                    centerVertically(trow);
 | 
			
		||||
    } */
 | 
			
		||||
 | 
			
		||||
    STATUSBAR_SETCOUNT(procview->num_process);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										64
									
								
								src/pstable.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,64 @@
 | 
			
		||||
// pstable.h				emacs, this is written in -*-c++-*-
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#ifndef PSTABLE_H
 | 
			
		||||
#define PSTABLE_H
 | 
			
		||||
 | 
			
		||||
#include "proc.h"
 | 
			
		||||
#include "htable.h"
 | 
			
		||||
 | 
			
		||||
class Pstable : public HeadedTable
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    Pstable(QWidget *parent, Procview *pv);
 | 
			
		||||
 | 
			
		||||
    void set_sortcol();
 | 
			
		||||
    void setProcview(Procview *pv);
 | 
			
		||||
    virtual void moveCol(int col, int place);
 | 
			
		||||
    void refresh();
 | 
			
		||||
 | 
			
		||||
    // called by super
 | 
			
		||||
    bool hasSelection() { return 0; };
 | 
			
		||||
 | 
			
		||||
    virtual bool isSelected(int row);
 | 
			
		||||
    virtual void setSelected(int row, bool sel);
 | 
			
		||||
    virtual int totalRow();
 | 
			
		||||
    virtual void checkTableModel();
 | 
			
		||||
 | 
			
		||||
  public slots:
 | 
			
		||||
    // void selection_update(const Svec<int> *row);
 | 
			
		||||
    void setSortColumn(int col);
 | 
			
		||||
    void subtree_folded(int row);
 | 
			
		||||
    void showTip(QPoint p, int index);
 | 
			
		||||
    void setTreeMode(bool treemode);
 | 
			
		||||
    void mouseOnCell(int row, int col);
 | 
			
		||||
    void mouseOutOfCell();
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    // implementation of the interface to HeadedTable
 | 
			
		||||
    virtual QString title(int col);
 | 
			
		||||
    virtual QString text(int row, int col);
 | 
			
		||||
    virtual int colWidth(int col);
 | 
			
		||||
    virtual int alignment(int col);
 | 
			
		||||
    virtual QString tipText(int col);
 | 
			
		||||
    virtual int rowDepth(int row);
 | 
			
		||||
    virtual NodeState folded(int row);
 | 
			
		||||
    virtual int parentRow(int row);
 | 
			
		||||
    virtual bool lastChild(int row);
 | 
			
		||||
    virtual char *total_selectedRow(int col);
 | 
			
		||||
    virtual int sizeHintForColumn(int col) const;
 | 
			
		||||
    virtual bool columnMovable(int col);
 | 
			
		||||
 | 
			
		||||
    virtual void overpaintCell(QPainter *p, int row, int col, int xpos);
 | 
			
		||||
    //	virtual bool hasChildren(int row);
 | 
			
		||||
 | 
			
		||||
    virtual void leaveEvent(QEvent *);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    Procview *procview;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // PSTABLE_H
 | 
			
		||||
							
								
								
									
										491
									
								
								src/pstable2.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,491 @@
 | 
			
		||||
 | 
			
		||||
#include "pstable2.h"
 | 
			
		||||
int flag_x = 0;
 | 
			
		||||
PstableModel::PstableModel(QObject *parent, Procview *pv) : HtableModel(parent)
 | 
			
		||||
{
 | 
			
		||||
    procview = pv;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QModelIndex PstableModel::index(int row, int col,
 | 
			
		||||
                                const QModelIndex &parent) const
 | 
			
		||||
{
 | 
			
		||||
    if (flag_x)
 | 
			
		||||
        printf("index(): row=%d col=%d  parent(%d %d)\n", row, col,
 | 
			
		||||
               parent.row(), parent.column());
 | 
			
		||||
    //		if(row<0 or column<0)  // root?
 | 
			
		||||
    //			return QModelIndex();
 | 
			
		||||
    Procinfo *pi;
 | 
			
		||||
 | 
			
		||||
    if (col < 0 or col >= procview->cats.size())
 | 
			
		||||
        return QModelIndex();
 | 
			
		||||
    // qFatal("Qps::Pstable2::sizeHintForColumn() Bug!: over col !!
 | 
			
		||||
    // %d\n",col);
 | 
			
		||||
    if (parent == QModelIndex())
 | 
			
		||||
    {
 | 
			
		||||
        if (row >= 0 and row < procview->root_procs.size())
 | 
			
		||||
        {
 | 
			
		||||
            Procinfo *pi = procview->root_procs[row]; // NULL possible!!
 | 
			
		||||
            return createIndex(row, col, pi);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            printf("out of row %d", row); // ???????????????????
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (parent.isValid())
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        Procinfo *ppi = static_cast<Procinfo *>(parent.internalPointer());
 | 
			
		||||
 | 
			
		||||
        if (ppi and row < ppi->table_children.size() and row >= 0)
 | 
			
		||||
        {
 | 
			
		||||
            Procinfo *pi = ppi->table_children[row];
 | 
			
		||||
            return createIndex(row, col, pi);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    printf("	indeX() error\n");
 | 
			
		||||
    // qFatal("Error : index() row=%d ",row);
 | 
			
		||||
    return QModelIndex();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Pure Virtual
 | 
			
		||||
QModelIndex PstableModel::parent(const QModelIndex &child) const
 | 
			
		||||
{
 | 
			
		||||
    // wrong	parent makes segfault
 | 
			
		||||
    // return QModelIndex();
 | 
			
		||||
    //	printf("parent() ! %d %d\n",child.row(),child.column());
 | 
			
		||||
    if (child.isValid())
 | 
			
		||||
    {
 | 
			
		||||
        Procinfo *pi = static_cast<Procinfo *>(child.internalPointer());
 | 
			
		||||
        // if (pi==NULL or pi->level==0 )//or pi->parent_row<0)
 | 
			
		||||
        if (pi->level < 1) // or pi->parent_row<0)
 | 
			
		||||
        {
 | 
			
		||||
            //	printf("root , pid=%d ppid=%d
 | 
			
		||||
            //\n",pi->pid,pi->ppid);
 | 
			
		||||
            return QModelIndex();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // parent_row == -1 segfault
 | 
			
		||||
        Procinfo *ppi = procview->procs.value(pi->ppid, 0); ///
 | 
			
		||||
        if (ppi == NULL)
 | 
			
		||||
            printf("error xxxxxxxxxxxx\n");
 | 
			
		||||
        // if(pi->ppid==2608)	printf("parent_row=%d
 | 
			
		||||
        // ppid=%d\n",pi->parent_row,pi->ppid);
 | 
			
		||||
        //	Procinfo *ppi=procview->linear_procs[pi->parent_row];
 | 
			
		||||
        // if (pi->ppid==0 or ppi==NULL)// or !procview->treeview)
 | 
			
		||||
        ////if(flag_x)	printf("parent : pid=%d  (row=%d
 | 
			
		||||
        /// ppid=%d)\n",pi->pid,ppi->table_child_seq,ppi->pid);
 | 
			
		||||
        return createIndex(ppi->table_child_seq, 0, ppi);
 | 
			
		||||
        // return createIndex(0 , 0 ,ppi);
 | 
			
		||||
    }
 | 
			
		||||
    printf("parent() Invalud\n");
 | 
			
		||||
    return QModelIndex(); // no parent!
 | 
			
		||||
 | 
			
		||||
    //	if(row>=0 and col>=0 and row<htable->nrows)
 | 
			
		||||
    //		return createIndex(htable->parentRow(row),col,NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int PstableModel::columnCount(const QModelIndex &parent) const
 | 
			
		||||
{
 | 
			
		||||
    if (parent.column() > 0)
 | 
			
		||||
        return 0;
 | 
			
		||||
    //	printf("columnCount() size=%d\n" ,procview->cats.size());
 | 
			
		||||
    return procview->cats.size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// pure virtual: return chilren count
 | 
			
		||||
int PstableModel::rowCount(const QModelIndex &parent) const
 | 
			
		||||
{
 | 
			
		||||
    if (parent.column() > 0)
 | 
			
		||||
        return 0;
 | 
			
		||||
 | 
			
		||||
    int count = 0;
 | 
			
		||||
    if (parent == QModelIndex())
 | 
			
		||||
    {
 | 
			
		||||
        count = procview->root_procs.size();
 | 
			
		||||
        //		printf("rowCount() root_procs size=%d\n"
 | 
			
		||||
        //,count);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        Procinfo *pi = static_cast<Procinfo *>(parent.internalPointer());
 | 
			
		||||
        count = pi->table_children.size();
 | 
			
		||||
    }
 | 
			
		||||
    //	printf("rowCount (%d %d),
 | 
			
		||||
    //%d\n",parent.row(),parent.column(),count);
 | 
			
		||||
    // if(pi->table_children.size()>0)
 | 
			
		||||
    // htable->setExpanded(index,false);
 | 
			
		||||
    //	if(count>0)	htable->setExpanded(parent,false);
 | 
			
		||||
    //	if(count>0)	htable->expand(parent);
 | 
			
		||||
    return count;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool PstableModel::hasChildren(const QModelIndex &parent) const
 | 
			
		||||
{
 | 
			
		||||
    int count;
 | 
			
		||||
    if (parent.column() > 0)
 | 
			
		||||
        return false;
 | 
			
		||||
    return rowCount(parent);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QVariant PstableModel::data(const QModelIndex &index, int role) const
 | 
			
		||||
{
 | 
			
		||||
    //	printf("data\n");
 | 
			
		||||
    Procinfo *pi = static_cast<Procinfo *>(index.internalPointer());
 | 
			
		||||
    int col = index.column();
 | 
			
		||||
 | 
			
		||||
    if (role == Qt::DisplayRole)
 | 
			
		||||
    {
 | 
			
		||||
        //	if(pi->child_seq_prev>=0 and pi->child_seq!=index.row())
 | 
			
		||||
        //	printf("========= not equal row =====\n");
 | 
			
		||||
        return procview->cats[index.column()]->string(pi);
 | 
			
		||||
        //	returhtable->text(index.row(),index.column());
 | 
			
		||||
    }
 | 
			
		||||
    else if (role == Qt::DecorationRole)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    else if (role == Qt::EditRole)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    else if (role == Qt::CheckStateRole)
 | 
			
		||||
    {
 | 
			
		||||
        //	if(item->enable)
 | 
			
		||||
        //		return Qt::Checked;
 | 
			
		||||
        //	else
 | 
			
		||||
        //		return Qt::Unchecked;
 | 
			
		||||
    }
 | 
			
		||||
    else if (role == Qt::TextAlignmentRole)
 | 
			
		||||
    {
 | 
			
		||||
        Category *cat = procview->cats[index.column()];
 | 
			
		||||
        return cat->alignment();
 | 
			
		||||
    }
 | 
			
		||||
    if (role == Qt::EditRole)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    else if (role == Qt::BackgroundColorRole)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    else if (role == Qt::SizeHintRole)
 | 
			
		||||
    {
 | 
			
		||||
        //	return QSize(18,18);
 | 
			
		||||
    }
 | 
			
		||||
    return QVariant();
 | 
			
		||||
}
 | 
			
		||||
// MOVE TO Procview
 | 
			
		||||
// slot: called when a title is clicked
 | 
			
		||||
 | 
			
		||||
// void Pstable::set_sortcol()
 | 
			
		||||
//	setSortedCol(i);
 | 
			
		||||
// connect(header(), SIGNAL(sectionPressed( int )),SLOT(setSortColumn(int )));
 | 
			
		||||
void Pstable2::setSortColumn(int col)
 | 
			
		||||
{
 | 
			
		||||
    // col=-1 no section
 | 
			
		||||
    if (col < 0 or col >= procview->cats.size())
 | 
			
		||||
        return;
 | 
			
		||||
    // qFatal("Qps::Pstable2::setSortColumn() Bug!: over col !! %d\n",col);
 | 
			
		||||
    // printf("setSortColumn()\n");
 | 
			
		||||
    procview->setSortColumn(col, false);
 | 
			
		||||
    setSortedCol(col); // void HeadedTable::setSortedCol(int col)
 | 
			
		||||
    refresh();         // no redraw
 | 
			
		||||
    model->update();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// sync Procview and HeadedTable
 | 
			
		||||
// set sorted column of table to procview->sortcol
 | 
			
		||||
void Pstable2::set_sortcol()
 | 
			
		||||
{
 | 
			
		||||
    for (int i = 0; i < procview->cats.size(); i++)
 | 
			
		||||
    {
 | 
			
		||||
        if (procview->cats[i] == procview->sortcat)
 | 
			
		||||
        {
 | 
			
		||||
            setSortedCol(i); // HeadedTable
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    setSortedCol(-1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// for Speed Optimize
 | 
			
		||||
int Pstable2::sizeHintForColumn(int col) const
 | 
			
		||||
{
 | 
			
		||||
    if (col < 0 or col >= procview->cats.size())
 | 
			
		||||
        qFatal("Qps::Pstable2::sizeHintForColumn() Bug!: over col !! %d\n",
 | 
			
		||||
               col);
 | 
			
		||||
    // int aw=fontMetrics().averageCharWidth();
 | 
			
		||||
    int aw = fontMetrics().width("0");
 | 
			
		||||
    // int title_witdh=fontMetrics().width(procview->cats[col]->name);
 | 
			
		||||
    // static int z5=fontMetrics ().width("00000");
 | 
			
		||||
    // static int z6=fontMetrics ().width("000000");
 | 
			
		||||
    int cat_id = procview->cats[col]->index;
 | 
			
		||||
    switch (cat_id)
 | 
			
		||||
    {
 | 
			
		||||
    // 	only COMMON Field
 | 
			
		||||
    //		case F_PID :
 | 
			
		||||
    case F_RSS:
 | 
			
		||||
    case F_NICE:
 | 
			
		||||
    case F_SIZE:
 | 
			
		||||
    case F_TIME:
 | 
			
		||||
        return aw * 6;
 | 
			
		||||
    case F_TTY:
 | 
			
		||||
    case F_MEM:
 | 
			
		||||
    case F_CPU:
 | 
			
		||||
        // return aw*7;
 | 
			
		||||
        return fontMetrics().width("%MEM") + 10;
 | 
			
		||||
    case F_WCPU:
 | 
			
		||||
        return fontMetrics().width("%WCPU") + 10;
 | 
			
		||||
    // return aw*4;
 | 
			
		||||
    case F_USER:
 | 
			
		||||
    case F_CMD:
 | 
			
		||||
    //		case F_CMDLINE:	return 300;
 | 
			
		||||
    default:
 | 
			
		||||
        return QTreeView::sizeHintForColumn(col);
 | 
			
		||||
        // return HeadedTable::sizeHintForColumn(col);
 | 
			
		||||
        // QTreeView::resizeColumnToContents (col);
 | 
			
		||||
        return -1;
 | 
			
		||||
        ;
 | 
			
		||||
    }
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// inner
 | 
			
		||||
QString Pstable2::title(int col)
 | 
			
		||||
{
 | 
			
		||||
    if (col < 0 or col >= procview->cats.size())
 | 
			
		||||
    {
 | 
			
		||||
        qFatal("Qps::Pstable2::title(): Bug! over col !! %d\n", col);
 | 
			
		||||
        return "";
 | 
			
		||||
    }
 | 
			
		||||
    return procview->cats[col]->name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString Pstable2::text(int row, int col) // not called
 | 
			
		||||
{
 | 
			
		||||
    if (col < 0 or col >= procview->cats.size())
 | 
			
		||||
        qFatal("Qps::Pstable2::text() Bug!: over col !! %d\n", col);
 | 
			
		||||
 | 
			
		||||
    return procview->cats[col]->string(procview->linear_procs[row]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Pstable2::totalRow() //???
 | 
			
		||||
{
 | 
			
		||||
    return procview->linear_procs.size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Pstable2::colWidth(int col)
 | 
			
		||||
{
 | 
			
		||||
    if (col < 0 or col >= procview->cats.size())
 | 
			
		||||
        qFatal("Qps::Pstable2::colWidth() Bug!: over col !! %d\n", col);
 | 
			
		||||
    ///	return 30;
 | 
			
		||||
    // this is -1 for variable width fields, htable keeps track of it
 | 
			
		||||
    return procview->cats[col]->width();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Pstable2::alignment(int col)
 | 
			
		||||
{
 | 
			
		||||
    if (col < 0 or col >= procview->cats.size())
 | 
			
		||||
        qFatal("Qps::Pstable2::alignment() Bug!: over col !! %d\n", col);
 | 
			
		||||
    // printf("debug:alignment()\n");
 | 
			
		||||
    Category *cat = procview->cats[col];
 | 
			
		||||
    return cat->alignment();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// virtual of HeadedTable
 | 
			
		||||
void Pstable2::setSelected(int row, bool sel)
 | 
			
		||||
{
 | 
			
		||||
    ///	printf("debug:setSelected()\n");
 | 
			
		||||
    Procinfo *pi = procview->linear_procs[row];
 | 
			
		||||
    if (pi->selected != sel)
 | 
			
		||||
    {
 | 
			
		||||
        pi->selected = sel;
 | 
			
		||||
        //		body->repaintRow(row);  // TEMP trick..
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// virtual
 | 
			
		||||
bool Pstable2::isSelected(int row)
 | 
			
		||||
{
 | 
			
		||||
    Procinfo *pi = procview->linear_procs[row];
 | 
			
		||||
    return pi->selected;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Pstable2::rowDepth(int row)
 | 
			
		||||
{
 | 
			
		||||
    //	if(row < procview->linear_procs.size())
 | 
			
		||||
    Procinfo *pi = procview->linear_procs[row];
 | 
			
		||||
    if (pi)
 | 
			
		||||
        return pi->level;
 | 
			
		||||
 | 
			
		||||
    printf("Qps bug: over row  %d!!!\n", row);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Pstable2::lastChild(int row)
 | 
			
		||||
{
 | 
			
		||||
    Procinfo *pi = procview->linear_procs[row];
 | 
			
		||||
    if (pi)
 | 
			
		||||
        return pi->lastchild;
 | 
			
		||||
    printf("Qps bug: over row  %d!!!\n", row);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
int Pstable2::childCount(int row)
 | 
			
		||||
{
 | 
			
		||||
        return procview->linear_procs[row]->table_children.size();
 | 
			
		||||
        //and !p->hidekids)
 | 
			
		||||
} */
 | 
			
		||||
 | 
			
		||||
// Segfault !!!!
 | 
			
		||||
// return  not PPID ! just virtual parent in tree
 | 
			
		||||
int Pstable2::parentRow(int row)
 | 
			
		||||
{
 | 
			
		||||
    return procview->linear_procs[row]->parent_row;
 | 
			
		||||
    /* int ppid= procview->linear_procs[row]->ppid;
 | 
			
		||||
    Procinfo *pi= procview->getProcinfoByPID(ppid);
 | 
			
		||||
    if(pi) return ppid;
 | 
			
		||||
    else return -1; */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DRAFT
 | 
			
		||||
QString Pstable2::tipText(int col)
 | 
			
		||||
{
 | 
			
		||||
    Category *cat = procview->cats[col];
 | 
			
		||||
    QString s(cat->help);
 | 
			
		||||
 | 
			
		||||
    // trick
 | 
			
		||||
    if (cat->index == F_STAT)
 | 
			
		||||
        s.append("\n(R =Running, S =Sleeping, T =sTopped, Z=Zombie)");
 | 
			
		||||
    if (cat->index == F_PLCY)
 | 
			
		||||
        s.append("\n(TS =Time Sharing)");
 | 
			
		||||
    if (cat->index == F_RSS)
 | 
			
		||||
        ;
 | 
			
		||||
    // s.append("\nRSS = CODE + DATA + SHARE\n"
 | 
			
		||||
    //	   "RSS = TRS  + DRS  + SHARE\n");
 | 
			
		||||
    /// s.append("\n(RSS = TRS + DRS)");
 | 
			
		||||
    if (cat == procview->sortcat)
 | 
			
		||||
        s.append(procview->reversed ? "\n(sorted backwards)" : "\n(sorted)");
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DRAFT  who call?
 | 
			
		||||
char *Pstable2::total_selectedRow(int col) { return 0; }
 | 
			
		||||
 | 
			
		||||
Pstable2::Pstable2(QWidget *parent, Procview *pv) : HeadedTable2(parent, 0)
 | 
			
		||||
{
 | 
			
		||||
    printf("read 3-2\n");
 | 
			
		||||
    procview = pv;
 | 
			
		||||
    model = new PstableModel(this, pv);
 | 
			
		||||
    setModel(model);
 | 
			
		||||
    // activate() double click
 | 
			
		||||
    // pressed() one click
 | 
			
		||||
    // entered() drag
 | 
			
		||||
    // connect(this, SIGNAL(activated ( const QModelIndex &
 | 
			
		||||
    // )),SLOT(selection_update(const QModelIndex&)));
 | 
			
		||||
    connect(this, SIGNAL(pressed(const QModelIndex &)),
 | 
			
		||||
            SLOT(selection_update(const QModelIndex &)));
 | 
			
		||||
    //	connect(header(), SIGNAL(sectionClicked( int
 | 
			
		||||
    //)),SLOT(setSortColumn(int
 | 
			
		||||
    //)));
 | 
			
		||||
    connect(header(), SIGNAL(sectionPressed(int)), SLOT(setSortColumn(int)));
 | 
			
		||||
    //	connect(this, SIGNAL(titleClicked(int)),
 | 
			
		||||
    // SLOT(setSortColumn(int)));
 | 
			
		||||
 | 
			
		||||
    printf("read 3-3\n");
 | 
			
		||||
    // modelIterate(rootIndex());
 | 
			
		||||
    // modelIterate(QModelIndex());
 | 
			
		||||
    // update(QModelIndex());
 | 
			
		||||
    // reset();
 | 
			
		||||
    //	expandAll();
 | 
			
		||||
    //	reset();
 | 
			
		||||
    printf("read 3-4\n");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// who call this ? : from qps.cpp
 | 
			
		||||
void Pstable2::setProcview(Procview *pv) { procview = pv; }
 | 
			
		||||
 | 
			
		||||
HeadedTable2::NodeState Pstable2::folded(int row)
 | 
			
		||||
{
 | 
			
		||||
    Procinfo *p = procview->linear_procs[row];
 | 
			
		||||
    return (p->table_children.size() > 0) ? (p->hidekids ? Closed : Open)
 | 
			
		||||
                                          : Leaf;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// slot: called when selection changes
 | 
			
		||||
//	called by
 | 
			
		||||
void Pstable2::selection_update(const QModelIndex &idx)
 | 
			
		||||
{
 | 
			
		||||
    QModelIndexList list = selectionModel()->selectedRows();
 | 
			
		||||
    printf("debug:selection_update()\n");
 | 
			
		||||
    // qps->update_menu_selection_status();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// slot: changes table mode
 | 
			
		||||
// call by
 | 
			
		||||
// 	1.void Qps::set_table_mode(bool treemode)
 | 
			
		||||
void Pstable2::setTreeMode(bool treemode)
 | 
			
		||||
{
 | 
			
		||||
    /// printf("Pstable setTreeMode\n");
 | 
			
		||||
    procview->treeview = treemode;
 | 
			
		||||
    procview->fieldArrange();
 | 
			
		||||
    set_sortcol();
 | 
			
		||||
    HeadedTable2::setTreeMode(treemode);
 | 
			
		||||
    Pstable2::refresh();
 | 
			
		||||
    if (treemode)
 | 
			
		||||
        setRootIsDecorated(true);
 | 
			
		||||
    else
 | 
			
		||||
        setRootIsDecorated(false);
 | 
			
		||||
 | 
			
		||||
    reset();
 | 
			
		||||
    expandAll();
 | 
			
		||||
    // model->update(); //SEGFAULT
 | 
			
		||||
    // rebuild();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Pstable2::columnMovable(int col)
 | 
			
		||||
{
 | 
			
		||||
    if (treemode)
 | 
			
		||||
    {
 | 
			
		||||
        if (col == 0)
 | 
			
		||||
            return false;
 | 
			
		||||
    }
 | 
			
		||||
    if (procview->cats[col]->index == F_CMDLINE)
 | 
			
		||||
        return false;
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// called by HeadedTable
 | 
			
		||||
// Description : FIELD movement by mouse drag
 | 
			
		||||
//	 				To place From col
 | 
			
		||||
//	virtual HeadedTable::moveCol(col,place);
 | 
			
		||||
void Pstable2::moveCol(int col, int place)
 | 
			
		||||
{
 | 
			
		||||
    // printf("Pstable::moveCol\n");
 | 
			
		||||
    procview->moveColumn(col, place);
 | 
			
		||||
    set_sortcol();
 | 
			
		||||
    //	update();
 | 
			
		||||
    refresh(); // width size changed ,...
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DRAFT CODE:
 | 
			
		||||
// 1.procview->refresh: proc.refresh, rebuild
 | 
			
		||||
// 2.resetwidth
 | 
			
		||||
// 3.repaint
 | 
			
		||||
 | 
			
		||||
// called by
 | 
			
		||||
// 	1.void Qps::refresh()
 | 
			
		||||
void Pstable2::refresh()
 | 
			
		||||
{
 | 
			
		||||
    printf("Pstable2:refresh()\n");
 | 
			
		||||
    procview->rebuild();                       // for Table
 | 
			
		||||
    setNumCols(procview->cats.size());         // 2. resetWidths()
 | 
			
		||||
    setNumRows(procview->linear_procs.size()); // 1.
 | 
			
		||||
                                               //	printf("catsize=%d
 | 
			
		||||
    // row=%d\n",procview->cats.size(),procview->linear_procs.size());
 | 
			
		||||
    //	update();
 | 
			
		||||
    //	update(QModelIndex());
 | 
			
		||||
    //	repaint();
 | 
			
		||||
    //	repaint_changed();
 | 
			
		||||
    // model->revert();	//temp
 | 
			
		||||
    //	model->submit();	//temp
 | 
			
		||||
    //	model->update();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										71
									
								
								src/pstable2.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,71 @@
 | 
			
		||||
 | 
			
		||||
#include "proc.h"
 | 
			
		||||
#include "htable2.h"
 | 
			
		||||
#include <QToolTip>
 | 
			
		||||
 | 
			
		||||
class PstableModel : public HtableModel
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    PstableModel(QObject *parent, Procview *procview);
 | 
			
		||||
    ~PstableModel(){};
 | 
			
		||||
    virtual QModelIndex index(int row, int column,
 | 
			
		||||
                              const QModelIndex &parent = QModelIndex()) const;
 | 
			
		||||
    virtual QModelIndex parent(const QModelIndex &child) const; // pure virtual
 | 
			
		||||
    virtual int rowCount(const QModelIndex &parent) const;
 | 
			
		||||
    virtual int columnCount(const QModelIndex &parent) const;
 | 
			
		||||
    virtual QVariant data(const QModelIndex &index, int role) const;
 | 
			
		||||
    virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
 | 
			
		||||
    // int columnCount(const QModelIndex &parent) const;
 | 
			
		||||
    //	HeadedTable2 *htable;
 | 
			
		||||
    Procview *procview;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Pstable2 : public HeadedTable2
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    Pstable2(QWidget *parent, Procview *pv);
 | 
			
		||||
 | 
			
		||||
    void set_sortcol();
 | 
			
		||||
    void setProcview(Procview *pv);
 | 
			
		||||
    void setTreeMode(bool treemode);
 | 
			
		||||
    virtual void moveCol(int col, int place);
 | 
			
		||||
    void refresh();
 | 
			
		||||
 | 
			
		||||
    // called by super
 | 
			
		||||
    bool hasSelection() { return selectionModel()->hasSelection(); };
 | 
			
		||||
 | 
			
		||||
    virtual bool isSelected(int row); // hmm
 | 
			
		||||
    virtual void setSelected(int row, bool sel);
 | 
			
		||||
    virtual int totalRow(); // DEL?
 | 
			
		||||
 | 
			
		||||
  public slots:
 | 
			
		||||
    void selection_update(const QModelIndex &); // hmm
 | 
			
		||||
    void setSortColumn(int col);
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void selection_changed();
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    // implementation of the interface to HeadedTable
 | 
			
		||||
    virtual QString title(int col);         // ok
 | 
			
		||||
    virtual QString text(int row, int col); // ok
 | 
			
		||||
    virtual int colWidth(int col);
 | 
			
		||||
    virtual int alignment(int col);   // ok
 | 
			
		||||
    virtual QString tipText(int col); // ok
 | 
			
		||||
 | 
			
		||||
    virtual int rowDepth(int row);
 | 
			
		||||
    virtual NodeState folded(int row);
 | 
			
		||||
    virtual int parentRow(int row);
 | 
			
		||||
    virtual bool lastChild(int row);
 | 
			
		||||
    virtual char *total_selectedRow(int col);
 | 
			
		||||
    virtual int sizeHintForColumn(int col) const;
 | 
			
		||||
    virtual bool columnMovable(int col);
 | 
			
		||||
 | 
			
		||||
    // virtual void drawCellContents(int row, int col, int w, int h,
 | 
			
		||||
    // QPainter *p);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    Procview *procview;
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										2553
									
								
								src/qps.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										318
									
								
								src/qps.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,318 @@
 | 
			
		||||
// qps.h				emacs, this is written in -*-c++-*-
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegrd, 1997-1999
 | 
			
		||||
 | 
			
		||||
#ifndef QPS_H
 | 
			
		||||
#define QPS_H
 | 
			
		||||
 | 
			
		||||
#ifndef USING_PCH
 | 
			
		||||
#include <QWidget>
 | 
			
		||||
#include <QMenuBar>
 | 
			
		||||
#include <QColor>
 | 
			
		||||
#include <QMenu>
 | 
			
		||||
#include <QCloseEvent>
 | 
			
		||||
#include <QTimerEvent>
 | 
			
		||||
#include <QPixmap>
 | 
			
		||||
#include <QUrl>
 | 
			
		||||
#include <QSystemTrayIcon>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if QT_VERSION >= 0x040200
 | 
			
		||||
#else
 | 
			
		||||
//#error Qt library version 4.2 or higher is needed for this version of qps
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define HTABLE1
 | 
			
		||||
#include "misc.h"
 | 
			
		||||
#ifdef HTABLE2
 | 
			
		||||
#include "pstable2.h"
 | 
			
		||||
#else
 | 
			
		||||
#include "pstable.h"
 | 
			
		||||
#endif
 | 
			
		||||
#include "proc.h"
 | 
			
		||||
#include "infobar.h"
 | 
			
		||||
#include "fieldsel.h"
 | 
			
		||||
#include "details.h"
 | 
			
		||||
#include "prefs.h"
 | 
			
		||||
#include "command.h"
 | 
			
		||||
 | 
			
		||||
#define DEBUG printf
 | 
			
		||||
 | 
			
		||||
#define FUNC_START
 | 
			
		||||
#define FUNC_END
 | 
			
		||||
 | 
			
		||||
#include <QSystemTrayIcon>
 | 
			
		||||
class Qps : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    Qps();
 | 
			
		||||
    ~Qps();
 | 
			
		||||
 | 
			
		||||
    void set_update_period(int milliseconds);
 | 
			
		||||
    void setWindowGroup(QWidget *w);
 | 
			
		||||
    void setCommand(int argc, char **argv);
 | 
			
		||||
    void setIconSize(int w, int h) { icon_width = w, icon_height = h; }
 | 
			
		||||
    void write_settings();
 | 
			
		||||
    void save_settings();
 | 
			
		||||
 | 
			
		||||
    QPixmap *get_load_icon();
 | 
			
		||||
 | 
			
		||||
    // settings
 | 
			
		||||
    static bool show_file_path;    // shows command/file map path
 | 
			
		||||
    static bool show_cmd_path;     // DEL CMDLINE shows command path
 | 
			
		||||
    static bool show_infobar;      // information bar is shown
 | 
			
		||||
    static bool show_ctrlbar;      // control bar is shown
 | 
			
		||||
    static bool show_statusbar;    //
 | 
			
		||||
    static bool show_mem_bar;      // memory is shown as a bar
 | 
			
		||||
    static bool show_swap_bar;     // swap is shown as a bar
 | 
			
		||||
    static bool show_cpu_bar;      // cpu states are shown as a bar
 | 
			
		||||
    static bool show_load_graph;   // load is shown as a graph
 | 
			
		||||
    static bool load_in_icon;      // load graph in icon
 | 
			
		||||
    static bool auto_save_options; // settings saved on exit
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    static bool hostname_lookup; // do a name lookup on socket addresses
 | 
			
		||||
    static bool service_lookup;  // map port numbers to service names
 | 
			
		||||
#endif
 | 
			
		||||
    static bool pids_to_selection; // selected processes' PIDS to X11 sel
 | 
			
		||||
    static bool vertical_cpu_bar;  // save space with SMP
 | 
			
		||||
 | 
			
		||||
    static int swaplimit;        // limit of swap redline, in K or %
 | 
			
		||||
    static bool swaplim_percent; // true if swaplimit is in %
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
    static bool
 | 
			
		||||
        normalize_nice;   // whether nice should be normalized (normal nice
 | 
			
		||||
                          // is 0 etc)
 | 
			
		||||
    static bool use_pmap; // use /proc/bin/pmap for map names
 | 
			
		||||
#endif
 | 
			
		||||
    static bool tree_gadgets; // use open/close gadgets (triangles)
 | 
			
		||||
    static bool tree_lines;   // draw tree branch lines
 | 
			
		||||
 | 
			
		||||
    //		static bool comm_is_magic;	//DEL, auto-remove COMM
 | 
			
		||||
    // when
 | 
			
		||||
    // switching
 | 
			
		||||
    static bool flag_systray; // trayicon , sytemtray
 | 
			
		||||
    static bool flag_exit;
 | 
			
		||||
    static bool flag_show; // last qps-main_window state
 | 
			
		||||
    static bool flag_useTabView;
 | 
			
		||||
    static bool flag_qps_hide;
 | 
			
		||||
 | 
			
		||||
    // colors which may be set by the user
 | 
			
		||||
    enum
 | 
			
		||||
    {
 | 
			
		||||
        COLOR_CPU_USER,
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
        COLOR_CPU_NICE,
 | 
			
		||||
#endif
 | 
			
		||||
        COLOR_CPU_SYS,
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
        COLOR_CPU_WAIT,
 | 
			
		||||
#endif
 | 
			
		||||
        COLOR_CPU_IDLE,
 | 
			
		||||
        COLOR_MEM_USED,
 | 
			
		||||
        COLOR_MEM_BUFF,
 | 
			
		||||
        COLOR_MEM_CACHE,
 | 
			
		||||
        COLOR_MEM_FREE,
 | 
			
		||||
        COLOR_SWAP_USED,
 | 
			
		||||
        COLOR_SWAP_FREE,
 | 
			
		||||
        COLOR_SWAP_WARN,
 | 
			
		||||
        COLOR_LOAD_BG,
 | 
			
		||||
        COLOR_LOAD_FG,
 | 
			
		||||
        COLOR_LOAD_LINES,
 | 
			
		||||
        COLOR_SELECTION_BG,
 | 
			
		||||
        COLOR_SELECTION_FG,
 | 
			
		||||
        NUM_COLORS
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    enum menuid
 | 
			
		||||
    {
 | 
			
		||||
        MENU_SIGQUIT,
 | 
			
		||||
        MENU_SIGILL,
 | 
			
		||||
        MENU_SIGABRT,
 | 
			
		||||
        MENU_SIGFPE,
 | 
			
		||||
        MENU_SIGSEGV,
 | 
			
		||||
        MENU_SIGPIPE,
 | 
			
		||||
        MENU_SIGALRM,
 | 
			
		||||
        MENU_SIGUSR1,
 | 
			
		||||
        MENU_SIGUSR2,
 | 
			
		||||
        MENU_SIGCHLD,
 | 
			
		||||
        MENU_SIGCONT,
 | 
			
		||||
        MENU_SIGSTOP,
 | 
			
		||||
        MENU_SIGTSTP,
 | 
			
		||||
        MENU_SIGTTIN,
 | 
			
		||||
        MENU_SIGTTOU,
 | 
			
		||||
        MENU_RENICE,
 | 
			
		||||
        MENU_SCHED,
 | 
			
		||||
        MENU_DETAILS,
 | 
			
		||||
        MENU_PARENT,
 | 
			
		||||
        MENU_CHILD,
 | 
			
		||||
        MENU_DYNASTY,
 | 
			
		||||
        MENU_SIGTERM,
 | 
			
		||||
        MENU_SIGHUP,
 | 
			
		||||
        MENU_SIGINT,
 | 
			
		||||
        MENU_SIGKILL,
 | 
			
		||||
        MENU_OTHERS,
 | 
			
		||||
        MENU_PROCS,
 | 
			
		||||
        MENU_FIELDS,
 | 
			
		||||
        MENU_CUSTOM,
 | 
			
		||||
        MENU_PATH,
 | 
			
		||||
        MENU_INFOBAR,
 | 
			
		||||
        MENU_CTRLBAR,
 | 
			
		||||
        MENU_CUMUL,
 | 
			
		||||
        MENU_PREFS,
 | 
			
		||||
        MENU_ADD_HIDDEN,
 | 
			
		||||
        MENU_REMOVE_HIDDEN,
 | 
			
		||||
        MENU_STATUS,
 | 
			
		||||
#ifdef MOSIX
 | 
			
		||||
        POPUP_MIGRATE,
 | 
			
		||||
#endif
 | 
			
		||||
        MENU_FIRST_COMMAND // must be last
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
  public slots:
 | 
			
		||||
    void start_screenshot();
 | 
			
		||||
    void clicked_trayicon(QSystemTrayIcon::ActivationReason);
 | 
			
		||||
    void clicked_trayicon();
 | 
			
		||||
    void sig_term();
 | 
			
		||||
    void sig_hup();
 | 
			
		||||
    void sig_stop();
 | 
			
		||||
    void sig_cont();
 | 
			
		||||
    void sig_kill();
 | 
			
		||||
    void signal_menu(QAction *);
 | 
			
		||||
    void run_command(QAction *);
 | 
			
		||||
    void about();
 | 
			
		||||
    void license();
 | 
			
		||||
    void menu_update();
 | 
			
		||||
    void menu_toggle_path();
 | 
			
		||||
    void menu_toggle_infobar();
 | 
			
		||||
    void menu_toggle_ctrlbar();
 | 
			
		||||
    void menu_toggle_statusbar();
 | 
			
		||||
    void menu_toggle_cumul();
 | 
			
		||||
    void menu_prefs();
 | 
			
		||||
    void menu_renice();
 | 
			
		||||
    void menu_sched();
 | 
			
		||||
    void Action_Detail();
 | 
			
		||||
    void menu_parent();
 | 
			
		||||
    void menu_children();
 | 
			
		||||
    void menu_dynasty();
 | 
			
		||||
    void menu_custom();
 | 
			
		||||
    void menu_remove_field();
 | 
			
		||||
    void menu_edit_cmd();
 | 
			
		||||
    void mig_menu(int id); // MOSIX only
 | 
			
		||||
    void make_command_menu();
 | 
			
		||||
    void view_menu(QAction *);
 | 
			
		||||
    void save_quit();
 | 
			
		||||
    void add_fields_menu(int id);
 | 
			
		||||
    void add_fields_menu(QAction *act);
 | 
			
		||||
    void tabChanged(int i);
 | 
			
		||||
 | 
			
		||||
    void show_popup_menu(QPoint p);
 | 
			
		||||
    void context_heading_menu(QPoint p, int col);
 | 
			
		||||
 | 
			
		||||
    void update_menu_selection_status();
 | 
			
		||||
    void field_added(int index);
 | 
			
		||||
    void field_removed(int index);
 | 
			
		||||
    void set_table_mode(bool treemode); // hmmm
 | 
			
		||||
 | 
			
		||||
    void details_closed(Details *d);
 | 
			
		||||
    void open_details(int row);
 | 
			
		||||
 | 
			
		||||
    void config_change();
 | 
			
		||||
 | 
			
		||||
    void update_timer();
 | 
			
		||||
    void refresh();
 | 
			
		||||
    void refresh_details();
 | 
			
		||||
    void test_popup(const QUrl &link);
 | 
			
		||||
    void update_menu_status();
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    // reimplementation of QWidget methods
 | 
			
		||||
    virtual void timerEvent(QTimerEvent *);
 | 
			
		||||
    virtual void closeEvent(QCloseEvent *);
 | 
			
		||||
    virtual void moveEvent(QMoveEvent *event);
 | 
			
		||||
    virtual void mouseMoveEvent(QMouseEvent *event);
 | 
			
		||||
    virtual void hideEvent(QHideEvent *event);
 | 
			
		||||
    virtual void resizeEvent(QResizeEvent *event);
 | 
			
		||||
    virtual void paintEvent(QPaintEvent *event);
 | 
			
		||||
    virtual void enterEvent(QEvent *event);
 | 
			
		||||
    virtual void leaveEvent(QEvent *event);
 | 
			
		||||
    virtual void showEvent(QShowEvent *event);
 | 
			
		||||
    virtual void focusInEvent(QFocusEvent *event);
 | 
			
		||||
    virtual void focusOutEvent(QFocusEvent *event);
 | 
			
		||||
    virtual void keyPressEvent(QKeyEvent *event);
 | 
			
		||||
    // bool event(QEvent *e);
 | 
			
		||||
    void transfer_selection();
 | 
			
		||||
    void adjust_popup_menu(QMenu *m, bool cont);
 | 
			
		||||
    void adjust_popup_menu();
 | 
			
		||||
    bool all_selected_stopped();
 | 
			
		||||
 | 
			
		||||
    void locate_relatives(int Procinfo::*a, int Procinfo::*b);
 | 
			
		||||
    QMenu *make_signal_popup_menu();
 | 
			
		||||
#ifdef MOSIX
 | 
			
		||||
    QMenu *make_migrate_menu();
 | 
			
		||||
    void migrate_selected(int sig);
 | 
			
		||||
#endif
 | 
			
		||||
    void send_to_selected(int sig);
 | 
			
		||||
    void sendsig(Procinfo *p, int sig);
 | 
			
		||||
    void earlier_refresh();
 | 
			
		||||
    bool read_settings();
 | 
			
		||||
 | 
			
		||||
    bool load_settings();
 | 
			
		||||
 | 
			
		||||
    void bar_visibility();
 | 
			
		||||
    void set_default_icon();
 | 
			
		||||
    void set_load_icon();
 | 
			
		||||
 | 
			
		||||
  public:
 | 
			
		||||
#ifdef HTABLE2
 | 
			
		||||
    Pstable2 *pstable; // test
 | 
			
		||||
#else
 | 
			
		||||
    Pstable *pstable;
 | 
			
		||||
#endif
 | 
			
		||||
    Procview *procview;
 | 
			
		||||
    StatusBar *statusBar;
 | 
			
		||||
    // Netable *netable;
 | 
			
		||||
    QTextEdit *logbox;
 | 
			
		||||
    void update_icon();
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    QMenuBar *menubar;
 | 
			
		||||
    QMenu *m_field; // Field Menu
 | 
			
		||||
    QMenu *m_view;  // Field Menu
 | 
			
		||||
    QAction *am_view;
 | 
			
		||||
    QMenu *m_command;
 | 
			
		||||
    QMenu *m_options;
 | 
			
		||||
    QMenu *m_popup;
 | 
			
		||||
    QMenu *m_headpopup;
 | 
			
		||||
    QMenu *m_fields;
 | 
			
		||||
    QMenu *popupx; // testing
 | 
			
		||||
 | 
			
		||||
    bool selection_items_enabled; // state of certain menu items (???)
 | 
			
		||||
 | 
			
		||||
    Infobar2 *infobar; // tmp
 | 
			
		||||
    ControlBar *ctrlbar;
 | 
			
		||||
    FieldSelect *field_win;
 | 
			
		||||
    Preferences *prefs_win;
 | 
			
		||||
    CommandDialog *command_win;
 | 
			
		||||
 | 
			
		||||
    QList<Details> details;
 | 
			
		||||
 | 
			
		||||
    int update_period;                      // in mili second
 | 
			
		||||
    static const int eternity = 0x7fffffff; // turns off automatic update
 | 
			
		||||
    // the Linux kernel updates its load average counters every 5 seconds
 | 
			
		||||
    // (kernel 2.0.29), so there is no point in reading it too often
 | 
			
		||||
    static const int load_update_period = 4800; // in ms
 | 
			
		||||
    int update_load_time;                       // time left to update load
 | 
			
		||||
 | 
			
		||||
    // size of our icon
 | 
			
		||||
    int icon_width;
 | 
			
		||||
    int icon_height;
 | 
			
		||||
    int timer_id;
 | 
			
		||||
 | 
			
		||||
    QPixmap *default_icon;
 | 
			
		||||
    bool default_icon_set; // true if default icon is current icon
 | 
			
		||||
    int context_col;       // where heading context menu was clicked
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // QPS_H
 | 
			
		||||
							
								
								
									
										11
									
								
								src/qps.qrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,11 @@
 | 
			
		||||
<RCC>
 | 
			
		||||
  <qresource>
 | 
			
		||||
    <file>icon/letters.png</file>
 | 
			
		||||
    <file>icon/vista.png</file>
 | 
			
		||||
    <file>icon/vpointer.png</file>
 | 
			
		||||
    <file>icon/vcross.png</file>
 | 
			
		||||
    <file>icon/pause.png</file>
 | 
			
		||||
    <file>icon/superman.png</file>
 | 
			
		||||
    <file>icon/preferences-system.png</file>
 | 
			
		||||
  </qresource>
 | 
			
		||||
</RCC>
 | 
			
		||||
							
								
								
									
										1205
									
								
								src/qrc_qps.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										389
									
								
								src/qticonloader.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,389 @@
 | 
			
		||||
/****************************************************************************
 | 
			
		||||
**
 | 
			
		||||
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 | 
			
		||||
** Contact: Qt Software Information (qt-info@nokia.com)
 | 
			
		||||
**
 | 
			
		||||
** This file is part of the QtGui module of the Qt Toolkit.
 | 
			
		||||
**
 | 
			
		||||
** Commercial Usage
 | 
			
		||||
** Licensees holding valid Qt Commercial licenses may use this file in
 | 
			
		||||
** accordance with the Qt Commercial License Agreement provided with the
 | 
			
		||||
** Software or, alternatively, in accordance with the terms contained in
 | 
			
		||||
** a written agreement between you and Nokia.
 | 
			
		||||
**
 | 
			
		||||
** GNU Lesser General Public License Usage
 | 
			
		||||
** Alternatively, this file may be used under the terms of the GNU Lesser
 | 
			
		||||
** General Public License version 2.1 as published by the Free Software
 | 
			
		||||
** Foundation and appearing in the file LICENSE.LGPL included in the
 | 
			
		||||
** packaging of this file.  Please review the following information to
 | 
			
		||||
** ensure the GNU Lesser General Public License version 2.1 requirements
 | 
			
		||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
			
		||||
**
 | 
			
		||||
** In addition, as a special exception, Nokia gives you certain
 | 
			
		||||
** additional rights. These rights are described in the Nokia Qt LGPL
 | 
			
		||||
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
 | 
			
		||||
** package.
 | 
			
		||||
**
 | 
			
		||||
** GNU General Public License Usage
 | 
			
		||||
** Alternatively, this file may be used under the terms of the GNU
 | 
			
		||||
** General Public License version 3.0 as published by the Free Software
 | 
			
		||||
** Foundation and appearing in the file LICENSE.GPL included in the
 | 
			
		||||
** packaging of this file.  Please review the following information to
 | 
			
		||||
** ensure the GNU General Public License version 3.0 requirements will be
 | 
			
		||||
** met: http://www.gnu.org/copyleft/gpl.html.
 | 
			
		||||
**
 | 
			
		||||
** If you are unsure which license is appropriate for your use, please
 | 
			
		||||
** contact the sales department at qt-sales@nokia.com.
 | 
			
		||||
**
 | 
			
		||||
****************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include "qticonloader.h"
 | 
			
		||||
#include <QtGui/QPixmapCache>
 | 
			
		||||
 | 
			
		||||
#include <QtCore/QList>
 | 
			
		||||
#include <QtCore/QHash>
 | 
			
		||||
#include <QtCore/QDir>
 | 
			
		||||
#include <QtCore/QString>
 | 
			
		||||
#include <QtCore/QLibrary>
 | 
			
		||||
#include <QtCore/QSettings>
 | 
			
		||||
#include <QtCore/QTextStream>
 | 
			
		||||
 | 
			
		||||
#ifdef Q_WS_X11
 | 
			
		||||
 | 
			
		||||
class QIconTheme
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    QIconTheme(QHash<int, QString> dirList, QStringList parents)
 | 
			
		||||
        : _dirList(dirList), _parents(parents), _valid(true)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    QIconTheme() : _valid(false) {}
 | 
			
		||||
    QHash<int, QString> dirList() { return _dirList; }
 | 
			
		||||
    QStringList parents() { return _parents; }
 | 
			
		||||
    bool isValid() { return _valid; }
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    QHash<int, QString> _dirList;
 | 
			
		||||
    QStringList _parents;
 | 
			
		||||
    bool _valid;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class QtIconLoaderImplementation
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    QtIconLoaderImplementation();
 | 
			
		||||
    QPixmap findIcon(int size, const QString &name) const;
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    QIconTheme parseIndexFile(const QString &themeName) const;
 | 
			
		||||
    void lookupIconTheme() const;
 | 
			
		||||
    QPixmap findIconHelper(int size, const QString &themeName,
 | 
			
		||||
                           const QString &iconName, QStringList &visited) const;
 | 
			
		||||
    mutable QString themeName;
 | 
			
		||||
    mutable QStringList iconDirs;
 | 
			
		||||
    mutable QHash<QString, QIconTheme> themeList;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Q_GLOBAL_STATIC(QtIconLoaderImplementation, iconLoaderInstance)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 | 
			
		||||
    Returns the standard icon for the given icon /a name
 | 
			
		||||
    as specified in the freedesktop icon spec
 | 
			
		||||
    http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
 | 
			
		||||
 | 
			
		||||
    /a fallback is an optional argument to specify the icon to be used if
 | 
			
		||||
    no icon is found on the platform. This is particularily useful for
 | 
			
		||||
    crossplatform code.
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
QIcon QtIconLoader::icon(const QString &name, const QIcon &fallback)
 | 
			
		||||
{
 | 
			
		||||
    QIcon icon;
 | 
			
		||||
#ifdef Q_WS_X11
 | 
			
		||||
    QString pngExtension(QLatin1String(".png"));
 | 
			
		||||
    QList<int> iconSizes;
 | 
			
		||||
    iconSizes << 16 << 24 << 32 << 48 << 64;
 | 
			
		||||
    Q_FOREACH (int size, iconSizes)
 | 
			
		||||
    {
 | 
			
		||||
        icon.addPixmap(
 | 
			
		||||
            iconLoaderInstance()->findIcon(size, name + pngExtension));
 | 
			
		||||
        //        icon.addPixmap(iconLoaderInstance()->findIcon(size,
 | 
			
		||||
        //        name));
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
    if (icon.isNull())
 | 
			
		||||
        icon = fallback;
 | 
			
		||||
    Q_UNUSED(name);
 | 
			
		||||
    return icon;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef Q_WS_X11
 | 
			
		||||
 | 
			
		||||
QtIconLoaderImplementation::QtIconLoaderImplementation() { lookupIconTheme(); }
 | 
			
		||||
 | 
			
		||||
extern "C" {
 | 
			
		||||
struct GConfClient;
 | 
			
		||||
struct GError;
 | 
			
		||||
typedef void (*Ptr_g_type_init)();
 | 
			
		||||
typedef GConfClient *(*Ptr_gconf_client_get_default)();
 | 
			
		||||
typedef char *(*Ptr_gconf_client_get_string)(GConfClient *, const char *,
 | 
			
		||||
                                             GError **);
 | 
			
		||||
typedef void (*Ptr_g_object_unref)(void *);
 | 
			
		||||
typedef void (*Ptr_g_error_free)(GError *);
 | 
			
		||||
typedef void (*Ptr_g_free)(void *);
 | 
			
		||||
static Ptr_g_type_init p_g_type_init = 0;
 | 
			
		||||
static Ptr_gconf_client_get_default p_gconf_client_get_default = 0;
 | 
			
		||||
static Ptr_gconf_client_get_string p_gconf_client_get_string = 0;
 | 
			
		||||
static Ptr_g_object_unref p_g_object_unref = 0;
 | 
			
		||||
static Ptr_g_error_free p_g_error_free = 0;
 | 
			
		||||
static Ptr_g_free p_g_free = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int kdeVersion()
 | 
			
		||||
{
 | 
			
		||||
    static int version = qgetenv("KDE_SESSION_VERSION").toInt();
 | 
			
		||||
    return version;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static QString kdeHome()
 | 
			
		||||
{
 | 
			
		||||
    static QString kdeHomePath;
 | 
			
		||||
    if (kdeHomePath.isEmpty())
 | 
			
		||||
    {
 | 
			
		||||
        kdeHomePath = QFile::decodeName(qgetenv("KDEHOME"));
 | 
			
		||||
        if (kdeHomePath.isEmpty())
 | 
			
		||||
        {
 | 
			
		||||
            int kdeSessionVersion = kdeVersion();
 | 
			
		||||
            QDir homeDir(QDir::homePath());
 | 
			
		||||
            QString kdeConfDir(QLatin1String("/.kde"));
 | 
			
		||||
            if (4 == kdeSessionVersion &&
 | 
			
		||||
                homeDir.exists(QLatin1String(".kde4")))
 | 
			
		||||
                kdeConfDir = QLatin1String("/.kde4");
 | 
			
		||||
            kdeHomePath = QDir::homePath() + kdeConfDir;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return kdeHomePath;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void QtIconLoaderImplementation::lookupIconTheme() const
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
#ifdef Q_WS_X11
 | 
			
		||||
    QString dataDirs = QFile::decodeName(getenv("XDG_DATA_DIRS"));
 | 
			
		||||
    if (dataDirs.isEmpty())
 | 
			
		||||
        dataDirs = QLatin1String("/usr/local/share/:/usr/share/");
 | 
			
		||||
 | 
			
		||||
    dataDirs.prepend(QDir::homePath() + QLatin1String("/:"));
 | 
			
		||||
    iconDirs = dataDirs.split(QLatin1Char(':'));
 | 
			
		||||
 | 
			
		||||
    // If we are running GNOME we resolve and use GConf. In all other
 | 
			
		||||
    // cases we currently use the KDE icon theme
 | 
			
		||||
 | 
			
		||||
    if (qgetenv("DESKTOP_SESSION") == "gnome" ||
 | 
			
		||||
        !qgetenv("GNOME_DESKTOP_SESSION_ID").isEmpty())
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        if (themeName.isEmpty())
 | 
			
		||||
        {
 | 
			
		||||
            // Resolve glib and gconf
 | 
			
		||||
 | 
			
		||||
            p_g_type_init = (Ptr_g_type_init)QLibrary::resolve(
 | 
			
		||||
                QLatin1String("gobject-2.0"), 0, "g_type_init");
 | 
			
		||||
            p_gconf_client_get_default =
 | 
			
		||||
                (Ptr_gconf_client_get_default)QLibrary::resolve(
 | 
			
		||||
                    QLatin1String("gconf-2"), 4, "gconf_client_get_default");
 | 
			
		||||
            p_gconf_client_get_string =
 | 
			
		||||
                (Ptr_gconf_client_get_string)QLibrary::resolve(
 | 
			
		||||
                    QLatin1String("gconf-2"), 4, "gconf_client_get_string");
 | 
			
		||||
            p_g_object_unref = (Ptr_g_object_unref)QLibrary::resolve(
 | 
			
		||||
                QLatin1String("gobject-2.0"), 0, "g_object_unref");
 | 
			
		||||
            p_g_error_free = (Ptr_g_error_free)QLibrary::resolve(
 | 
			
		||||
                QLatin1String("glib-2.0"), 0, "g_error_free");
 | 
			
		||||
            p_g_free = (Ptr_g_free)QLibrary::resolve(QLatin1String("glib-2.0"),
 | 
			
		||||
                                                     0, "g_free");
 | 
			
		||||
 | 
			
		||||
            if (p_g_type_init && p_gconf_client_get_default &&
 | 
			
		||||
                p_gconf_client_get_string && p_g_object_unref &&
 | 
			
		||||
                p_g_error_free && p_g_free)
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
                p_g_type_init();
 | 
			
		||||
                GConfClient *client = p_gconf_client_get_default();
 | 
			
		||||
                GError *err = 0;
 | 
			
		||||
 | 
			
		||||
                char *str = p_gconf_client_get_string(
 | 
			
		||||
                    client, "/desktop/gnome/interface/icon_theme", &err);
 | 
			
		||||
                if (!err)
 | 
			
		||||
                {
 | 
			
		||||
                    themeName = QString::fromUtf8(str);
 | 
			
		||||
                    p_g_free(str);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                p_g_object_unref(client);
 | 
			
		||||
                if (err)
 | 
			
		||||
                    p_g_error_free(err);
 | 
			
		||||
            }
 | 
			
		||||
            if (themeName.isEmpty())
 | 
			
		||||
                themeName = QLatin1String("gnome");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!themeName.isEmpty())
 | 
			
		||||
            return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // KDE (and others)
 | 
			
		||||
    if (dataDirs.isEmpty())
 | 
			
		||||
        dataDirs = QLatin1String("/usr/local/share/:/usr/share/");
 | 
			
		||||
 | 
			
		||||
    dataDirs += QLatin1Char(':') + kdeHome() + QLatin1String("/share");
 | 
			
		||||
    dataDirs.prepend(QDir::homePath() + QLatin1String("/:"));
 | 
			
		||||
    QStringList kdeDirs =
 | 
			
		||||
        QFile::decodeName(getenv("KDEDIRS")).split(QLatin1Char(':'));
 | 
			
		||||
    Q_FOREACH (const QString dirName, kdeDirs)
 | 
			
		||||
        dataDirs.append(QLatin1Char(':') + dirName + QLatin1String("/share"));
 | 
			
		||||
    iconDirs = dataDirs.split(QLatin1Char(':'));
 | 
			
		||||
 | 
			
		||||
    QFileInfo fileInfo(QLatin1String("/usr/share/icons/default.kde"));
 | 
			
		||||
    QDir dir(fileInfo.canonicalFilePath());
 | 
			
		||||
    QString kdeDefault = kdeVersion() >= 4 ? QString::fromLatin1("oxygen")
 | 
			
		||||
                                           : QString::fromLatin1("crystalsvg");
 | 
			
		||||
    QString defaultTheme = fileInfo.exists() ? dir.dirName() : kdeDefault;
 | 
			
		||||
    QSettings settings(kdeHome() + QLatin1String("/share/config/kdeglobals"),
 | 
			
		||||
                       QSettings::IniFormat);
 | 
			
		||||
    settings.beginGroup(QLatin1String("Icons"));
 | 
			
		||||
    themeName = settings.value(QLatin1String("Theme"), defaultTheme).toString();
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QIconTheme
 | 
			
		||||
QtIconLoaderImplementation::parseIndexFile(const QString &themeName) const
 | 
			
		||||
{
 | 
			
		||||
    QIconTheme theme;
 | 
			
		||||
    QFile themeIndex;
 | 
			
		||||
    QStringList parents;
 | 
			
		||||
    QHash<int, QString> dirList;
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < iconDirs.size() && !themeIndex.exists(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        const QString &contentDir = QLatin1String(
 | 
			
		||||
            iconDirs[i].startsWith(QDir::homePath()) ? "/.icons/" : "/icons/");
 | 
			
		||||
        themeIndex.setFileName(iconDirs[i] + contentDir + themeName +
 | 
			
		||||
                               QLatin1String("/index.theme"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (themeIndex.exists())
 | 
			
		||||
    {
 | 
			
		||||
        QSettings indexReader(themeIndex.fileName(), QSettings::IniFormat);
 | 
			
		||||
        Q_FOREACH (const QString &key, indexReader.allKeys())
 | 
			
		||||
        {
 | 
			
		||||
            if (key.endsWith("/Size"))
 | 
			
		||||
            {
 | 
			
		||||
                if (int size = indexReader.value(key).toInt())
 | 
			
		||||
                    dirList.insertMulti(size, key.left(key.size() - 5));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Parent themes provide fallbacks for missing icons
 | 
			
		||||
        parents = indexReader.value(QLatin1String("Icon Theme/Inherits"))
 | 
			
		||||
                      .toStringList();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (kdeVersion() >= 3)
 | 
			
		||||
    {
 | 
			
		||||
        QFileInfo fileInfo(QLatin1String("/usr/share/icons/default.kde"));
 | 
			
		||||
        QDir dir(fileInfo.canonicalFilePath());
 | 
			
		||||
        QString defaultKDETheme =
 | 
			
		||||
            dir.exists() ? dir.dirName()
 | 
			
		||||
                         : kdeVersion() == 3 ? QString::fromLatin1("crystalsvg")
 | 
			
		||||
                                             : QString::fromLatin1("oxygen");
 | 
			
		||||
        if (!parents.contains(defaultKDETheme) && themeName != defaultKDETheme)
 | 
			
		||||
            parents.append(defaultKDETheme);
 | 
			
		||||
    }
 | 
			
		||||
    else if (parents.isEmpty() && themeName != QLatin1String("hicolor"))
 | 
			
		||||
    {
 | 
			
		||||
        parents.append(QLatin1String("hicolor"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    theme = QIconTheme(dirList, parents);
 | 
			
		||||
    return theme;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QPixmap QtIconLoaderImplementation::findIconHelper(int size,
 | 
			
		||||
                                                   const QString &themeName,
 | 
			
		||||
                                                   const QString &iconName,
 | 
			
		||||
                                                   QStringList &visited) const
 | 
			
		||||
{
 | 
			
		||||
    QPixmap pixmap;
 | 
			
		||||
 | 
			
		||||
    if (!themeName.isEmpty())
 | 
			
		||||
    {
 | 
			
		||||
        visited << themeName;
 | 
			
		||||
        QIconTheme theme = themeList.value(themeName);
 | 
			
		||||
 | 
			
		||||
        if (!theme.isValid())
 | 
			
		||||
        {
 | 
			
		||||
            theme = parseIndexFile(themeName);
 | 
			
		||||
            themeList.insert(themeName, theme);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!theme.isValid())
 | 
			
		||||
            return QPixmap();
 | 
			
		||||
 | 
			
		||||
        QList<QString> subDirs = theme.dirList().values(size);
 | 
			
		||||
 | 
			
		||||
        for (int i = 0; i < iconDirs.size(); ++i)
 | 
			
		||||
        {
 | 
			
		||||
            for (int j = 0; j < subDirs.size(); ++j)
 | 
			
		||||
            {
 | 
			
		||||
                QString contentDir = (iconDirs[i].startsWith(QDir::homePath()))
 | 
			
		||||
                                         ? QLatin1String("/.icons/")
 | 
			
		||||
                                         : QLatin1String("/icons/");
 | 
			
		||||
                QString fileName = iconDirs[i] + contentDir + themeName +
 | 
			
		||||
                                   QLatin1Char('/') + subDirs[j] +
 | 
			
		||||
                                   QLatin1Char('/') + iconName;
 | 
			
		||||
                QFile file(fileName);
 | 
			
		||||
                if (file.exists())
 | 
			
		||||
                    pixmap.load(fileName);
 | 
			
		||||
                if (!pixmap.isNull())
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (pixmap.isNull())
 | 
			
		||||
        {
 | 
			
		||||
            QStringList parents = theme.parents();
 | 
			
		||||
            // search recursively through inherited themes
 | 
			
		||||
            for (int i = 0; pixmap.isNull() && i < parents.size(); ++i)
 | 
			
		||||
            {
 | 
			
		||||
                QString parentTheme = parents[i].trimmed();
 | 
			
		||||
                if (!visited.contains(parentTheme)) // guard
 | 
			
		||||
                                                    // against
 | 
			
		||||
                                                    // endless
 | 
			
		||||
                                                    // recursion
 | 
			
		||||
                    pixmap =
 | 
			
		||||
                        findIconHelper(size, parentTheme, iconName, visited);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return pixmap;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QPixmap QtIconLoaderImplementation::findIcon(int size,
 | 
			
		||||
                                             const QString &name) const
 | 
			
		||||
{
 | 
			
		||||
    QPixmap pixmap;
 | 
			
		||||
    QString pixmapName = QLatin1String("$qt") + name + QString::number(size);
 | 
			
		||||
    if (QPixmapCache::find(pixmapName, pixmap))
 | 
			
		||||
        return pixmap;
 | 
			
		||||
 | 
			
		||||
    if (!themeName.isEmpty())
 | 
			
		||||
    {
 | 
			
		||||
        QStringList visited;
 | 
			
		||||
        pixmap = findIconHelper(size, themeName, name, visited);
 | 
			
		||||
    }
 | 
			
		||||
    QPixmapCache::insert(pixmapName, pixmap);
 | 
			
		||||
    return pixmap;
 | 
			
		||||
}
 | 
			
		||||
#endif // Q_WS_X11
 | 
			
		||||
							
								
								
									
										55
									
								
								src/qticonloader.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,55 @@
 | 
			
		||||
/****************************************************************************
 | 
			
		||||
**
 | 
			
		||||
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 | 
			
		||||
** Contact: Qt Software Information (qt-info@nokia.com)
 | 
			
		||||
**
 | 
			
		||||
** This file is part of the QtGui module of the Qt Toolkit.
 | 
			
		||||
**
 | 
			
		||||
** Commercial Usage
 | 
			
		||||
** Licensees holding valid Qt Commercial licenses may use this file in
 | 
			
		||||
** accordance with the Qt Commercial License Agreement provided with the
 | 
			
		||||
** Software or, alternatively, in accordance with the terms contained in
 | 
			
		||||
** a written agreement between you and Nokia.
 | 
			
		||||
**
 | 
			
		||||
** GNU Lesser General Public License Usage
 | 
			
		||||
** Alternatively, this file may be used under the terms of the GNU Lesser
 | 
			
		||||
** General Public License version 2.1 as published by the Free Software
 | 
			
		||||
** Foundation and appearing in the file LICENSE.LGPL included in the
 | 
			
		||||
** packaging of this file.  Please review the following information to
 | 
			
		||||
** ensure the GNU Lesser General Public License version 2.1 requirements
 | 
			
		||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
			
		||||
**
 | 
			
		||||
** In addition, as a special exception, Nokia gives you certain
 | 
			
		||||
** additional rights. These rights are described in the Nokia Qt LGPL
 | 
			
		||||
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
 | 
			
		||||
** package.
 | 
			
		||||
**
 | 
			
		||||
** GNU General Public License Usage
 | 
			
		||||
** Alternatively, this file may be used under the terms of the GNU
 | 
			
		||||
** General Public License version 3.0 as published by the Free Software
 | 
			
		||||
** Foundation and appearing in the file LICENSE.GPL included in the
 | 
			
		||||
** packaging of this file.  Please review the following information to
 | 
			
		||||
** ensure the GNU General Public License version 3.0 requirements will be
 | 
			
		||||
** met: http://www.gnu.org/copyleft/gpl.html.
 | 
			
		||||
**
 | 
			
		||||
** If you are unsure which license is appropriate for your use, please
 | 
			
		||||
** contact the sales department at qt-sales@nokia.com.
 | 
			
		||||
**
 | 
			
		||||
****************************************************************************/
 | 
			
		||||
 | 
			
		||||
#ifndef QTICONLOADER_H
 | 
			
		||||
#define QTICONLOADER_H
 | 
			
		||||
 | 
			
		||||
#include <QtGui/QIcon>
 | 
			
		||||
 | 
			
		||||
// This is the QtIconLoader
 | 
			
		||||
// Version 0.1
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
class QtIconLoader
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    static QIcon icon(const QString &name, const QIcon &fallback = QIcon());
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // QTICONLOADER_H
 | 
			
		||||
							
								
								
									
										1793
									
								
								src/qttableview.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										219
									
								
								src/qttableview.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,219 @@
 | 
			
		||||
/**********************************************************************
 | 
			
		||||
** $Id: qttableview.h,v 1.46 2011/08/27 00:13:41 fasthyun Exp $
 | 
			
		||||
**
 | 
			
		||||
** Definition of QtTableView class
 | 
			
		||||
**
 | 
			
		||||
** Created : 941115
 | 
			
		||||
**
 | 
			
		||||
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
 | 
			
		||||
**
 | 
			
		||||
** This file contains a class moved out of the Qt GUI Toolkit API. It
 | 
			
		||||
** may be used, distributed and modified without limitation.
 | 
			
		||||
**
 | 
			
		||||
**********************************************************************/
 | 
			
		||||
 | 
			
		||||
#ifndef QTTABLEVIEW_H
 | 
			
		||||
#define QTTABLEVIEW_H
 | 
			
		||||
 | 
			
		||||
#ifndef USING_PCH
 | 
			
		||||
#include <QScrollBar>
 | 
			
		||||
#include <QAbstractScrollArea>
 | 
			
		||||
#include <QPainter>
 | 
			
		||||
#include <QPaintEvent>
 | 
			
		||||
#include <QPushButton>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
class QScrollBar;
 | 
			
		||||
class QtTableView : public QAbstractScrollArea
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    QWidget *view;
 | 
			
		||||
    int flag_view;
 | 
			
		||||
    int cellWidth() const;
 | 
			
		||||
    int cellHeight() const;
 | 
			
		||||
    void repaintRow(int row); // paintRow();
 | 
			
		||||
    void coverCornerSquare(bool);
 | 
			
		||||
    void clearCache() {}
 | 
			
		||||
    void repaintChanged();
 | 
			
		||||
    virtual bool isCellChanged(int r, int c) { return true; };
 | 
			
		||||
    virtual void eraseRight(QPainter *, QRect &r) { return; }
 | 
			
		||||
    virtual void checkProfile(){};
 | 
			
		||||
    QSize tmp_size; // testing.
 | 
			
		||||
    int tmp_x;
 | 
			
		||||
    bool test;
 | 
			
		||||
    QColor backColor;
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    QtTableView(QWidget *parent = 0, const char *name = 0);
 | 
			
		||||
    ~QtTableView();
 | 
			
		||||
 | 
			
		||||
    int numRows() const;
 | 
			
		||||
    int numCols() const;
 | 
			
		||||
    void setNumRows(int);
 | 
			
		||||
    void setNumCols(int);
 | 
			
		||||
 | 
			
		||||
    int topCell() const;
 | 
			
		||||
    int leftCell() const;
 | 
			
		||||
    void setTopCell(int row);
 | 
			
		||||
    void setLeftCell(int col);
 | 
			
		||||
    void setTopLeftCell(int row, int col);
 | 
			
		||||
 | 
			
		||||
    int xOffset() const;
 | 
			
		||||
    int yOffset() const;
 | 
			
		||||
    virtual void setXOffset(int);
 | 
			
		||||
    virtual void setYOffset(int);
 | 
			
		||||
    virtual void setOffset(int x, int y, bool updateScrBars = true);
 | 
			
		||||
    virtual void scrollTrigger(int x, int y){}; // tmp
 | 
			
		||||
 | 
			
		||||
    virtual int cellWidth(int col);
 | 
			
		||||
    int cellHeight(int row);
 | 
			
		||||
    virtual void setCellWidth(int);
 | 
			
		||||
    virtual void setCellHeight(int);
 | 
			
		||||
 | 
			
		||||
    int totalWidth();
 | 
			
		||||
    int totalHeight();
 | 
			
		||||
 | 
			
		||||
    uint tableFlags() const;
 | 
			
		||||
    //    bool	testTableFlags( uint f ) const;
 | 
			
		||||
    virtual void setTableFlags(uint f);
 | 
			
		||||
    void clearTableFlags(uint f = ~0);
 | 
			
		||||
 | 
			
		||||
    void setAutoUpdate(bool);
 | 
			
		||||
 | 
			
		||||
    void repaintCell(int row, int column, bool usecache = false);
 | 
			
		||||
 | 
			
		||||
    QRect cellUpdateRect() const;
 | 
			
		||||
    QRect viewRect() const;
 | 
			
		||||
 | 
			
		||||
    int lastRowVisible() const;
 | 
			
		||||
    int lastColVisible() const;
 | 
			
		||||
 | 
			
		||||
    bool rowIsVisible(int row) const;
 | 
			
		||||
    bool colIsVisible(int col) const;
 | 
			
		||||
 | 
			
		||||
    QScrollBar *verticalScrollBar() const;
 | 
			
		||||
    QScrollBar *horizontalScrollBar() const;
 | 
			
		||||
 | 
			
		||||
  private slots:
 | 
			
		||||
    void horSbValue(int);
 | 
			
		||||
    void horSbSliding(int);
 | 
			
		||||
    void horSbSlidingDone();
 | 
			
		||||
    void verSbValue(int);
 | 
			
		||||
    void verSbSliding(int);
 | 
			
		||||
    void verSbSlidingDone();
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    virtual void paintCell(QPainter *, int row, int col, bool update) = 0;
 | 
			
		||||
    virtual void paintEvent(QPaintEvent *);
 | 
			
		||||
    virtual void resizeEvent(QResizeEvent *);
 | 
			
		||||
    virtual void scrollContentsBy(int dx, int dy);
 | 
			
		||||
 | 
			
		||||
    int findRow(int yPos) const;
 | 
			
		||||
    int findCol(int xPos) const;
 | 
			
		||||
    int findColNoMinus(int xPos) const;
 | 
			
		||||
 | 
			
		||||
    bool rowYPos(int row, int *yPos) const;
 | 
			
		||||
    bool colXPos(int col, int *xPos) const;
 | 
			
		||||
 | 
			
		||||
    int maxXOffset();
 | 
			
		||||
    int maxYOffset();
 | 
			
		||||
    int maxColOffset();
 | 
			
		||||
    int maxRowOffset();
 | 
			
		||||
 | 
			
		||||
    int minViewX() const;
 | 
			
		||||
    int minViewY() const;
 | 
			
		||||
    int maxViewX() const;
 | 
			
		||||
    int maxViewY() const;
 | 
			
		||||
    int viewWidth() const;
 | 
			
		||||
    int viewHeight() const;
 | 
			
		||||
 | 
			
		||||
    void updateScrollBars();
 | 
			
		||||
    void updateTableSize();
 | 
			
		||||
 | 
			
		||||
    QRect cellUpdateR;
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    int findRawRow(int yPos, int *cellMaxY, int *cellMinY = 0,
 | 
			
		||||
                   bool goOutsideView = false) const;
 | 
			
		||||
    int findRawCol(int xPos, int *cellMaxX, int *cellMinX = 0,
 | 
			
		||||
                   bool goOutsideView = false) const;
 | 
			
		||||
    int maxColsVisible() const;
 | 
			
		||||
 | 
			
		||||
    void updateScrollBars(uint);
 | 
			
		||||
    void showOrHideScrollBars();
 | 
			
		||||
 | 
			
		||||
    int nRows;
 | 
			
		||||
    int nCols;
 | 
			
		||||
    int xOffs, yOffs;
 | 
			
		||||
    int xCellOffs, yCellOffs;
 | 
			
		||||
    short xCellDelta, yCellDelta;
 | 
			
		||||
    short cellH, cellW; //
 | 
			
		||||
 | 
			
		||||
    uint eraseInPaint : 1;
 | 
			
		||||
    uint verSliding : 1;
 | 
			
		||||
    uint verSnappingOff : 1;
 | 
			
		||||
    uint horSliding : 1;
 | 
			
		||||
    uint horSnappingOff : 1;
 | 
			
		||||
    uint coveringCornerSquare : 1;
 | 
			
		||||
    uint sbDirty : 8;
 | 
			
		||||
    uint inSbUpdate : 1;
 | 
			
		||||
 | 
			
		||||
    bool enablePaint;
 | 
			
		||||
 | 
			
		||||
    uint tFlags;
 | 
			
		||||
 | 
			
		||||
    QScrollBar *vScrollBar;
 | 
			
		||||
    QScrollBar *hScrollBar;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const uint Tbl_vScrollBar = 0x00000001;
 | 
			
		||||
const uint Tbl_hScrollBar = 0x00000002;
 | 
			
		||||
const uint Tbl_autoVScrollBar = 0x00000004;
 | 
			
		||||
const uint Tbl_autoHScrollBar = 0x00000008;
 | 
			
		||||
const uint Tbl_autoScrollBars = 0x0000000C;
 | 
			
		||||
 | 
			
		||||
const uint Tbl_clipCellPainting = 0x00000100;
 | 
			
		||||
const uint Tbl_cutCellsV = 0x00000200;
 | 
			
		||||
const uint Tbl_cutCellsH = 0x00000400;
 | 
			
		||||
const uint Tbl_cutCells = 0x00000600;
 | 
			
		||||
 | 
			
		||||
const uint Tbl_scrollLastHCell = 0x00000800;
 | 
			
		||||
const uint Tbl_scrollLastVCell = 0x00001000;
 | 
			
		||||
const uint Tbl_scrollLastCell = 0x00001800;
 | 
			
		||||
 | 
			
		||||
const uint Tbl_smoothHScrolling = 0x00002000;
 | 
			
		||||
const uint Tbl_smoothVScrolling = 0x00004000;
 | 
			
		||||
const uint Tbl_smoothScrolling = 0x00006000;
 | 
			
		||||
 | 
			
		||||
const uint Tbl_snapToHGrid = 0x00008000;
 | 
			
		||||
const uint Tbl_snapToVGrid = 0x00010000;
 | 
			
		||||
const uint Tbl_snapToGrid = 0x00018000;
 | 
			
		||||
 | 
			
		||||
inline int QtTableView::numRows() const { return nRows; }
 | 
			
		||||
 | 
			
		||||
inline int QtTableView::numCols() const { return nCols; }
 | 
			
		||||
 | 
			
		||||
inline int QtTableView::topCell() const { return yCellOffs; }
 | 
			
		||||
 | 
			
		||||
inline int QtTableView::leftCell() const { return xCellOffs; }
 | 
			
		||||
 | 
			
		||||
inline int QtTableView::xOffset() const { return xOffs; }
 | 
			
		||||
 | 
			
		||||
inline int QtTableView::yOffset() const { return yOffs; }
 | 
			
		||||
 | 
			
		||||
inline int QtTableView::cellHeight() const { return cellH; }
 | 
			
		||||
 | 
			
		||||
inline int QtTableView::cellWidth() const { return cellW; }
 | 
			
		||||
 | 
			
		||||
inline uint QtTableView::tableFlags() const { return tFlags; }
 | 
			
		||||
 | 
			
		||||
#define testTableFlags(f) ((tFlags & f) != 0)
 | 
			
		||||
// inline bool QtTableView::testTableFlags( uint f ) const{ return (tFlags & f)
 | 
			
		||||
// != 0; }
 | 
			
		||||
 | 
			
		||||
inline QRect QtTableView::cellUpdateRect() const { return cellUpdateR; }
 | 
			
		||||
 | 
			
		||||
inline void QtTableView::updateScrollBars() { updateScrollBars(0); }
 | 
			
		||||
 | 
			
		||||
#endif // QTTABLEVIEW_H
 | 
			
		||||
							
								
								
									
										425
									
								
								src/screenshot.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,425 @@
 | 
			
		||||
#include <QtGui>
 | 
			
		||||
#include <QSizeGrip>
 | 
			
		||||
#include "screenshot.h"
 | 
			
		||||
#include <QStatusBar>
 | 
			
		||||
#include <QMouseEvent>
 | 
			
		||||
#include <QVBoxLayout>
 | 
			
		||||
#include <QPushButton>
 | 
			
		||||
#include <QStyle>
 | 
			
		||||
#include <QStyleOptionFrame>
 | 
			
		||||
#include <QApplication>
 | 
			
		||||
#include <QDesktopWidget>
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
SizeGrip::SizeGrip()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
        setWindowFlags( Qt::FramelessWindowHint);
 | 
			
		||||
} */
 | 
			
		||||
 | 
			
		||||
QSizeGrip *sg;
 | 
			
		||||
int window_width = 320;
 | 
			
		||||
int window_height = 240;
 | 
			
		||||
 | 
			
		||||
TitleBar::TitleBar(QWidget *w) : QWidget(w)
 | 
			
		||||
{
 | 
			
		||||
    //	setWindowFlags( Qt::FramelessWindowHint);
 | 
			
		||||
    //    resize(window_width,32);
 | 
			
		||||
    setMinimumHeight(32);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TitleBar::mousePressEvent(QMouseEvent *)
 | 
			
		||||
{
 | 
			
		||||
    //	press_pos = e->pos();
 | 
			
		||||
    //	printf("x=%d y=%d\n",press_pos.x(),press_pos.y());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TitleBar::mouseMoveEvent(QMouseEvent *e)
 | 
			
		||||
{
 | 
			
		||||
    if (e->buttons() == Qt::LeftButton) //  Button state )
 | 
			
		||||
    {
 | 
			
		||||
        // move(e->globalX()-e->x(), e->globalY()-e->y());//
 | 
			
		||||
        // coe->x(),e->y());
 | 
			
		||||
        //		move(e->globalX() - press_pos.x(), e->globalY()-
 | 
			
		||||
        // press_pos.y());//
 | 
			
		||||
        // coe->x(),e->y());
 | 
			
		||||
        //		sg->move(x()-100,y()-100);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ShotArea::ShotArea()
 | 
			
		||||
{
 | 
			
		||||
    setLineWidth(3);
 | 
			
		||||
    setFrameStyle(QFrame::Panel | QFrame::Raised);
 | 
			
		||||
    setAttribute(Qt::WA_OpaquePaintEvent);
 | 
			
		||||
    setAttribute(Qt::WA_NoSystemBackground);
 | 
			
		||||
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ShotArea::resizeEvent(QResizeEvent * /* event */)
 | 
			
		||||
{
 | 
			
		||||
    // printf("ShotArea::resizeEvent()\n");
 | 
			
		||||
    // QPixmap pixmap = QPixmap(screenshotLabel->size());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ShotArea::paintEvent(QPaintEvent *event)
 | 
			
		||||
{
 | 
			
		||||
    //	printf("ShotArea::paintEvent\n");
 | 
			
		||||
    //	QPainter painter(this);
 | 
			
		||||
    //	painter.setOpacity(1.0);
 | 
			
		||||
    //	painter.fillRect(10, 10, 100, 80, QColor(255,255,255,120));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ShotArea::mousePressEvent(QMouseEvent *e)
 | 
			
		||||
{
 | 
			
		||||
    press_pos = e->pos();
 | 
			
		||||
    ///	printf("x=%d y=%d\n",press_pos.x(),press_pos.y());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ShotArea::mouseMoveEvent(QMouseEvent *e)
 | 
			
		||||
{
 | 
			
		||||
    if (e->buttons() == Qt::LeftButton) //  Button state )
 | 
			
		||||
    {
 | 
			
		||||
        // move(e->globalX()-e->x(), e->globalY()-e->y());//
 | 
			
		||||
        // coe->x(),e->y());
 | 
			
		||||
        //		move(e->globalX() - press_pos.x(), e->globalY()-
 | 
			
		||||
        // press_pos.y());//
 | 
			
		||||
        // coe->x(),e->y());
 | 
			
		||||
        //		sg->move(x()-100,y()-100);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#include <QX11Info>
 | 
			
		||||
Screenshot::Screenshot(QWidget *p) : QWidget(p)
 | 
			
		||||
{
 | 
			
		||||
    // Qt::WindowTitleHint
 | 
			
		||||
    // Qt::CustomizeWindowHint );
 | 
			
		||||
    //  setWindowTitle(tr("Screenshot"));
 | 
			
		||||
    //	TitleBar *titlebar=new TitleBar(this);
 | 
			
		||||
    QStatusBar *statusbar = new QStatusBar(this);
 | 
			
		||||
    shotarea = new ShotArea();
 | 
			
		||||
    //	setWindowFlags(Qt::WindowStaysOnTopHint);
 | 
			
		||||
    setWindowFlags(Qt::FramelessWindowHint);
 | 
			
		||||
    // setWindowFlags(Qt::X11BypassWindowManagerHint);
 | 
			
		||||
    setStyleSheet( // padding: 2px
 | 
			
		||||
        "QWidget { background-color : rgba(20,20,20,70%); color: "
 | 
			
		||||
        "rgb(0,255,150);}"
 | 
			
		||||
        "QPushButton,QToolButton,QLineEdit { border-width: 1px; "
 | 
			
		||||
        "padding:3px; "
 | 
			
		||||
        "border-style: solid;  border-color: rgb(210,50,130); "
 | 
			
		||||
        "border-radius: 5px "
 | 
			
		||||
        ";}"
 | 
			
		||||
        "QPushButton:hover,QToolButton:hover { color:rgb(40,255,190); "
 | 
			
		||||
        "padding:3px; border-width: 1px; border-style: solid;  "
 | 
			
		||||
        "border-color: "
 | 
			
		||||
        "rgb(230,80,170); border-radius: 5px ;}"
 | 
			
		||||
        "QPushButton:pressed,QToolButton:pressed { color:rgb(0,255,150); "
 | 
			
		||||
        "padding:3px; border-width: 2px; border-style: solid;  "
 | 
			
		||||
        "border-color: "
 | 
			
		||||
        "rgb(210,50,130); border-radius: 5px ;}"
 | 
			
		||||
        "QComboBox { border-width: 1px; padding:3px; border-style: solid;  "
 | 
			
		||||
        "border-color: rgb(50,200,130); border-radius: 5px ;}"
 | 
			
		||||
        "QLabel { border-width: 1px; padding:3px; border-style: solid;  "
 | 
			
		||||
        "border-color: rgb(65,16,40); border-radius: 5px ;}"
 | 
			
		||||
        "QComboBox:drop-down { border-width: 2px; padding:0px; "
 | 
			
		||||
        "border-style: "
 | 
			
		||||
        "solid;  border-color: rgb(50,200,130); border-radius: 3px ;}");
 | 
			
		||||
 | 
			
		||||
// sg=new QSizeGrip(NULL);
 | 
			
		||||
//	sg->show();
 | 
			
		||||
//	sg->move(100,100);
 | 
			
		||||
// QStyle::PE_Frame
 | 
			
		||||
// createOptionsGroupBox();
 | 
			
		||||
// createButtonsLayout();
 | 
			
		||||
 | 
			
		||||
#if QT_VERSION > 0x040500
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    mainLayout = new QVBoxLayout;
 | 
			
		||||
#if QT_VERSION < 0x040300
 | 
			
		||||
    mainLayout->setMargin(3); // qt-4.2
 | 
			
		||||
#else
 | 
			
		||||
    mainLayout->setContentsMargins(3, 3, 3, 3); // qt-4.3
 | 
			
		||||
#endif
 | 
			
		||||
    mainLayout->setSpacing(0);
 | 
			
		||||
 | 
			
		||||
    //	mainLayout->addWidget(titlebar);
 | 
			
		||||
    mainLayout->addWidget(shotarea);
 | 
			
		||||
    // mainLayout->addLayout(buttonsLayout);
 | 
			
		||||
    mainLayout->addWidget(statusbar);
 | 
			
		||||
 | 
			
		||||
    //  saveScreenshotButton = createButton(tr("Save"),this,
 | 
			
		||||
    //  SLOT(saveScreenshot()));
 | 
			
		||||
    saveScreenshotButton = new QPushButton("Save");
 | 
			
		||||
    connect(saveScreenshotButton, SIGNAL(clicked()), this,
 | 
			
		||||
            SLOT(saveScreenshot()));
 | 
			
		||||
 | 
			
		||||
    statusbar->addWidget(saveScreenshotButton);
 | 
			
		||||
    //	statusbar->addWidget( quitScreenshotButton);
 | 
			
		||||
    statusbar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
 | 
			
		||||
    setLayout(mainLayout);
 | 
			
		||||
    // delaySpinBox->setValue(5);
 | 
			
		||||
 | 
			
		||||
    setMouseTracking(true);
 | 
			
		||||
 | 
			
		||||
    // 	if (QApplication::desktop()->winId() < 0)
 | 
			
		||||
    // 		printf("Qps: Null Desktop\n");
 | 
			
		||||
    resize(300, 240);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static QPoint init_pos;
 | 
			
		||||
void Screenshot::mousePressEvent(QMouseEvent *e)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    press_pos = e->globalPos();
 | 
			
		||||
    init_pos = pos();
 | 
			
		||||
    // printf("x=%d y=%d\n",press_pos.x(),press_pos.y());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Screenshot::mouseMoveEvent(QMouseEvent *e)
 | 
			
		||||
{
 | 
			
		||||
    if (e->buttons() == Qt::LeftButton) //  Button state )
 | 
			
		||||
    {
 | 
			
		||||
        move(init_pos + e->globalPos() - press_pos);
 | 
			
		||||
        // move(x() + e->globalX() - press_pos.x(), y()+e->globalY()-
 | 
			
		||||
        // press_pos.y());// coe->x(),e->y());
 | 
			
		||||
        // sg->move(x()-100,y()-100);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern bool flag_xcompmgr;
 | 
			
		||||
void Screenshot::paintEvent(QPaintEvent *e)
 | 
			
		||||
{
 | 
			
		||||
    QPainter p(this);
 | 
			
		||||
    // printf("Screenshot::paintEvent\n");
 | 
			
		||||
    //	setAttribute(Qt::WA_NoSystemBackground);
 | 
			
		||||
    if (0) // if(flag_xcompmgr)//setWindowOpacity (0.9);
 | 
			
		||||
           // //_NET_WM_WINDOW_OPACITY
 | 
			
		||||
    {
 | 
			
		||||
        setAttribute(Qt::WA_OpaquePaintEvent);
 | 
			
		||||
        //	setAttribute(Qt::WA_);
 | 
			
		||||
        //	p.setOpacity(0.1);
 | 
			
		||||
        p.setCompositionMode(QPainter::CompositionMode_Source); // need!
 | 
			
		||||
        p.fillRect(rect(), Qt::transparent);                    // clear!
 | 
			
		||||
        // 	QRect rectR(shotarea->x(),shotarea->y(),
 | 
			
		||||
        // shotarea->width(),shotarea->height());
 | 
			
		||||
        //	p.fillRect(rectR,QColor(0,255,0,10));
 | 
			
		||||
        //	p.fillRect(rect(),QColor(255,255,255,255));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return;
 | 
			
		||||
    QStyleOptionFrame opt;
 | 
			
		||||
    QRect rectR(shotarea->x() - 1, shotarea->y() - 1, shotarea->width() + 2,
 | 
			
		||||
                shotarea->height() + 2);
 | 
			
		||||
    opt.rect = rectR;
 | 
			
		||||
    opt.lineWidth = 2;
 | 
			
		||||
    opt.midLineWidth = 1;
 | 
			
		||||
    opt.state = opt.state | QStyle::State_Sunken;
 | 
			
		||||
    /// style()->drawControl(QStyle::CE_Header, &opt, p, this);
 | 
			
		||||
    style()->drawPrimitive(QStyle::PE_Frame, &opt, &p, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Screenshot::resizeEvent(QResizeEvent *e /* event */)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    //	printf("Screenshot::resizeEvent()\n");
 | 
			
		||||
    //	QWidget::resizeEvent(e);
 | 
			
		||||
    //	return;
 | 
			
		||||
    if (flag_xcompmgr == false)
 | 
			
		||||
    {
 | 
			
		||||
        QPixmap pixmap = QPixmap(size());
 | 
			
		||||
        QPainter painter(&pixmap);
 | 
			
		||||
        // painter.eraseRect(0,0,width(),height());
 | 
			
		||||
        painter.fillRect(0, 0, width(), height(), QColor(0, 0, 0));
 | 
			
		||||
        painter.fillRect(shotarea->x() + 1, shotarea->y() + 1,
 | 
			
		||||
                         shotarea->width() - 2, shotarea->height() - 2
 | 
			
		||||
                         // painter.fillRect(shotarea->geometry()
 | 
			
		||||
                         ,
 | 
			
		||||
                         QColor(255, 255, 255));
 | 
			
		||||
#if QT_VERSION >= 0x040300
 | 
			
		||||
        setMask(
 | 
			
		||||
            pixmap.createMaskFromColor(QColor(255, 255, 255), Qt::MaskInColor));
 | 
			
		||||
// setMask(pixmap.mask()); // with alpha channel ,notwork
 | 
			
		||||
#else
 | 
			
		||||
//	#error Qt library version 4.2 or higher is needed for this version of
 | 
			
		||||
// qps
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //  QSize scaledSize = originalPixmap.size();
 | 
			
		||||
    //  scaledSize.scale(screenshotLabel->size(), Qt::KeepAspectRatio);
 | 
			
		||||
    //  if (!screenshotLabel->pixmap()|| scaledSize !=
 | 
			
		||||
    //  screenshotLabel->pixmap()->size())
 | 
			
		||||
    //    updateScreenshotLabel();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Screenshot::newScreenshot()
 | 
			
		||||
{
 | 
			
		||||
    //    newScreenshotButton->setDisabled(true);
 | 
			
		||||
    //		shootScreen();
 | 
			
		||||
    //    QTimer::singleShot(delaySpinBox->value() * 1000, this,
 | 
			
		||||
    //    SLOT(shootScreen()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Screenshot::saveScreenshot()
 | 
			
		||||
{
 | 
			
		||||
    shootScreen();
 | 
			
		||||
    QString format = "png";
 | 
			
		||||
    QString path = QDir::homePath() + "/Desktop"; // *** ooooooo
 | 
			
		||||
    if (QFile::exists(path))
 | 
			
		||||
        path = path + tr("/untitled.") + format;
 | 
			
		||||
    else
 | 
			
		||||
        path = QDir::homePath();
 | 
			
		||||
 | 
			
		||||
    QString fileName = QFileDialog::getSaveFileName(
 | 
			
		||||
        this, tr("Save As"), path,
 | 
			
		||||
        tr("%1 Files (*.%2);;All Files (*)").arg(format.toUpper()).arg(format));
 | 
			
		||||
    if (!fileName.isEmpty())
 | 
			
		||||
        originalPixmap.save(fileName, format.toLatin1());
 | 
			
		||||
 | 
			
		||||
    //	setWindowFlags(Qt::X11BypassWindowManagerHint);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Screenshot::shootScreen()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    //    if (delaySpinBox->value() != 0)  qApp->beep();
 | 
			
		||||
    originalPixmap = QPixmap::grabWindow(
 | 
			
		||||
        QApplication::desktop()->winId(), geometry().x() + shotarea->x(),
 | 
			
		||||
        geometry().y() + shotarea->y(), shotarea->width(), shotarea->height());
 | 
			
		||||
    ///   updateScreenshotLabel();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Screenshot::updateCheckBox()
 | 
			
		||||
{
 | 
			
		||||
    if (delaySpinBox->value() == 0)
 | 
			
		||||
        hideThisWindowCheckBox->setDisabled(true);
 | 
			
		||||
    else
 | 
			
		||||
        hideThisWindowCheckBox->setDisabled(false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Screenshot::createOptionsGroupBox()
 | 
			
		||||
{
 | 
			
		||||
    optionsGroupBox = new QGroupBox(tr("Options"));
 | 
			
		||||
 | 
			
		||||
    delaySpinBox = new QSpinBox;
 | 
			
		||||
    delaySpinBox->setSuffix(tr(" s"));
 | 
			
		||||
    delaySpinBox->setMaximum(60);
 | 
			
		||||
    connect(delaySpinBox, SIGNAL(valueChanged(int)), this,
 | 
			
		||||
            SLOT(updateCheckBox()));
 | 
			
		||||
 | 
			
		||||
    delaySpinBoxLabel = new QLabel(tr("Screenshot Delay:"));
 | 
			
		||||
 | 
			
		||||
    hideThisWindowCheckBox = new QCheckBox(tr("Hide This Window"));
 | 
			
		||||
 | 
			
		||||
    optionsGroupBoxLayout = new QGridLayout;
 | 
			
		||||
    optionsGroupBoxLayout->addWidget(delaySpinBoxLabel, 0, 0);
 | 
			
		||||
    optionsGroupBoxLayout->addWidget(delaySpinBox, 0, 1);
 | 
			
		||||
    optionsGroupBoxLayout->addWidget(hideThisWindowCheckBox, 1, 0, 1, 2);
 | 
			
		||||
    optionsGroupBox->setLayout(optionsGroupBoxLayout);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Screenshot::createButtonsLayout()
 | 
			
		||||
{
 | 
			
		||||
    newScreenshotButton =
 | 
			
		||||
        createButton(tr("New Screenshot"), this, SLOT(newScreenshot()));
 | 
			
		||||
    quitScreenshotButton = createButton(tr("Quit"), this, SLOT(close()));
 | 
			
		||||
 | 
			
		||||
    buttonsLayout = new QHBoxLayout;
 | 
			
		||||
    buttonsLayout->addStretch();
 | 
			
		||||
    buttonsLayout->addWidget(newScreenshotButton);
 | 
			
		||||
    buttonsLayout->addWidget(saveScreenshotButton);
 | 
			
		||||
    buttonsLayout->addWidget(quitScreenshotButton);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QPushButton *Screenshot::createButton(const QString &text, QWidget *receiver,
 | 
			
		||||
                                      const char *member)
 | 
			
		||||
{
 | 
			
		||||
    QPushButton *button = new QPushButton(text);
 | 
			
		||||
    button->connect(button, SIGNAL(clicked()), receiver, member);
 | 
			
		||||
    return button;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// preview
 | 
			
		||||
void Screenshot::updateScreenshotLabel()
 | 
			
		||||
{
 | 
			
		||||
    screenshotLabel->setPixmap(originalPixmap.scaled(screenshotLabel->size(),
 | 
			
		||||
                                                     Qt::KeepAspectRatio,
 | 
			
		||||
                                                     Qt::SmoothTransformation));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//#include "widget.h"
 | 
			
		||||
 | 
			
		||||
#include <QApplication>
 | 
			
		||||
#include <X11/extensions/Xrender.h>
 | 
			
		||||
 | 
			
		||||
int screenshot_main(int argc, char **argv)
 | 
			
		||||
// int screenshot_main()
 | 
			
		||||
{
 | 
			
		||||
    // qWarning("Please make sure you're running a composition manager!");
 | 
			
		||||
    bool argbVisual = false;
 | 
			
		||||
    Display *dpy = QX11Info::display(); // open default display
 | 
			
		||||
    if (!dpy)
 | 
			
		||||
    {
 | 
			
		||||
        qWarning("Cannot connect to the X server");
 | 
			
		||||
        exit(1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int screen = DefaultScreen(dpy);
 | 
			
		||||
    Colormap colormap = 0;
 | 
			
		||||
    Visual *visual = 0;
 | 
			
		||||
    int eventBase, errorBase;
 | 
			
		||||
 | 
			
		||||
    if (0 and XRenderQueryExtension(dpy, &eventBase, &errorBase))
 | 
			
		||||
    {
 | 
			
		||||
        int nvi;
 | 
			
		||||
        XVisualInfo templ;
 | 
			
		||||
        templ.screen = screen;
 | 
			
		||||
        templ.depth = 32;
 | 
			
		||||
        templ.c_class = TrueColor;
 | 
			
		||||
        XVisualInfo *xvi = XGetVisualInfo(
 | 
			
		||||
            dpy, VisualScreenMask | VisualDepthMask | VisualClassMask, &templ,
 | 
			
		||||
            &nvi);
 | 
			
		||||
 | 
			
		||||
        printf("nvi=%d\n", nvi);
 | 
			
		||||
        for (int i = 0; i < nvi; ++i)
 | 
			
		||||
        {
 | 
			
		||||
            XRenderPictFormat *format =
 | 
			
		||||
                XRenderFindVisualFormat(dpy, xvi[i].visual);
 | 
			
		||||
            if (format->type == PictTypeDirect && format->direct.alphaMask > 0)
 | 
			
		||||
            {
 | 
			
		||||
                visual = xvi[i].visual;
 | 
			
		||||
                colormap = XCreateColormap(dpy, RootWindow(dpy, screen), visual,
 | 
			
		||||
                                           AllocNone);
 | 
			
		||||
                argbVisual = true;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (argbVisual == true)
 | 
			
		||||
    {
 | 
			
		||||
        qWarning("Found ARGB visual. Starting app...");
 | 
			
		||||
        //    	QApplication app(dpy, argc, argv, Qt::HANDLE(visual),
 | 
			
		||||
        //    Qt::HANDLE(colormap));
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        // qWarning("Couldn't find ARGB visual... Exiting.");
 | 
			
		||||
        //    	QApplication app(dpy, argc, argv);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //    QApplication app(dpy, argc, argv, Qt::HANDLE(visual),
 | 
			
		||||
    //    Qt::HANDLE(colormap));
 | 
			
		||||
    QApplication app(argc, argv);
 | 
			
		||||
 | 
			
		||||
    Display *dsp = QX11Info::display(); // get the display(X server?)
 | 
			
		||||
 | 
			
		||||
    Screenshot *w = new Screenshot();
 | 
			
		||||
    w->show();
 | 
			
		||||
    // Widget w;
 | 
			
		||||
    // w.resize(400, 300);
 | 
			
		||||
    // w.show();
 | 
			
		||||
 | 
			
		||||
    return app.exec();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										110
									
								
								src/screenshot.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,110 @@
 | 
			
		||||
#ifndef SCREENSHOT_H
 | 
			
		||||
#define SCREENSHOT_H
 | 
			
		||||
 | 
			
		||||
#include <QPixmap>
 | 
			
		||||
#include <QFrame>
 | 
			
		||||
 | 
			
		||||
#include <QCheckBox>
 | 
			
		||||
#include <QGridLayout>
 | 
			
		||||
#include <QGroupBox>
 | 
			
		||||
#include <QHBoxLayout>
 | 
			
		||||
#include <QLabel>
 | 
			
		||||
#include <QPushButton>
 | 
			
		||||
#include <QSpinBox>
 | 
			
		||||
#include <QVBoxLayout>
 | 
			
		||||
#include <QFileDialog>
 | 
			
		||||
 | 
			
		||||
class TitleBar : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    TitleBar(QWidget *w);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    //    void resizeEvent(QResizeEvent *event);
 | 
			
		||||
    void mouseMoveEvent(QMouseEvent *event);
 | 
			
		||||
    void mousePressEvent(QMouseEvent *e);
 | 
			
		||||
  private slots:
 | 
			
		||||
  private:
 | 
			
		||||
    QPoint press_pos;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class ShotArea : public QFrame
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    ShotArea();
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    //    void resizeEvent(QResizeEvent *event);
 | 
			
		||||
 | 
			
		||||
    virtual void resizeEvent(QResizeEvent *e);
 | 
			
		||||
    virtual void paintEvent(QPaintEvent *event);
 | 
			
		||||
    void mouseMoveEvent(QMouseEvent *event);
 | 
			
		||||
    void mousePressEvent(QMouseEvent *e);
 | 
			
		||||
  private slots:
 | 
			
		||||
  private:
 | 
			
		||||
    QPoint press_pos;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
class SizeGrip : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    SizeGrip();
 | 
			
		||||
protected:
 | 
			
		||||
//    void resizeEvent(QResizeEvent *event);
 | 
			
		||||
        void mouseMoveEvent ( QMouseEvent * event );
 | 
			
		||||
        void mousePressEvent(QMouseEvent *e);
 | 
			
		||||
private slots:
 | 
			
		||||
private:
 | 
			
		||||
        QPoint press_pos;
 | 
			
		||||
};
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
class Screenshot : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
  public:
 | 
			
		||||
    Screenshot(QWidget *p = 0);
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    void resizeEvent(QResizeEvent *event);
 | 
			
		||||
    void mouseMoveEvent(QMouseEvent *event);
 | 
			
		||||
    void mousePressEvent(QMouseEvent *e);
 | 
			
		||||
    virtual void paintEvent(QPaintEvent *event);
 | 
			
		||||
 | 
			
		||||
  private slots:
 | 
			
		||||
    void newScreenshot();
 | 
			
		||||
    void saveScreenshot();
 | 
			
		||||
    void shootScreen();
 | 
			
		||||
    void updateCheckBox();
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    void createOptionsGroupBox();
 | 
			
		||||
    void createButtonsLayout();
 | 
			
		||||
    QPushButton *createButton(const QString &text, QWidget *receiver,
 | 
			
		||||
                              const char *member);
 | 
			
		||||
    void updateScreenshotLabel();
 | 
			
		||||
 | 
			
		||||
    QPoint press_pos;
 | 
			
		||||
    QPixmap originalPixmap;
 | 
			
		||||
 | 
			
		||||
    QLabel *screenshotLabel;
 | 
			
		||||
    QGroupBox *optionsGroupBox;
 | 
			
		||||
    QSpinBox *delaySpinBox;
 | 
			
		||||
    QLabel *delaySpinBoxLabel;
 | 
			
		||||
    QCheckBox *hideThisWindowCheckBox;
 | 
			
		||||
    QPushButton *newScreenshotButton;
 | 
			
		||||
    QPushButton *saveScreenshotButton;
 | 
			
		||||
    QPushButton *quitScreenshotButton;
 | 
			
		||||
 | 
			
		||||
    QVBoxLayout *mainLayout;
 | 
			
		||||
    QGridLayout *optionsGroupBoxLayout;
 | 
			
		||||
    QHBoxLayout *buttonsLayout;
 | 
			
		||||
    ShotArea *shotarea;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										88
									
								
								src/stable.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,88 @@
 | 
			
		||||
// for Precompiled Header !
 | 
			
		||||
#include <time.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#if defined __cplusplus
 | 
			
		||||
 | 
			
		||||
#include <QBitArray>
 | 
			
		||||
#include <QHash>
 | 
			
		||||
#include <QVector>
 | 
			
		||||
#include <QList>
 | 
			
		||||
#include <QRect>
 | 
			
		||||
#include <QString>
 | 
			
		||||
#include <QStringList>
 | 
			
		||||
#include <QProcess>
 | 
			
		||||
#include <QSettings>
 | 
			
		||||
 | 
			
		||||
#include <QItemDelegate>
 | 
			
		||||
#include <QStandardItemModel>
 | 
			
		||||
 | 
			
		||||
#include <QShortcut>
 | 
			
		||||
#include <QAction>
 | 
			
		||||
 | 
			
		||||
#include <QHBoxLayout>
 | 
			
		||||
#include <QVBoxLayout>
 | 
			
		||||
#include <QGridLayout>
 | 
			
		||||
 | 
			
		||||
#include <QColor>
 | 
			
		||||
#include <QFont>
 | 
			
		||||
 | 
			
		||||
#include <QWidget>
 | 
			
		||||
#include <QLabel>
 | 
			
		||||
#include <QFrame>
 | 
			
		||||
#include <QPixmap>
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
#include <QSlider>
 | 
			
		||||
#include <QSpinBox>
 | 
			
		||||
#include <QTabWidget>
 | 
			
		||||
 | 
			
		||||
#include <QStyleOption>
 | 
			
		||||
#include <QAbstractScrollArea>
 | 
			
		||||
 | 
			
		||||
#include <QPainter>
 | 
			
		||||
#include <QScrollBar>
 | 
			
		||||
 | 
			
		||||
#include <QAbstractButton>
 | 
			
		||||
#include <QPushButton>
 | 
			
		||||
#include <QCheckBox>
 | 
			
		||||
#include <QRadioButton>
 | 
			
		||||
#include <QStatusBar>
 | 
			
		||||
#include <QToolButton>
 | 
			
		||||
#include <QGroupBox>
 | 
			
		||||
#include <QMessageBox>
 | 
			
		||||
 | 
			
		||||
#include <QToolTip>
 | 
			
		||||
#include <QLineEdit>
 | 
			
		||||
#include <QComboBox>
 | 
			
		||||
#include <QTextEdit>
 | 
			
		||||
 | 
			
		||||
#include <QTimeLine>
 | 
			
		||||
#include <QDir>
 | 
			
		||||
 | 
			
		||||
#include <QMenu>
 | 
			
		||||
#include <QMenuBar>
 | 
			
		||||
 | 
			
		||||
#include <QListView>
 | 
			
		||||
#include <QHeaderView>
 | 
			
		||||
#include <QTreeView>
 | 
			
		||||
 | 
			
		||||
#include <QTextBrowser>
 | 
			
		||||
#include <QUrl>
 | 
			
		||||
 | 
			
		||||
#include <QClipboard>
 | 
			
		||||
#include <QApplication>
 | 
			
		||||
#include <QSessionManager>
 | 
			
		||||
 | 
			
		||||
#include <QPaintEvent>
 | 
			
		||||
#include <QMouseEvent>
 | 
			
		||||
#include <QCloseEvent>
 | 
			
		||||
#include <QTimerEvent>
 | 
			
		||||
#include <QKeyEvent>
 | 
			
		||||
#include <QResizeEvent>
 | 
			
		||||
 | 
			
		||||
#include <QFontComboBox>
 | 
			
		||||
 | 
			
		||||
#include "svec.h"
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										145
									
								
								src/svec.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,145 @@
 | 
			
		||||
// svec.C
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
// implement a stretchy vector class:
 | 
			
		||||
// An Svec<T> grows automatically (doubles when full), so that adding
 | 
			
		||||
// elements to the end has an amortized cost of O(1).
 | 
			
		||||
// For now, only use this for types not requiring a con/destructor.
 | 
			
		||||
 | 
			
		||||
#ifndef SVEC_C
 | 
			
		||||
#define SVEC_C
 | 
			
		||||
 | 
			
		||||
#include "svec.h"
 | 
			
		||||
////#define fatal(str) { printf("fatal error: %s\n",str); exit(0);}
 | 
			
		||||
#define fatal printf
 | 
			
		||||
 | 
			
		||||
template <class T> Svec<T>::Svec(const Svec<T> &s)
 | 
			
		||||
{
 | 
			
		||||
    int n = s.size();
 | 
			
		||||
    if (n < 8)
 | 
			
		||||
        n = 8;
 | 
			
		||||
    vect = (T *)malloc(n * sizeof(T));
 | 
			
		||||
    alloced = n;
 | 
			
		||||
    used = s.size();
 | 
			
		||||
    for (int i = 0; i < used; i++)
 | 
			
		||||
        vect[i] = s[i];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class T> Svec<T> &Svec<T>::operator=(const Svec<T> &s)
 | 
			
		||||
{
 | 
			
		||||
    if (this != &s)
 | 
			
		||||
    {
 | 
			
		||||
        if (alloced < s.size())
 | 
			
		||||
        {
 | 
			
		||||
            alloced = s.size();
 | 
			
		||||
            vect = (T *)realloc(vect, alloced * sizeof(T));
 | 
			
		||||
        }
 | 
			
		||||
        for (int i = 0; i < s.size(); i++)
 | 
			
		||||
        {
 | 
			
		||||
            vect[i] = s.vect[i];
 | 
			
		||||
        }
 | 
			
		||||
        used = s.size();
 | 
			
		||||
    }
 | 
			
		||||
    return *this;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
template<class T>
 | 
			
		||||
void Svec<T>::indexerr(int index) const
 | 
			
		||||
{
 | 
			
		||||
    fatal("Svec: index out of range (%d, valid is 0..%d)", index, used - 1);
 | 
			
		||||
}
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
template <class T> void Svec<T>::setSize(int newsize)
 | 
			
		||||
{
 | 
			
		||||
    while (newsize > alloced)
 | 
			
		||||
        grow();
 | 
			
		||||
    used = newsize;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class T> void Svec<T>::setextend(int index, T value)
 | 
			
		||||
{
 | 
			
		||||
#ifdef CHECK_INDICES
 | 
			
		||||
    if (index < 0)
 | 
			
		||||
        fatal("const Svec: negative index");
 | 
			
		||||
#endif
 | 
			
		||||
    while (index >= alloced)
 | 
			
		||||
        grow();
 | 
			
		||||
    if (index >= used)
 | 
			
		||||
        used = index + 1;
 | 
			
		||||
    vect[index] = value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class T> void Svec<T>::insert(int index, T value)
 | 
			
		||||
{
 | 
			
		||||
#ifdef CHECK_INDICES
 | 
			
		||||
    if (index < 0 || index > used)
 | 
			
		||||
        fatal("Svec: index out of range");
 | 
			
		||||
#endif
 | 
			
		||||
    if ((used + 1) > alloced)
 | 
			
		||||
        grow();
 | 
			
		||||
 | 
			
		||||
    /*int i;
 | 
			
		||||
    T v;
 | 
			
		||||
          v=vect[i+1];
 | 
			
		||||
    for(i = index; j < =used ; i++)
 | 
			
		||||
        vect[i+1]=v;
 | 
			
		||||
        vect[i+1]=vect[i]; //vect[index+1]=vect[index];
 | 
			
		||||
        */
 | 
			
		||||
 | 
			
		||||
    // old
 | 
			
		||||
    for (int j = used - 1; j >= index; j--)
 | 
			
		||||
        vect[j + 1] = vect[j];
 | 
			
		||||
 | 
			
		||||
    vect[index] = value;
 | 
			
		||||
 | 
			
		||||
    used++;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// for int,float type , no delete
 | 
			
		||||
template <class T> void Svec<T>::remove(int index)
 | 
			
		||||
{
 | 
			
		||||
#ifdef CHECK_INDICES
 | 
			
		||||
    if (index < 0 || index >= used)
 | 
			
		||||
        fatal("Svec: index out of range");
 | 
			
		||||
#endif
 | 
			
		||||
    for (int j = index; j < used - 1; j++)
 | 
			
		||||
        vect[j] = vect[j + 1];
 | 
			
		||||
    used--;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// for class type
 | 
			
		||||
template <class T> void Svec<T>::Delete(int index)
 | 
			
		||||
{
 | 
			
		||||
#ifdef CHECK_INDICES
 | 
			
		||||
    if (index < 0 || index >= used)
 | 
			
		||||
        fatal("Svec: index out of range");
 | 
			
		||||
#endif
 | 
			
		||||
    delete vect[index];
 | 
			
		||||
    for (int j = index; j < used - 1; j++)
 | 
			
		||||
        vect[j] = vect[j + 1];
 | 
			
		||||
    used--;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Assuming T is "pointer to U", delete all contents.
 | 
			
		||||
// Warning: duplicated objects will be deleted twice --- doubleplusungood
 | 
			
		||||
template <class T> void Svec<T>::purge()
 | 
			
		||||
{
 | 
			
		||||
    for (int i = 0; i < used; i++)
 | 
			
		||||
        delete vect[i];
 | 
			
		||||
    used = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" {
 | 
			
		||||
typedef int (*compare_func)(const void *, const void *);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class T> void Svec<T>::sort(int (*compare)(const T *a, const T *b))
 | 
			
		||||
{
 | 
			
		||||
    qsort(vect, used, sizeof(T), (compare_func)compare);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // SVEC_C
 | 
			
		||||
							
								
								
									
										138
									
								
								src/svec.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,138 @@
 | 
			
		||||
// svec.h					emacs, this is a -*-c++-*- file
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#ifndef SVEC_H
 | 
			
		||||
#define SVEC_H
 | 
			
		||||
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
 | 
			
		||||
template <typename Key, typename T> class SHash : public std::map<Key, T>
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    T value(Key k, T r)
 | 
			
		||||
    {
 | 
			
		||||
        using namespace std;
 | 
			
		||||
        typename map<Key, T>::const_iterator it;
 | 
			
		||||
        it = map<Key, T>::find(k);
 | 
			
		||||
        if (it == map<Key, T>::end())
 | 
			
		||||
            return r;
 | 
			
		||||
        return (*it).second;
 | 
			
		||||
    }
 | 
			
		||||
    void insert(Key k, T r)
 | 
			
		||||
    {
 | 
			
		||||
        using namespace std;
 | 
			
		||||
        map<Key, T>::insert(pair<Key, T>(k, r));
 | 
			
		||||
    }
 | 
			
		||||
    bool contains(Key k)
 | 
			
		||||
    {
 | 
			
		||||
        if (value(k, NULL) == NULL)
 | 
			
		||||
            return false;
 | 
			
		||||
        else
 | 
			
		||||
            return true;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
//#ifndef NDEBUG
 | 
			
		||||
//#define CHECK_INDICES		// Check invalid vector indices (the default)
 | 
			
		||||
//#endif
 | 
			
		||||
 | 
			
		||||
template <class T> class Svec
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    Svec(int max = 16);
 | 
			
		||||
    Svec(const Svec<T> &s);
 | 
			
		||||
    ~Svec();
 | 
			
		||||
 | 
			
		||||
    Svec<T> &operator=(const Svec<T> &s);
 | 
			
		||||
    int size() const;
 | 
			
		||||
    void setSize(int newsize);
 | 
			
		||||
    T &operator[](int i);
 | 
			
		||||
    T operator[](int i) const;
 | 
			
		||||
    void set(int i, T val);
 | 
			
		||||
    void sort(int (*compare)(const T *a, const T *b));
 | 
			
		||||
    void add(T x);
 | 
			
		||||
    void insert(int index, T val);
 | 
			
		||||
    void remove(int index);
 | 
			
		||||
    void Delete(int index);
 | 
			
		||||
    void clear();
 | 
			
		||||
    void purge(); // like clear() but deletes all contents
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    void grow();
 | 
			
		||||
    void setextend(int index, T value);
 | 
			
		||||
    void indexerr(int index) const;
 | 
			
		||||
 | 
			
		||||
    T *vect;
 | 
			
		||||
    int alloced; // # of entries allocated
 | 
			
		||||
    int used;    // # of entries actually used (size)
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <class T> inline Svec<T>::Svec(int max) : alloced(max), used(0)
 | 
			
		||||
{
 | 
			
		||||
    vect = (T *)malloc(max * sizeof(T));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class T> inline Svec<T>::~Svec() { free(vect); }
 | 
			
		||||
 | 
			
		||||
template <class T> inline int Svec<T>::size() const { return used; }
 | 
			
		||||
 | 
			
		||||
template <class T> inline T &Svec<T>::operator[](int i)
 | 
			
		||||
{
 | 
			
		||||
#ifdef CHECK_INDICES
 | 
			
		||||
    if (i < 0 || i >= used)
 | 
			
		||||
        indexerr(i);
 | 
			
		||||
#endif
 | 
			
		||||
    return vect[i];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class T> inline T Svec<T>::operator[](int i) const
 | 
			
		||||
{
 | 
			
		||||
#ifdef CHECK_INDICES
 | 
			
		||||
    if (i < 0 || i >= used)
 | 
			
		||||
        indexerr(i);
 | 
			
		||||
#endif
 | 
			
		||||
    return vect[i];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class T> inline void Svec<T>::set(int i, T val)
 | 
			
		||||
{
 | 
			
		||||
    if (i < 0 || i >= used)
 | 
			
		||||
        setextend(i, val);
 | 
			
		||||
    else
 | 
			
		||||
        vect[i] = val;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class T> inline void Svec<T>::add(T x)
 | 
			
		||||
{
 | 
			
		||||
    if (++used > alloced)
 | 
			
		||||
        grow();
 | 
			
		||||
    vect[used - 1] = x;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
template<class T>
 | 
			
		||||
inline void Svec<T>::add(T x)
 | 
			
		||||
{
 | 
			
		||||
    if(++used > alloced)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    vect[used - 1] = x;
 | 
			
		||||
}
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
template <class T> inline void Svec<T>::clear() { used = 0; }
 | 
			
		||||
 | 
			
		||||
template <class T> inline void Svec<T>::grow()
 | 
			
		||||
{
 | 
			
		||||
    //	printf("size=%d\n",sizeof(T));
 | 
			
		||||
    vect = (T *)realloc(vect, (alloced *= 2) * sizeof(T));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // SVEC_H
 | 
			
		||||
							
								
								
									
										170
									
								
								src/translations/qps.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,170 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<!DOCTYPE TS>
 | 
			
		||||
<TS version="2.1">
 | 
			
		||||
<context>
 | 
			
		||||
    <name>ControlBar</name>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../misc.cpp" line="964"/>
 | 
			
		||||
        <source>Pause (Ctrl+Space)</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
</context>
 | 
			
		||||
<context>
 | 
			
		||||
    <name>EventDialog</name>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="23"/>
 | 
			
		||||
        <source>Watchdog 0.1 alpha</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="117"/>
 | 
			
		||||
        <source>Eventcat</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="162"/>
 | 
			
		||||
        <source>Select condition</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="170"/>
 | 
			
		||||
        <source>labelDescrition</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="193"/>
 | 
			
		||||
        <source>Enable</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="219"/>
 | 
			
		||||
        <source>process name</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="229"/>
 | 
			
		||||
        <source>cpu</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="248"/>
 | 
			
		||||
        <source>%</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="280"/>
 | 
			
		||||
        <source>include already running process</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="309"/>
 | 
			
		||||
        <source>run command</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="342"/>
 | 
			
		||||
        <source>show Message</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="367"/>
 | 
			
		||||
        <source>Help (Not yet. just concept)</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="394"/>
 | 
			
		||||
        <source>%p : pid
 | 
			
		||||
%c : command</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="425"/>
 | 
			
		||||
        <source>New</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="432"/>
 | 
			
		||||
        <source>Add</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="439"/>
 | 
			
		||||
        <source>Delete</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../watchdog.ui" line="446"/>
 | 
			
		||||
        <source>Close</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
</context>
 | 
			
		||||
<context>
 | 
			
		||||
    <name>ExecWindow</name>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../message.ui" line="13"/>
 | 
			
		||||
        <source>Qps</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../message.ui" line="27"/>
 | 
			
		||||
        <source>Ok</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
</context>
 | 
			
		||||
<context>
 | 
			
		||||
    <name>Qps</name>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../qps.cpp" line="335"/>
 | 
			
		||||
        <source>Detail</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
</context>
 | 
			
		||||
<context>
 | 
			
		||||
    <name>Screenshot</name>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../screenshot.cpp" line="271"/>
 | 
			
		||||
        <source>/untitled.</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../screenshot.cpp" line="276"/>
 | 
			
		||||
        <source>Save As</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../screenshot.cpp" line="277"/>
 | 
			
		||||
        <source>%1 Files (*.%2);;All Files (*)</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../screenshot.cpp" line="304"/>
 | 
			
		||||
        <source>Options</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../screenshot.cpp" line="307"/>
 | 
			
		||||
        <source> s</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../screenshot.cpp" line="312"/>
 | 
			
		||||
        <source>Screenshot Delay:</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../screenshot.cpp" line="314"/>
 | 
			
		||||
        <source>Hide This Window</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../screenshot.cpp" line="326"/>
 | 
			
		||||
        <source>New Screenshot</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
    <message>
 | 
			
		||||
        <location filename="../screenshot.cpp" line="327"/>
 | 
			
		||||
        <source>Quit</source>
 | 
			
		||||
        <translation type="unfinished"></translation>
 | 
			
		||||
    </message>
 | 
			
		||||
</context>
 | 
			
		||||
</TS>
 | 
			
		||||
							
								
								
									
										240
									
								
								src/trayicon.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,240 @@
 | 
			
		||||
/*
 | 
			
		||||
        really sucking codes.. sorry..
 | 
			
		||||
        from psi ,  modified and cleand by fasthyun@magicn.com
 | 
			
		||||
        trayicon_x11.cpp - X11 trayicon (for use with KDE and GNOME)
 | 
			
		||||
        Copyright (C) 2003  Justin Karneges
 | 
			
		||||
        GNOME2 Notification Area support: Tomasz Sterna
 | 
			
		||||
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <QApplication> // *****should be First!!!
 | 
			
		||||
#include "global.h"     // Qps *qps;
 | 
			
		||||
#include "trayicon.h"
 | 
			
		||||
 | 
			
		||||
#include <QMouseEvent>
 | 
			
		||||
#include <QDesktopWidget>
 | 
			
		||||
#include <QPainter>
 | 
			
		||||
#include <QToolTip>
 | 
			
		||||
 | 
			
		||||
// QIcon icon = iconComboBox->itemIcon(index);
 | 
			
		||||
//   trayIcon->setIcon(icon);
 | 
			
		||||
 | 
			
		||||
extern bool flag_session_start;
 | 
			
		||||
//----------------------------------------------------------------------------
 | 
			
		||||
// common stuff
 | 
			
		||||
//----------------------------------------------------------------------------
 | 
			
		||||
// for Gnome2 Notification Area
 | 
			
		||||
static int dock_xerror = 0;
 | 
			
		||||
extern bool flag_xcompmgr;
 | 
			
		||||
 | 
			
		||||
#define SYSTEM_TRAY_REQUEST_DOCK 0
 | 
			
		||||
#define SYSTEM_TRAY_BEGIN_MESSAGE 1
 | 
			
		||||
#define SYSTEM_TRAY_CANCEL_MESSAGE 2
 | 
			
		||||
 | 
			
		||||
TrayIcon::TrayIcon(const QPixmap &icon, const QString &tooltip, QMenu *popup,
 | 
			
		||||
                   QWidget *parent, const char *name)
 | 
			
		||||
    : QSystemTrayIcon(0 /* shoud be NULL!! */), pop(popup), pm(icon),
 | 
			
		||||
      tip(tooltip)
 | 
			
		||||
{
 | 
			
		||||
    flag_show_tip = false;
 | 
			
		||||
    flag_systray_ready = false;
 | 
			
		||||
    inTray = false;
 | 
			
		||||
    isWMDock = false;
 | 
			
		||||
 | 
			
		||||
    QSystemTrayIcon::setIcon(icon);
 | 
			
		||||
    QSystemTrayIcon::setContextMenu(popup);
 | 
			
		||||
 | 
			
		||||
    if (!pm.width() || !pm.height())
 | 
			
		||||
        pm = QPixmap(45, 45);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
  Removes the icon from the system tray and frees all allocated resources.
 | 
			
		||||
*/
 | 
			
		||||
TrayIcon::~TrayIcon() { sysRemove(); }
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
  Sets the context menu to \a popup. The context menu will pop up when the
 | 
			
		||||
  user clicks the system tray entry with the right mouse button.
 | 
			
		||||
*/
 | 
			
		||||
void TrayIcon::setPopup(QMenu *popup) { pop = popup; }
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
  Returns the current popup menu.
 | 
			
		||||
*/
 | 
			
		||||
QMenu *TrayIcon::popup() const { return pop; }
 | 
			
		||||
 | 
			
		||||
QPixmap TrayIcon::icon() const { return pm; }
 | 
			
		||||
 | 
			
		||||
//----------------------------------------------------------------------------
 | 
			
		||||
// TrayIcon
 | 
			
		||||
//----------------------------------------------------------------------------
 | 
			
		||||
// DRAFT Code (by fasthyun@magicn.com)
 | 
			
		||||
void TrayIcon::init_TrayIconFreeDesktop() {}
 | 
			
		||||
 | 
			
		||||
void TrayIcon::init_WindowMakerDock() {}
 | 
			
		||||
 | 
			
		||||
void TrayIcon::sysInstall()
 | 
			
		||||
{
 | 
			
		||||
    /// boolSysTray=hasSysTray();
 | 
			
		||||
 | 
			
		||||
    if (hasSysTray() == true)
 | 
			
		||||
    {
 | 
			
		||||
        show();
 | 
			
		||||
    }
 | 
			
		||||
    /*
 | 
			
		||||
    if(hasSysTray()==false)
 | 
			
		||||
    {
 | 
			
		||||
            setFixedSize(46,46); // setIconSize
 | 
			
		||||
            init_WindowMakerDock();
 | 
			
		||||
            setSysTray(true);
 | 
			
		||||
    } */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TrayIcon::hasSysTray() { return QSystemTrayIcon::isSystemTrayAvailable(); }
 | 
			
		||||
 | 
			
		||||
void TrayIcon::sysRemove()
 | 
			
		||||
{
 | 
			
		||||
    // printf("Qps: sysRemove\n");
 | 
			
		||||
    inTray = false;
 | 
			
		||||
    /// boolSysTray=isWMDock=false;
 | 
			
		||||
    hide();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
  update systray icon
 | 
			
		||||
  called by qps::refresh()
 | 
			
		||||
*/
 | 
			
		||||
void TrayIcon::setIcon(const QPixmap &pix)
 | 
			
		||||
{
 | 
			
		||||
    QSystemTrayIcon::setIcon(pix);
 | 
			
		||||
    if (isVisible() == false)
 | 
			
		||||
        return;
 | 
			
		||||
    pm = pix;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
  \property TrayIcon::toolTip
 | 
			
		||||
  \brief the tooltip for the system tray entry
 | 
			
		||||
 | 
			
		||||
  On some systems, the tooltip's length is limited and will be truncated as
 | 
			
		||||
  necessary.
 | 
			
		||||
*/
 | 
			
		||||
void TrayIcon::setToolTip(const QString &tooltip)
 | 
			
		||||
{
 | 
			
		||||
    if (pop->isVisible())
 | 
			
		||||
        flag_show_tip = false;
 | 
			
		||||
    if (flag_show_tip)
 | 
			
		||||
        QToolTip::showText(tip_pos, tooltip);
 | 
			
		||||
    else
 | 
			
		||||
        QToolTip::hideText();
 | 
			
		||||
    tip = tooltip;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TrayIcon::leaveEvent(QEvent *) { flag_show_tip = false; }
 | 
			
		||||
 | 
			
		||||
void TrayIcon::mouseMoveEvent(QMouseEvent *e)
 | 
			
		||||
{
 | 
			
		||||
    // printf("move\n");
 | 
			
		||||
    // QToolTip::showText(QPoint(0,0),"" );
 | 
			
		||||
    // QToolTip::showText(e->globalPos(),tip );
 | 
			
		||||
    tip_pos = e->globalPos();
 | 
			
		||||
    flag_show_tip = true;
 | 
			
		||||
    QToolTip::showText(tip_pos, tip);
 | 
			
		||||
    e->accept();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TrayIcon::mousePressEvent(QMouseEvent *e)
 | 
			
		||||
{
 | 
			
		||||
    // test_xapp();
 | 
			
		||||
    // This is for X11, menus appear on mouse press
 | 
			
		||||
    // I'm not sure whether Mac should be here or below.. Somebody check?
 | 
			
		||||
    switch (e->button())
 | 
			
		||||
    {
 | 
			
		||||
    case Qt::RightButton:
 | 
			
		||||
        if (pop)
 | 
			
		||||
        {
 | 
			
		||||
            pop->popup(e->globalPos());
 | 
			
		||||
            e->accept();
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case Qt::LeftButton:
 | 
			
		||||
    case Qt::MidButton:
 | 
			
		||||
        // emit clicked( e->globalPos(), e->button() );
 | 
			
		||||
        emit clicked(e->globalPos());
 | 
			
		||||
    default:
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    e->ignore();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TrayIcon::mouseReleaseEvent(QMouseEvent *e)
 | 
			
		||||
{
 | 
			
		||||
    //	printf("mouseReleaseEvent\n");
 | 
			
		||||
    switch (e->button())
 | 
			
		||||
    {
 | 
			
		||||
    case Qt::RightButton:
 | 
			
		||||
        if (pop)
 | 
			
		||||
        {
 | 
			
		||||
            // Necessary to make keyboard focus
 | 
			
		||||
            // and menu closing work on Windows.
 | 
			
		||||
            //	e->accept();
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case Qt::LeftButton:
 | 
			
		||||
    case Qt::MidButton:
 | 
			
		||||
        // emit clicked( e->globalPos(), e->button() );
 | 
			
		||||
        // emit clicked( e->globalPos());
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    e->ignore();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TrayIcon::mouseDoubleClickEvent(QMouseEvent *e)
 | 
			
		||||
{
 | 
			
		||||
    if (e->button() == Qt::LeftButton)
 | 
			
		||||
        emit doubleClicked(e->globalPos());
 | 
			
		||||
    e->accept();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// this will be called  before shown !!
 | 
			
		||||
void TrayIcon::paintEvent(QPaintEvent *)
 | 
			
		||||
{
 | 
			
		||||
    /*
 | 
			
		||||
    //printf("paintEvent()\n");
 | 
			
		||||
    QPainter p(this);
 | 
			
		||||
    int w,h;
 | 
			
		||||
    if(isVisible()==false) // ** important to prevent X11 Error !!
 | 
			
		||||
    {
 | 
			
		||||
    //	printf("paintEvent(): hidden\n");
 | 
			
		||||
            return;
 | 
			
		||||
    }
 | 
			
		||||
    w=width()/2 ;
 | 
			
		||||
    h=height()/2;
 | 
			
		||||
    p.drawPixmap(w - pm.width()/2, h - pm.height()/2, pm); */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// for session logout ?? never called
 | 
			
		||||
void TrayIcon::closeEvent(QCloseEvent *e)
 | 
			
		||||
{
 | 
			
		||||
    printf("TrayIcon::closeEvent()\n");
 | 
			
		||||
    e->accept();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// called after size changed
 | 
			
		||||
void TrayIcon::resizeEvent(QResizeEvent *e)
 | 
			
		||||
{
 | 
			
		||||
    int w, h;
 | 
			
		||||
    // printf("TrayIcon::resizeEvent(): w=%d,h=%d\n",width(),height());
 | 
			
		||||
    // if(isVisible()==false) return;  // X11 error !!
 | 
			
		||||
    /// w=width();h=height();
 | 
			
		||||
    if (isWMDock)
 | 
			
		||||
    {
 | 
			
		||||
        /// w=w-14;h=h-14;
 | 
			
		||||
    }
 | 
			
		||||
    // qps->setIconSize(w,h);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void QPS_SHOW();
 | 
			
		||||
							
								
								
									
										98
									
								
								src/trayicon.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,98 @@
 | 
			
		||||
/*
 | 
			
		||||
 * trayicon.h - system-independent trayicon class (adapted from Qt example)
 | 
			
		||||
 * Copyright (C) 2003  Justin Karneges
 | 
			
		||||
 *
 | 
			
		||||
 * This library is free software; you can redistribute it and/or
 | 
			
		||||
 * modify it under the terms of the GNU Lesser General Public
 | 
			
		||||
 * License as published by the Free Software Foundation; either
 | 
			
		||||
 * version 2.1 of the License, or (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This library 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
 | 
			
		||||
 * Lesser General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU Lesser General Public
 | 
			
		||||
 * License along with this library; if not, write to the Free Software
 | 
			
		||||
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef CS_TRAYICON_H
 | 
			
		||||
#define CS_TRAYICON_H
 | 
			
		||||
 | 
			
		||||
#include <QWidget>
 | 
			
		||||
#include <QMenu>
 | 
			
		||||
 | 
			
		||||
#include <QSystemTrayIcon>
 | 
			
		||||
 | 
			
		||||
//----------------------------------------------------------------------------
 | 
			
		||||
// TrayIconPrivate
 | 
			
		||||
//----------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
class TrayIcon : public QSystemTrayIcon
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
  public:
 | 
			
		||||
    TrayIcon(const QPixmap &, const QString &, QMenu *popup = 0,
 | 
			
		||||
             QWidget *parent = 0, const char *name = 0);
 | 
			
		||||
    ~TrayIcon();
 | 
			
		||||
 | 
			
		||||
    // use WindowMaker dock mode.  ignored on non-X11 platforms
 | 
			
		||||
    void setWMDock(bool use) { isWMDock = use; }
 | 
			
		||||
    bool checkWMDock() { return isWMDock; }
 | 
			
		||||
    bool hasSysTray();
 | 
			
		||||
    void setSysTray(bool val)
 | 
			
		||||
    { // boolSysTray=val;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Set a popup menu to handle RMB
 | 
			
		||||
    void setPopup(QMenu *);
 | 
			
		||||
    QMenu *popup() const;
 | 
			
		||||
 | 
			
		||||
    QPixmap icon() const;
 | 
			
		||||
 | 
			
		||||
    void sysInstall();
 | 
			
		||||
    void sysRemove();
 | 
			
		||||
 | 
			
		||||
    void init_TrayIconFreeDesktop();
 | 
			
		||||
    void init_WindowMakerDock();
 | 
			
		||||
 | 
			
		||||
  public slots:
 | 
			
		||||
    void setIcon(const QPixmap &icon);
 | 
			
		||||
    void setToolTip(const QString &tip);
 | 
			
		||||
signals:
 | 
			
		||||
    void clicked(const QPoint &);
 | 
			
		||||
    void clicked(const QPoint &, int);
 | 
			
		||||
    void doubleClicked(const QPoint &);
 | 
			
		||||
    void closed();
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    //	bool event( QEvent *e );
 | 
			
		||||
    virtual void mouseMoveEvent(QMouseEvent *e);
 | 
			
		||||
    virtual void mousePressEvent(QMouseEvent *e);
 | 
			
		||||
    virtual void mouseReleaseEvent(QMouseEvent *e);
 | 
			
		||||
    virtual void mouseDoubleClickEvent(QMouseEvent *e);
 | 
			
		||||
    virtual void leaveEvent(QEvent *);
 | 
			
		||||
 | 
			
		||||
    void paintEvent(QPaintEvent *);
 | 
			
		||||
    void resizeEvent(QResizeEvent *e);
 | 
			
		||||
    //	void hideEvent ( QHideEvent *e ); // called after hide()
 | 
			
		||||
    void closeEvent(QCloseEvent *e);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    QMenu *pop;
 | 
			
		||||
    QPixmap pm;
 | 
			
		||||
    QString tip;
 | 
			
		||||
    QPoint tip_pos;
 | 
			
		||||
 | 
			
		||||
    bool isWMDock;
 | 
			
		||||
    //	bool boolSysTray; //DEL?
 | 
			
		||||
    bool inTray;
 | 
			
		||||
    bool flag_systray_ready;
 | 
			
		||||
    bool flag_show_tip;
 | 
			
		||||
 | 
			
		||||
    // DEL void sysUpdateToolTip();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // CS_TRAYICON_H
 | 
			
		||||
							
								
								
									
										211
									
								
								src/ttystr.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,211 @@
 | 
			
		||||
// ttystr.C
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <sys/types.h> //major() minor()
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <sys/mman.h>
 | 
			
		||||
#include <dirent.h>
 | 
			
		||||
#include "ttystr.h"
 | 
			
		||||
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
 | 
			
		||||
// Table of various tty devices (mostly serial boards)
 | 
			
		||||
 | 
			
		||||
struct Ttytab
 | 
			
		||||
{
 | 
			
		||||
    short dev_maj; // major number of tty
 | 
			
		||||
    char prefix;
 | 
			
		||||
    char callout; // 1 if callout device, 0 if tty
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static Ttytab ttytab[] = {{19, 'C', 0}, // Cyclades
 | 
			
		||||
                          {20, 'b', 1},
 | 
			
		||||
                          {22, 'D', 0}, // Digiboard
 | 
			
		||||
                          {23, 'd', 1},
 | 
			
		||||
                          {24, 'E', 0}, // Stallion
 | 
			
		||||
                          {25, 'e', 1},
 | 
			
		||||
                          {32, 'X', 0}, // Specialix
 | 
			
		||||
                          {33, 'x', 1},
 | 
			
		||||
                          {46, 'R', 0}, // Comtrol Rocketport
 | 
			
		||||
                          {47, 'r', 1},
 | 
			
		||||
                          {48, 'L', 0}, // SDL RISCom
 | 
			
		||||
                          {49, 'l', 1},
 | 
			
		||||
                          {57, 'P', 0}, // Hayes ESP
 | 
			
		||||
                          {58, 'p', 1},
 | 
			
		||||
                          {71, 'F', 0}, // Computone IntelliPort II
 | 
			
		||||
                          {72, 'f', 1},
 | 
			
		||||
                          {75, 'W', 0}, // Specialix IO8+
 | 
			
		||||
                          {76, 'w', 1},
 | 
			
		||||
                          {78, 'M', 0}, // PAM Software's multimodem boards
 | 
			
		||||
                          {79, 'm', 1},
 | 
			
		||||
                          {105, 'V', 0}, // Comtrol VS-1000
 | 
			
		||||
                          {106, 'v', 1},
 | 
			
		||||
                          {0, 0, 0}};
 | 
			
		||||
 | 
			
		||||
// Return tty name of a device. Remove leading "tty" if any.
 | 
			
		||||
// Return "-" if devnr is zero, "?" if unknown.
 | 
			
		||||
QString Ttystr::name(dev_t devnr)
 | 
			
		||||
{
 | 
			
		||||
    if (devnr == 0)
 | 
			
		||||
        return "-";
 | 
			
		||||
 | 
			
		||||
    int dmin = minor(devnr);
 | 
			
		||||
    int dmaj = major(devnr);
 | 
			
		||||
    char name[40];
 | 
			
		||||
    switch (dmaj)
 | 
			
		||||
    {
 | 
			
		||||
    case 3:
 | 
			
		||||
        // BSD-style pty slaves
 | 
			
		||||
        name[0] = "pqrstuvwxyzabcde"[(dmin >> 4) & 0xf];
 | 
			
		||||
        name[1] = "0123456789abcdef"[dmin & 0xf];
 | 
			
		||||
        name[2] = '\0';
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case 4:
 | 
			
		||||
        if (dmin < 64)
 | 
			
		||||
        {
 | 
			
		||||
            // virtual console 0..63
 | 
			
		||||
            sprintf(name, "%d", dmin);
 | 
			
		||||
        }
 | 
			
		||||
        else if (dmin < 128)
 | 
			
		||||
        {
 | 
			
		||||
            // serial port 0..63
 | 
			
		||||
            sprintf(name, "S%d", dmin - 64);
 | 
			
		||||
        }
 | 
			
		||||
        else if (dmin >= 192 && dmin < 256)
 | 
			
		||||
        {
 | 
			
		||||
            // obsolete tty devices
 | 
			
		||||
            name[0] = "pqrs"[(dmin >> 4) & 0x3];
 | 
			
		||||
            name[1] = "0123456789abcdef"[dmin & 0xf];
 | 
			
		||||
            name[2] = '\0';
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            strcpy(name, "?");
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case 5:
 | 
			
		||||
        // alternate tty devices
 | 
			
		||||
        switch (dmin)
 | 
			
		||||
        {
 | 
			
		||||
        case 0:
 | 
			
		||||
            strcpy(name, "tty");
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case 1:
 | 
			
		||||
            strcpy(name, "console");
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case 2:
 | 
			
		||||
            strcpy(name, "ptmx");
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        default:
 | 
			
		||||
            if (dmin >= 64 && dmin < 128)
 | 
			
		||||
            {
 | 
			
		||||
                // callout devices 0..63
 | 
			
		||||
                sprintf(name, "cua%d", dmin - 64);
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
                strcpy(name, "?");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
        if (dmaj >= 136 && dmaj < 144)
 | 
			
		||||
        {
 | 
			
		||||
            // Unix98 pty slaves
 | 
			
		||||
            sprintf(name, "pts/%d", ((dmaj - 136) << 8) + dmin);
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Various serial tty devices
 | 
			
		||||
        for (int i = 0; ttytab[i].dev_maj; i++)
 | 
			
		||||
        {
 | 
			
		||||
            if (dmaj == ttytab[i].dev_maj)
 | 
			
		||||
            {
 | 
			
		||||
                sprintf(name, "%s%c%d", ttytab[i].callout ? "cu" : "",
 | 
			
		||||
                        ttytab[i].prefix, dmin);
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        strcpy(name, "?");
 | 
			
		||||
    }
 | 
			
		||||
    return name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // LINUX
 | 
			
		||||
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
 | 
			
		||||
QHash<int, char *> Ttystr::dict;
 | 
			
		||||
bool Ttystr::scanned = FALSE;
 | 
			
		||||
 | 
			
		||||
// return tty name, '-' if no tty, "??" if unidentifiable tty
 | 
			
		||||
QString Ttystr::name(dev_t devnr)
 | 
			
		||||
{
 | 
			
		||||
    if (!scanned)
 | 
			
		||||
    {
 | 
			
		||||
        read_devs();
 | 
			
		||||
        scanned = TRUE; // just scan /dev once
 | 
			
		||||
    }
 | 
			
		||||
    QString s;
 | 
			
		||||
    if (devnr == (dev_t)-1)
 | 
			
		||||
        s = "-";
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        char *ts = dict.value(devnr, NULL);
 | 
			
		||||
 | 
			
		||||
        if (ts)
 | 
			
		||||
            s = ts;
 | 
			
		||||
        else
 | 
			
		||||
            s = "??";
 | 
			
		||||
    }
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// scan device directory or subdirectory thereof
 | 
			
		||||
void Ttystr::scandevdir(const char *prefix)
 | 
			
		||||
{
 | 
			
		||||
    char dirname[80] = "/dev";
 | 
			
		||||
    strcat(dirname, prefix);
 | 
			
		||||
    DIR *d = opendir(dirname);
 | 
			
		||||
    if (!d)
 | 
			
		||||
        return;
 | 
			
		||||
    struct dirent *e;
 | 
			
		||||
    struct stat sb;
 | 
			
		||||
    char name[80];
 | 
			
		||||
    while ((e = readdir(d)) != 0)
 | 
			
		||||
    {
 | 
			
		||||
        sprintf(name, "/dev%s/%s", prefix, e->d_name);
 | 
			
		||||
        if (stat(name, &sb) >= 0)
 | 
			
		||||
        {
 | 
			
		||||
            if (S_ISCHR(sb.st_mode))
 | 
			
		||||
            {
 | 
			
		||||
                dev_t d = sb.st_rdev;
 | 
			
		||||
                if (!dict.value(d, NULL))
 | 
			
		||||
                {
 | 
			
		||||
                    dict.insert(sb.st_rdev, strdup(name + 5)); // skip "/dev/"
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    closedir(d);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Ttystr::read_devs()
 | 
			
		||||
{
 | 
			
		||||
    // scan /dev and various subdirectories. In case of duplicates, pick
 | 
			
		||||
    // the first name encountered
 | 
			
		||||
    scandevdir("/term");
 | 
			
		||||
    scandevdir("");
 | 
			
		||||
    scandevdir("/pts");
 | 
			
		||||
    scandevdir("/cua");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // SOLARIS
 | 
			
		||||
							
								
								
									
										35
									
								
								src/ttystr.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,35 @@
 | 
			
		||||
// ttystr.h
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#ifndef TTYSTR_H
 | 
			
		||||
#define TTYSTR_H
 | 
			
		||||
 | 
			
		||||
#include "config.h"
 | 
			
		||||
#include <QString>
 | 
			
		||||
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
#include <sys/sysmacros.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
#include <QHash>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
class Ttystr
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    static QString name(dev_t devnr);
 | 
			
		||||
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
  private:
 | 
			
		||||
    static void read_devs();
 | 
			
		||||
    static void scandevdir(const char *prefix);
 | 
			
		||||
 | 
			
		||||
    static QHash<int, char *> dict;
 | 
			
		||||
    static bool scanned;
 | 
			
		||||
#endif
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // TTYSTR_H
 | 
			
		||||
							
								
								
									
										61
									
								
								src/uidstr.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,61 @@
 | 
			
		||||
// uidstr.C
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#include <pwd.h>
 | 
			
		||||
#include <grp.h>
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "uidstr.h"
 | 
			
		||||
 | 
			
		||||
QHash<int, char *> Uidstr::udict;
 | 
			
		||||
QHash<int, char *> Uidstr::gdict;
 | 
			
		||||
 | 
			
		||||
// return user name (possibly numeric)
 | 
			
		||||
QString Uidstr::userName(int uid)
 | 
			
		||||
{
 | 
			
		||||
    char *p = udict.value(uid, NULL);
 | 
			
		||||
    if (!p)
 | 
			
		||||
    {
 | 
			
		||||
        struct passwd *pw = getpwuid(uid);
 | 
			
		||||
        if (!pw)
 | 
			
		||||
        {
 | 
			
		||||
            p = (char *)malloc(11);
 | 
			
		||||
            sprintf(p, "%d", uid);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            p = strdup(pw->pw_name);
 | 
			
		||||
        udict.insert(uid, p);
 | 
			
		||||
        // if(udict.count() > udict.size() * 3)
 | 
			
		||||
        // udict.resize(udict.count());
 | 
			
		||||
    }
 | 
			
		||||
    QString s(p);
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// return group name (possibly numeric)
 | 
			
		||||
 | 
			
		||||
QString Uidstr::groupName(int gid)
 | 
			
		||||
{
 | 
			
		||||
    char *p = gdict[gid];
 | 
			
		||||
    if (!p)
 | 
			
		||||
    {
 | 
			
		||||
        struct group *gr = getgrgid(gid);
 | 
			
		||||
        if (!gr)
 | 
			
		||||
        {
 | 
			
		||||
            p = (char *)malloc(11);
 | 
			
		||||
            sprintf(p, "%d", gid);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            p = strdup(gr->gr_name);
 | 
			
		||||
        gdict.insert(gid, p);
 | 
			
		||||
        // if(gdict.count() > gdict.size() * 3)
 | 
			
		||||
        // gdict.resize(gdict.count());
 | 
			
		||||
    }
 | 
			
		||||
    QString s(p);
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										23
									
								
								src/uidstr.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,23 @@
 | 
			
		||||
// uidstr.h
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#ifndef UIDSTR_H
 | 
			
		||||
#define UIDSTR_H
 | 
			
		||||
 | 
			
		||||
#include <QHash>
 | 
			
		||||
#include <QString>
 | 
			
		||||
 | 
			
		||||
class Uidstr
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    static QString userName(int uid);
 | 
			
		||||
    static QString groupName(int gid);
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    static QHash<int, char *> udict;
 | 
			
		||||
    static QHash<int, char *> gdict;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // UIDSTR_H
 | 
			
		||||
							
								
								
									
										0
									
								
								src/watchdog.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										0
									
								
								src/watchdog.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										458
									
								
								src/watchdog.ui
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,458 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<ui version="4.0">
 | 
			
		||||
 <class>EventDialog</class>
 | 
			
		||||
 <widget class="QDialog" name="EventDialog">
 | 
			
		||||
  <property name="geometry">
 | 
			
		||||
   <rect>
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
    <y>0</y>
 | 
			
		||||
    <width>680</width>
 | 
			
		||||
    <height>533</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="sizePolicy">
 | 
			
		||||
   <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
 | 
			
		||||
    <horstretch>0</horstretch>
 | 
			
		||||
    <verstretch>0</verstretch>
 | 
			
		||||
   </sizepolicy>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="focusPolicy">
 | 
			
		||||
   <enum>Qt::WheelFocus</enum>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowTitle">
 | 
			
		||||
   <string>Watchdog 0.1 alpha</string>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="styleSheet">
 | 
			
		||||
   <string notr="true">QPushButtonX {
 | 
			
		||||
	color: rgb(244, 244, 244);
 | 
			
		||||
	border-image: url(:/icon/vista.png);
 | 
			
		||||
}
 | 
			
		||||
QWidget {
 | 
			
		||||
} 
 | 
			
		||||
QFrame, QLabel, QToolTip {
 | 
			
		||||
 } 
 | 
			
		||||
 </string>
 | 
			
		||||
  </property>
 | 
			
		||||
  <layout class="QVBoxLayout">
 | 
			
		||||
   <property name="spacing">
 | 
			
		||||
    <number>6</number>
 | 
			
		||||
   </property>
 | 
			
		||||
   <property name="leftMargin">
 | 
			
		||||
    <number>9</number>
 | 
			
		||||
   </property>
 | 
			
		||||
   <property name="topMargin">
 | 
			
		||||
    <number>9</number>
 | 
			
		||||
   </property>
 | 
			
		||||
   <property name="rightMargin">
 | 
			
		||||
    <number>9</number>
 | 
			
		||||
   </property>
 | 
			
		||||
   <property name="bottomMargin">
 | 
			
		||||
    <number>9</number>
 | 
			
		||||
   </property>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QListView" name="listView">
 | 
			
		||||
     <property name="sizePolicy">
 | 
			
		||||
      <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
 | 
			
		||||
       <horstretch>0</horstretch>
 | 
			
		||||
       <verstretch>0</verstretch>
 | 
			
		||||
      </sizepolicy>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="minimumSize">
 | 
			
		||||
      <size>
 | 
			
		||||
       <width>8</width>
 | 
			
		||||
       <height>1</height>
 | 
			
		||||
      </size>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="maximumSize">
 | 
			
		||||
      <size>
 | 
			
		||||
       <width>16777215</width>
 | 
			
		||||
       <height>51</height>
 | 
			
		||||
      </size>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QTableView" name="tableView">
 | 
			
		||||
     <property name="enabled">
 | 
			
		||||
      <bool>true</bool>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="sizePolicy">
 | 
			
		||||
      <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
 | 
			
		||||
       <horstretch>0</horstretch>
 | 
			
		||||
       <verstretch>0</verstretch>
 | 
			
		||||
      </sizepolicy>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="focusPolicy">
 | 
			
		||||
      <enum>Qt::NoFocus</enum>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="contextMenuPolicy">
 | 
			
		||||
      <enum>Qt::NoContextMenu</enum>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="alternatingRowColors">
 | 
			
		||||
      <bool>true</bool>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="selectionMode">
 | 
			
		||||
      <enum>QAbstractItemView::SingleSelection</enum>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="selectionBehavior">
 | 
			
		||||
      <enum>QAbstractItemView::SelectRows</enum>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="showGrid">
 | 
			
		||||
      <bool>false</bool>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="gridStyle">
 | 
			
		||||
      <enum>Qt::NoPen</enum>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QGroupBox" name="groupBox_2">
 | 
			
		||||
     <property name="sizePolicy">
 | 
			
		||||
      <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
 | 
			
		||||
       <horstretch>0</horstretch>
 | 
			
		||||
       <verstretch>0</verstretch>
 | 
			
		||||
      </sizepolicy>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="title">
 | 
			
		||||
      <string>Eventcat</string>
 | 
			
		||||
     </property>
 | 
			
		||||
     <layout class="QVBoxLayout">
 | 
			
		||||
      <property name="spacing">
 | 
			
		||||
       <number>6</number>
 | 
			
		||||
      </property>
 | 
			
		||||
      <property name="leftMargin">
 | 
			
		||||
       <number>9</number>
 | 
			
		||||
      </property>
 | 
			
		||||
      <property name="topMargin">
 | 
			
		||||
       <number>9</number>
 | 
			
		||||
      </property>
 | 
			
		||||
      <property name="rightMargin">
 | 
			
		||||
       <number>9</number>
 | 
			
		||||
      </property>
 | 
			
		||||
      <property name="bottomMargin">
 | 
			
		||||
       <number>9</number>
 | 
			
		||||
      </property>
 | 
			
		||||
      <item>
 | 
			
		||||
       <layout class="QHBoxLayout">
 | 
			
		||||
        <property name="spacing">
 | 
			
		||||
         <number>6</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="leftMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="topMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="rightMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="bottomMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <item>
 | 
			
		||||
         <widget class="QComboBox" name="comboBox">
 | 
			
		||||
          <property name="sizePolicy">
 | 
			
		||||
           <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
 | 
			
		||||
            <horstretch>0</horstretch>
 | 
			
		||||
            <verstretch>0</verstretch>
 | 
			
		||||
           </sizepolicy>
 | 
			
		||||
          </property>
 | 
			
		||||
          <item>
 | 
			
		||||
           <property name="text">
 | 
			
		||||
            <string>Select condition</string>
 | 
			
		||||
           </property>
 | 
			
		||||
          </item>
 | 
			
		||||
         </widget>
 | 
			
		||||
        </item>
 | 
			
		||||
        <item>
 | 
			
		||||
         <widget class="QLabel" name="labelDesc">
 | 
			
		||||
          <property name="text">
 | 
			
		||||
           <string>labelDescrition</string>
 | 
			
		||||
          </property>
 | 
			
		||||
         </widget>
 | 
			
		||||
        </item>
 | 
			
		||||
        <item>
 | 
			
		||||
         <spacer>
 | 
			
		||||
          <property name="orientation">
 | 
			
		||||
           <enum>Qt::Horizontal</enum>
 | 
			
		||||
          </property>
 | 
			
		||||
          <property name="sizeHint" stdset="0">
 | 
			
		||||
           <size>
 | 
			
		||||
            <width>36</width>
 | 
			
		||||
            <height>20</height>
 | 
			
		||||
           </size>
 | 
			
		||||
          </property>
 | 
			
		||||
         </spacer>
 | 
			
		||||
        </item>
 | 
			
		||||
        <item>
 | 
			
		||||
         <widget class="QCheckBox" name="checkBox">
 | 
			
		||||
          <property name="enabled">
 | 
			
		||||
           <bool>false</bool>
 | 
			
		||||
          </property>
 | 
			
		||||
          <property name="text">
 | 
			
		||||
           <string>Enable</string>
 | 
			
		||||
          </property>
 | 
			
		||||
         </widget>
 | 
			
		||||
        </item>
 | 
			
		||||
       </layout>
 | 
			
		||||
      </item>
 | 
			
		||||
      <item>
 | 
			
		||||
       <layout class="QHBoxLayout">
 | 
			
		||||
        <property name="spacing">
 | 
			
		||||
         <number>6</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="leftMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="topMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="rightMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="bottomMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <item>
 | 
			
		||||
         <widget class="QLabel" name="label_procname">
 | 
			
		||||
          <property name="text">
 | 
			
		||||
           <string>process name</string>
 | 
			
		||||
          </property>
 | 
			
		||||
         </widget>
 | 
			
		||||
        </item>
 | 
			
		||||
        <item>
 | 
			
		||||
         <widget class="QLineEdit" name="proc_name"/>
 | 
			
		||||
        </item>
 | 
			
		||||
        <item>
 | 
			
		||||
         <widget class="QLabel" name="label_cpu">
 | 
			
		||||
          <property name="text">
 | 
			
		||||
           <string>cpu</string>
 | 
			
		||||
          </property>
 | 
			
		||||
         </widget>
 | 
			
		||||
        </item>
 | 
			
		||||
        <item>
 | 
			
		||||
         <widget class="QSpinBox" name="spinBox">
 | 
			
		||||
          <property name="toolTip">
 | 
			
		||||
           <string/>
 | 
			
		||||
          </property>
 | 
			
		||||
          <property name="statusTip">
 | 
			
		||||
           <string/>
 | 
			
		||||
          </property>
 | 
			
		||||
          <property name="whatsThis">
 | 
			
		||||
           <string/>
 | 
			
		||||
          </property>
 | 
			
		||||
          <property name="accessibleName">
 | 
			
		||||
           <string/>
 | 
			
		||||
          </property>
 | 
			
		||||
          <property name="suffix">
 | 
			
		||||
           <string>%</string>
 | 
			
		||||
          </property>
 | 
			
		||||
          <property name="prefix">
 | 
			
		||||
           <string/>
 | 
			
		||||
          </property>
 | 
			
		||||
          <property name="value">
 | 
			
		||||
           <number>90</number>
 | 
			
		||||
          </property>
 | 
			
		||||
         </widget>
 | 
			
		||||
        </item>
 | 
			
		||||
        <item>
 | 
			
		||||
         <spacer>
 | 
			
		||||
          <property name="orientation">
 | 
			
		||||
           <enum>Qt::Horizontal</enum>
 | 
			
		||||
          </property>
 | 
			
		||||
          <property name="sizeHint" stdset="0">
 | 
			
		||||
           <size>
 | 
			
		||||
            <width>40</width>
 | 
			
		||||
            <height>20</height>
 | 
			
		||||
           </size>
 | 
			
		||||
          </property>
 | 
			
		||||
         </spacer>
 | 
			
		||||
        </item>
 | 
			
		||||
        <item>
 | 
			
		||||
         <widget class="QCheckBox" name="checkBox_alreadyrun">
 | 
			
		||||
          <property name="enabled">
 | 
			
		||||
           <bool>false</bool>
 | 
			
		||||
          </property>
 | 
			
		||||
          <property name="font">
 | 
			
		||||
           <font/>
 | 
			
		||||
          </property>
 | 
			
		||||
          <property name="text">
 | 
			
		||||
           <string>include already running process</string>
 | 
			
		||||
          </property>
 | 
			
		||||
          <property name="checked">
 | 
			
		||||
           <bool>true</bool>
 | 
			
		||||
          </property>
 | 
			
		||||
         </widget>
 | 
			
		||||
        </item>
 | 
			
		||||
       </layout>
 | 
			
		||||
      </item>
 | 
			
		||||
      <item>
 | 
			
		||||
       <layout class="QHBoxLayout">
 | 
			
		||||
        <property name="spacing">
 | 
			
		||||
         <number>6</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="leftMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="topMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="rightMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="bottomMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <item>
 | 
			
		||||
         <widget class="QLabel" name="label_3">
 | 
			
		||||
          <property name="text">
 | 
			
		||||
           <string>run command</string>
 | 
			
		||||
          </property>
 | 
			
		||||
         </widget>
 | 
			
		||||
        </item>
 | 
			
		||||
        <item>
 | 
			
		||||
         <widget class="QLineEdit" name="command">
 | 
			
		||||
          <property name="toolTip">
 | 
			
		||||
           <string/>
 | 
			
		||||
          </property>
 | 
			
		||||
         </widget>
 | 
			
		||||
        </item>
 | 
			
		||||
       </layout>
 | 
			
		||||
      </item>
 | 
			
		||||
      <item>
 | 
			
		||||
       <layout class="QHBoxLayout">
 | 
			
		||||
        <property name="spacing">
 | 
			
		||||
         <number>6</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="leftMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="topMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="rightMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="bottomMargin">
 | 
			
		||||
         <number>0</number>
 | 
			
		||||
        </property>
 | 
			
		||||
        <item>
 | 
			
		||||
         <widget class="QCheckBox" name="checkShowMsg">
 | 
			
		||||
          <property name="text">
 | 
			
		||||
           <string>show Message</string>
 | 
			
		||||
          </property>
 | 
			
		||||
         </widget>
 | 
			
		||||
        </item>
 | 
			
		||||
        <item>
 | 
			
		||||
         <widget class="QLineEdit" name="message">
 | 
			
		||||
          <property name="text">
 | 
			
		||||
           <string/>
 | 
			
		||||
          </property>
 | 
			
		||||
         </widget>
 | 
			
		||||
        </item>
 | 
			
		||||
       </layout>
 | 
			
		||||
      </item>
 | 
			
		||||
     </layout>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QGroupBox" name="groupBox">
 | 
			
		||||
     <property name="sizePolicy">
 | 
			
		||||
      <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
 | 
			
		||||
       <horstretch>0</horstretch>
 | 
			
		||||
       <verstretch>0</verstretch>
 | 
			
		||||
      </sizepolicy>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="title">
 | 
			
		||||
      <string>Help (Not yet. just concept)</string>
 | 
			
		||||
     </property>
 | 
			
		||||
     <layout class="QVBoxLayout">
 | 
			
		||||
      <property name="spacing">
 | 
			
		||||
       <number>4</number>
 | 
			
		||||
      </property>
 | 
			
		||||
      <property name="leftMargin">
 | 
			
		||||
       <number>9</number>
 | 
			
		||||
      </property>
 | 
			
		||||
      <property name="topMargin">
 | 
			
		||||
       <number>9</number>
 | 
			
		||||
      </property>
 | 
			
		||||
      <property name="rightMargin">
 | 
			
		||||
       <number>9</number>
 | 
			
		||||
      </property>
 | 
			
		||||
      <property name="bottomMargin">
 | 
			
		||||
       <number>9</number>
 | 
			
		||||
      </property>
 | 
			
		||||
      <item>
 | 
			
		||||
       <widget class="QLabel" name="label_2">
 | 
			
		||||
        <property name="sizePolicy">
 | 
			
		||||
         <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
 | 
			
		||||
          <horstretch>0</horstretch>
 | 
			
		||||
          <verstretch>0</verstretch>
 | 
			
		||||
         </sizepolicy>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="text">
 | 
			
		||||
         <string>%p : pid
 | 
			
		||||
%c : command</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </widget>
 | 
			
		||||
      </item>
 | 
			
		||||
     </layout>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <layout class="QHBoxLayout">
 | 
			
		||||
     <property name="spacing">
 | 
			
		||||
      <number>6</number>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="leftMargin">
 | 
			
		||||
      <number>0</number>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="topMargin">
 | 
			
		||||
      <number>0</number>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="rightMargin">
 | 
			
		||||
      <number>0</number>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="bottomMargin">
 | 
			
		||||
      <number>0</number>
 | 
			
		||||
     </property>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QPushButton" name="newButton">
 | 
			
		||||
       <property name="styleSheet">
 | 
			
		||||
        <string/>
 | 
			
		||||
       </property>
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>New</string>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QPushButton" name="addButton">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Add</string>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QPushButton" name="delButton">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Delete</string>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QPushButton" name="closeButton">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Close</string>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
    </layout>
 | 
			
		||||
   </item>
 | 
			
		||||
  </layout>
 | 
			
		||||
 </widget>
 | 
			
		||||
 <resources>
 | 
			
		||||
  <include location="qps.qrc"/>
 | 
			
		||||
 </resources>
 | 
			
		||||
 <connections/>
 | 
			
		||||
</ui>
 | 
			
		||||
							
								
								
									
										185
									
								
								src/wchan.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,185 @@
 | 
			
		||||
// wchan.C
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <sys/utsname.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <sys/mman.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
 | 
			
		||||
#include "config.h"
 | 
			
		||||
 | 
			
		||||
#include "wchan.h"
 | 
			
		||||
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
QHash<int, char *> Wchan::dict;
 | 
			
		||||
char *Wchan::sysmap = 0;
 | 
			
		||||
bool Wchan::sysmap_inited = false;
 | 
			
		||||
int Wchan::sysmap_size = 0;
 | 
			
		||||
 | 
			
		||||
// return malloc:ed hex representation of x
 | 
			
		||||
static char *hexstr(unsigned long x)
 | 
			
		||||
{
 | 
			
		||||
    char *p = (char *)malloc(sizeof(long) * 2 + 1);
 | 
			
		||||
    sprintf(p, sizeof(long) == 8 ? "%016lx" : "%08lx", x);
 | 
			
		||||
    return p;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// called  by ????
 | 
			
		||||
// return wchan symbol (possibly numeric, and empty string if addr=0)
 | 
			
		||||
 | 
			
		||||
QString Wchan::name(unsigned long addr)
 | 
			
		||||
{
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
    return "";
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef SOLARIS
 | 
			
		||||
    char buf[sizeof(long) * 2 + 1];
 | 
			
		||||
    sprintf(buf, sizeof(long) == 8 ? "%016lx" : "%08lx", addr);
 | 
			
		||||
    return QString(buf);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
 | 
			
		||||
// return true if open succeeds
 | 
			
		||||
bool Wchan::open_sysmap()
 | 
			
		||||
{
 | 
			
		||||
    // common places to look for a valid System.map
 | 
			
		||||
    static const char *paths[] = {
 | 
			
		||||
        "/boot/System.map-%s", "/boot/System.map", "/lib/modules/%s/System.map",
 | 
			
		||||
        "/usr/src/linux-%s/System.map", "/usr/src/linux/System.map",
 | 
			
		||||
        "/usr/local/src/linux-%s/System.map", "/usr/local/src/linux/System.map",
 | 
			
		||||
        0};
 | 
			
		||||
    sysmap_inited = true; // don't try again
 | 
			
		||||
    for (const char **p = paths; *p; p++)
 | 
			
		||||
    {
 | 
			
		||||
        char buf[80];
 | 
			
		||||
        struct utsname ub;
 | 
			
		||||
        uname(&ub);
 | 
			
		||||
        int major, minor, lvl;
 | 
			
		||||
        if (sscanf(ub.release, "%d.%d.%d", &major, &minor, &lvl) != 3)
 | 
			
		||||
            major = -1; // non-standard release, silently accept it
 | 
			
		||||
        sprintf(buf, *p, ub.release);
 | 
			
		||||
        if (try_sysmap(buf))
 | 
			
		||||
        { // try_sysmap
 | 
			
		||||
            if (major >= 0)
 | 
			
		||||
            {
 | 
			
		||||
                char vstr[40];
 | 
			
		||||
                sprintf(vstr, "Version_%d", (major << 16) + (minor << 8) + lvl);
 | 
			
		||||
                // map a zero page at the end to terminate
 | 
			
		||||
                // string
 | 
			
		||||
                int ps = getpagesize();
 | 
			
		||||
 | 
			
		||||
                mmap(sysmap + ((sysmap_size + ps - 1) & ~(ps - 1)), ps,
 | 
			
		||||
                     PROT_READ, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
 | 
			
		||||
                if (!strstr(sysmap, vstr))
 | 
			
		||||
                {
 | 
			
		||||
                    fprintf(stderr, "qps warning: %s does "
 | 
			
		||||
                                    "not match current "
 | 
			
		||||
                                    "kernel\n",
 | 
			
		||||
                            buf);
 | 
			
		||||
                    munmap(sysmap, sysmap_size + ps);
 | 
			
		||||
                    sysmap = 0;
 | 
			
		||||
                    continue; // search the list for a
 | 
			
		||||
                              // better file
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// try mapping System.map from path, return true if success
 | 
			
		||||
bool Wchan::try_sysmap(const char *path)
 | 
			
		||||
{
 | 
			
		||||
    int fd = open(path, O_RDONLY);
 | 
			
		||||
    struct stat sbuf;
 | 
			
		||||
    if (fd >= 0)
 | 
			
		||||
    {
 | 
			
		||||
        if (fstat(fd, &sbuf) == 0)
 | 
			
		||||
        {
 | 
			
		||||
            sysmap_size = sbuf.st_size;
 | 
			
		||||
            // make room for a zero page after the sysmap
 | 
			
		||||
            sysmap = (char *)mmap(0, sysmap_size + getpagesize(), PROT_READ,
 | 
			
		||||
                                  MAP_SHARED, fd, 0);
 | 
			
		||||
            close(fd);
 | 
			
		||||
            if (sysmap != (char *)-1)
 | 
			
		||||
                return true;
 | 
			
		||||
            sysmap = 0;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        close(fd);
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
inline int Wchan::beginning_of_line(int ofs)
 | 
			
		||||
{
 | 
			
		||||
    // seek backwards to beginning of line
 | 
			
		||||
    while (ofs >= 0 && sysmap[ofs] != '\n')
 | 
			
		||||
        ofs--;
 | 
			
		||||
    return ofs + 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
char *Wchan::find_sym(unsigned long addr)
 | 
			
		||||
{
 | 
			
		||||
    // use binary search to find symbol; return malloced string
 | 
			
		||||
    int l = 0, r = sysmap_size;
 | 
			
		||||
    for (;;)
 | 
			
		||||
    {
 | 
			
		||||
        unsigned long a;
 | 
			
		||||
        char buf[80];
 | 
			
		||||
        int m = (l + r) / 2;
 | 
			
		||||
        m = beginning_of_line(m);
 | 
			
		||||
        if (m == l)
 | 
			
		||||
        {
 | 
			
		||||
            // see if there is a line further down
 | 
			
		||||
            while (m < r - 1 && sysmap[m] != '\n')
 | 
			
		||||
                m++;
 | 
			
		||||
            if (m < r - 1)
 | 
			
		||||
            {
 | 
			
		||||
                m++;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                if (r == sysmap_size)
 | 
			
		||||
                {
 | 
			
		||||
                    // after last item, probably in a
 | 
			
		||||
                    // module. give hex addr
 | 
			
		||||
                    return hexstr(addr);
 | 
			
		||||
                }
 | 
			
		||||
                m = l;
 | 
			
		||||
                sscanf(sysmap + m, "%lx %*c %s", &a, buf);
 | 
			
		||||
                // strip leading sys_ or do_ to reduce field
 | 
			
		||||
                // width
 | 
			
		||||
                char *p = buf;
 | 
			
		||||
                if (strncmp(buf, "do_", 3) == 0)
 | 
			
		||||
                    p += 3;
 | 
			
		||||
                if (strncmp(buf, "sys_", 4) == 0)
 | 
			
		||||
                    p += 4;
 | 
			
		||||
                return strdup(p);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        sscanf(sysmap + m, "%lx %*c %s", &a, buf);
 | 
			
		||||
        if (addr < a)
 | 
			
		||||
        {
 | 
			
		||||
            r = m;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            l = m;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // LINUX
 | 
			
		||||
							
								
								
									
										31
									
								
								src/wchan.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,31 @@
 | 
			
		||||
// wchan.h
 | 
			
		||||
//
 | 
			
		||||
// This program is free software. See the file COPYING for details.
 | 
			
		||||
// Author: Mattias Engdegård, 1997-1999
 | 
			
		||||
 | 
			
		||||
#ifndef WCHAN_H
 | 
			
		||||
#define WCHAN_H
 | 
			
		||||
 | 
			
		||||
#include <QHash>
 | 
			
		||||
#include <QString>
 | 
			
		||||
 | 
			
		||||
class Wchan
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    static QString name(unsigned long addr);
 | 
			
		||||
 | 
			
		||||
#ifdef LINUX
 | 
			
		||||
  private:
 | 
			
		||||
    static bool open_sysmap();
 | 
			
		||||
    static bool try_sysmap(const char *path);
 | 
			
		||||
    static char *find_sym(unsigned long addr);
 | 
			
		||||
    static inline int beginning_of_line(int ofs);
 | 
			
		||||
 | 
			
		||||
    static QHash<int, char *> dict;
 | 
			
		||||
    static char *sysmap;       // pointer to mmap()ed System.map
 | 
			
		||||
    static bool sysmap_inited; // if an attempt to read sysmap has been made
 | 
			
		||||
    static int sysmap_size;
 | 
			
		||||
#endif
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // WCHAN_H
 | 
			
		||||