[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 01/473: Initial import.
noreply at xfce.org
noreply at xfce.org
Mon Feb 16 23:52:51 CET 2015
This is an automated email from the git hooks/post-receive script.
gottcode pushed a commit to branch master
in repository panel-plugins/xfce4-whiskermenu-plugin.
commit 3aa6792cd4855e84e5d835db70a50a1c62cca6a7
Author: Graeme Gott <graeme at gottcode.org>
Date: Thu Jun 20 07:02:16 2013 -0400
Initial import.
---
CMakeLists.txt | 36 ++
COPYING | 339 +++++++++++++++++
CREDITS | 8 +
icons/CMakeLists.txt | 35 ++
icons/hi128-app-whiskermenu.png | Bin 0 -> 6036 bytes
icons/hi16-app-whiskermenu.png | Bin 0 -> 661 bytes
icons/hi22-app-whiskermenu.png | Bin 0 -> 894 bytes
icons/hi24-app-whiskermenu.png | Bin 0 -> 1021 bytes
icons/hi256-app-whiskermenu.png | Bin 0 -> 12386 bytes
icons/hi32-app-whiskermenu.png | Bin 0 -> 1355 bytes
icons/hi48-app-whiskermenu.png | Bin 0 -> 2183 bytes
icons/hi64-app-whiskermenu.png | Bin 0 -> 2940 bytes
icons/hisc-app-whiskermenu.svg | 51 +++
po/CMakeLists.txt | 3 +
po/en_GB/CMakeLists.txt | 1 +
po/en_GB/xfce4-whiskermenu-plugin.po | 107 ++++++
po/xfce4-whiskermenu-plugin.pot | 107 ++++++
src/CMakeLists.txt | 86 +++++
src/applications_page.cpp | 325 +++++++++++++++++
src/applications_page.hpp | 84 +++++
src/configuration_dialog.cpp | 166 +++++++++
src/configuration_dialog.hpp | 54 +++
src/favorites_page.cpp | 52 +++
src/favorites_page.hpp | 37 ++
src/filter_page.cpp | 86 +++++
src/filter_page.hpp | 52 +++
src/launcher.cpp | 296 +++++++++++++++
src/launcher.hpp | 75 ++++
src/launcher_model.cpp | 117 ++++++
src/launcher_model.hpp | 77 ++++
src/launcher_view.cpp | 157 ++++++++
src/launcher_view.hpp | 65 ++++
src/list_page.cpp | 186 ++++++++++
src/list_page.hpp | 67 ++++
src/menu.cpp | 669 ++++++++++++++++++++++++++++++++++
src/menu.hpp | 126 +++++++
src/page.cpp | 333 +++++++++++++++++
src/page.hpp | 79 ++++
src/panel_plugin.cpp | 202 ++++++++++
src/panel_plugin.hpp | 71 ++++
src/recent_page.cpp | 57 +++
src/recent_page.hpp | 41 +++
src/register_plugin.c | 21 ++
src/resizer_widget.cpp | 148 ++++++++
src/resizer_widget.hpp | 67 ++++
src/search_page.cpp | 181 +++++++++
src/search_page.hpp | 51 +++
src/section_button.cpp | 40 ++
src/section_button.hpp | 32 ++
src/slot.hpp | 98 +++++
update-po.sh | 8 +
whiskermenu.desktop | 8 +
52 files changed, 4901 insertions(+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..98b43ca
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,36 @@
+cmake_minimum_required(VERSION 2.8)
+cmake_policy(VERSION 2.8)
+
+project(whiskermenu)
+
+if(NOT DEFINED LIB_INSTALL_DIR)
+ if (DEFINED CMAKE_INSTALL_LIBDIR)
+ set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR})
+ else()
+ set(LIB_INSTALL_DIR lib)
+ endif()
+endif()
+
+if(NOT DEFINED DATA_INSTALL_DIR)
+ if (DEFINED CMAKE_DATA_PATH)
+ set(DATA_INSTALL_DIR ${CMAKE_DATA_PATH})
+ else()
+ set(DATA_INSTALL_DIR share)
+ endif()
+endif()
+
+if(NOT DEFINED ICON_INSTALL_DIR)
+ set(ICON_INSTALL_DIR ${DATA_INSTALL_DIR}/icons)
+endif()
+
+if(NOT DEFINED LOCALE_INSTALL_DIR)
+ if (DEFINED CMAKE_LOCALE_PATH)
+ set(LOCALE_INSTALL_DIR ${CMAKE_LOCALE_PATH})
+ else()
+ set(LOCALE_INSTALL_DIR ${DATA_INSTALL_DIR}/locale)
+ endif()
+endif()
+
+add_subdirectory(src)
+add_subdirectory(po)
+add_subdirectory(icons)
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..d159169
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,339 @@
+ 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
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
diff --git a/CREDITS b/CREDITS
new file mode 100644
index 0000000..54799ea
--- /dev/null
+++ b/CREDITS
@@ -0,0 +1,8 @@
+Developers
+----------
+* Graeme Gott
+
+Libraries
+---------
+* Xfce >= 4.8 (exo, garcon, libxfce4panel, libxfce4ui, libxfce4util), http://xfce.org/
+* GTK+, http://gtk.org/
diff --git a/icons/CMakeLists.txt b/icons/CMakeLists.txt
new file mode 100644
index 0000000..4659c16
--- /dev/null
+++ b/icons/CMakeLists.txt
@@ -0,0 +1,35 @@
+install(FILES hi16-app-whiskermenu.png
+ DESTINATION ${ICON_INSTALL_DIR}/hicolor/16x16/apps
+ RENAME xfce4-whiskermenu.png)
+
+install(FILES hi22-app-whiskermenu.png
+ DESTINATION ${ICON_INSTALL_DIR}/hicolor/22x22/apps
+ RENAME xfce4-whiskermenu.png)
+
+install(FILES hi24-app-whiskermenu.png
+ DESTINATION ${ICON_INSTALL_DIR}/hicolor/24x24/apps
+ RENAME xfce4-whiskermenu.png)
+
+install(FILES hi32-app-whiskermenu.png
+ DESTINATION ${ICON_INSTALL_DIR}/hicolor/32x32/apps
+ RENAME xfce4-whiskermenu.png)
+
+install(FILES hi48-app-whiskermenu.png
+ DESTINATION ${ICON_INSTALL_DIR}/hicolor/48x48/apps
+ RENAME xfce4-whiskermenu.png)
+
+install(FILES hi64-app-whiskermenu.png
+ DESTINATION ${ICON_INSTALL_DIR}/hicolor/64x64/apps
+ RENAME xfce4-whiskermenu.png)
+
+install(FILES hi128-app-whiskermenu.png
+ DESTINATION ${ICON_INSTALL_DIR}/hicolor/128x128/apps
+ RENAME xfce4-whiskermenu.png)
+
+install(FILES hi256-app-whiskermenu.png
+ DESTINATION ${ICON_INSTALL_DIR}/hicolor/256x256/apps
+ RENAME xfce4-whiskermenu.png)
+
+install(FILES hisc-app-whiskermenu.svg
+ DESTINATION ${ICON_INSTALL_DIR}/hicolor/scalable/apps
+ RENAME xfce4-whiskermenu.svg)
diff --git a/icons/hi128-app-whiskermenu.png b/icons/hi128-app-whiskermenu.png
new file mode 100644
index 0000000..97af279
Binary files /dev/null and b/icons/hi128-app-whiskermenu.png differ
diff --git a/icons/hi16-app-whiskermenu.png b/icons/hi16-app-whiskermenu.png
new file mode 100644
index 0000000..29e8cf2
Binary files /dev/null and b/icons/hi16-app-whiskermenu.png differ
diff --git a/icons/hi22-app-whiskermenu.png b/icons/hi22-app-whiskermenu.png
new file mode 100644
index 0000000..f722c86
Binary files /dev/null and b/icons/hi22-app-whiskermenu.png differ
diff --git a/icons/hi24-app-whiskermenu.png b/icons/hi24-app-whiskermenu.png
new file mode 100644
index 0000000..6e69c28
Binary files /dev/null and b/icons/hi24-app-whiskermenu.png differ
diff --git a/icons/hi256-app-whiskermenu.png b/icons/hi256-app-whiskermenu.png
new file mode 100644
index 0000000..3ab4b89
Binary files /dev/null and b/icons/hi256-app-whiskermenu.png differ
diff --git a/icons/hi32-app-whiskermenu.png b/icons/hi32-app-whiskermenu.png
new file mode 100644
index 0000000..55de4ab
Binary files /dev/null and b/icons/hi32-app-whiskermenu.png differ
diff --git a/icons/hi48-app-whiskermenu.png b/icons/hi48-app-whiskermenu.png
new file mode 100644
index 0000000..867e13d
Binary files /dev/null and b/icons/hi48-app-whiskermenu.png differ
diff --git a/icons/hi64-app-whiskermenu.png b/icons/hi64-app-whiskermenu.png
new file mode 100644
index 0000000..94edc31
Binary files /dev/null and b/icons/hi64-app-whiskermenu.png differ
diff --git a/icons/hisc-app-whiskermenu.svg b/icons/hisc-app-whiskermenu.svg
new file mode 100644
index 0000000..b96a3ff
--- /dev/null
+++ b/icons/hisc-app-whiskermenu.svg
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ version="1.1"
+ width="256"
+ height="256"
+ id="svg3047">
+ <title
+ id="title4531">Whisker Menu icon</title>
+ <defs
+ id="defs3049" />
+ <metadata
+ id="metadata3052">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title>Whisker Menu icon</dc:title>
+ <dc:date>2013-06-16</dc:date>
+ <dc:creator>
+ <cc:Agent>
+ <dc:title>Graeme Gott</dc:title>
+ </cc:Agent>
+ </dc:creator>
+ <cc:license
+ rdf:resource="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ transform="translate(0,-796.36218)"
+ id="layer1">
+ <path
+ d="m 31,-39 a 128,128 0 1 1 -256,0 128,128 0 1 1 256,0 z"
+ transform="matrix(0,1,-1,0,89,1021.3622)"
+ id="path4343"
+ style="fill:#00aade;fill-opacity:1;stroke:none" />
+ <path
+ d="m 176.71247,843.52721 c -8.77257,1.33197 -13.05793,55.65997 -9.13767,63.00177 6.7093,-4.38075 16.71593,-25.32353 19.83835,-32.46275 -2.43538,6.62425 -5.4897,38.0344 -4.23218,38.40222 2.65019,3.54452 38.60951,-55.74065 28.15842,-59.9719 -1.50218,-0.60818 -11.59641,17.93248 -20.00667,36.8392 0.0957,-8.08746 6.62958,-32.52417 3.96767,-39.94119 -5.32564,-1.57757 -15.44977,21.63041 -19.59787,32.48678 -1.29688,-5.51301 5.68984,-35.67969 1.00995,-38.35413 z m -79.329316,5.72306 c -2.6 [...]
+ id="path602"
+ style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:none" />
+ </g>
+</svg>
diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt
new file mode 100644
index 0000000..d8a8cf8
--- /dev/null
+++ b/po/CMakeLists.txt
@@ -0,0 +1,3 @@
+find_package(Gettext REQUIRED)
+
+add_subdirectory(en_GB)
diff --git a/po/en_GB/CMakeLists.txt b/po/en_GB/CMakeLists.txt
new file mode 100644
index 0000000..18afcbc
--- /dev/null
+++ b/po/en_GB/CMakeLists.txt
@@ -0,0 +1 @@
+GETTEXT_PROCESS_PO_FILES(en_GB ALL INSTALL_DESTINATION ${LOCALE_INSTALL_DIR} PO_FILES xfce4-whiskermenu-plugin.po)
diff --git a/po/en_GB/xfce4-whiskermenu-plugin.po b/po/en_GB/xfce4-whiskermenu-plugin.po
new file mode 100644
index 0000000..e7a76f7
--- /dev/null
+++ b/po/en_GB/xfce4-whiskermenu-plugin.po
@@ -0,0 +1,107 @@
+# British English translations for whiskermenu package.
+# Copyright (C) 2013 Graeme Gott
+# This file is distributed under the same license as the whiskermenu package.
+# Graeme Gott <graeme at gottcode.org>, 2013.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: whiskermenu 1.0.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2013-06-15 20:23+0000\n"
+"PO-Revision-Date: 2013-06-15 20:23+0000\n"
+"Last-Translator: Graeme Gott <graeme at gottcode.org>\n"
+"Language-Team: \n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: src/applications_page.cpp:298
+msgid "All"
+msgstr "All"
+
+#: src/configuration_dialog.cpp:52
+msgid "Whisker Menu"
+msgstr "Whisker Menu"
+
+#: src/configuration_dialog.cpp:66
+msgid "Appearance"
+msgstr "Appearance"
+
+#: src/configuration_dialog.cpp:71
+msgid "Show applications by _name"
+msgstr "Show applications by _name"
+
+#: src/configuration_dialog.cpp:77
+msgid "Show application _descriptions"
+msgstr "Show application _descriptions"
+
+#: src/configuration_dialog.cpp:86
+msgid "_Icon:"
+msgstr "_Icon:"
+
+#: src/configuration_dialog.cpp:118
+msgid "Select An Icon"
+msgstr "Select An Icon"
+
+#: src/launcher.cpp:263
+#, c-format
+msgid "Failed to execute command \"%s\"."
+msgstr "Failed to execute command \"%s\"."
+
+#: src/menu.cpp:88
+msgid "All Settings"
+msgstr "All Settings"
+
+#: src/menu.cpp:91
+msgid "Lock Screen"
+msgstr "Lock Screen"
+
+#: src/menu.cpp:94
+msgid "Log Out"
+msgstr "Log Out"
+
+#: src/menu.cpp:108
+msgid "Favorites"
+msgstr "Favourites"
+
+#: src/menu.cpp:114
+msgid "Recently Used"
+msgstr "Recently Used"
+
+#: src/menu.cpp:636
+msgid "Failed to open settings manager."
+msgstr "Failed to open settings manager."
+
+#: src/menu.cpp:650
+msgid "Failed to lock screen."
+msgstr "Failed to lock screen."
+
+#: src/menu.cpp:664
+msgid "Failed to log out."
+msgstr "Failed to log out."
+
+#: src/page.cpp:170
+msgid "Add to Favorites"
+msgstr "Add to Favourites"
+
+#: src/page.cpp:176
+msgid "Remove From Favorites"
+msgstr "Remove From Favourites"
+
+#: src/page.cpp:181
+msgid "Add to Desktop"
+msgstr "Add to Desktop"
+
+#: src/page.cpp:185
+msgid "Add to Panel"
+msgstr "Add to Panel"
+
+#: src/page.cpp:265
+msgid "Unable to add launcher to desktop."
+msgstr "Unable to add launcher to desktop."
+
+#: src/page.cpp:303 src/page.cpp:312
+msgid "Unable to add launcher to panel."
+msgstr "Unable to add launcher to panel."
diff --git a/po/xfce4-whiskermenu-plugin.pot b/po/xfce4-whiskermenu-plugin.pot
new file mode 100644
index 0000000..5a25db1
--- /dev/null
+++ b/po/xfce4-whiskermenu-plugin.pot
@@ -0,0 +1,107 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL at ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: whiskermenu 1.0.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2013-06-15 20:23+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
+"Language-Team: LANGUAGE <LL at li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: src/applications_page.cpp:298
+msgid "All"
+msgstr ""
+
+#: src/configuration_dialog.cpp:52
+msgid "Whisker Menu"
+msgstr ""
+
+#: src/configuration_dialog.cpp:66
+msgid "Appearance"
+msgstr ""
+
+#: src/configuration_dialog.cpp:71
+msgid "Show applications by _name"
+msgstr ""
+
+#: src/configuration_dialog.cpp:77
+msgid "Show application _descriptions"
+msgstr ""
+
+#: src/configuration_dialog.cpp:86
+msgid "_Icon:"
+msgstr ""
+
+#: src/configuration_dialog.cpp:118
+msgid "Select An Icon"
+msgstr ""
+
+#: src/launcher.cpp:263
+#, c-format
+msgid "Failed to execute command \"%s\"."
+msgstr ""
+
+#: src/menu.cpp:88
+msgid "All Settings"
+msgstr ""
+
+#: src/menu.cpp:91
+msgid "Lock Screen"
+msgstr ""
+
+#: src/menu.cpp:94
+msgid "Log Out"
+msgstr ""
+
+#: src/menu.cpp:108
+msgid "Favorites"
+msgstr ""
+
+#: src/menu.cpp:114
+msgid "Recently Used"
+msgstr ""
+
+#: src/menu.cpp:636
+msgid "Failed to open settings manager."
+msgstr ""
+
+#: src/menu.cpp:650
+msgid "Failed to lock screen."
+msgstr ""
+
+#: src/menu.cpp:664
+msgid "Failed to log out."
+msgstr ""
+
+#: src/page.cpp:170
+msgid "Add to Favorites"
+msgstr ""
+
+#: src/page.cpp:176
+msgid "Remove From Favorites"
+msgstr ""
+
+#: src/page.cpp:181
+msgid "Add to Desktop"
+msgstr ""
+
+#: src/page.cpp:185
+msgid "Add to Panel"
+msgstr ""
+
+#: src/page.cpp:265
+msgid "Unable to add launcher to desktop."
+msgstr ""
+
+#: src/page.cpp:303 src/page.cpp:312
+msgid "Unable to add launcher to panel."
+msgstr ""
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..3cbad02
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,86 @@
+set(WHISKERMENU_FLAGS "-Wall -Wextra -Werror")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WHISKERMENU_FLAGS}")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -std=c++11 ${WHISKERMENU_FLAGS}")
+set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed")
+
+find_package(GTK2 REQUIRED)
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(exo REQUIRED exo-1)
+pkg_check_modules(garcon REQUIRED garcon-1)
+pkg_check_modules(libxfce4panel REQUIRED libxfce4panel-1.0>=4.8)
+pkg_check_modules(libxfce4ui REQUIRED libxfce4ui-1>=4.8)
+pkg_check_modules(libxfce4util REQUIRED libxfce4util-1.0>=4.8)
+
+if (NOT DEFINED DISABLE_DEPRECATED)
+ if(${libxfce4panel_VERSION} VERSION_LESS "4.10")
+ set(DISABLE_DEPRECATED OFF)
+ else()
+ set(DISABLE_DEPRECATED ON)
+ endif()
+endif()
+
+include_directories(
+ ${exo_INCLUDE_DIRS}
+ ${garcon_INCLUDE_DIRS}
+ ${libxfce4panel_INCLUDE_DIRS}
+ ${libxfce4ui_INCLUDE_DIRS}
+ ${libxfce4util_INCLUDE_DIRS}
+ ${GTK2_INCLUDE_DIRS})
+
+link_directories(
+ ${exo_LIBRARY_DIRS}
+ ${garcon_LIBRARY_DIRS}
+ ${libxfce4panel_LIBRARY_DIRS}
+ ${libxfce4ui_LIBRARY_DIRS}
+ ${libxfce4util_LIBRARY_DIRS})
+
+add_definitions(
+ -DGETTEXT_PACKAGE="whiskermenu"
+ -DLOCALEDIR="${CMAKE_INSTALL_PREFIX}/${LOCALE_INSTALL_DIR}"
+ -DGSEAL_ENABLE=1
+ -DGDK_DISABLE_SINGLE_INCLUDES=1
+ -DGDK_PIXBUF_DISABLE_SINGLE_INCLUDES=1
+ -DGTK_DISABLE_SINGLE_INCLUDES=1
+ -DGTK_MULTIHEAD_SAFE=1
+ ${exo_CFLAGS_OTHER}
+ ${garcon_CFLAGS_OTHER}
+ ${libxfce4panel_CFLAGS_OTHER}
+ ${libxfce4ui_CFLAGS_OTHER}
+ ${libxfce4util_CFLAGS_OTHER})
+
+if(${DISABLE_DEPRECATED})
+ add_definitions(
+ -DG_DISABLE_DEPRECATED=1
+ -DGDK_DISABLE_DEPRECATED=1
+ -DGDK_PIXBUF_DISABLE_DEPRECATED=1
+ -DGTK_DISABLE_DEPRECATED=1)
+endif()
+
+add_library(whiskermenu SHARED
+ applications_page.cpp
+ configuration_dialog.cpp
+ favorites_page.cpp
+ filter_page.cpp
+ launcher.cpp
+ launcher_model.cpp
+ launcher_view.cpp
+ list_page.cpp
+ menu.cpp
+ page.cpp
+ panel_plugin.cpp
+ recent_page.cpp
+ register_plugin.c
+ resizer_widget.cpp
+ search_page.cpp
+ section_button.cpp)
+
+target_link_libraries(whiskermenu
+ ${exo_LIBRARIES}
+ ${garcon_LIBRARIES}
+ ${libxfce4panel_LIBRARIES}
+ ${libxfce4ui_LIBRARIES}
+ ${libxfce4util_LIBRARIES}
+ ${GTK2_LIBRARIES})
+
+install(TARGETS whiskermenu LIBRARY DESTINATION ${LIB_INSTALL_DIR}/xfce4/panel/plugins)
+install(FILES ../whiskermenu.desktop DESTINATION ${DATA_INSTALL_DIR}/xfce4/panel/plugins)
diff --git a/src/applications_page.cpp b/src/applications_page.cpp
new file mode 100644
index 0000000..ac01311
--- /dev/null
+++ b/src/applications_page.cpp
@@ -0,0 +1,325 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "applications_page.hpp"
+
+#include "launcher.hpp"
+#include "launcher_model.hpp"
+#include "launcher_view.hpp"
+#include "menu.hpp"
+#include "section_button.hpp"
+#include "slot.hpp"
+
+#include <algorithm>
+#include <map>
+
+extern "C"
+{
+#include <libxfce4util/libxfce4util.h>
+}
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+ApplicationsPage::Category::Category(GarconMenuDirectory* directory)
+{
+ // Fetch icon
+ m_icon = garcon_menu_directory_get_icon_name(directory);
+
+ // Fetch text
+ m_text = garcon_menu_directory_get_name(directory);
+}
+
+//-----------------------------------------------------------------------------
+
+ApplicationsPage::ApplicationsPage(Menu* menu) :
+ FilterPage(menu),
+ m_garcon_menu(nullptr),
+ m_current_category(nullptr)
+{
+ // Set desktop environment for applications
+ const gchar* desktop = g_getenv("XDG_CURRENT_DESKTOP");
+ if (G_LIKELY(!desktop))
+ {
+ desktop = "XFCE";
+ }
+ else if (*desktop == '\0')
+ {
+ desktop = nullptr;
+ }
+ garcon_set_environment(desktop);
+}
+
+//-----------------------------------------------------------------------------
+
+ApplicationsPage::~ApplicationsPage()
+{
+ clear_applications();
+}
+
+//-----------------------------------------------------------------------------
+
+void ApplicationsPage::apply_filter(GtkToggleButton* togglebutton)
+{
+ // Find category matching button
+ auto i = m_category_buttons.find(GTK_RADIO_BUTTON(togglebutton));
+ if (i == m_category_buttons.end())
+ {
+ return;
+ }
+
+ // Apply filter
+ m_current_category = i->second;
+ refilter();
+ m_current_category = nullptr;
+
+ // Scroll to top
+ GtkTreeIter iter;
+ GtkTreePath* path = gtk_tree_path_new_first();
+ if (gtk_tree_model_get_iter(get_view()->get_model(), &iter, path))
+ {
+ get_view()->scroll_to_path(path);
+ get_view()->unselect_all();
+ }
+ gtk_tree_path_free(path);
+}
+
+//-----------------------------------------------------------------------------
+
+bool ApplicationsPage::on_filter(GtkTreeModel* model, GtkTreeIter* iter)
+{
+ if (!m_current_category)
+ {
+ return true;
+ }
+
+ Launcher* launcher = nullptr;
+ gtk_tree_model_get(model, iter, LauncherModel::COLUMN_LAUNCHER, &launcher, -1);
+
+ auto category = m_categories[m_current_category];
+ return std::find(category.cbegin(), category.cend(), launcher) != category.cend();
+}
+
+//-----------------------------------------------------------------------------
+
+void ApplicationsPage::reload_applications()
+{
+ // Remove previous menu data
+ clear_applications();
+
+ // Populate map of menu data
+ m_garcon_menu = garcon_menu_new_applications();
+ g_object_ref(m_garcon_menu);
+ if (garcon_menu_load(m_garcon_menu, nullptr, nullptr))
+ {
+ g_signal_connect_slot(m_garcon_menu, "reload-required", &ApplicationsPage::reload_applications, this);
+ load_menu(m_garcon_menu);
+ }
+
+ // Create sorted list of menu items
+ std::map<std::string, Launcher*> sorted_items;
+ for (const auto& i : m_items)
+ {
+ gchar* collation_key = g_utf8_collate_key(i.second->get_text(), -1);
+ sorted_items[collation_key] = i.second;
+ g_free(collation_key);
+ }
+
+ // Add all items to model
+ LauncherModel model;
+ for (const auto& i : sorted_items)
+ {
+ model.append_item(i.second);
+ }
+
+ // Create filter model and pass ownership to view, do not delete!
+ set_model(model.get_model());
+
+ // Update filters
+ reload_categories();
+
+ // Update menu items of other panels
+ get_menu()->set_items(m_items);
+}
+
+//-----------------------------------------------------------------------------
+
+void ApplicationsPage::clear_applications()
+{
+ // Free categories
+ for (auto& i : m_category_buttons)
+ {
+ if (GTK_IS_WIDGET(i.first))
+ {
+ gtk_widget_destroy(GTK_WIDGET(i.first));
+ }
+ }
+ m_category_buttons.clear();
+
+ for (auto& i : m_categories)
+ {
+ delete i.first;
+ }
+ m_categories.clear();
+
+ // Free menu items
+ get_menu()->unset_items();
+ unset_model();
+
+ for (auto& i : m_items)
+ {
+ delete i.second;
+ }
+ m_items.clear();
+
+ // Unreference menu
+ if (m_garcon_menu)
+ {
+ g_object_unref(m_garcon_menu);
+ m_garcon_menu = nullptr;
+ }
+
+ // Clear menu item cache
+ GarconMenuItemCache* cache = garcon_menu_item_cache_get_default();
+ garcon_menu_item_cache_invalidate(cache);
+ g_object_unref(cache);
+}
+
+//-----------------------------------------------------------------------------
+
+void ApplicationsPage::load_menu(GarconMenu* menu)
+{
+ GarconMenuDirectory* directory = garcon_menu_get_directory(menu);
+
+ // Skip hidden categories
+ if (directory && !garcon_menu_directory_get_visible(directory))
+ {
+ g_object_unref(directory);
+ return;
+ }
+
+ // Only track single level of categories
+ bool first_level = directory && (garcon_menu_get_parent(menu) == m_garcon_menu);
+ if (first_level)
+ {
+ m_current_category = new Category(directory);
+ }
+ if (directory)
+ {
+ g_object_unref(directory);
+ }
+
+ // Add submenus
+ GList* menus = garcon_menu_get_menus(menu);
+ for (GList* li = menus; li != nullptr; li = li->next)
+ {
+ load_menu(GARCON_MENU(li->data));
+ }
+ g_list_free(menus);
+
+ // Add items
+ GarconMenuItemPool* pool = garcon_menu_get_item_pool(menu);
+ if (G_LIKELY(pool))
+ {
+ garcon_menu_item_pool_foreach(pool, (GHFunc)&ApplicationsPage::load_menu_item, this);
+ }
+
+ // Only track single level of categories
+ if (first_level)
+ {
+ // Free unused categories
+ auto i = m_categories.find(m_current_category);
+ if (i == m_categories.end())
+ {
+ delete m_current_category;
+ }
+ // Do not track empty categories
+ else if (i->second.empty())
+ {
+ m_categories.erase(i);
+ delete m_current_category;
+ }
+ m_current_category = nullptr;
+ }
+
+ // Listen for menu changes
+ g_signal_connect_slot(menu, "directory-changed", &ApplicationsPage::reload_applications, this);
+}
+
+//-----------------------------------------------------------------------------
+
+void ApplicationsPage::load_menu_item(const gchar* desktop_id, GarconMenuItem* menu_item, ApplicationsPage* page)
+{
+ // Skip hidden items
+ if (!garcon_menu_element_get_visible(GARCON_MENU_ELEMENT(menu_item)))
+ {
+ return;
+ }
+
+ // Add to map
+ std::string key(desktop_id);
+ auto iter = page->m_items.find(key);
+ if (iter == page->m_items.end())
+ {
+ iter = page->m_items.emplace(std::move(key), new Launcher(menu_item)).first;
+ }
+
+ // Add menu item to current category
+ if (page->m_current_category)
+ {
+ page->m_categories[page->m_current_category].push_back(iter->second);
+ }
+
+ // Listen for menu changes
+ g_signal_connect_slot(menu_item, "changed", &ApplicationsPage::reload_applications, page);
+}
+
+//-----------------------------------------------------------------------------
+
+void ApplicationsPage::reload_categories()
+{
+ std::vector<GtkRadioButton*> category_buttons;
+
+ // Add button for all applications
+ GtkRadioButton* all_button = new_section_button("applications-other", _("All"));
+ g_signal_connect_slot(all_button, "toggled", &ApplicationsPage::apply_filter, this);
+ m_category_buttons.emplace(all_button, nullptr);
+ category_buttons.push_back(all_button);
+
+ // Create sorted list of categories
+ std::map<std::string, Category*> sorted_categories;
+ for (const auto& i : m_categories)
+ {
+ gchar* collation_key = g_utf8_collate_key(i.first->get_text(), -1);
+ sorted_categories[collation_key] = i.first;
+ g_free(collation_key);
+ }
+
+ // Add buttons for sorted categories
+ for (const auto& i : sorted_categories)
+ {
+ GtkRadioButton* category_button = new_section_button(i.second->get_icon(), i.second->get_text());
+ g_signal_connect_slot(category_button, "toggled", &ApplicationsPage::apply_filter, this);
+ m_category_buttons.emplace(category_button, i.second);
+ category_buttons.push_back(category_button);
+ }
+
+ // Add category buttons to window
+ get_menu()->set_categories(category_buttons);
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/applications_page.hpp b/src/applications_page.hpp
new file mode 100644
index 0000000..d47d716
--- /dev/null
+++ b/src/applications_page.hpp
@@ -0,0 +1,84 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_APPLICATIONS_PAGE_HPP
+#define WHISKERMENU_APPLICATIONS_PAGE_HPP
+
+#include "filter_page.hpp"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+extern "C"
+{
+#include <garcon/garcon.h>
+}
+
+namespace WhiskerMenu
+{
+
+class Launcher;
+class LauncherView;
+class Menu;
+
+class ApplicationsPage : public FilterPage
+{
+ class Category
+ {
+ public:
+ Category(GarconMenuDirectory* directory);
+
+ const gchar* get_icon() const
+ {
+ return m_icon.c_str();
+ }
+
+ const gchar* get_text() const
+ {
+ return m_text.c_str();
+ }
+
+ private:
+ std::string m_icon;
+ std::string m_text;
+ };
+
+public:
+ ApplicationsPage(Menu* menu);
+ ~ApplicationsPage();
+
+ void reload_applications();
+
+private:
+ void apply_filter(GtkToggleButton* togglebutton);
+ bool on_filter(GtkTreeModel* model, GtkTreeIter* iter);
+ void clear_applications();
+ void load_menu(GarconMenu* menu);
+ static void load_menu_item(const gchar* desktop_id, GarconMenuItem* menu_item, ApplicationsPage* page);
+ void reload_categories();
+
+private:
+ GarconMenu* m_garcon_menu;
+ Category* m_current_category;
+ std::unordered_map<GtkRadioButton*, Category*> m_category_buttons;
+ std::unordered_map<Category*, std::vector<Launcher*>> m_categories;
+ std::unordered_map<std::string, Launcher*> m_items;
+};
+
+}
+
+#endif // WHISKERMENU_APPLICATIONS_PAGE_HPP
diff --git a/src/configuration_dialog.cpp b/src/configuration_dialog.cpp
new file mode 100644
index 0000000..f23efbe
--- /dev/null
+++ b/src/configuration_dialog.cpp
@@ -0,0 +1,166 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "configuration_dialog.hpp"
+
+#include "launcher.hpp"
+#include "panel_plugin.hpp"
+#include "slot.hpp"
+
+extern "C"
+{
+#include <exo/exo.h>
+#include <libxfce4panel/libxfce4panel.h>
+#include <libxfce4ui/libxfce4ui.h>
+}
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+static void whiskermenu_config_dialog_delete(ConfigurationDialog* dialog)
+{
+ delete dialog;
+ dialog = nullptr;
+}
+
+//-----------------------------------------------------------------------------
+
+ConfigurationDialog::ConfigurationDialog(PanelPlugin* plugin) :
+ m_plugin(plugin)
+{
+ // Create dialog window
+ GtkWindow* window = nullptr;
+ GtkWidget* toplevel = gtk_widget_get_toplevel(m_plugin->get_button());
+ if (gtk_widget_is_toplevel(toplevel))
+ {
+ window = GTK_WINDOW(toplevel);
+ }
+ m_window = xfce_titled_dialog_new_with_buttons(_("Whisker Menu"), window, GTK_DIALOG_NO_SEPARATOR, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, nullptr);
+ gtk_window_set_icon_name(GTK_WINDOW(m_window), GTK_STOCK_PROPERTIES);
+ gtk_window_set_position(GTK_WINDOW(m_window), GTK_WIN_POS_CENTER);
+ g_signal_connect_slot(m_window, "response", &ConfigurationDialog::response, this);
+ g_signal_connect_swapped(m_window, "destroy", G_CALLBACK(whiskermenu_config_dialog_delete), this);
+
+ // Fetch contents box
+ GtkBox* contents_vbox = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(m_window)));
+
+ // Create size group for labels
+ GtkSizeGroup* label_size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+
+ // Create appearance section
+ GtkBox* appearance_vbox = GTK_BOX(gtk_vbox_new(false, 8));
+ GtkWidget* appearance_frame = xfce_gtk_frame_box_new_with_content(_("Appearance"), GTK_WIDGET(appearance_vbox));
+ gtk_box_pack_start(contents_vbox, appearance_frame, false, false, 0);
+ gtk_container_set_border_width(GTK_CONTAINER(appearance_frame), 6);
+
+ // Add option to use generic names
+ m_show_names = gtk_check_button_new_with_mnemonic(_("Show applications by _name"));
+ gtk_box_pack_start(appearance_vbox, m_show_names, true, true, 0);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_show_names), Launcher::get_show_name());
+ g_signal_connect_slot(m_show_names, "toggled", &ConfigurationDialog::toggle_show_name, this);
+
+ // Add option to hide descriptions
+ m_show_descriptions = gtk_check_button_new_with_mnemonic(_("Show application _descriptions"));
+ gtk_box_pack_start(appearance_vbox, m_show_descriptions, true, true, 0);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_show_descriptions), Launcher::get_show_description());
+ g_signal_connect_slot(m_show_descriptions, "toggled", &ConfigurationDialog::toggle_show_description, this);
+
+ // Add icon selector
+ GtkBox* hbox = GTK_BOX(gtk_hbox_new(false, 2));
+ gtk_box_pack_start(appearance_vbox, GTK_WIDGET(hbox), false, false, 0);
+
+ GtkWidget* label = gtk_label_new_with_mnemonic(_("_Icon:"));
+ gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+ gtk_box_pack_start(hbox, label, false, false, 0);
+ gtk_size_group_add_widget(label_size_group, label);
+
+ m_icon_button = gtk_button_new();
+ gtk_box_pack_start(hbox, m_icon_button, false, false, 0);
+ gtk_label_set_mnemonic_widget(GTK_LABEL(label), m_icon_button);
+ g_signal_connect_slot(m_icon_button, "clicked", &ConfigurationDialog::choose_icon, this);
+
+ m_icon = xfce_panel_image_new_from_source(m_plugin->get_button_icon_name().c_str());
+ xfce_panel_image_set_size(XFCE_PANEL_IMAGE(m_icon), 48);
+ gtk_container_add(GTK_CONTAINER(m_icon_button), m_icon);
+
+ // Show GTK window
+ gtk_widget_show_all(m_window);
+
+ m_plugin->set_configure_enabled(false);
+}
+
+//-----------------------------------------------------------------------------
+
+ConfigurationDialog::~ConfigurationDialog()
+{
+ m_plugin->set_configure_enabled(true);
+}
+
+//-----------------------------------------------------------------------------
+
+void ConfigurationDialog::choose_icon()
+{
+ GtkWidget* chooser = exo_icon_chooser_dialog_new(_("Select An Icon"),
+ GTK_WINDOW(m_window),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+ nullptr);
+
+ gtk_dialog_set_default_response(GTK_DIALOG(chooser), GTK_RESPONSE_ACCEPT);
+ gtk_dialog_set_alternative_button_order(GTK_DIALOG(chooser),
+ GTK_RESPONSE_ACCEPT,
+ GTK_RESPONSE_CANCEL, -1);
+ exo_icon_chooser_dialog_set_icon(EXO_ICON_CHOOSER_DIALOG(chooser), m_plugin->get_button_icon_name().c_str());
+
+ if (gtk_dialog_run(GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT)
+ {
+ gchar* icon = exo_icon_chooser_dialog_get_icon(EXO_ICON_CHOOSER_DIALOG(chooser));
+ xfce_panel_image_set_from_source(XFCE_PANEL_IMAGE(m_icon), icon);
+ m_plugin->set_button_icon_name(icon);
+ g_free(icon);
+ }
+
+ gtk_widget_destroy(chooser);
+}
+
+//-----------------------------------------------------------------------------
+
+void ConfigurationDialog::toggle_show_name(GtkToggleButton*)
+{
+ Launcher::set_show_name(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_show_names)));
+ m_plugin->reload();
+}
+
+//-----------------------------------------------------------------------------
+
+void ConfigurationDialog::toggle_show_description(GtkToggleButton*)
+{
+ Launcher::set_show_description(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_show_descriptions)));
+ m_plugin->reload();
+}
+
+//-----------------------------------------------------------------------------
+
+void ConfigurationDialog::response(GtkDialog*, gint response_id)
+{
+ if (response_id == GTK_RESPONSE_CLOSE)
+ {
+ gtk_widget_destroy(m_window);
+ }
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/configuration_dialog.hpp b/src/configuration_dialog.hpp
new file mode 100644
index 0000000..003dc6b
--- /dev/null
+++ b/src/configuration_dialog.hpp
@@ -0,0 +1,54 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_CONFIGURATION_DIALOG_HPP
+#define WHISKERMENU_CONFIGURATION_DIALOG_HPP
+
+extern "C"
+{
+#include <gtk/gtk.h>
+}
+
+namespace WhiskerMenu
+{
+
+class PanelPlugin;
+
+class ConfigurationDialog
+{
+public:
+ ConfigurationDialog(PanelPlugin* plugin);
+ ~ConfigurationDialog();
+
+private:
+ void choose_icon();
+ void toggle_show_name(GtkToggleButton*);
+ void toggle_show_description(GtkToggleButton*);
+ void response(GtkDialog* dialog, gint response_id);
+
+private:
+ PanelPlugin* m_plugin;
+
+ GtkWidget* m_window;
+ GtkWidget* m_icon;
+ GtkWidget* m_icon_button;
+ GtkWidget* m_show_names;
+ GtkWidget* m_show_descriptions;
+};
+
+}
+
+#endif // WHISKERMENU_CONFIGURATION_DIALOG_HPP
diff --git a/src/favorites_page.cpp b/src/favorites_page.cpp
new file mode 100644
index 0000000..59d0f7f
--- /dev/null
+++ b/src/favorites_page.cpp
@@ -0,0 +1,52 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "favorites_page.hpp"
+
+#include "launcher.hpp"
+#include "launcher_model.hpp"
+#include "launcher_view.hpp"
+
+#include <algorithm>
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+FavoritesPage::FavoritesPage(XfceRc* settings, Menu* menu) :
+ ListPage(settings, "favorites",
+ {"exo-terminal-emulator.desktop",
+ "exo-file-manager.desktop",
+ "exo-mail-reader.desktop",
+ "exo-web-browser.desktop"},
+ menu)
+{
+ get_view()->set_reorderable(true);
+}
+
+//-----------------------------------------------------------------------------
+
+void FavoritesPage::add(Launcher* launcher)
+{
+ // Remove item if already in list
+ remove(launcher);
+
+ // Add to list of items
+ LauncherModel model(GTK_LIST_STORE(get_view()->get_model()));
+ model.append_item(launcher);
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/favorites_page.hpp b/src/favorites_page.hpp
new file mode 100644
index 0000000..298be13
--- /dev/null
+++ b/src/favorites_page.hpp
@@ -0,0 +1,37 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_FAVORITES_PAGE_HPP
+#define WHISKERMENU_FAVORITES_PAGE_HPP
+
+#include "list_page.hpp"
+
+namespace WhiskerMenu
+{
+
+class Launcher;
+
+class FavoritesPage : public ListPage
+{
+public:
+ FavoritesPage(XfceRc* settings, Menu* menu);
+
+ void add(Launcher* launcher);
+};
+
+}
+
+#endif // WHISKERMENU_FAVORITES_PAGE_HPP
diff --git a/src/filter_page.cpp b/src/filter_page.cpp
new file mode 100644
index 0000000..29cb89a
--- /dev/null
+++ b/src/filter_page.cpp
@@ -0,0 +1,86 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "filter_page.hpp"
+
+#include "launcher_view.hpp"
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+FilterPage::FilterPage(Menu* menu) :
+ Page(menu),
+ m_filter_model(nullptr)
+{
+}
+
+//-----------------------------------------------------------------------------
+
+FilterPage::~FilterPage()
+{
+ unset_model();
+}
+
+//-----------------------------------------------------------------------------
+
+GtkTreeModel* FilterPage::get_model() const
+{
+ return m_filter_model ? gtk_tree_model_filter_get_model(m_filter_model) : nullptr;
+}
+
+//-----------------------------------------------------------------------------
+
+void FilterPage::refilter()
+{
+ if (m_filter_model)
+ {
+ gtk_tree_model_filter_refilter(m_filter_model);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+GtkTreePath* FilterPage::convert_child_path_to_path(GtkTreePath* path) const
+{
+ return gtk_tree_model_filter_convert_child_path_to_path((m_filter_model), path);
+}
+
+//-----------------------------------------------------------------------------
+
+void FilterPage::set_model(GtkTreeModel* model)
+{
+ unset_model();
+
+ m_filter_model = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(model, nullptr));
+ gtk_tree_model_filter_set_visible_func(m_filter_model, (GtkTreeModelFilterVisibleFunc)&FilterPage::filter_visible, this, nullptr);
+ get_view()->set_model(GTK_TREE_MODEL(m_filter_model));
+}
+
+//-----------------------------------------------------------------------------
+
+void FilterPage::unset_model()
+{
+ get_view()->unset_model();
+
+ if (m_filter_model)
+ {
+ g_object_unref(m_filter_model);
+ m_filter_model = nullptr;
+ }
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/filter_page.hpp b/src/filter_page.hpp
new file mode 100644
index 0000000..db4b008
--- /dev/null
+++ b/src/filter_page.hpp
@@ -0,0 +1,52 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_FILTER_PAGE_HPP
+#define WHISKERMENU_FILTER_PAGE_HPP
+
+#include "page.hpp"
+
+namespace WhiskerMenu
+{
+
+class FilterPage : public Page
+{
+public:
+ FilterPage(Menu* menu);
+ ~FilterPage();
+
+ GtkTreeModel* get_model() const;
+
+protected:
+ GtkTreePath* convert_child_path_to_path(GtkTreePath* path) const;
+ virtual bool on_filter(GtkTreeModel* model, GtkTreeIter* iter)=0;
+ void refilter();
+ void set_model(GtkTreeModel* model);
+ void unset_model();
+
+private:
+ static gboolean filter_visible(GtkTreeModel* model, GtkTreeIter* iter, FilterPage* page)
+ {
+ return page->on_filter(model, iter);
+ }
+
+private:
+ GtkTreeModelFilter* m_filter_model;
+};
+
+}
+
+#endif // WHISKERMENU_FILTER_PAGE_HPP
diff --git a/src/launcher.cpp b/src/launcher.cpp
new file mode 100644
index 0000000..b7adaf5
--- /dev/null
+++ b/src/launcher.cpp
@@ -0,0 +1,296 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "launcher.hpp"
+
+extern "C"
+{
+#include <exo/exo.h>
+#include <libxfce4ui/libxfce4ui.h>
+}
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+static bool f_show_name = true;
+static bool f_show_description = true;
+
+//-----------------------------------------------------------------------------
+
+static void replace_with_quoted_string(std::string& command, size_t& index, const gchar* unquoted)
+{
+ if (!exo_str_is_empty(unquoted))
+ {
+ gchar* quoted = g_shell_quote(unquoted);
+ command.replace(index, 2, quoted);
+ index += strlen(quoted);
+ g_free(quoted);
+ }
+ else
+ {
+ command.erase(index, 2);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+static void replace_with_quoted_string(std::string& command, size_t& index, const char* prefix, const gchar* unquoted)
+{
+ if (!exo_str_is_empty(unquoted))
+ {
+ command.replace(index, 2, prefix);
+ index += strlen(prefix);
+
+ gchar* quoted = g_shell_quote(unquoted);
+ command.insert(index, quoted);
+ index += strlen(quoted);
+ g_free(quoted);
+ }
+ else
+ {
+ command.erase(index, 2);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+static void replace_with_quoted_string(std::string& command, size_t& index, gchar* unquoted)
+{
+ replace_with_quoted_string(command, index, unquoted);
+ g_free(unquoted);
+}
+
+//-----------------------------------------------------------------------------
+
+Launcher::Launcher(GarconMenuItem* item) :
+ m_item(item),
+ m_icon(nullptr),
+ m_text(nullptr)
+{
+ garcon_menu_item_ref(m_item);
+
+ // Fetch icon
+ const gchar* icon = garcon_menu_item_get_icon_name(m_item);
+ if (G_LIKELY(icon))
+ {
+ if (!g_path_is_absolute(icon))
+ {
+ gchar* pos = g_strrstr(icon, ".");
+ m_icon = !pos ? g_strdup(icon) : g_strndup(icon, pos - icon);
+ }
+ else
+ {
+ m_icon = g_strdup(icon);
+ }
+ }
+
+ // Fetch text
+ const gchar* name = garcon_menu_item_get_name(m_item);
+ if (G_UNLIKELY(!name))
+ {
+ name = "";
+ }
+
+ const gchar* generic_name = garcon_menu_item_get_generic_name(m_item);
+ if (G_UNLIKELY(!generic_name))
+ {
+ generic_name = "";
+ }
+
+ // Create display text
+ const gchar* display_name = (f_show_name || exo_str_is_empty(generic_name)) ? name : generic_name;
+ if (f_show_description)
+ {
+ const gchar* details = garcon_menu_item_get_comment(m_item);
+ if (!details)
+ {
+ details = generic_name;
+ }
+ m_text = g_markup_printf_escaped("<b>%s</b>\n%s", display_name, details);
+ }
+ else
+ {
+ m_text = g_markup_printf_escaped("%s", display_name);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+Launcher::~Launcher()
+{
+ garcon_menu_item_unref(m_item);
+ g_free(m_icon);
+ g_free(m_text);
+}
+
+//-----------------------------------------------------------------------------
+
+const gchar* Launcher::get_search_text()
+{
+ if (!m_search_text.empty())
+ {
+ return m_search_text.c_str();
+ }
+
+ // Combine name, comment, and generic name into single casefolded string
+ const gchar* name = garcon_menu_item_get_name(m_item);
+ if (name)
+ {
+ gchar* normalized = g_utf8_normalize(name, -1, G_NORMALIZE_DEFAULT);
+ gchar* utf8 = g_utf8_casefold(normalized, -1);
+ m_search_text += utf8;
+ g_free(utf8);
+ g_free(normalized);
+ m_search_text += '\n';
+ }
+
+ const gchar* generic_name = garcon_menu_item_get_generic_name(m_item);
+ if (generic_name)
+ {
+ gchar* normalized = g_utf8_normalize(generic_name, -1, G_NORMALIZE_DEFAULT);
+ gchar* utf8 = g_utf8_casefold(normalized, -1);
+ m_search_text += utf8;
+ g_free(utf8);
+ g_free(normalized);
+ m_search_text += '\n';
+ }
+
+ const gchar* comment = garcon_menu_item_get_comment(m_item);
+ if (comment)
+ {
+ gchar* normalized = g_utf8_normalize(comment, -1, G_NORMALIZE_DEFAULT);
+ gchar* utf8 = g_utf8_casefold(normalized, -1);
+ m_search_text += utf8;
+ g_free(utf8);
+ g_free(normalized);
+ }
+
+ return m_search_text.c_str();
+}
+
+//-----------------------------------------------------------------------------
+
+void Launcher::run(GdkScreen* screen) const
+{
+ const gchar* string = garcon_menu_item_get_command(m_item);
+ if (exo_str_is_empty(string))
+ {
+ return;
+ }
+ std::string command(string);
+
+ if (garcon_menu_item_requires_terminal(m_item))
+ {
+ command.insert(0, "exo-open --launch TerminalEmulator ");
+ }
+
+ // Expand the field codes
+ size_t length = command.length() - 1;
+ for (size_t i = 0; i < length; ++i)
+ {
+ if (G_UNLIKELY(command[i] == '%'))
+ {
+ switch (command[i + 1])
+ {
+ case 'i':
+ replace_with_quoted_string(command, i, "--icon ", garcon_menu_item_get_icon_name(m_item));
+ length = command.length() - 1;
+ break;
+
+ case 'c':
+ replace_with_quoted_string(command, i, garcon_menu_item_get_name(m_item));
+ length = command.length() - 1;
+ break;
+
+ case 'k':
+ replace_with_quoted_string(command, i, garcon_menu_item_get_uri(m_item));
+ length = command.length() - 1;
+ break;
+
+ case '%':
+ command.erase(i, 1);
+ length = command.length() - 1;
+ break;
+
+ case 'f':
+ // unsupported, pass in a single file dropped on launcher
+ case 'F':
+ // unsupported, pass in a list of files dropped on launcher
+ case 'u':
+ // unsupported, pass in a single URL dropped on launcher
+ case 'U':
+ // unsupported, pass in a list of URLs dropped on launcher
+ default:
+ command.erase(i, 2);
+ length = command.length() - 1;
+ break;
+ }
+ }
+ }
+
+ // Parse and spawn command
+ gchar** argv;
+ gboolean result = false;
+ GError* error = nullptr;
+ if (g_shell_parse_argv(command.c_str(), nullptr, &argv, &error))
+ {
+ result = xfce_spawn_on_screen(screen,
+ garcon_menu_item_get_path(m_item),
+ argv, nullptr, G_SPAWN_SEARCH_PATH,
+ garcon_menu_item_supports_startup_notification(m_item),
+ gtk_get_current_event_time(),
+ garcon_menu_item_get_icon_name(m_item),
+ &error);
+ g_strfreev(argv);
+ }
+
+ if (G_UNLIKELY(!result))
+ {
+ xfce_dialog_show_error(nullptr, error, _("Failed to execute command \"%s\"."), string);
+ g_error_free(error);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+bool Launcher::get_show_name()
+{
+ return f_show_name;
+}
+
+//-----------------------------------------------------------------------------
+
+bool Launcher::get_show_description()
+{
+ return f_show_description;
+}
+
+//-----------------------------------------------------------------------------
+
+void Launcher::set_show_name(bool show)
+{
+ f_show_name = show;
+}
+
+//-----------------------------------------------------------------------------
+
+void Launcher::set_show_description(bool show)
+{
+ f_show_description = show;
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/launcher.hpp b/src/launcher.hpp
new file mode 100644
index 0000000..52059e1
--- /dev/null
+++ b/src/launcher.hpp
@@ -0,0 +1,75 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_LAUNCHER_HPP
+#define WHISKERMENU_LAUNCHER_HPP
+
+#include <string>
+
+extern "C"
+{
+#include <garcon/garcon.h>
+#include <gdk/gdk.h>
+}
+
+namespace WhiskerMenu
+{
+
+class Launcher
+{
+public:
+ Launcher(GarconMenuItem* item);
+ ~Launcher();
+
+ const gchar* get_icon() const
+ {
+ return m_icon;
+ }
+
+ const gchar* get_text() const
+ {
+ return m_text;
+ }
+
+ const gchar* get_search_text();
+
+ GarconMenuItem* get_item() const
+ {
+ return m_item;
+ }
+
+ void run(GdkScreen* screen) const;
+
+ static bool get_show_name();
+ static bool get_show_description();
+ static void set_show_name(bool show);
+ static void set_show_description(bool show);
+
+private:
+ Launcher(Launcher&& launcher)=delete;
+ Launcher(const Launcher& launcher)=delete;
+ Launcher& operator=(const Launcher& launcher)=delete;
+
+private:
+ GarconMenuItem* m_item;
+ gchar* m_icon;
+ gchar* m_text;
+ std::string m_search_text;
+};
+
+}
+
+#endif // WHISKERMENU_LAUNCHER_HPP
diff --git a/src/launcher_model.cpp b/src/launcher_model.cpp
new file mode 100644
index 0000000..0a9b6bf
--- /dev/null
+++ b/src/launcher_model.cpp
@@ -0,0 +1,117 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "launcher_model.hpp"
+
+#include "launcher.hpp"
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+LauncherModel::LauncherModel()
+{
+ m_model = gtk_list_store_new(
+ N_COLUMNS,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_POINTER);
+}
+
+//-----------------------------------------------------------------------------
+
+LauncherModel::LauncherModel(GtkListStore* model) :
+ m_model(model)
+{
+ if (G_LIKELY(m_model))
+ {
+ g_object_ref(m_model);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+LauncherModel::~LauncherModel()
+{
+ if (G_LIKELY(m_model))
+ {
+ g_object_unref(m_model);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void LauncherModel::insert_item(Launcher* launcher, int position)
+{
+ gtk_list_store_insert_with_values(
+ m_model, nullptr, position,
+ COLUMN_ICON, launcher->get_icon(),
+ COLUMN_TEXT, launcher->get_text(),
+ COLUMN_LAUNCHER, launcher,
+ -1);
+}
+
+//-----------------------------------------------------------------------------
+
+void LauncherModel::remove_item(Launcher* launcher)
+{
+ GtkTreeModel* model = GTK_TREE_MODEL(m_model);
+ GtkTreeIter iter;
+ Launcher* test_launcher = nullptr;
+
+ bool valid = gtk_tree_model_get_iter_first(model, &iter);
+ while (valid)
+ {
+ gtk_tree_model_get(model, &iter, COLUMN_LAUNCHER, &test_launcher, -1);
+ if (test_launcher == launcher)
+ {
+ gtk_list_store_remove(m_model, &iter);
+ break;
+ }
+ valid = gtk_tree_model_iter_next(model, &iter);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void LauncherModel::remove_first_item()
+{
+ GtkTreeIter iter;
+ if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(m_model), &iter))
+ {
+ gtk_list_store_remove(m_model, &iter);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void LauncherModel::remove_last_item()
+{
+ GtkTreeModel* model = GTK_TREE_MODEL(m_model);
+ gint size = gtk_tree_model_iter_n_children(model, nullptr);
+ if (!size)
+ {
+ return;
+ }
+
+ GtkTreeIter iter;
+ if (gtk_tree_model_iter_nth_child(model, &iter, nullptr, size - 1))
+ {
+ gtk_list_store_remove(m_model, &iter);
+ }
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/launcher_model.hpp b/src/launcher_model.hpp
new file mode 100644
index 0000000..75b525f
--- /dev/null
+++ b/src/launcher_model.hpp
@@ -0,0 +1,77 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_LAUNCHER_MODEL_HPP
+#define WHISKERMENU_LAUNCHER_MODEL_HPP
+
+extern "C"
+{
+#include <gtk/gtk.h>
+}
+
+namespace WhiskerMenu
+{
+
+class Launcher;
+
+class LauncherModel
+{
+public:
+ LauncherModel();
+ LauncherModel(GtkListStore* model);
+ ~LauncherModel();
+
+ GtkTreeModel* get_model() const
+ {
+ return GTK_TREE_MODEL(m_model);
+ }
+
+ void append_item(Launcher* launcher)
+ {
+ insert_item(launcher, INT_MAX);
+ }
+
+ void insert_item(Launcher* launcher, int position);
+
+ void prepend_item(Launcher* launcher)
+ {
+ insert_item(launcher, 0);
+ }
+
+ void remove_item(Launcher* launcher);
+ void remove_first_item();
+ void remove_last_item();
+
+ enum Columns
+ {
+ COLUMN_ICON = 0,
+ COLUMN_TEXT,
+ COLUMN_LAUNCHER,
+ N_COLUMNS
+ };
+
+private:
+ LauncherModel(const LauncherModel &model)=delete;
+ LauncherModel(LauncherModel &&model)=delete;
+ LauncherModel & operator=(const LauncherModel &model)=delete;
+
+private:
+ GtkListStore* m_model;
+};
+
+}
+
+#endif // WHISKERMENU_LAUNCHER_MODEL_HPP
diff --git a/src/launcher_view.cpp b/src/launcher_view.cpp
new file mode 100644
index 0000000..63da705
--- /dev/null
+++ b/src/launcher_view.cpp
@@ -0,0 +1,157 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "launcher_view.hpp"
+
+#include "launcher_model.hpp"
+
+#include <algorithm>
+
+extern "C"
+{
+#include <exo/exo.h>
+}
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+LauncherView::LauncherView() :
+ m_model(nullptr)
+{
+ // Create the view
+ m_view = GTK_TREE_VIEW(exo_tree_view_new());
+ gtk_tree_view_set_headers_visible(m_view, false);
+ gtk_tree_view_set_enable_tree_lines(m_view, false);
+ gtk_tree_view_set_rules_hint(m_view, false);
+ gtk_tree_view_set_hover_selection(m_view, true);
+ gtk_tree_view_set_enable_search(m_view, false);
+
+ // Add a column for the icon and text
+ GtkTreeViewColumn* column = gtk_tree_view_column_new();
+ gtk_tree_view_column_set_expand(column, true);
+ gtk_tree_view_column_set_visible(column, true);
+
+ int width = 0, height = 0;
+ gtk_icon_size_lookup(GTK_ICON_SIZE_DND, &width, &height);
+ GtkCellRenderer* icon_renderer = exo_cell_renderer_icon_new();
+ g_object_set(icon_renderer, "size", std::max(width, height), nullptr);
+ gtk_tree_view_column_pack_start(column, icon_renderer, false);
+ gtk_tree_view_column_add_attribute(column, icon_renderer, "icon", LauncherModel::COLUMN_ICON);
+
+ GtkCellRenderer* text_renderer = gtk_cell_renderer_text_new();
+ g_object_set(text_renderer, "ellipsize", PANGO_ELLIPSIZE_END, nullptr);
+ gtk_tree_view_column_pack_start(column, text_renderer, true);
+ gtk_tree_view_column_add_attribute(column, text_renderer, "markup", LauncherModel::COLUMN_TEXT);
+
+ gtk_tree_view_append_column(m_view, column);
+
+ // Use single clicks to activate items
+ exo_tree_view_set_single_click(EXO_TREE_VIEW(m_view), true);
+
+ // Only allow up to one selected item
+ GtkTreeSelection* selection = gtk_tree_view_get_selection(m_view);
+ gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
+
+ g_object_ref_sink(m_view);
+}
+
+//-----------------------------------------------------------------------------
+
+LauncherView::~LauncherView()
+{
+ m_model = nullptr;
+
+ g_object_unref(m_view);
+}
+
+//-----------------------------------------------------------------------------
+
+GtkTreePath* LauncherView::get_selected_path() const
+{
+ GtkTreePath* path = nullptr;
+ GtkTreeSelection* selection = gtk_tree_view_get_selection(m_view);
+ GtkTreeIter iter;
+ if (gtk_tree_selection_get_selected(selection, nullptr, &iter))
+ {
+ path = gtk_tree_model_get_path(m_model, &iter);
+ }
+ return path;
+}
+
+//-----------------------------------------------------------------------------
+
+void LauncherView::activate_path(GtkTreePath* path)
+{
+ GtkTreeViewColumn* column = gtk_tree_view_get_column(m_view, 0);
+ gtk_tree_view_row_activated(m_view, path, column);
+}
+
+//-----------------------------------------------------------------------------
+
+void LauncherView::scroll_to_path(GtkTreePath* path)
+{
+ gtk_tree_view_scroll_to_cell(m_view, path, nullptr, true, 0.5f, 0.5f);
+}
+
+//-----------------------------------------------------------------------------
+
+void LauncherView::select_path(GtkTreePath* path)
+{
+ GtkTreeSelection* selection = gtk_tree_view_get_selection(m_view);
+ gtk_tree_selection_select_path(selection, path);
+}
+
+//-----------------------------------------------------------------------------
+
+void LauncherView::set_reorderable(bool reorderable)
+{
+ gtk_tree_view_set_reorderable(m_view, reorderable);
+}
+
+//-----------------------------------------------------------------------------
+
+void LauncherView::set_selection_mode(GtkSelectionMode mode)
+{
+ GtkTreeSelection* selection = gtk_tree_view_get_selection(m_view);
+ gtk_tree_selection_set_mode(selection, mode);
+}
+
+//-----------------------------------------------------------------------------
+
+void LauncherView::unselect_all()
+{
+ GtkTreeSelection* selection = gtk_tree_view_get_selection(m_view);
+ gtk_tree_selection_unselect_all(selection);
+}
+
+//-----------------------------------------------------------------------------
+
+void LauncherView::set_model(GtkTreeModel* model)
+{
+ m_model = model;
+ gtk_tree_view_set_model(m_view, model);
+}
+
+//-----------------------------------------------------------------------------
+
+void LauncherView::unset_model()
+{
+ m_model = nullptr;
+ gtk_tree_view_set_model(m_view, nullptr);
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/launcher_view.hpp b/src/launcher_view.hpp
new file mode 100644
index 0000000..f2c395c
--- /dev/null
+++ b/src/launcher_view.hpp
@@ -0,0 +1,65 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_LAUNCHER_VIEW_HPP
+#define WHISKERMENU_LAUNCHER_VIEW_HPP
+
+extern "C"
+{
+#include <gtk/gtk.h>
+}
+
+namespace WhiskerMenu
+{
+
+class LauncherView
+{
+public:
+ LauncherView();
+ ~LauncherView();
+
+ GtkWidget* get_widget() const
+ {
+ return GTK_WIDGET(m_view);
+ }
+
+ GtkTreePath* get_selected_path() const;
+ void activate_path(GtkTreePath* path);
+
+ void scroll_to_path(GtkTreePath* path);
+ void select_path(GtkTreePath* path);
+
+ void set_reorderable(bool reorderable);
+ void set_selection_mode(GtkSelectionMode mode);
+
+ void unselect_all();
+
+ GtkTreeModel* get_model() const
+ {
+ return m_model;
+ }
+
+ void set_model(GtkTreeModel* model);
+ void unset_model();
+
+private:
+ GtkTreeModel* m_model;
+ GtkTreeView* m_view;
+};
+
+}
+
+#endif // WHISKERMENU_LAUNCHER_VIEW_HPP
diff --git a/src/list_page.cpp b/src/list_page.cpp
new file mode 100644
index 0000000..177d38e
--- /dev/null
+++ b/src/list_page.cpp
@@ -0,0 +1,186 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "list_page.hpp"
+
+#include "launcher.hpp"
+#include "launcher_model.hpp"
+#include "launcher_view.hpp"
+#include "slot.hpp"
+
+#include <algorithm>
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+static std::vector<std::string> read_list(XfceRc* rc, const gchar* key, std::vector<std::string> default_list)
+{
+ if (!rc || !xfce_rc_has_entry(rc, key))
+ {
+ return default_list;
+ }
+
+ std::vector<std::string> list;
+ gchar** values = xfce_rc_read_list_entry(rc, key, ",");
+ for (size_t i = 0; values[i] != nullptr; ++i)
+ {
+ list.push_back(values[i]);
+ }
+ g_strfreev(values);
+ return list;
+}
+
+//-----------------------------------------------------------------------------
+
+ListPage::ListPage(XfceRc* rc, const gchar* key, std::vector<std::string> default_desktop_ids, Menu* menu) :
+ Page(menu),
+ m_key(key),
+ m_desktop_ids(read_list(rc, key, default_desktop_ids))
+{
+}
+
+//-----------------------------------------------------------------------------
+
+ListPage::~ListPage()
+{
+ unset_menu_items();
+}
+
+//-----------------------------------------------------------------------------
+
+bool ListPage::contains(Launcher* launcher) const
+{
+ std::string desktop_id = garcon_menu_item_get_desktop_id(launcher->get_item());
+ return std::find(m_desktop_ids.cbegin(), m_desktop_ids.cend(), desktop_id) != m_desktop_ids.cend();
+}
+
+//-----------------------------------------------------------------------------
+
+void ListPage::remove(Launcher* launcher)
+{
+ LauncherModel model(GTK_LIST_STORE(get_view()->get_model()));
+ model.remove_item(launcher);
+}
+
+//-----------------------------------------------------------------------------
+
+void ListPage::save(XfceRc* settings)
+{
+ // Save list
+ std::string desktop_ids;
+ for (const auto& desktop_id : m_desktop_ids)
+ {
+ if (!desktop_ids.empty())
+ {
+ desktop_ids += ",";
+ }
+ desktop_ids += desktop_id;
+ }
+ xfce_rc_write_entry(settings, m_key, desktop_ids.c_str());
+}
+
+//-----------------------------------------------------------------------------
+
+void ListPage::set_menu_items(std::unordered_map<std::string, Launcher*> items)
+{
+ // Create new model for treeview
+ LauncherModel model;
+
+ // Fetch menu items or remove them from list if missing
+ for (auto i = m_desktop_ids.begin(); i != m_desktop_ids.end(); ++i)
+ {
+ auto item = items.find(*i);
+ if (item != items.end())
+ {
+ model.append_item(item->second);
+ }
+ else
+ {
+ i = m_desktop_ids.erase(i);
+ --i;
+ }
+ }
+
+ // Replace treeview contents
+ get_view()->set_model(model.get_model());
+ g_signal_connect_slot(get_view()->get_model(), "row-changed", &ListPage::on_row_changed, this);
+ g_signal_connect_slot(get_view()->get_model(), "row-inserted", &ListPage::on_row_inserted, this);
+ g_signal_connect_slot(get_view()->get_model(), "row-deleted", &ListPage::on_row_deleted, this);
+}
+
+//-----------------------------------------------------------------------------
+
+void ListPage::unset_menu_items()
+{
+ // Clear treeview
+ get_view()->unset_model();
+}
+
+//-----------------------------------------------------------------------------
+
+void ListPage::on_row_changed(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter)
+{
+ size_t pos = gtk_tree_path_get_indices(path)[0];
+ if (pos >= m_desktop_ids.size())
+ {
+ return;
+ }
+
+ Launcher* launcher;
+ gtk_tree_model_get(model, iter, LauncherModel::COLUMN_LAUNCHER, &launcher, -1);
+ if (launcher)
+ {
+ m_desktop_ids[pos] = garcon_menu_item_get_desktop_id(launcher->get_item());
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void ListPage::on_row_inserted(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter)
+{
+ size_t pos = gtk_tree_path_get_indices(path)[0];
+
+ std::string desktop_id;
+ Launcher* launcher;
+ gtk_tree_model_get(model, iter, LauncherModel::COLUMN_LAUNCHER, &launcher, -1);
+ if (launcher)
+ {
+ desktop_id = garcon_menu_item_get_desktop_id(launcher->get_item());
+ }
+
+ if (pos >= m_desktop_ids.size())
+ {
+ m_desktop_ids.emplace_back(std::move(desktop_id));
+ }
+ else if (m_desktop_ids.at(pos) != desktop_id)
+ {
+ m_desktop_ids.emplace(m_desktop_ids.begin() + pos, std::move(desktop_id));
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void ListPage::on_row_deleted(GtkTreeModel*, GtkTreePath* path)
+{
+ size_t pos = gtk_tree_path_get_indices(path)[0];
+ if (pos < m_desktop_ids.size())
+ {
+ m_desktop_ids.erase(m_desktop_ids.begin() + pos);
+ }
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/list_page.hpp b/src/list_page.hpp
new file mode 100644
index 0000000..7ff4544
--- /dev/null
+++ b/src/list_page.hpp
@@ -0,0 +1,67 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_LIST_PAGE_HPP
+#define WHISKERMENU_LIST_PAGE_HPP
+
+#include "page.hpp"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+extern "C"
+{
+#include <libxfce4util/libxfce4util.h>
+}
+
+namespace WhiskerMenu
+{
+
+class Launcher;
+class LauncherView;
+
+class ListPage : public Page
+{
+public:
+ ListPage(XfceRc* settings, const gchar* key, std::vector<std::string> default_desktop_ids, Menu* menu);
+ ~ListPage();
+
+ bool contains(Launcher* launcher) const;
+ size_t size() const
+ {
+ return m_desktop_ids.size();
+ }
+
+ virtual void add(Launcher* launcher)=0;
+ void remove(Launcher* launcher);
+ void save(XfceRc* settings);
+ void set_menu_items(std::unordered_map<std::string, Launcher*> items);
+ void unset_menu_items();
+
+private:
+ void on_row_changed(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter);
+ void on_row_inserted(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter);
+ void on_row_deleted(GtkTreeModel* model, GtkTreePath* path);
+
+private:
+ const gchar* m_key;
+ std::vector<std::string> m_desktop_ids;
+};
+
+}
+
+#endif // WHISKERMENU_LIST_PAGE_HPP
diff --git a/src/menu.cpp b/src/menu.cpp
new file mode 100644
index 0000000..722ac2e
--- /dev/null
+++ b/src/menu.cpp
@@ -0,0 +1,669 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "menu.hpp"
+
+#include "applications_page.hpp"
+#include "favorites_page.hpp"
+#include "launcher_model.hpp"
+#include "launcher_view.hpp"
+#include "recent_page.hpp"
+#include "resizer_widget.hpp"
+#include "search_page.hpp"
+#include "section_button.hpp"
+#include "slot.hpp"
+
+extern "C"
+{
+#include <exo/exo.h>
+#include <gdk/gdkkeysyms.h>
+#include <libxfce4ui/libxfce4ui.h>
+}
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+static GtkButton* new_action_button(const gchar* icon, const gchar* text)
+{
+ GtkButton* button = GTK_BUTTON(gtk_button_new());
+ gtk_button_set_relief(button, GTK_RELIEF_NONE);
+ gtk_widget_set_tooltip_text(GTK_WIDGET(button), text);
+
+ GtkWidget* image = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_LARGE_TOOLBAR);
+ gtk_container_add(GTK_CONTAINER(button), GTK_WIDGET(image));
+
+ return button;
+}
+
+//-----------------------------------------------------------------------------
+
+Menu::Menu(XfceRc* settings) :
+ m_window(nullptr),
+ m_geometry{0,0,400,500},
+ m_layout_left(true),
+ m_layout_bottom(true)
+{
+ // Create the window
+ m_window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
+ gtk_window_set_modal(m_window, true);
+ gtk_window_set_decorated(m_window, false);
+ gtk_window_set_skip_taskbar_hint(m_window, true);
+ gtk_window_set_skip_pager_hint(m_window, true);
+ gtk_window_stick(m_window);
+ gtk_widget_add_events(GTK_WIDGET(m_window), GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK | GDK_STRUCTURE_MASK);
+ g_signal_connect_slot(m_window, "enter-notify-event", &Menu::on_enter_notify_event, this);
+ g_signal_connect_slot(m_window, "leave-notify-event", &Menu::on_leave_notify_event, this);
+ g_signal_connect_slot(m_window, "button-press-event", &Menu::on_button_press_event, this);
+ g_signal_connect_slot(m_window, "key-press-event", &Menu::on_key_press_event, this);
+ g_signal_connect_slot(m_window, "map-event", &Menu::on_map_event, this);
+ g_signal_connect_slot(m_window, "configure-event", &Menu::on_configure_event, this);
+
+ // Create the border of the window
+ GtkWidget* frame = gtk_frame_new(nullptr);
+ gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);
+ gtk_container_add(GTK_CONTAINER(m_window), frame);
+
+ // Create the username label
+ gchar* username = g_markup_printf_escaped("<b><big>%s</big></b>", g_get_real_name());
+ m_username = GTK_LABEL(gtk_label_new(nullptr));
+ gtk_label_set_markup(m_username, username);
+ gtk_misc_set_alignment(GTK_MISC(m_username), 0.0f, 0.5f);
+ g_free(username);
+
+ // Create action buttons
+ m_settings_button = new_action_button("preferences-desktop", _("All Settings"));
+ g_signal_connect_slot(m_settings_button, "clicked", &Menu::launch_settings_manager, this);
+
+ m_lock_screen_button = new_action_button("system-lock-screen", _("Lock Screen"));
+ g_signal_connect_slot(m_lock_screen_button, "clicked", &Menu::lock_screen, this);
+
+ m_log_out_button = new_action_button("system-log-out", _("Log Out"));
+ g_signal_connect_slot(m_log_out_button, "clicked", &Menu::log_out, this);
+
+ m_resizer = new ResizerWidget(m_window);
+
+ // Create search entry
+ m_search_entry = GTK_ENTRY(gtk_entry_new());
+ gtk_entry_set_icon_from_stock(m_search_entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_FIND);
+ gtk_entry_set_icon_activatable(m_search_entry, GTK_ENTRY_ICON_SECONDARY, false);
+ g_signal_connect_slot(m_search_entry, "changed", &Menu::search, this);
+
+ // Create favorites
+ m_favorites = new FavoritesPage(settings, this);
+
+ m_favorites_button = new_section_button("user-bookmarks", _("Favorites"));
+ g_signal_connect_slot(m_favorites_button, "toggled", &Menu::favorites_toggled, this);
+
+ // Create recent
+ m_recent = new RecentPage(settings, this);
+
+ m_recent_button = new_section_button("document-open-recent", _("Recently Used"));
+ gtk_radio_button_set_group(m_recent_button, gtk_radio_button_get_group(m_favorites_button));
+ g_signal_connect_slot(m_recent_button, "toggled", &Menu::recent_toggled, this);
+
+ // Create applications
+ m_applications = new ApplicationsPage(this);
+
+ // Create search results
+ m_search_results = new SearchPage(this);
+
+ // Create box for packing children
+ m_vbox = GTK_BOX(gtk_vbox_new(false, 6));
+ gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(m_vbox));
+ gtk_container_set_border_width(GTK_CONTAINER(m_vbox), 2);
+
+ // Create box for packing username and action buttons
+ m_title_box = GTK_BOX(gtk_hbox_new(false, 0));
+ gtk_box_pack_start(m_vbox, GTK_WIDGET(m_title_box), false, false, 0);
+ gtk_box_pack_start(m_title_box, GTK_WIDGET(m_username), true, true, 0);
+ gtk_box_pack_start(m_title_box, GTK_WIDGET(m_settings_button), false, false, 0);
+ gtk_box_pack_start(m_title_box, GTK_WIDGET(m_lock_screen_button), false, false, 0);
+ gtk_box_pack_start(m_title_box, GTK_WIDGET(m_log_out_button), false, false, 0);
+ gtk_box_pack_start(m_title_box, GTK_WIDGET(m_resizer->get_widget()), false, false, 0);
+
+ // Add search to layout
+ gtk_box_pack_start(m_vbox, GTK_WIDGET(m_search_entry), false, true, 0);
+
+ // Create box for packing launcher pages and sidebar
+ m_contents_box = GTK_BOX(gtk_hbox_new(false, 6));
+ gtk_box_pack_start(m_vbox, GTK_WIDGET(m_contents_box), true, true, 0);
+ gtk_box_pack_start(m_contents_box, m_search_results->get_widget(), true, true, 0);
+
+ // Create box for packing launcher pages
+ m_panels_box = GTK_BOX(gtk_vbox_new(false, 0));
+ gtk_box_pack_start(m_contents_box, GTK_WIDGET(m_panels_box), true, true, 0);
+ gtk_box_pack_start(m_panels_box, m_favorites->get_widget(), true, true, 0);
+ gtk_box_pack_start(m_panels_box, m_recent->get_widget(), true, true, 0);
+ gtk_box_pack_start(m_panels_box, m_applications->get_widget(), true, true, 0);
+
+ // Create box for packing sidebar
+ m_sidebar_box = GTK_BOX(gtk_vbox_new(false, 0));
+ gtk_box_pack_start(m_contents_box, GTK_WIDGET(m_sidebar_box), false, false, 0);
+ gtk_box_pack_start(m_sidebar_box, GTK_WIDGET(m_favorites_button), false, false, 0);
+ gtk_box_pack_start(m_sidebar_box, GTK_WIDGET(m_recent_button), false, false, 0);
+ gtk_box_pack_start(m_sidebar_box, gtk_hseparator_new(), false, true, 0);
+
+ // Populate app menu
+ m_applications->reload_applications();
+
+ // Show widgets
+ gtk_widget_show_all(GTK_WIDGET(m_vbox));
+ gtk_widget_hide(m_recent->get_widget());
+ gtk_widget_hide(m_applications->get_widget());
+ gtk_widget_hide(m_search_results->get_widget());
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_favorites_button), true);
+ gtk_widget_show(frame);
+
+ // Resize to last known size
+ if (settings)
+ {
+ m_geometry.width = std::max(300, xfce_rc_read_int_entry(settings, "menu-width", m_geometry.width));
+ m_geometry.height = std::max(400, xfce_rc_read_int_entry(settings, "menu-height", m_geometry.height));
+ }
+ gtk_window_set_default_size(m_window, m_geometry.width, m_geometry.height);
+
+ g_object_ref_sink(m_window);
+}
+
+//-----------------------------------------------------------------------------
+
+Menu::~Menu()
+{
+ delete m_applications;
+ delete m_search_results;
+ delete m_recent;
+ delete m_favorites;
+
+ delete m_resizer;
+ g_object_unref(m_window);
+}
+
+//-----------------------------------------------------------------------------
+
+void Menu::hide()
+{
+ gdk_pointer_ungrab(gtk_get_current_event_time());
+
+ // Hide window
+ gtk_widget_hide(GTK_WIDGET(m_window));
+
+ // Reset mouse cursor by forcing favorites to hide
+ gtk_widget_hide(m_favorites->get_widget());
+
+ // Switch back to favorites
+ show_favorites();
+}
+
+//-----------------------------------------------------------------------------
+
+void Menu::show(GtkWidget* parent, bool horizontal)
+{
+ // Reset mouse cursor by forcing favorites to hide
+ gtk_widget_show(m_favorites->get_widget());
+
+ // Fetch parent geometry
+ GdkWindow* window = gtk_widget_get_window(parent);
+ int parent_x = 0, parent_y = 0;
+ gdk_window_get_origin(window, &parent_x, &parent_y);
+ int parent_w = gdk_window_get_width(window);
+ int parent_h = gdk_window_get_height(window);
+
+ // Fetch screen geomtry
+ GdkScreen* screen = gtk_widget_get_screen(GTK_WIDGET(m_window));
+ int root_w = gdk_screen_get_width(GDK_SCREEN(screen));
+ int root_h = gdk_screen_get_height(GDK_SCREEN(screen));
+
+ // Find window position
+ bool layout_left = ((2 * parent_x) + parent_w) < root_w;
+ if (horizontal)
+ {
+ m_geometry.x = layout_left ? parent_x : (parent_x + parent_w - m_geometry.width);
+ }
+ else
+ {
+ m_geometry.x = layout_left ? (parent_x + parent_w) : (parent_x - m_geometry.width);
+ }
+
+ bool layout_bottom = ((2 * parent_y) + parent_h) > root_h;
+ if (horizontal)
+ {
+ m_geometry.y = layout_bottom ? (parent_y - m_geometry.height) : (parent_y + parent_h);
+ }
+ else
+ {
+ m_geometry.y = layout_bottom ? (parent_y + parent_h - m_geometry.height) : parent_y;
+ }
+
+ // Prevent window from leaving screen
+ GdkRectangle monitor;
+ int monitor_num = gdk_screen_get_monitor_at_window(screen, window);
+ gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor);
+
+ int monitor_r = monitor.x + monitor.width;
+ if (m_geometry.x < monitor.x)
+ {
+ m_geometry.width += m_geometry.x - monitor.x;
+ m_geometry.x = monitor.x;
+ gtk_window_resize(GTK_WINDOW(m_window), m_geometry.width, m_geometry.height);
+ }
+ else if ((m_geometry.x + m_geometry.width) > monitor_r)
+ {
+ m_geometry.width = monitor_r - m_geometry.x;
+ gtk_window_resize(GTK_WINDOW(m_window), m_geometry.width, m_geometry.height);
+ }
+
+ int monitor_b = monitor.y + monitor.height;
+ if (m_geometry.y < monitor.y)
+ {
+ m_geometry.height += m_geometry.y - monitor.y;
+ m_geometry.y = monitor.y;
+ gtk_window_resize(GTK_WINDOW(m_window), m_geometry.width, m_geometry.height);
+ }
+ else if ((m_geometry.y + m_geometry.height) > monitor_b)
+ {
+ m_geometry.height = monitor_b - m_geometry.y;
+ gtk_window_resize(GTK_WINDOW(m_window), m_geometry.width, m_geometry.height);
+ }
+
+ // Move window
+ gtk_window_move(m_window, m_geometry.x, m_geometry.y);
+
+ // Set corner for resizer
+ if (layout_left)
+ {
+ if (layout_bottom)
+ {
+ m_resizer->set_corner(ResizerWidget::TopRight);
+ }
+ else
+ {
+ m_resizer->set_corner(ResizerWidget::BottomRight);
+ }
+ }
+ else
+ {
+ if (layout_bottom)
+ {
+ m_resizer->set_corner(ResizerWidget::TopLeft);
+ }
+ else
+ {
+ m_resizer->set_corner(ResizerWidget::BottomLeft);
+ }
+ }
+
+ // Relayout window if necessary
+ if (gtk_widget_get_direction(GTK_WIDGET(m_window)) == GTK_TEXT_DIR_RTL)
+ {
+ layout_left = !layout_left;
+ }
+ if (layout_left != m_layout_left)
+ {
+ m_layout_left = layout_left;
+ if (m_layout_left)
+ {
+ gtk_misc_set_alignment(GTK_MISC(m_username), 0.0f, 0.5f);
+
+ gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_username), 0);
+ gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_settings_button), 1);
+ gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_lock_screen_button), 2);
+ gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_log_out_button), 3);
+ gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_resizer->get_widget()), 4);
+
+ gtk_box_reorder_child(m_contents_box, GTK_WIDGET(m_panels_box), 1);
+ gtk_box_reorder_child(m_contents_box, GTK_WIDGET(m_sidebar_box), 2);
+ }
+ else
+ {
+ gtk_misc_set_alignment(GTK_MISC(m_username), 1.0f, 0.5f);
+
+ gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_username), 4);
+ gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_settings_button), 3);
+ gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_lock_screen_button), 2);
+ gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_log_out_button), 1);
+ gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_resizer->get_widget()), 0);
+
+ gtk_box_reorder_child(m_contents_box, GTK_WIDGET(m_panels_box), 2);
+ gtk_box_reorder_child(m_contents_box, GTK_WIDGET(m_sidebar_box), 1);
+ }
+ }
+
+ if (layout_bottom != m_layout_bottom)
+ {
+ m_layout_bottom = layout_bottom;
+ if (m_layout_bottom)
+ {
+ gtk_box_reorder_child(m_vbox, GTK_WIDGET(m_title_box), 0);
+ gtk_box_reorder_child(m_vbox, GTK_WIDGET(m_search_entry), 1);
+ gtk_box_reorder_child(m_vbox, GTK_WIDGET(m_contents_box), 2);
+ }
+ else
+ {
+ gtk_box_reorder_child(m_vbox, GTK_WIDGET(m_title_box), 2);
+ gtk_box_reorder_child(m_vbox, GTK_WIDGET(m_search_entry), 1);
+ gtk_box_reorder_child(m_vbox, GTK_WIDGET(m_contents_box), 0);
+ }
+ }
+
+ // Show window
+ gtk_widget_show(GTK_WIDGET(m_window));
+ gtk_window_move(m_window, m_geometry.x, m_geometry.y);
+}
+
+//-----------------------------------------------------------------------------
+
+void Menu::save(XfceRc* settings)
+{
+ if (settings)
+ {
+ m_favorites->save(settings);
+ m_recent->save(settings);
+ xfce_rc_write_int_entry(settings, "menu-width", m_geometry.width);
+ xfce_rc_write_int_entry(settings, "menu-height", m_geometry.height);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void Menu::set_categories(std::vector<GtkRadioButton*> categories)
+{
+ for (const auto& i : categories)
+ {
+ gtk_radio_button_set_group(i, gtk_radio_button_get_group(m_recent_button));
+ gtk_box_pack_start(m_sidebar_box, GTK_WIDGET(i), false, false, 0);
+ g_signal_connect_slot(i, "toggled", &Menu::category_toggled, this);
+ }
+ gtk_widget_show_all(GTK_WIDGET(m_sidebar_box));
+
+ show_favorites();
+}
+
+//-----------------------------------------------------------------------------
+
+void Menu::set_items(std::unordered_map<std::string, Launcher*> items)
+{
+ m_search_results->set_menu_items(m_applications->get_model());
+ m_favorites->set_menu_items(items);
+ m_recent->set_menu_items(items);
+
+ // Handle switching to favorites are added
+ GtkTreeModel* favorites_model = m_favorites->get_view()->get_model();
+ g_signal_connect_slot(favorites_model, "row-inserted", &Menu::show_favorites, this);
+}
+
+//-----------------------------------------------------------------------------
+
+void Menu::unset_items()
+{
+ m_search_results->unset_menu_items();
+ m_favorites->unset_menu_items();
+ m_recent->unset_menu_items();
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean Menu::on_enter_notify_event(GtkWidget*, GdkEventCrossing* event)
+{
+ // Don't grab cursor over menu
+ if ((event->x_root >= m_geometry.x) && (event->x_root < (m_geometry.x + m_geometry.width))
+ && (event->y_root >= m_geometry.y) && (event->y_root < (m_geometry.y + m_geometry.height)))
+ {
+ if (gdk_pointer_is_grabbed())
+ {
+ gdk_pointer_ungrab(gtk_get_current_event_time());
+ }
+ }
+
+ return false;
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean Menu::on_leave_notify_event(GtkWidget*, GdkEventCrossing* event)
+{
+ if (gdk_pointer_is_grabbed())
+ {
+ return false;
+ }
+
+ // Track mouse clicks outside of menu
+ if ((event->x_root <= m_geometry.x) || (event->x_root >= m_geometry.x + m_geometry.width)
+ || (event->y_root <= m_geometry.y) || (event->y_root >= m_geometry.y + m_geometry.height))
+ {
+ gdk_pointer_grab(gtk_widget_get_window(GTK_WIDGET(m_window)), true,
+ GdkEventMask(
+ GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
+ GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
+ GDK_POINTER_MOTION_MASK
+ ),
+ nullptr, nullptr, event->time);
+ }
+
+ return false;
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean Menu::on_button_press_event(GtkWidget*, GdkEventButton* event)
+{
+ // Hide menu if user clicks outside
+ if ((event->x < 0) || (event->x > m_geometry.width) || (event->y < 0) || (event->y > m_geometry.height))
+ {
+ hide();
+ }
+ return false;
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean Menu::on_key_press_event(GtkWidget* widget, GdkEventKey* event)
+{
+ // Hide if escape is pressed and there is no text in search entry
+ if ( (event->keyval == GDK_Escape) && exo_str_is_empty(gtk_entry_get_text(m_search_entry)) )
+ {
+ hide();
+ return true;
+ }
+
+ // Make up and down keys always scroll current list of applications
+ if ((event->keyval == GDK_KEY_Up) || (event->keyval == GDK_KEY_Down))
+ {
+ GtkWidget* widget = nullptr;
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_favorites_button)))
+ {
+ widget = m_favorites->get_view()->get_widget();
+ }
+ else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_recent_button)))
+ {
+ widget = m_recent->get_view()->get_widget();
+ }
+ else
+ {
+ widget = m_applications->get_view()->get_widget();
+ }
+ gtk_widget_grab_focus(widget);
+ return false;
+ }
+
+ // Pass other key presses to search entry
+ GtkWidget* search_entry = GTK_WIDGET(m_search_entry);
+ if (!gtk_widget_has_focus(search_entry) && (search_entry != widget)
+ && (event->keyval != GDK_Shift_L) && (event->keyval != GDK_Shift_R)
+ && (event->keyval != GDK_Control_L) && (event->keyval != GDK_Control_R)
+ && !(event->state & GDK_SHIFT_MASK) && !(event->state & GDK_CONTROL_MASK)
+ && (event->keyval != GDK_Tab) && (event->keyval != GDK_Return)
+ && (event->keyval != GDK_KEY_Menu))
+ {
+ gtk_widget_grab_focus(search_entry);
+ }
+ return false;
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean Menu::on_map_event(GtkWidget*, GdkEventAny*)
+{
+ gtk_window_set_keep_above(m_window, true);
+
+ // Track mouse clicks outside of menu
+ gdk_pointer_grab(gtk_widget_get_window(GTK_WIDGET(m_window)), true,
+ GdkEventMask(
+ GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
+ GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
+ GDK_POINTER_MOTION_MASK
+ ),
+ nullptr, nullptr, gtk_get_current_event_time());
+
+ // Focus search entry
+ gtk_widget_grab_focus(GTK_WIDGET(m_search_entry));
+
+ return false;
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean Menu::on_configure_event(GtkWidget*, GdkEventConfigure* event)
+{
+ if (event->width && event->height)
+ {
+ m_geometry.width = event->width;
+ m_geometry.height = event->height;
+ }
+ return false;
+}
+
+//-----------------------------------------------------------------------------
+
+void Menu::favorites_toggled()
+{
+ gtk_widget_hide(m_recent->get_widget());
+ gtk_widget_hide(m_applications->get_widget());
+ gtk_widget_show_all(m_favorites->get_widget());
+}
+
+//-----------------------------------------------------------------------------
+
+void Menu::recent_toggled()
+{
+ gtk_widget_hide(m_favorites->get_widget());
+ gtk_widget_hide(m_applications->get_widget());
+ gtk_widget_show_all(m_recent->get_widget());
+}
+
+//-----------------------------------------------------------------------------
+
+void Menu::category_toggled()
+{
+ gtk_widget_hide(m_favorites->get_widget());
+ gtk_widget_hide(m_recent->get_widget());
+ gtk_widget_show_all(m_applications->get_widget());
+}
+
+//-----------------------------------------------------------------------------
+
+void Menu::show_favorites()
+{
+ // Switch to favorites panel
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_favorites_button), true);
+
+ // Clear search entry
+ gtk_entry_set_text(m_search_entry, "");
+ gtk_widget_grab_focus(GTK_WIDGET(m_search_entry));
+}
+
+//-----------------------------------------------------------------------------
+
+void Menu::search()
+{
+ // Fetch search string
+ gchar* filter_string = nullptr;
+ const gchar* text = gtk_entry_get_text(m_search_entry);
+ if (!exo_str_is_empty(text))
+ {
+ gchar* normalized = g_utf8_normalize(text, -1, G_NORMALIZE_DEFAULT);
+ filter_string = g_utf8_casefold(normalized, -1);
+ g_free(normalized);
+ }
+
+ // Update search entry icon
+ bool visible = filter_string != nullptr;
+ gtk_entry_set_icon_from_stock(m_search_entry, GTK_ENTRY_ICON_SECONDARY, !visible ? GTK_STOCK_FIND : GTK_STOCK_CLEAR);
+ gtk_entry_set_icon_activatable(m_search_entry, GTK_ENTRY_ICON_SECONDARY, visible);
+
+ if (visible)
+ {
+ // Show search results
+ gtk_widget_hide(GTK_WIDGET(m_sidebar_box));
+ gtk_widget_hide(GTK_WIDGET(m_panels_box));
+ gtk_widget_show(m_search_results->get_widget());
+ }
+ else
+ {
+ // Show active panel
+ gtk_widget_hide(m_search_results->get_widget());
+ gtk_widget_show(GTK_WIDGET(m_panels_box));
+ gtk_widget_show(GTK_WIDGET(m_sidebar_box));
+ }
+
+ // Apply filter
+ m_search_results->set_filter((visible && (g_utf8_strlen(filter_string, -1) > 2)) ? filter_string : nullptr);
+ g_free(filter_string);
+}
+
+//-----------------------------------------------------------------------------
+
+void Menu::launch_settings_manager()
+{
+ hide();
+
+ GError* error = nullptr;
+ if (g_spawn_command_line_async("xfce4-settings-manager", &error) == false)
+ {
+ xfce_dialog_show_error(nullptr, error, _("Failed to open settings manager."));
+ g_error_free(error);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void Menu::lock_screen()
+{
+ hide();
+
+ GError* error = nullptr;
+ if (g_spawn_command_line_async("xflock4", &error) == false)
+ {
+ xfce_dialog_show_error(nullptr, error, _("Failed to lock screen."));
+ g_error_free(error);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void Menu::log_out()
+{
+ hide();
+
+ GError* error = nullptr;
+ if (g_spawn_command_line_async("xfce4-session-logout", &error) == false)
+ {
+ xfce_dialog_show_error(nullptr, error, _("Failed to log out."));
+ g_error_free(error);
+ }
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/menu.hpp b/src/menu.hpp
new file mode 100644
index 0000000..5a13f8b
--- /dev/null
+++ b/src/menu.hpp
@@ -0,0 +1,126 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_MENU_HPP
+#define WHISKERMENU_MENU_HPP
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+extern "C"
+{
+#include <gtk/gtk.h>
+#include <libxfce4util/libxfce4util.h>
+}
+
+namespace WhiskerMenu
+{
+
+class ApplicationsPage;
+class FavoritesPage;
+class Launcher;
+class ResizerWidget;
+class RecentPage;
+class SearchPage;
+
+class Menu
+{
+public:
+ Menu(XfceRc* settings);
+ ~Menu();
+
+ GtkWidget* get_widget() const
+ {
+ return GTK_WIDGET(m_window);
+ }
+
+ GtkEntry* get_search_entry() const
+ {
+ return m_search_entry;
+ }
+
+ ApplicationsPage* get_applications() const
+ {
+ return m_applications;
+ }
+
+ FavoritesPage* get_favorites() const
+ {
+ return m_favorites;
+ }
+
+ RecentPage* get_recent() const
+ {
+ return m_recent;
+ }
+
+ void hide();
+ void show(GtkWidget* parent, bool horizontal);
+ void save(XfceRc* settings);
+ void set_categories(std::vector<GtkRadioButton*> categories);
+ void set_items(std::unordered_map<std::string, Launcher*> items);
+ void unset_items();
+
+private:
+ gboolean on_enter_notify_event(GtkWidget*, GdkEventCrossing* event);
+ gboolean on_leave_notify_event(GtkWidget*, GdkEventCrossing* event);
+ gboolean on_button_press_event(GtkWidget*, GdkEventButton* event);
+ gboolean on_key_press_event(GtkWidget* widget, GdkEventKey* event);
+ gboolean on_map_event(GtkWidget* widget, GdkEventAny* event);
+ gboolean on_configure_event(GtkWidget* widget, GdkEventConfigure* event);
+ void favorites_toggled();
+ void recent_toggled();
+ void category_toggled();
+ void show_favorites();
+ void search();
+ void launch_settings_manager();
+ void lock_screen();
+ void log_out();
+
+private:
+ GtkWindow* m_window;
+
+ GtkBox* m_vbox;
+ GtkBox* m_title_box;
+ GtkBox* m_contents_box;
+ GtkBox* m_panels_box;
+ GtkBox* m_sidebar_box;
+
+ GtkLabel* m_username;
+ GtkButton* m_settings_button;
+ GtkButton* m_lock_screen_button;
+ GtkButton* m_log_out_button;
+ ResizerWidget* m_resizer;
+
+ GtkEntry* m_search_entry;
+
+ SearchPage* m_search_results;
+ FavoritesPage* m_favorites;
+ RecentPage* m_recent;
+ ApplicationsPage* m_applications;
+
+ GtkRadioButton* m_favorites_button;
+ GtkRadioButton* m_recent_button;
+
+ GdkRectangle m_geometry;
+ bool m_layout_left;
+ bool m_layout_bottom;
+};
+
+}
+
+#endif // WHISKERMENU_MENU_HPP
diff --git a/src/page.cpp b/src/page.cpp
new file mode 100644
index 0000000..2d76ab0
--- /dev/null
+++ b/src/page.cpp
@@ -0,0 +1,333 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "page.hpp"
+
+#include "favorites_page.hpp"
+#include "launcher.hpp"
+#include "launcher_model.hpp"
+#include "launcher_view.hpp"
+#include "menu.hpp"
+#include "recent_page.hpp"
+#include "slot.hpp"
+
+extern "C"
+{
+#include <libxfce4ui/libxfce4ui.h>
+}
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+Page::Page(Menu* menu) :
+ m_menu(menu),
+ m_selected_path(nullptr)
+{
+ // Create view
+ m_view = new LauncherView;
+ g_signal_connect_slot(m_view->get_widget(), "button-press-event", &Page::view_button_press_event, this);
+ g_signal_connect_slot(m_view->get_widget(), "popup-menu", &Page::view_popup_menu_event, this);
+ g_signal_connect_slot(m_view->get_widget(), "row-activated", &Page::launcher_activated, this);
+ g_signal_connect_swapped(m_view->get_widget(), "start-interactive-search", G_CALLBACK(gtk_widget_grab_focus), m_menu->get_search_entry());
+
+ // Add scrolling to view
+ m_widget = gtk_scrolled_window_new(nullptr, nullptr);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_widget), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(m_widget), GTK_SHADOW_ETCHED_IN);
+ gtk_container_add(GTK_CONTAINER(m_widget), m_view->get_widget());
+ g_signal_connect_slot(m_widget, "unmap", &Page::on_unmap, this);
+ g_object_ref_sink(m_widget);
+}
+
+//-----------------------------------------------------------------------------
+
+Page::~Page()
+{
+ if (m_selected_path)
+ {
+ gtk_tree_path_free(m_selected_path);
+ }
+
+ delete m_view;
+ g_object_unref(m_widget);
+}
+
+//-----------------------------------------------------------------------------
+
+Launcher* Page::get_selected_launcher() const
+{
+ Launcher* launcher = nullptr;
+ if (m_selected_path)
+ {
+ GtkTreeModel* model = m_view->get_model();
+ GtkTreeIter iter;
+ gtk_tree_model_get_iter(model, &iter, m_selected_path);
+ gtk_tree_model_get(model, &iter, LauncherModel::COLUMN_LAUNCHER, &launcher, -1);
+ }
+ return launcher;
+}
+
+//-----------------------------------------------------------------------------
+
+void Page::launcher_activated(GtkTreeView* view, GtkTreePath* path, GtkTreeViewColumn*)
+{
+ GtkTreeIter iter;
+ GtkTreeModel* model = gtk_tree_view_get_model(view);
+ gtk_tree_model_get_iter(model, &iter, path);
+
+ // Find launcher
+ Launcher* launcher = nullptr;
+ gtk_tree_model_get(model, &iter, LauncherModel::COLUMN_LAUNCHER, &launcher, -1);
+
+ // Add to recent
+ m_menu->get_recent()->add(launcher);
+
+ // Hide window
+ m_menu->hide();
+
+ // Execute app
+ launcher->run(gtk_widget_get_screen(GTK_WIDGET(view)));
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean Page::view_button_press_event(GtkWidget* view, GdkEventButton* event)
+{
+ GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
+ GtkTreeIter iter;
+ if (gtk_tree_selection_get_selected(selection, nullptr, &iter)
+ && (event->type == GDK_BUTTON_PRESS)
+ && (event->button == 3))
+ {
+ create_context_menu(&iter, event);
+ return true;
+ }
+
+ return false;
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean Page::view_popup_menu_event(GtkWidget* view)
+{
+ GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
+ GtkTreeIter iter;
+ if (gtk_tree_selection_get_selected(selection, nullptr, &iter))
+ {
+ create_context_menu(&iter, nullptr);
+ return true;
+ }
+
+ return false;
+}
+
+//-----------------------------------------------------------------------------
+
+void Page::on_unmap()
+{
+ // Clear selection and scroll to top
+ GtkTreeModel* model = m_view->get_model();
+ GtkTreeIter iter;
+ if (gtk_tree_model_get_iter_first(model, &iter))
+ {
+ GtkTreePath* path = gtk_tree_model_get_path(model, &iter);
+ get_view()->scroll_to_path(path);
+ get_view()->unselect_all();
+ gtk_tree_path_free(path);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void Page::create_context_menu(GtkTreeIter* iter, GdkEventButton* event)
+{
+ gtk_tree_view_set_hover_selection(GTK_TREE_VIEW(m_view->get_widget()), false);
+ m_selected_path = gtk_tree_model_get_path(m_view->get_model(), iter);
+
+ // Create context menu
+ GtkWidget* menu = gtk_menu_new();
+ g_signal_connect_slot(menu, "selection-done", &Page::destroy_context_menu, this);
+
+ // Add menu items
+ GtkWidget* menuitem = nullptr;
+
+ if (!m_menu->get_favorites()->contains(get_selected_launcher()))
+ {
+ menuitem = gtk_menu_item_new_with_label(_("Add to Favorites"));
+ g_signal_connect_slot(menuitem, "activate", &Page::add_selected_to_favorites, this);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+ }
+ else
+ {
+ menuitem = gtk_menu_item_new_with_label(_("Remove From Favorites"));
+ g_signal_connect_slot(menuitem, "activate", &Page::remove_selected_from_favorites, this);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+ }
+
+ menuitem = gtk_menu_item_new_with_label(_("Add to Desktop"));
+ g_signal_connect_slot(menuitem, "activate", &Page::add_selected_to_desktop, this);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+
+ menuitem = gtk_menu_item_new_with_label(_("Add to Panel"));
+ g_signal_connect_slot(menuitem, "activate", &Page::add_selected_to_panel, this);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+
+ gtk_widget_show_all(menu);
+
+ // Show context menu
+ int button = 0;
+ int event_time;
+ GtkMenuPositionFunc position_func = nullptr;
+ if (event)
+ {
+ button = event->button;
+ event_time = event->time;
+ }
+ else
+ {
+ position_func = (GtkMenuPositionFunc)&Page::position_context_menu;
+ event_time = gtk_get_current_event_time ();
+ }
+
+ gtk_menu_attach_to_widget(GTK_MENU(menu), m_view->get_widget(), nullptr);
+ gtk_menu_popup(GTK_MENU(menu), nullptr, nullptr, position_func, this, button, event_time);
+}
+
+//-----------------------------------------------------------------------------
+
+void Page::destroy_context_menu(GtkMenuShell* menu)
+{
+ if (m_selected_path)
+ {
+ gtk_tree_path_free(m_selected_path);
+ m_selected_path = nullptr;
+ }
+ gtk_tree_view_set_hover_selection(GTK_TREE_VIEW(m_view->get_widget()), true);
+
+ gtk_widget_destroy(GTK_WIDGET(menu));
+}
+
+//-----------------------------------------------------------------------------
+
+void Page::position_context_menu(GtkMenu*, gint* x, gint* y, gboolean* push_in, Page* page)
+{
+ // Find rectangle of selected row
+ GtkTreeView* treeview = GTK_TREE_VIEW(page->m_view->get_widget());
+ GdkRectangle rect;
+ GtkTreeViewColumn* column = gtk_tree_view_get_column(treeview, 0);
+ gtk_tree_view_get_cell_area(treeview, page->m_selected_path, column, &rect);
+
+ int root_x;
+ int root_y;
+ gdk_window_get_root_coords(gtk_tree_view_get_bin_window(treeview), rect.x, rect.y, &root_x, &root_y);
+
+ // Position context menu centered on row
+ *push_in = false;
+ *x = root_x + (rect.width >> 2);
+ *y = root_y + (rect.height >> 1);
+}
+
+//-----------------------------------------------------------------------------
+
+void Page::add_selected_to_desktop()
+{
+ // Fetch desktop folder
+ const gchar* desktop_path = g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP);
+ GFile* desktop_folder = g_file_new_for_path(desktop_path);
+
+ // Fetch launcher source
+ Launcher* launcher = get_selected_launcher();
+ GFile* source_file = garcon_menu_item_get_file(launcher->get_item());
+
+ // Fetch launcher destination
+ char* basename = g_file_get_basename(source_file);
+ GFile* destination_file = g_file_get_child(desktop_folder, basename);
+ g_free(basename);
+
+ // Copy launcher to desktop folder
+ GError* error = nullptr;
+ if (!g_file_copy(source_file, destination_file, G_FILE_COPY_NONE, nullptr, nullptr, nullptr, &error))
+ {
+ xfce_dialog_show_error(nullptr, error, _("Unable to add launcher to desktop."));
+ g_error_free(error);
+ }
+
+ g_object_unref(destination_file);
+ g_object_unref(source_file);
+ g_object_unref(desktop_folder);
+}
+
+//-----------------------------------------------------------------------------
+
+void Page::add_selected_to_panel()
+{
+ // Connect to Xfce panel through D-Bus
+ GError* error = nullptr;
+ GDBusProxy* proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ nullptr,
+ "org.xfce.Panel",
+ "/org/xfce/Panel",
+ "org.xfce.Panel",
+ nullptr,
+ &error);
+ if (proxy)
+ {
+ // Fetch launcher desktop ID
+ Launcher* launcher = get_selected_launcher();
+ const gchar* parameters[] = { garcon_menu_item_get_desktop_id(launcher->get_item()), nullptr };
+
+ // Tell panel to add item
+ if (!g_dbus_proxy_call_sync(proxy,
+ "AddNewItem",
+ g_variant_new("(s^as)", "launcher", parameters),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ nullptr,
+ &error))
+ {
+ xfce_dialog_show_error(nullptr, error, _("Unable to add launcher to panel."));
+ g_error_free(error);
+ }
+
+ // Disconnect from D-Bus
+ g_object_unref(proxy);
+ }
+ else
+ {
+ xfce_dialog_show_error(nullptr, error, _("Unable to add launcher to panel."));
+ g_error_free(error);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void Page::add_selected_to_favorites()
+{
+ Launcher* launcher = get_selected_launcher();
+ m_menu->get_favorites()->add(launcher);
+}
+
+//-----------------------------------------------------------------------------
+
+void Page::remove_selected_from_favorites()
+{
+ Launcher* launcher = get_selected_launcher();
+ m_menu->get_favorites()->remove(launcher);
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/page.hpp b/src/page.hpp
new file mode 100644
index 0000000..d29d2b3
--- /dev/null
+++ b/src/page.hpp
@@ -0,0 +1,79 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_PAGE_HPP
+#define WHISKERMENU_PAGE_HPP
+
+extern "C"
+{
+#include <gtk/gtk.h>
+}
+
+namespace WhiskerMenu
+{
+
+class FavoritesPage;
+class Launcher;
+class LauncherView;
+class Menu;
+
+class Page
+{
+public:
+ Page(Menu* menu);
+ virtual ~Page();
+
+ GtkWidget* get_widget() const
+ {
+ return m_widget;
+ }
+
+ LauncherView* get_view() const
+ {
+ return m_view;
+ }
+
+protected:
+ Menu* get_menu() const
+ {
+ return m_menu;
+ }
+
+private:
+ Launcher* get_selected_launcher() const;
+
+ void launcher_activated(GtkTreeView* view, GtkTreePath* path, GtkTreeViewColumn*);
+ gboolean view_button_press_event(GtkWidget* view, GdkEventButton* event);
+ gboolean view_popup_menu_event(GtkWidget* view);
+ void on_unmap();
+ void create_context_menu(GtkTreeIter* iter, GdkEventButton* event);
+ void destroy_context_menu(GtkMenuShell* menu);
+ static void position_context_menu(GtkMenu*, gint* x, gint* y, gboolean* push_in, Page* page);
+ void add_selected_to_desktop();
+ void add_selected_to_panel();
+ void add_selected_to_favorites();
+ void remove_selected_from_favorites();
+
+private:
+ Menu* m_menu;
+ GtkWidget* m_widget;
+ LauncherView* m_view;
+ GtkTreePath* m_selected_path;
+};
+
+}
+
+#endif // WHISKERMENU_PAGE_HPP
diff --git a/src/panel_plugin.cpp b/src/panel_plugin.cpp
new file mode 100644
index 0000000..b90f720
--- /dev/null
+++ b/src/panel_plugin.cpp
@@ -0,0 +1,202 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "panel_plugin.hpp"
+
+#include "applications_page.hpp"
+#include "configuration_dialog.hpp"
+#include "launcher.hpp"
+#include "menu.hpp"
+#include "slot.hpp"
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+extern "C" void whiskermenu_construct(XfcePanelPlugin* plugin)
+{
+ xfce_textdomain(GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
+ new PanelPlugin(plugin);
+}
+
+static void whiskermenu_free(XfcePanelPlugin*, PanelPlugin* whiskermenu)
+{
+ delete whiskermenu;
+ whiskermenu = nullptr;
+}
+
+//-----------------------------------------------------------------------------
+
+PanelPlugin::PanelPlugin(XfcePanelPlugin* plugin) :
+ m_plugin(plugin),
+ m_button_icon_name("xfce4-whiskermenu"),
+ m_menu(nullptr)
+{
+ // Load settings
+ gchar* file = xfce_panel_plugin_lookup_rc_file(m_plugin);
+ if (file)
+ {
+ XfceRc* settings = xfce_rc_simple_open(file, true);
+ g_free(file);
+
+ m_button_icon_name = xfce_rc_read_entry(settings, "button-icon", m_button_icon_name.c_str());
+ Launcher::set_show_name(xfce_rc_read_bool_entry(settings, "launcher-show-name", true));
+ Launcher::set_show_description(xfce_rc_read_bool_entry(settings, "launcher-show-description", true));
+ m_menu = new Menu(settings);
+
+ xfce_rc_close(settings);
+ }
+ else
+ {
+ m_menu = new Menu(nullptr);
+ }
+ g_signal_connect_slot(m_menu->get_widget(), "map", &PanelPlugin::menu_shown, this);
+ g_signal_connect_slot(m_menu->get_widget(), "unmap", &PanelPlugin::menu_hidden, this);
+
+ // Create toggle button
+ m_button = xfce_create_panel_toggle_button();
+ gtk_button_set_relief(GTK_BUTTON(m_button), GTK_RELIEF_NONE);
+ m_button_icon = XFCE_PANEL_IMAGE(xfce_panel_image_new_from_source(m_button_icon_name.c_str()));
+ xfce_panel_image_set_size(m_button_icon, -1);
+ gtk_container_add(GTK_CONTAINER(m_button), GTK_WIDGET(m_button_icon));
+ gtk_widget_show_all(m_button);
+ g_signal_connect_slot(m_button, "button-press-event", &PanelPlugin::button_clicked, this);
+
+ // Add plugin to panel
+ gtk_container_add(GTK_CONTAINER(plugin), m_button);
+ xfce_panel_plugin_add_action_widget(plugin, m_button);
+
+ // Connect plugin signals to functions
+ g_signal_connect(plugin, "free-data", G_CALLBACK(whiskermenu_free), this);
+ g_signal_connect_slot(plugin, "configure-plugin", &PanelPlugin::configure, this);
+ g_signal_connect_slot(plugin, "save", &PanelPlugin::save, this);
+ g_signal_connect_slot(plugin, "size-changed", &PanelPlugin::size_changed, this);
+ xfce_panel_plugin_menu_show_configure(plugin);
+}
+
+//-----------------------------------------------------------------------------
+
+PanelPlugin::~PanelPlugin()
+{
+ delete m_menu;
+ m_menu = nullptr;
+
+ gtk_widget_destroy(m_button);
+}
+
+//-----------------------------------------------------------------------------
+
+void PanelPlugin::reload()
+{
+ m_menu->hide();
+ m_menu->get_applications()->reload_applications();
+}
+
+//-----------------------------------------------------------------------------
+
+void PanelPlugin::set_button_icon_name(std::string icon)
+{
+ m_button_icon_name = icon;
+ xfce_panel_image_set_from_source(m_button_icon, icon.c_str());
+}
+
+//-----------------------------------------------------------------------------
+
+void PanelPlugin::set_configure_enabled(bool enabled)
+{
+ if (enabled)
+ {
+ xfce_panel_plugin_unblock_menu(m_plugin);
+ }
+ else
+ {
+ xfce_panel_plugin_block_menu(m_plugin);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean PanelPlugin::button_clicked(GtkWidget*, GdkEventButton* event)
+{
+ if (event->button != 1 || event->state & GDK_CONTROL_MASK)
+ {
+ return false;
+ }
+
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_button)) == true)
+ {
+ m_menu->hide();
+ }
+ else
+ {
+ m_menu->show(m_button, xfce_panel_plugin_get_orientation(m_plugin) == GTK_ORIENTATION_HORIZONTAL);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_button), true);
+ }
+
+ return true;
+}
+
+//-----------------------------------------------------------------------------
+
+void PanelPlugin::menu_hidden()
+{
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_button), false);
+ xfce_panel_plugin_block_autohide(m_plugin, false);
+}
+
+//-----------------------------------------------------------------------------
+
+void PanelPlugin::menu_shown()
+{
+ xfce_panel_plugin_block_autohide(m_plugin, true);
+}
+
+//-----------------------------------------------------------------------------
+
+void PanelPlugin::configure()
+{
+ new ConfigurationDialog(this);
+}
+
+//-----------------------------------------------------------------------------
+
+void PanelPlugin::save()
+{
+ gchar* file = xfce_panel_plugin_save_location(m_plugin, true);
+ if (!file)
+ {
+ return;
+ }
+ XfceRc* settings = xfce_rc_simple_open(file, false);
+ g_free(file);
+
+ xfce_rc_write_entry(settings, "button-icon", m_button_icon_name.c_str());
+ xfce_rc_write_bool_entry(settings, "launcher-show-name", Launcher::get_show_name());
+ xfce_rc_write_bool_entry(settings, "launcher-show-description", Launcher::get_show_description());
+ m_menu->save(settings);
+
+ xfce_rc_close(settings);
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean PanelPlugin::size_changed(XfcePanelPlugin*, gint size)
+{
+ gtk_widget_set_size_request(GTK_WIDGET(m_plugin), size, size);
+ return true;
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/panel_plugin.hpp b/src/panel_plugin.hpp
new file mode 100644
index 0000000..1ab78ad
--- /dev/null
+++ b/src/panel_plugin.hpp
@@ -0,0 +1,71 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_PANEL_PLUGIN_HPP
+#define WHISKERMENU_PANEL_PLUGIN_HPP
+
+#include <string>
+
+extern "C"
+{
+#include <gtk/gtk.h>
+#include <libxfce4panel/libxfce4panel.h>
+}
+
+namespace WhiskerMenu
+{
+
+class Menu;
+
+class PanelPlugin
+{
+public:
+ PanelPlugin(XfcePanelPlugin* plugin);
+ ~PanelPlugin();
+
+ GtkWidget* get_button() const
+ {
+ return m_button;
+ }
+
+ std::string get_button_icon_name() const
+ {
+ return m_button_icon_name;
+ }
+
+ void reload();
+ void set_button_icon_name(std::string icon);
+ void set_configure_enabled(bool enabled);
+
+private:
+ gboolean button_clicked(GtkWidget*, GdkEventButton* event);
+ void menu_hidden();
+ void menu_shown();
+ void configure();
+ void save();
+ gboolean size_changed(XfcePanelPlugin*, gint size);
+
+private:
+ XfcePanelPlugin* m_plugin;
+ GtkWidget* m_button;
+ std::string m_button_icon_name;
+ XfcePanelImage* m_button_icon;
+ Menu* m_menu;
+};
+
+}
+
+#endif // WHISKERMENU_PANEL_PLUGIN_HPP
diff --git a/src/recent_page.cpp b/src/recent_page.cpp
new file mode 100644
index 0000000..d2411b4
--- /dev/null
+++ b/src/recent_page.cpp
@@ -0,0 +1,57 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "recent_page.hpp"
+
+#include "launcher.hpp"
+#include "launcher_model.hpp"
+#include "launcher_view.hpp"
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+RecentPage::RecentPage(XfceRc* settings, Menu* menu) :
+ ListPage(settings, "recent", std::vector<std::string>(), menu),
+ m_max_items(10)
+{
+ // Prevent going over max
+ LauncherModel model(GTK_LIST_STORE(get_view()->get_model()));
+ while (size() > m_max_items)
+ {
+ model.remove_last_item();
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void RecentPage::add(Launcher* launcher)
+{
+ // Remove item if already in list
+ remove(launcher);
+
+ // Prepend to list of items
+ LauncherModel model(GTK_LIST_STORE(get_view()->get_model()));
+ model.prepend_item(launcher);
+
+ // Prevent going over max
+ while (size() > m_max_items)
+ {
+ model.remove_last_item();
+ }
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/recent_page.hpp b/src/recent_page.hpp
new file mode 100644
index 0000000..ac97f4c
--- /dev/null
+++ b/src/recent_page.hpp
@@ -0,0 +1,41 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_RECENT_PAGE_HPP
+#define WHISKERMENU_RECENT_PAGE_HPP
+
+#include "list_page.hpp"
+
+namespace WhiskerMenu
+{
+
+class Launcher;
+class LauncherView;
+
+class RecentPage : public ListPage
+{
+public:
+ RecentPage(XfceRc* settings, Menu* menu);
+
+ void add(Launcher* launcher);
+
+private:
+ size_t m_max_items;
+};
+
+}
+
+#endif // WHISKERMENU_RECENT_PAGE_HPP
diff --git a/src/register_plugin.c b/src/register_plugin.c
new file mode 100644
index 0000000..dc39122
--- /dev/null
+++ b/src/register_plugin.c
@@ -0,0 +1,21 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include <libxfce4panel/xfce-panel-plugin.h>
+
+extern void whiskermenu_construct(XfcePanelPlugin* plugin);
+
+XFCE_PANEL_PLUGIN_REGISTER(whiskermenu_construct)
diff --git a/src/resizer_widget.cpp b/src/resizer_widget.cpp
new file mode 100644
index 0000000..6f06355
--- /dev/null
+++ b/src/resizer_widget.cpp
@@ -0,0 +1,148 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "resizer_widget.hpp"
+
+#include "slot.hpp"
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+ResizerWidget::ResizerWidget(GtkWindow* window) :
+ m_window(window),
+ m_cursor(nullptr)
+{
+ m_alignment = GTK_ALIGNMENT(gtk_alignment_new(1,0,0,0));
+
+ m_drawing = gtk_drawing_area_new();
+ gtk_widget_set_size_request(m_drawing, 10, 10);
+ gtk_widget_add_events(m_drawing, GDK_BUTTON_PRESS_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
+ gtk_container_add(GTK_CONTAINER(m_alignment), m_drawing);
+
+ g_signal_connect_slot(m_drawing, "button-press-event", &ResizerWidget::on_button_press_event, this);
+ g_signal_connect_slot(m_drawing, "enter-notify-event", &ResizerWidget::on_enter_notify_event, this);
+ g_signal_connect_slot(m_drawing, "leave-notify-event", &ResizerWidget::on_leave_notify_event, this);
+ g_signal_connect_slot(m_drawing, "expose-event", &ResizerWidget::on_expose_event, this);
+
+ set_corner(TopRight);
+}
+
+//-----------------------------------------------------------------------------
+
+ResizerWidget::~ResizerWidget()
+{
+ if (m_cursor)
+ {
+ gdk_cursor_unref(m_cursor);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void ResizerWidget::set_corner(Corner corner)
+{
+ GdkCursorType type;
+ switch (corner)
+ {
+ case BottomLeft:
+ gtk_alignment_set(m_alignment, 0,1,0,0);
+ m_shape = { {10,10}, {0,10}, {0,0} };
+ m_edge = GDK_WINDOW_EDGE_SOUTH_WEST;
+ type = GDK_BOTTOM_LEFT_CORNER;
+ break;
+ case TopLeft:
+ gtk_alignment_set(m_alignment, 0,0,0,0);
+ m_shape = { {10,0}, {0,10}, {0,0} };
+ m_edge = GDK_WINDOW_EDGE_NORTH_WEST;
+ type = GDK_TOP_LEFT_CORNER;
+ break;
+ case BottomRight:
+ gtk_alignment_set(m_alignment, 1,1,0,0);
+ m_shape = { {10,10}, {0,10}, {10,0} };
+ m_edge = GDK_WINDOW_EDGE_SOUTH_EAST;
+ type = GDK_BOTTOM_RIGHT_CORNER;
+ break;
+ case TopRight:
+ default:
+ gtk_alignment_set(m_alignment, 1,0,0,0);
+ m_shape = { {10,0}, {10,10}, {0,0} };
+ m_edge = GDK_WINDOW_EDGE_NORTH_EAST;
+ type = GDK_TOP_RIGHT_CORNER;
+ break;
+ }
+
+ if (m_cursor)
+ {
+ gdk_cursor_unref(m_cursor);
+ }
+ m_cursor = gdk_cursor_new_for_display(gtk_widget_get_display(GTK_WIDGET(m_alignment)), type);
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean ResizerWidget::on_button_press_event(GtkWidget*, GdkEventButton* event)
+{
+ gtk_window_begin_resize_drag(m_window,
+ m_edge,
+ event->button,
+ event->x_root,
+ event->y_root,
+ event->time);
+ return true;
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean ResizerWidget::on_enter_notify_event(GtkWidget* widget, GdkEventCrossing*)
+{
+ GdkWindow* window = gtk_widget_get_window(widget);
+ gdk_window_set_cursor(window, m_cursor);
+ return false;
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean ResizerWidget::on_leave_notify_event(GtkWidget* widget, GdkEventCrossing*)
+{
+ GdkWindow* window = gtk_widget_get_window(widget);
+ gdk_window_set_cursor(window, nullptr);
+ return false;
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean ResizerWidget::on_expose_event(GtkWidget* widget, GdkEventExpose*)
+{
+ cairo_t* cr = gdk_cairo_create(gtk_widget_get_window(widget));
+
+ GtkStyle* style = gtk_widget_get_style(widget);
+ const GdkColor& color = style->text[GTK_STATE_NORMAL];
+ cairo_set_source_rgb(cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0);
+
+ cairo_move_to(cr, m_shape.back().x, m_shape.back().y);
+ for (const GdkPoint& point : m_shape)
+ {
+ cairo_line_to(cr, point.x, point.y);
+ }
+ cairo_fill(cr);
+
+ cairo_destroy(cr);
+
+ return true;
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/resizer_widget.hpp b/src/resizer_widget.hpp
new file mode 100644
index 0000000..2f7a26f
--- /dev/null
+++ b/src/resizer_widget.hpp
@@ -0,0 +1,67 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_RESIZER_WIDGET_HPP
+#define WHISKERMENU_RESIZER_WIDGET_HPP
+
+#include <vector>
+
+extern "C"
+{
+#include <gtk/gtk.h>
+}
+
+namespace WhiskerMenu
+{
+
+class ResizerWidget
+{
+public:
+ ResizerWidget(GtkWindow* window);
+ ~ResizerWidget();
+
+ GtkWidget* get_widget() const
+ {
+ return GTK_WIDGET(m_alignment);
+ }
+
+ enum Corner
+ {
+ TopLeft,
+ TopRight,
+ BottomLeft,
+ BottomRight
+ };
+ void set_corner(Corner corner);
+
+private:
+ gboolean on_button_press_event(GtkWidget* widget, GdkEventButton* event);
+ gboolean on_enter_notify_event(GtkWidget* widget, GdkEventCrossing* event);
+ gboolean on_leave_notify_event(GtkWidget* widget, GdkEventCrossing* event);
+ gboolean on_expose_event(GtkWidget* widget, GdkEventExpose* event);
+
+private:
+ GtkWindow* m_window;
+ GtkAlignment* m_alignment;
+ GtkWidget* m_drawing;
+ GdkCursor* m_cursor;
+ GdkWindowEdge m_edge;
+ std::vector<GdkPoint> m_shape;
+};
+
+}
+
+#endif // WHISKERMENU_RESIZER_WIDGET_HPP
diff --git a/src/search_page.cpp b/src/search_page.cpp
new file mode 100644
index 0000000..c00f7b9
--- /dev/null
+++ b/src/search_page.cpp
@@ -0,0 +1,181 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "search_page.hpp"
+
+#include "launcher.hpp"
+#include "launcher_model.hpp"
+#include "launcher_view.hpp"
+#include "menu.hpp"
+#include "slot.hpp"
+
+extern "C"
+{
+#include <gdk/gdkkeysyms.h>
+}
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+SearchPage::SearchPage(Menu* menu) :
+ FilterPage(menu),
+ m_filter_matching_path(nullptr)
+{
+ get_view()->set_selection_mode(GTK_SELECTION_BROWSE);
+
+ g_signal_connect_slot(menu->get_search_entry(), "icon-release", &SearchPage::clear_search, this);
+ g_signal_connect_slot(menu->get_search_entry(), "key-press-event", &SearchPage::search_entry_key_press, this);
+}
+
+//-----------------------------------------------------------------------------
+
+SearchPage::~SearchPage()
+{
+ unset_menu_items();
+}
+
+//-----------------------------------------------------------------------------
+
+void SearchPage::set_filter(const gchar* filter)
+{
+ // Store filter string
+ std::string old_filter_string = m_filter_string;
+ if (filter)
+ {
+ m_filter_string = filter;
+ }
+ else
+ {
+ m_filter_string.clear();
+ }
+ if (m_filter_string == old_filter_string)
+ {
+ return;
+ }
+
+ // Apply filter
+ refilter();
+
+ if (m_filter_matching_path)
+ {
+ // Scroll to and select first result that begins with search string
+ GtkTreePath* path = convert_child_path_to_path(m_filter_matching_path);
+ gtk_tree_path_free(m_filter_matching_path);
+ m_filter_matching_path = nullptr;
+
+ get_view()->select_path(path);
+ get_view()->scroll_to_path(path);
+ gtk_tree_path_free(path);
+ }
+ else
+ {
+ // Find first result
+ GtkTreeIter iter;
+ GtkTreePath* path = gtk_tree_path_new_first();
+ bool found = gtk_tree_model_get_iter(get_view()->get_model(), &iter, path);
+
+ // Scroll to and select first result
+ if (found)
+ {
+ get_view()->select_path(path);
+ get_view()->scroll_to_path(path);
+ }
+
+ gtk_tree_path_free(path);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void SearchPage::set_menu_items(GtkTreeModel* model)
+{
+ set_model(model);
+}
+
+//-----------------------------------------------------------------------------
+
+void SearchPage::unset_menu_items()
+{
+ unset_model();
+}
+
+//-----------------------------------------------------------------------------
+
+bool SearchPage::on_filter(GtkTreeModel* model, GtkTreeIter* iter)
+{
+ if (m_filter_string.empty())
+ {
+ return false;
+ }
+
+ // Check if launcher search string contains text
+ Launcher* launcher = nullptr;
+ gtk_tree_model_get(model, iter, LauncherModel::COLUMN_LAUNCHER, &launcher, -1);
+ gchar* result = g_strstr_len(launcher->get_search_text(), -1, m_filter_string.c_str());
+
+ // Check if launcher search string starts with text
+ if (!m_filter_matching_path && (result == launcher->get_search_text()))
+ {
+ m_filter_matching_path = gtk_tree_model_get_path(model, iter);
+ }
+
+ return result != nullptr;
+}
+
+//-----------------------------------------------------------------------------
+
+void SearchPage::clear_search(GtkEntry* entry, GtkEntryIconPosition icon_pos, GdkEvent*)
+{
+ if (icon_pos == GTK_ENTRY_ICON_SECONDARY)
+ {
+ gtk_entry_set_text(GTK_ENTRY(entry), "");
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean SearchPage::search_entry_key_press(GtkWidget* widget, GdkEventKey* event)
+{
+ if (event->keyval == GDK_Escape)
+ {
+ GtkEntry* entry = GTK_ENTRY(widget);
+ const gchar* text = gtk_entry_get_text(entry);
+ if ((text != nullptr) && (*text != '\0'))
+ {
+ gtk_entry_set_text(entry, "");
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else if (event->keyval == GDK_Return)
+ {
+ GtkTreePath* path = get_view()->get_selected_path();
+ if (path)
+ {
+ get_view()->activate_path(path);
+ gtk_tree_path_free(path);
+ }
+ return true;
+ }
+
+ return false;
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/search_page.hpp b/src/search_page.hpp
new file mode 100644
index 0000000..4500321
--- /dev/null
+++ b/src/search_page.hpp
@@ -0,0 +1,51 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_SEARCH_PAGE_HPP
+#define WHISKERMENU_SEARCH_PAGE_HPP
+
+#include "filter_page.hpp"
+
+#include <string>
+
+namespace WhiskerMenu
+{
+
+class LauncherView;
+
+class SearchPage : public FilterPage
+{
+public:
+ SearchPage(Menu* menu);
+ ~SearchPage();
+
+ void set_filter(const gchar* filter);
+ void set_menu_items(GtkTreeModel* model);
+ void unset_menu_items();
+
+private:
+ bool on_filter(GtkTreeModel* model, GtkTreeIter* iter);
+ void clear_search(GtkEntry* entry, GtkEntryIconPosition icon_pos, GdkEvent*);
+ gboolean search_entry_key_press(GtkWidget* widget, GdkEventKey* event);
+
+private:
+ std::string m_filter_string;
+ GtkTreePath* m_filter_matching_path;
+};
+
+}
+
+#endif // WHISKERMENU_SEARCH_PAGE_HPP
diff --git a/src/section_button.cpp b/src/section_button.cpp
new file mode 100644
index 0000000..27a3f62
--- /dev/null
+++ b/src/section_button.cpp
@@ -0,0 +1,40 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "section_button.hpp"
+
+//-----------------------------------------------------------------------------
+
+GtkRadioButton* WhiskerMenu::new_section_button(const gchar* icon, const gchar* text)
+{
+ GtkWidget* button = gtk_radio_button_new(nullptr);
+ gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(button), false);
+ gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
+ gtk_button_set_focus_on_click(GTK_BUTTON(button), false);
+
+ GtkBox* box = GTK_BOX(gtk_hbox_new(false, 4));
+ gtk_container_add(GTK_CONTAINER(button), GTK_WIDGET(box));
+
+ GtkWidget* image = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_LARGE_TOOLBAR);
+ gtk_box_pack_start(box, GTK_WIDGET(image), false, false, 0);
+
+ GtkWidget* label = gtk_label_new(text);
+ gtk_box_pack_start(box, label, false, true, 0);
+
+ return GTK_RADIO_BUTTON(button);
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/section_button.hpp b/src/section_button.hpp
new file mode 100644
index 0000000..33a3c4c
--- /dev/null
+++ b/src/section_button.hpp
@@ -0,0 +1,32 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_SECTION_BUTTON_HPP
+#define WHISKERMENU_SECTION_BUTTON_HPP
+
+extern "C"
+{
+#include <gtk/gtk.h>
+}
+
+namespace WhiskerMenu
+{
+
+GtkRadioButton* new_section_button(const gchar* icon, const gchar* text);
+
+}
+
+#endif // WHISKERMENU_SECTION_BUTTON_HPP
diff --git a/src/slot.hpp b/src/slot.hpp
new file mode 100644
index 0000000..25e8cf0
--- /dev/null
+++ b/src/slot.hpp
@@ -0,0 +1,98 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_SLOT_HPP
+#define WHISKERMENU_SLOT_HPP
+
+extern "C"
+{
+#include <glib-object.h>
+}
+
+namespace WhiskerMenu
+{
+
+// Member functions without parameters
+template <typename T, typename R>
+struct Slot0
+{
+ T* instance;
+ R (T::*member)();
+};
+
+template <typename T, typename R>
+R invoke_slot0(Slot0<T,R>* slot)
+{
+ return (slot->instance->*slot->member)();
+}
+
+template <typename T, typename R>
+void delete_slot0(Slot0<T,R>* slot)
+{
+ delete slot;
+ slot = nullptr;
+}
+
+template<typename T, typename R>
+gulong g_signal_connect_slot(gpointer signal_obj, const gchar* detailed_signal, R (T::*member)(), T* instance)
+{
+ return g_signal_connect_closure(signal_obj, detailed_signal,
+ g_cclosure_new_swap
+ (
+ (GCallback)&invoke_slot0<T,R>,
+ new Slot0<T,R>{instance, member},
+ (GClosureNotify)&delete_slot0<T,R>
+ ),
+ false);
+}
+
+// Member functions with parameters
+template <typename T, typename R, typename... Args>
+struct SlotArgs
+{
+ T* instance;
+ R (T::*member)(Args...);
+};
+
+template <typename T, typename R, typename... Args>
+R invoke_slot_args(Args... args, SlotArgs<T,R,Args...>* slot)
+{
+ return (slot->instance->*slot->member)(args...);
+}
+
+template <typename T, typename R, typename... Args>
+void delete_slot_args(SlotArgs<T,R,Args...>* slot)
+{
+ delete slot;
+ slot = nullptr;
+}
+
+template<typename T, typename R, typename... Args>
+gulong g_signal_connect_slot(gpointer signal_obj, const gchar* detailed_signal, R (T::*member)(Args...), T* instance)
+{
+ return g_signal_connect_closure(signal_obj, detailed_signal,
+ g_cclosure_new
+ (
+ (GCallback)&invoke_slot_args<T,R,Args...>,
+ new SlotArgs<T,R,Args...>{instance, member},
+ (GClosureNotify)&delete_slot_args<T,R,Args...>
+ ),
+ false);
+}
+
+}
+
+#endif // WHISKERMENU_SLOT_HPP
diff --git a/update-po.sh b/update-po.sh
new file mode 100755
index 0000000..5b7b240
--- /dev/null
+++ b/update-po.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+xgettext --language=C++ --keyword=_ --package-name="whiskermenu" --package-version="1.0.0" `find src -name \*.cpp | sort` -o po/xfce4-whiskermenu-plugin.pot
+
+for pofile in `find po -name \*.po`;
+do
+ msgmerge --quiet --update --backup=none $pofile po/xfce4-whiskermenu-plugin.pot
+done
diff --git a/whiskermenu.desktop b/whiskermenu.desktop
new file mode 100644
index 0000000..d893b02
--- /dev/null
+++ b/whiskermenu.desktop
@@ -0,0 +1,8 @@
+[Xfce Panel]
+Type=X-XFCE-PanelPlugin
+Encoding=UTF-8
+Name=Whisker Menu
+Comment=Show a menu to easily access installed applications
+Icon=xfce4-whiskermenu
+X-XFCE-Module=whiskermenu
+X-XFCE-Internal=false
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list