diff --git a/kdeplasma-addons/CMakeLists.txt b/kdeplasma-addons/CMakeLists.txt new file mode 100644 index 00000000..20f070a4 --- /dev/null +++ b/kdeplasma-addons/CMakeLists.txt @@ -0,0 +1,70 @@ +project(kdeplasma-addons) + +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) + +find_package(KDE4 REQUIRED) +include (KDE4Defaults) +include(MacroLibrary) +include(MacroOptionalDependPackage) + +macro_optional_find_package(KDE4Workspace) +macro_log_feature(KDE4WORKSPACE_FOUND "kdebase workspace" "KDE base workspace libraries" "http://www.kde.org" FALSE "" "Needed for building several Plasma plugins") + +macro_optional_find_package(QCA2) +macro_log_feature(QCA2_FOUND "QCA2" "Qt Cryptographic Architecture" "http://delta.affinix.com/qca" FALSE "2.0.0" "Needed for building microblog dataengine") + +macro_optional_find_package(KdepimLibs) +macro_log_feature(KDEPIMLIBS_FOUND "kdepimlibs" "KDE PIM libraries" "http://www.kde.org" FALSE "" "Needed for building several Plasma plugins") +find_package(Boost) + +set(LIBATTICA_MIN_VERSION "0.1.1") +macro_optional_find_package(LibAttica) +macro_log_feature(LIBATTICA_FOUND "libattica" "Attica Library" "http://websvn.kde.org/trunk/kdesupport/attica/" FALSE "" "Needed for building the Open Collaboration Services plasma dataengine and applets") + +macro_optional_find_package(OpenGL) +macro_log_feature(OPENGL_FOUND "OpenGL" "API for developing portable, interactive 2D and 3D graphics applications" "http://mesa3d.sourceforge.net" FALSE "" "STRONGLY RECOMMENDED: The 3D hardware acceleration available through the OpenGL API is used in applications ranging from graphics and modellers to screensavers and video players.") + +macro_optional_find_package(Nepomuk) +macro_log_feature(NEPOMUK_FOUND "Nepomuk" "Handles all kinds of metadata on the KDE desktop to provide a semantic desktop" "http://nepomuk.kde.org/" FALSE "" "STRONGLY_RECOMMENDED: Nepomuk is used to provide metadata on objects like files, emails etc. to provide a semantic desktop.") +macro_bool_to_01(NEPOMUK_FOUND HAVE_NEPOMUK) + + +macro_optional_find_package(QJSON) +macro_log_feature(QJSON_FOUND "QJSon" "Used for various Internet runners, for parsing API responses, and the microblog dataengine" "" FALSE "" "") + +macro_optional_find_package(QtOAuth) +macro_log_feature(QTOAUTH_FOUND "QtOAuth" "QtOAuth Library - required to build the Plasma Microblog DataEngine" "https://github.com/ayoy/qoauth" FALSE "" "Needed for building Plasma Microblog DataEngine") + +macro_optional_depend_package(Marble "Marble") +if (DEPEND_PACKAGE_Marble) + macro_optional_find_package(Marble) +else (DEPEND_PACKAGE_Marble) + set (MARBLE_FOUND FALSE) +endif (DEPEND_PACKAGE_Marble) +macro_log_feature(MARBLE_FOUND "Marble" "Desktop Globe" "http://marble.kde.org" FALSE "" "RECOMMENDED: Marble is used to provide a desktop globe wallpaper for Plasma.") + +macro_optional_find_package(DBusMenuQt) +macro_log_feature(DBUSMENUQT_FOUND "DBusMenuQt" "DBusMenu Qt" "https://launchpad.net/libdbusmenu-qt/" FALSE "" "Needed for Unity support in IconTasks.") + +if (NEPOMUK_FOUND) + include_directories( ${SOPRANO_INCLUDE_DIR} ${NEPOMUK_INCLUDE_DIR} ) +endif (NEPOMUK_FOUND) + +add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) +add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS) +include_directories (${KDE4_INCLUDES} + ${KDE4WORKSPACE_INCLUDE_DIR} + ${KDEPIMLIBS_INCLUDE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/libs) + +add_subdirectory(libs) +add_subdirectory(applets) +add_subdirectory(dataengines) +add_subdirectory(runners) + +add_subdirectory(scriptengines) +add_subdirectory(wallpapers) +add_subdirectory(containments) +add_subdirectory(cmake) + +macro_display_feature_log() diff --git a/kdeplasma-addons/COPYING b/kdeplasma-addons/COPYING new file mode 100644 index 00000000..5185fd3f --- /dev/null +++ b/kdeplasma-addons/COPYING @@ -0,0 +1,346 @@ +NOTE! The GPL below is copyrighted by the Free Software Foundation, but +the instance of code that it refers to (the kde programs) are copyrighted +by the authors who actually wrote it. + +--------------------------------------------------------------------------- + + 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 Library 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. + + + Copyright (C) 19yy + + 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) 19yy 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. + + , 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 Library General +Public License instead of this License. diff --git a/kdeplasma-addons/COPYING.LIB b/kdeplasma-addons/COPYING.LIB new file mode 100644 index 00000000..2d2d780e --- /dev/null +++ b/kdeplasma-addons/COPYING.LIB @@ -0,0 +1,510 @@ + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations +below. + + When we speak of free software, we are referring to freedom of use, +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 and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it +becomes a de-facto standard. To achieve this, non-free programs must +be allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, 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 library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete 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 distribute a copy of this License along with the +Library. + + 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 Library or any portion +of it, thus forming a work based on the Library, 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) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +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 Library, 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 Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you 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. + + If distribution of 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 satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at least + three years, to give the same user the materials specified in + Subsection 6a, above, for a charge no more than the cost of + performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be 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. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library 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. + + 9. 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 Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +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 with +this License. + + 11. 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 Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library 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 Library. + +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. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library 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. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser 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 Library +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 Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +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 + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "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 +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. 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 LIBRARY 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 +LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), 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 Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms +of the ordinary General Public License). + + To apply these terms, attach the following notices to the library. +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. + + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or +your school, if any, to sign a "copyright disclaimer" for the library, +if necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James + Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/kdeplasma-addons/CTestConfig.cmake b/kdeplasma-addons/CTestConfig.cmake new file mode 100644 index 00000000..045e0c38 --- /dev/null +++ b/kdeplasma-addons/CTestConfig.cmake @@ -0,0 +1,13 @@ +## This file should be placed in the root directory of your project. +## Then modify the CMakeLists.txt file in the root directory of your +## project to incorporate the testing dashboard. +## # The following are required to uses Dart and the Cdash dashboard +## ENABLE_TESTING() +## INCLUDE(CTest) +set(CTEST_PROJECT_NAME "kdeplasma-addons") +set(CTEST_NIGHTLY_START_TIME "20:00:00 CET") + +set(CTEST_DROP_METHOD "http") +set(CTEST_DROP_SITE "my.cdash.org") +set(CTEST_DROP_LOCATION "/submit.php?project=kdeplasma-addons") +set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/kdeplasma-addons/Mainpage.dox b/kdeplasma-addons/Mainpage.dox new file mode 100644 index 00000000..3ca2343a --- /dev/null +++ b/kdeplasma-addons/Mainpage.dox @@ -0,0 +1,7 @@ +/** @mainpage Plasma Add-Ons + * + * This module contains all kinds of Plasma add-ons. + * + */ +// DOXYGEN_NAME=Plasma Add-Ons +// DOXYGEN_ENABLE=YES diff --git a/kdeplasma-addons/applets/CMakeLists.txt b/kdeplasma-addons/applets/CMakeLists.txt new file mode 100644 index 00000000..00254f6c --- /dev/null +++ b/kdeplasma-addons/applets/CMakeLists.txt @@ -0,0 +1,99 @@ + +# this works also for the weatherutils include dir, but should be done properly, Alex +include_directories(${PLASMACLOCK_INCLUDE_DIR}) + +if(KDE4_PLASMA_OPENGL_FOUND) + message(STATUS "libplasma supports OpenGL applets") +else(KDE4_PLASMA_OPENGL_FOUND) + message(STATUS "libplasma doesn't support OpenGL applets") +endif(KDE4_PLASMA_OPENGL_FOUND) + +add_subdirectory(bball) +if(KDE4WORKSPACE_FOUND) + add_subdirectory(binary-clock) + add_subdirectory(fuzzy-clock) + add_subdirectory(weather) + if(NOT WIN32 AND DBUSMENUQT_FOUND) + add_subdirectory(icontasks) + endif(NOT WIN32 AND DBUSMENUQT_FOUND) +endif(KDE4WORKSPACE_FOUND) +add_subdirectory(blackboard) +add_subdirectory(bookmarks) +add_subdirectory(bubblemon) +add_subdirectory(calculator) +add_subdirectory(charselect) +add_subdirectory(comic) +add_subdirectory(fifteenPuzzle) +add_subdirectory(fileWatcher) +add_subdirectory(frame) +add_subdirectory(kolourpicker) +add_subdirectory(konqprofiles) +add_subdirectory(konsoleprofiles) +add_subdirectory(life) +add_subdirectory(luna) +add_subdirectory(magnifique) +add_subdirectory(microblog) +add_subdirectory(notes) +add_subdirectory(nowplaying) +if(LIBATTICA_FOUND) + add_subdirectory(knowledgebase) + add_subdirectory(community) + add_subdirectory(social-news) +endif(LIBATTICA_FOUND) +add_subdirectory(pastebin) +add_subdirectory(previewer) +add_subdirectory(rememberthemilk) +add_subdirectory(rssnow) +add_subdirectory(spellcheck) +add_subdirectory(showdashboard) +add_subdirectory(timer) + +add_subdirectory(eyes) + +add_subdirectory(unitconverter) +add_subdirectory(weatherstation) + +if(QT_QTWEBKIT_FOUND) + add_subdirectory(dict) + add_subdirectory(news) +endif(QT_QTWEBKIT_FOUND) + +if(PHONON_FOUND) + add_subdirectory(mediaplayer) +endif(PHONON_FOUND) + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/qalculate/cmake_modules) +macro_optional_find_package(Qalculate) +if ( QALCULATE_FOUND ) + macro_log_feature(QALCULATE_FOUND "Qalculate!" "Qalculate Library" "http://qalculate.sourceforge.net/" FALSE "" "Needed for building the Qalculate plasma applet") + add_subdirectory(qalculate) +endif( QALCULATE_FOUND ) + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/kdeobservatory/cmake/modules) +macro_optional_find_package(Qwt) +if ( Qwt5-Qt4_FOUND ) + add_subdirectory(kdeobservatory) +endif( Qwt5-Qt4_FOUND ) + +if(NOT WIN32) +if(${KDE_PLATFORM_PROFILE} STREQUAL "Desktop") + if(KDE4WORKSPACE_FOUND) + add_subdirectory(lancelot) + endif(KDE4WORKSPACE_FOUND) +endif(${KDE_PLATFORM_PROFILE} STREQUAL "Desktop") + add_subdirectory(incomingmsg) + add_subdirectory(leavenote) + add_subdirectory(showdesktop) + add_subdirectory(paste) + add_subdirectory(plasmaboard) + add_subdirectory(systemloadviewer) +endif(NOT WIN32) + +if (Q_WS_X11) + if (X11_Xrender_FOUND) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/kimpanel/cmake) + add_subdirectory(kimpanel) + endif (X11_Xrender_FOUND) +endif (Q_WS_X11) + +add_subdirectory(webslice) diff --git a/kdeplasma-addons/applets/bball/CMakeLists.txt b/kdeplasma-addons/applets/bball/CMakeLists.txt new file mode 100644 index 00000000..a3ab3e95 --- /dev/null +++ b/kdeplasma-addons/applets/bball/CMakeLists.txt @@ -0,0 +1,20 @@ +project(bball) + +set(bball_SRCS bball.cpp) + +kde4_add_ui_files(bball_SRCS bballConfig.ui) + +kde4_add_plugin(plasma_applet_bball ${bball_SRCS}) + +target_link_libraries(plasma_applet_bball ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${KDE4_PHONON_LIBS} ) + +install(TARGETS plasma_applet_bball + DESTINATION ${PLUGIN_INSTALL_DIR}) + +install(FILES plasma-applet-bball.desktop + DESTINATION ${SERVICES_INSTALL_DIR}) + +install(FILES bball.svgz football.svgz bounce.ogg + DESTINATION ${DATA_INSTALL_DIR}/bball/) + +kde4_install_icons(${ICON_INSTALL_DIR}) diff --git a/kdeplasma-addons/applets/bball/Messages.sh b/kdeplasma-addons/applets/bball/Messages.sh new file mode 100755 index 00000000..b58b4016 --- /dev/null +++ b/kdeplasma-addons/applets/bball/Messages.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash +$EXTRACTRC *.ui >> rc.cpp +$XGETTEXT *.cpp -o $podir/plasma_applet_BbalL.pot diff --git a/kdeplasma-addons/applets/bball/bball.cpp b/kdeplasma-addons/applets/bball/bball.cpp new file mode 100644 index 00000000..937c69f8 --- /dev/null +++ b/kdeplasma-addons/applets/bball/bball.cpp @@ -0,0 +1,450 @@ +/*************************************************************************** + * Copyright 2008 by Thomas Gillespie * + * Copyright 2010 by Enrico Ros * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "bball.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#ifdef Q_CC_MSVC +#include +#endif + +// default values +static const int initial_ball_radius = 64; + +using namespace Plasma; + +bballApplet::bballApplet(QObject * parent, const QVariantList & args): + Plasma::Applet(parent, args), + // keep this in sync with readConfiguration's default values + m_overlay_enabled(false), + m_overlay_opacity(0), + m_gravity(1.5), + m_friction(0.03), + m_restitution(0.8), + m_sound_enabled(false), + m_sound_volume(100), + m_auto_bounce_enabled(false), + m_auto_bounce_strength(0), + // more status + m_radius(initial_ball_radius), + m_angle(0), + m_angularVelocity(0), + m_mousePressed(false), + m_soundPlayer(0), + m_audioOutput(0) +{ + setHasConfigurationInterface(true); + //TODO figure out why it is not good enough to set it here + // but that it needs to be set in constraintsEvent + // see also the icon applet + // update: apparently it gets reset when the formfactor changes + // this can be caught in constraintsEvent with Plasma::FormFactorConstraint + setBackgroundHints(NoBackground); + resize(contentSizeHint()); +} + +void bballApplet::init() +{ + configChanged(); + // monitor the scene for size changes (so we change the bouncing rect) + if (scene()) + connect(scene(), SIGNAL(sceneRectChanged(QRectF)), this, SLOT(updateScreenRect())); + m_timer.start(25, this); +} + +void bballApplet::paintInterface(QPainter * p, const QStyleOptionGraphicsItem * option, const QRect & contentsRect) +{ + Q_UNUSED(option); + Q_UNUSED(contentsRect); + + if (m_ballPixmap.isNull()) + return; + + if (m_angle) { + p->translate(m_radius, m_radius); + p->rotate(360 * m_angle / 6.28); + p->translate(-m_radius, -m_radius); + if (m_velocity.length() < 300) { + p->setRenderHint(QPainter::SmoothPixmapTransform); + p->setRenderHint(QPainter::Antialiasing); + } + } + p->drawPixmap(QPoint(0, 0), m_ballPixmap); +} + +QSizeF bballApplet::contentSizeHint() const +{ + return QSizeF(m_radius * 2, m_radius * 2); +} + +void bballApplet::createConfigurationInterface(KConfigDialog *parent) +{ + QWidget *widget = new QWidget; + ui.setupUi(widget); + + // Appearance + ui.imageUrl->setUrl(KUrl::fromPath(m_image_url)); + ui.colourizeEnabled->setChecked(m_overlay_enabled); + ui.colourizeLabel->setEnabled(m_overlay_enabled); + ui.colourize->setEnabled(m_overlay_enabled); + ui.colourize->setColor(m_overlay_colour); + ui.colourizeOpacityLabel->setEnabled(m_overlay_enabled); + ui.colourizeOpacitySlider->setEnabled(m_overlay_enabled); + ui.colourizeOpacitySlider->setSliderPosition(static_cast< int >(m_overlay_opacity/2.55)-1); + + // Physics + ui.gravity->setSliderPosition(static_cast< int >(m_gravity * 100)); + ui.friction->setSliderPosition(static_cast< int >(m_friction * 100)); + ui.resitution->setSliderPosition(static_cast < int >(m_restitution * 100)); + + // Sound + ui.soundEnabled->setChecked(m_sound_enabled); + ui.soundVolumeLabel->setEnabled(m_sound_enabled); + ui.soundVolume->setEnabled(m_sound_enabled); + ui.soundVolume->setSliderPosition(m_sound_volume); + ui.soundFileLabel->setEnabled(m_sound_enabled); + ui.soundFile->setEnabled(m_sound_enabled); + ui.soundFile->setUrl(KUrl::fromPath(m_sound_url)); + + // Misc + ui.autoBounceEnabled->setChecked(m_auto_bounce_enabled); + ui.autoBounceStrengthLabel->setEnabled(m_auto_bounce_enabled); + ui.autoBounceStrength->setValue(static_cast < int >(m_auto_bounce_strength)); + ui.autoBounceStrength->setEnabled(m_auto_bounce_enabled); + + parent->addPage(widget, i18n("General"), icon()); + connect(ui.imageUrl, SIGNAL(textChanged(QString)), parent, SLOT(settingsModified())); + connect(ui.colourizeEnabled, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); + connect(ui.colourize, SIGNAL(changed(QColor)), parent, SLOT(settingsModified())); + connect(ui.colourizeOpacitySlider, SIGNAL(valueChanged(int)), parent, SLOT(settingsModified())); + connect(ui.gravity, SIGNAL(valueChanged(int)), parent, SLOT(settingsModified())); + connect(ui.friction, SIGNAL(valueChanged(int)), parent, SLOT(settingsModified())); + connect(ui.resitution, SIGNAL(valueChanged(int)), parent, SLOT(settingsModified())); + connect(ui.soundEnabled, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); + connect(ui.soundVolume, SIGNAL(valueChanged(int)), parent, SLOT(settingsModified())); + connect(ui.soundFile, SIGNAL(textChanged(QString)), parent, SLOT(settingsModified())); + connect(ui.autoBounceEnabled, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); + connect(ui.autoBounceStrength, SIGNAL(valueChanged(int)), parent, SLOT(settingsModified())); + connect(parent, SIGNAL(accepted()), this, SLOT(configurationChanged())); +} + +void bballApplet::mousePressEvent(QGraphicsSceneMouseEvent * event) +{ + if (immutability() != Plasma::Mutable) + return; + + if (m_geometry.isNull()) + syncGeometry(); + + // reset timing + m_timer.stop(); + m_time = QTime(); + update(); + + // reset physics + m_velocity = QVector2D(); + m_angularVelocity = 0; + + // save mouse position + m_mouseScenePos = event->scenePos(); + m_mousePressed = true; + + event->accept(); +} + +void bballApplet::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) +{ + if (immutability() != Plasma::Mutable) + return; + + // TODO: use real timing instead of the fixed step (1/0.025) + m_velocity = QVector2D(m_mouseScenePos - m_prevMouseScenePos) / 0.025; + m_mousePressed = false; + m_timer.start(25, this); + event->accept(); +} + +void bballApplet::mouseMoveEvent(QGraphicsSceneMouseEvent * event) +{ + if (immutability() != Plasma::Mutable) + return; + + m_prevMouseScenePos = m_mouseScenePos; + m_mouseScenePos = event->scenePos(); + m_geometry.translate(m_mouseScenePos - m_prevMouseScenePos); + setGeometry(m_geometry); + event->accept(); +} + +void bballApplet::timerEvent(QTimerEvent *event) +{ + if (event->timerId() == m_timer.timerId()) { + updatePhysics(); + return; + } + Applet::timerEvent(event); +} + +void bballApplet::constraintsEvent(Plasma::Constraints constraints) +{ + if (constraints & Plasma::LocationConstraint) + m_geometry = QRectF(); + + if (constraints & Plasma::FormFactorConstraint) + setBackgroundHints(NoBackground); + + if (constraints & Plasma::SizeConstraint) + syncGeometry(); +} + +void bballApplet::updateScreenRect() +{ + m_screenRect = QDesktopWidget().availableGeometry(); + m_timer.start(25, this); +} + +void bballApplet::configurationChanged() +{ + KConfigGroup cg = config(); + + // Appearance + if (KIO::NetAccess::exists(ui.imageUrl->url(), KIO::NetAccess::SourceSide, NULL)) { + m_image_url = ui.imageUrl->url().path(); + cg.writeEntry("ImgURL", m_image_url); + m_ballSvg.setImagePath(m_image_url); + } else + KMessageBox::error(0, i18n("The given image could not be loaded. The image will not be changed.")); + m_overlay_enabled = ui.colourizeEnabled->checkState() == Qt::Checked; + cg.writeEntry("OverlayEnabled", m_overlay_enabled); + m_overlay_colour = ui.colourize->color(); + cg.writeEntry("OverlayColour", m_overlay_colour); + m_overlay_opacity = static_cast< int >(ui.colourizeOpacitySlider->value() * 2.55); + cg.writeEntry("OverlayOpacity", m_overlay_opacity); + updateScaledBallImage(); + + // Physics + m_gravity = (qreal)ui.gravity->value() / 100.0; + cg.writeEntry("Gravity", m_gravity); + m_friction = (qreal)ui.friction->value() / 100.0; + cg.writeEntry("Friction", 1.0 - m_friction); // RETROCOMP + m_restitution = ui.resitution->value () / 100.0; + cg.writeEntry("Resitution", m_restitution); + + // Sound + m_sound_enabled = ui.soundEnabled->checkState() == Qt::Checked; + cg.writeEntry("SoundEnabled", m_sound_enabled); + if (m_sound_enabled) { + if (KIO::NetAccess::exists(ui.soundFile->url(), KIO::NetAccess::SourceSide, NULL)) { + m_sound_url = ui.soundFile->url().path(); + cg.writeEntry("SoundURL", m_sound_url); + if (m_soundPlayer) + m_soundPlayer->setCurrentSource(m_sound_url); + } else + KMessageBox::error(0, i18n("The given sound could not be loaded. The sound will not be changed.")); + } + m_sound_volume = ui.soundVolume->value(); + cg.writeEntry("SoundVolume", m_sound_volume); + if (m_audioOutput) + m_audioOutput->setVolume(m_sound_volume); + + // Misc + m_auto_bounce_enabled = ui.autoBounceEnabled->checkState() == Qt::Checked; + cg.writeEntry("AutoBounceEnabled", m_auto_bounce_enabled); + m_auto_bounce_strength = ui.autoBounceStrength->value(); + cg.writeEntry ("AutoBounceStrength", m_auto_bounce_strength); + if (m_auto_bounce_enabled || m_gravity > 0) + m_timer.start(25, this); + + // mouse - undo the mouse clicked + m_mousePressed = false; + + update(); +} + +void bballApplet::configChanged() +{ + KConfigGroup cg = config (); + + // Appearance + m_image_url = cg.readEntry("ImgURL", KStandardDirs::locate("data", QLatin1String( "bball/bball.svgz" ))); + m_overlay_enabled = cg.readEntry("OverlayEnabled", false); + m_overlay_colour = cg.readEntry("OverlayColour", QColor(Qt::white)); + m_overlay_opacity = cg.readEntry("OverlayOpacity", 0); + m_ballSvg.setImagePath(m_image_url); + updateScaledBallImage(); + + // Physics + m_gravity = cg.readEntry("Gravity", 1.5); + m_friction = 1.0 - cg.readEntry("Friction", 0.97); // RETROCOMP + m_restitution = cg.readEntry("Resitution", 0.8); + + // Sound + m_sound_enabled = cg.readEntry("SoundEnabled", false); + m_sound_url = cg.readEntry("SoundURL", KStandardDirs::locate ("data", QLatin1String( "bball/bounce.ogg" ))); + m_sound_volume = cg.readEntry("SoundVolume", 100); + + // Misc + m_auto_bounce_enabled = cg.readEntry("AutoBounceEnabled", false); + m_auto_bounce_strength = cg.readEntry("AutoBounceStrength", 0); +} + +void bballApplet::updatePhysics() +{ + // find out the delta-time since the last call + if (m_time.isNull()) + m_time.start(); + qreal dT = qMin((qreal)m_time.restart() / 1000.0, 0.5); + + // skip progessing if externally moved (disabled because plasma moves this too frequently) + //if (m_geometry != geometry()) + // m_geometry = QRectF(); + + // skip if dragging + if (m_mousePressed || m_geometry.isNull() || m_radius < 1) + return; + + if (m_screenRect.isNull()) + updateScreenRect(); + + // add some randomness if autobouncing + if (m_auto_bounce_enabled && rand() < RAND_MAX/35) { + m_velocity += QVector2D( + (rand() - RAND_MAX/2) * m_auto_bounce_strength * 0.0000005, + (rand() - RAND_MAX/2) * m_auto_bounce_strength * 0.0000005); + } + + // update velocity and position + m_velocity += QVector2D(0, (qreal)m_screenRect.height() * m_gravity * dT); + m_velocity *= (1.0 - 2 * m_friction * dT); + m_geometry.translate((m_velocity * dT).toPointF()); + + // floor + bool collision = false; + bool bottom = false; + if (m_geometry.bottom() >= m_screenRect.bottom() && m_velocity.y() > 0) { + m_geometry.moveBottom(m_screenRect.bottom()); + m_velocity *= QVector2D(1, -m_restitution); + m_angularVelocity = m_velocity.x() / m_radius; + collision = true; + bottom = true; + } + + // ceiling + if (m_geometry.top() <= m_screenRect.top() && m_velocity.y() < 0) { + m_geometry.moveTop(m_screenRect.top ()); + m_velocity *= QVector2D(1, -m_restitution); + m_angularVelocity = -m_velocity.x() / m_radius; + collision = true; + } + + // right + if (m_geometry.right() >= m_screenRect.right() && m_velocity.x() > 0) { + m_geometry.moveRight(m_screenRect.right() - 0.1); + m_velocity *= QVector2D(-m_restitution, 1); + m_angularVelocity = -m_velocity.y() / m_radius; + if (bottom) + m_velocity.setX(0); + collision = true; + } + + // left + if (m_geometry.left() <= m_screenRect.left() && m_velocity.x() < 0) { + m_geometry.moveLeft(m_screenRect.left () + 0.1); + m_velocity *= QVector2D(-m_restitution, 1); + m_angularVelocity = m_velocity.y() / m_radius; + if (bottom) + m_velocity.setX(0); + collision = true; + } + + m_angularVelocity *= (0.9999 - 2 * m_friction * dT); + m_angle += m_angularVelocity * dT; + + // stop animation if reached bottom and still + if (m_velocity.length() < 10.0 && qAbs(m_angularVelocity) < 0.1 && !m_auto_bounce_enabled) { + m_timer.stop(); + update(); + return; + } + + // move this and update graphics + setGeometry(m_geometry); + update(); + + if (collision) + playBoingSound(); +} + +void bballApplet::playBoingSound() +{ + if (!m_sound_enabled || m_velocity.x() == 0.0 || m_velocity.y() == 0.0) + return; + + // create the player if missing + if (!m_soundPlayer) { + m_soundPlayer = new Phonon::MediaObject(this); + m_soundPlayer->setCurrentSource(m_sound_url); + m_audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); + m_audioOutput->setVolume(m_sound_volume); + createPath(m_soundPlayer, m_audioOutput); + } + + // play the sound + m_soundPlayer->seek(0); + m_soundPlayer->play(); +} + +void bballApplet::syncGeometry() +{ + m_geometry = geometry(); + m_radius = static_cast(geometry().width()) / 2; + updateScaledBallImage(); +} + +void bballApplet::updateScaledBallImage() +{ + // regen m_ballPixmap + m_ballSvg.resize(contentSizeHint()); + m_ballPixmap = m_ballSvg.pixmap(); + + // tint the pixmap if requested + if (m_overlay_enabled) { + QPainter p(&m_ballPixmap); + p.setRenderHint(QPainter::Antialiasing, true); + p.setPen(Qt::NoPen); + QColor brush = m_overlay_colour; + brush.setAlpha(m_overlay_opacity); + p.setBrush(brush); + p.drawEllipse(QRectF(0, 0, m_radius * 2, m_radius * 2)); + } +} + +#include "bball.moc" diff --git a/kdeplasma-addons/applets/bball/bball.h b/kdeplasma-addons/applets/bball/bball.h new file mode 100644 index 00000000..7e54eaef --- /dev/null +++ b/kdeplasma-addons/applets/bball/bball.h @@ -0,0 +1,119 @@ +/*************************************************************************** + * Copyright 2008 by Thomas Gillespie * + * Copyright 2010 by Enrico Ros * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef bball_HEADER +#define bball_HEADER + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include "ui_bballConfig.h" + +class QGraphicsSceneMouseEvent; +class QSizeF; + +class bballApplet : public Plasma::Applet +{ + Q_OBJECT +public: + bballApplet(QObject * parent, const QVariantList & args); + + // ::Plasma::Applet + void init(); + void paintInterface(QPainter * painter, const QStyleOptionGraphicsItem * option, const QRect & contentsRect); + QSizeF contentSizeHint() const; + void createConfigurationInterface(KConfigDialog *parent); + + // ::QGraphicsItem + void mousePressEvent(QGraphicsSceneMouseEvent * event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); + void mouseMoveEvent(QGraphicsSceneMouseEvent * event); + void timerEvent(QTimerEvent *event); + +protected: + // ::Plasma::Applet + void constraintsEvent(Plasma::Constraints constraints); + +protected Q_SLOTS: + void updateScreenRect(); + void configurationChanged(); + +public slots: + void configChanged(); + +private: + void updatePhysics(); + void playBoingSound(); + void syncGeometry(); + void updateScaledBallImage(); + + // config values + QString m_image_url; + bool m_overlay_enabled; + int m_overlay_opacity; + QColor m_overlay_colour; + + qreal m_gravity, m_friction, m_restitution; + + bool m_sound_enabled; + int m_sound_volume; + QString m_sound_url; + + bool m_auto_bounce_enabled; + qreal m_auto_bounce_strength; + + // status + QBasicTimer m_timer; + QTime m_time; + + QRectF m_screenRect; + + int m_radius; + QRectF m_geometry; + QVector2D m_velocity; + + qreal m_angle; + qreal m_angularVelocity; + + Plasma::Svg m_ballSvg; + QPixmap m_ballPixmap; + + bool m_mousePressed; + QPointF m_mouseScenePos; + QPointF m_prevMouseScenePos; + + Ui::bballConfig ui; + + Phonon::MediaObject * m_soundPlayer; + Phonon::AudioOutput * m_audioOutput; +}; + +K_EXPORT_PLASMA_APPLET (BbalL, bballApplet) +#endif diff --git a/kdeplasma-addons/applets/bball/bball.svgz b/kdeplasma-addons/applets/bball/bball.svgz new file mode 100644 index 00000000..e61ec867 Binary files /dev/null and b/kdeplasma-addons/applets/bball/bball.svgz differ diff --git a/kdeplasma-addons/applets/bball/bballConfig.ui b/kdeplasma-addons/applets/bball/bballConfig.ui new file mode 100644 index 00000000..86d3b138 --- /dev/null +++ b/kdeplasma-addons/applets/bball/bballConfig.ui @@ -0,0 +1,568 @@ + + + bballConfig + + + + 0 + 0 + 546 + 437 + + + + Configure BbalL! + + + + + + + 75 + true + + + + Appearance + + + + + + + + 0 + 0 + + + + *.png *.gif *.svg *.svgz *.jpeg *.jpg + + + Qt::NonModal + + + + + + + + + false + + + + + + + Enabled + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + false + + + Colorize opacity: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + colourizeOpacitySlider + + + + + + + Qt::Horizontal + + + + + + + + 75 + true + + + + Physics + + + + + + + 500 + + + Qt::Horizontal + + + + + + + 30 + + + Qt::Horizontal + + + + + + + 100 + + + Qt::Horizontal + + + + + + + Sound enabled: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + soundEnabled + + + + + + + + + + + + + + false + + + Qt::Horizontal + + + + + + + false + + + Bounce effect: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + soundFile + + + + + + + false + + + + 0 + 0 + + + + + + + + + 75 + true + + + + Auto Bounce + + + + + + + Qt::Vertical + + + + 361 + 40 + + + + + + + + Image: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + imageUrl + + + + + + + false + + + Colorize: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + colourize + + + + + + + Gravity: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + gravity + + + + + + + Friction: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + friction + + + + + + + Restitution: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + resitution + + + + + + + + 75 + true + + + + Sound + + + + + + + false + + + Volume: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + soundVolume + + + + + + + + + + + + + + Auto bounce: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + autoBounceEnabled + + + + + + + false + + + Auto bounce strength: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + autoBounceStrength + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + false + + + 50 + + + Qt::Horizontal + + + + + + + + KUrlRequester + QFrame +
kurlrequester.h
+ 1 +
+ + KColorButton + QPushButton +
kcolorbutton.h
+
+
+ + + + colourizeEnabled + clicked(bool) + colourize + setEnabled(bool) + + + 302 + 158 + + + 218 + 160 + + + + + colourizeEnabled + clicked(bool) + colourizeOpacitySlider + setEnabled(bool) + + + 372 + 160 + + + 375 + 230 + + + + + autoBounceEnabled + clicked(bool) + autoBounceStrength + setEnabled(bool) + + + 177 + 104 + + + 182 + 194 + + + + + autoBounceEnabled + clicked(bool) + autoBounceStrengthLabel + setEnabled(bool) + + + 212 + 110 + + + 80 + 200 + + + + + colourizeEnabled + clicked(bool) + colourizeLabel + setEnabled(bool) + + + 340 + 145 + + + 56 + 163 + + + + + colourizeEnabled + clicked(bool) + colourizeOpacityLabel + setEnabled(bool) + + + 404 + 158 + + + 92 + 219 + + + + + soundEnabled + clicked(bool) + soundVolumeLabel + setEnabled(bool) + + + 130 + 103 + + + 63 + 157 + + + + + soundEnabled + clicked(bool) + soundVolume + setEnabled(bool) + + + 284 + 101 + + + 289 + 151 + + + + + soundEnabled + clicked(bool) + soundFileLabel + setEnabled(bool) + + + 233 + 99 + + + 55 + 224 + + + + + soundEnabled + clicked(bool) + soundFile + setEnabled(bool) + + + 253 + 106 + + + 269 + 221 + + + + +
diff --git a/kdeplasma-addons/applets/bball/bounce.ogg b/kdeplasma-addons/applets/bball/bounce.ogg new file mode 100644 index 00000000..812fbdc3 Binary files /dev/null and b/kdeplasma-addons/applets/bball/bounce.ogg differ diff --git a/kdeplasma-addons/applets/bball/football.svgz b/kdeplasma-addons/applets/bball/football.svgz new file mode 100644 index 00000000..40724615 Binary files /dev/null and b/kdeplasma-addons/applets/bball/football.svgz differ diff --git a/kdeplasma-addons/applets/bball/hi128-app-bball.png b/kdeplasma-addons/applets/bball/hi128-app-bball.png new file mode 100644 index 00000000..908c28f1 Binary files /dev/null and b/kdeplasma-addons/applets/bball/hi128-app-bball.png differ diff --git a/kdeplasma-addons/applets/bball/hi16-app-bball.png b/kdeplasma-addons/applets/bball/hi16-app-bball.png new file mode 100644 index 00000000..c243a10b Binary files /dev/null and b/kdeplasma-addons/applets/bball/hi16-app-bball.png differ diff --git a/kdeplasma-addons/applets/bball/hi32-app-bball.png b/kdeplasma-addons/applets/bball/hi32-app-bball.png new file mode 100644 index 00000000..98923b91 Binary files /dev/null and b/kdeplasma-addons/applets/bball/hi32-app-bball.png differ diff --git a/kdeplasma-addons/applets/bball/hi48-app-bball.png b/kdeplasma-addons/applets/bball/hi48-app-bball.png new file mode 100644 index 00000000..e02fdad0 Binary files /dev/null and b/kdeplasma-addons/applets/bball/hi48-app-bball.png differ diff --git a/kdeplasma-addons/applets/bball/hi64-app-bball.png b/kdeplasma-addons/applets/bball/hi64-app-bball.png new file mode 100644 index 00000000..308e0b72 Binary files /dev/null and b/kdeplasma-addons/applets/bball/hi64-app-bball.png differ diff --git a/kdeplasma-addons/applets/bball/hisc-app-bball.svgz b/kdeplasma-addons/applets/bball/hisc-app-bball.svgz new file mode 100644 index 00000000..cf6c16c7 Binary files /dev/null and b/kdeplasma-addons/applets/bball/hisc-app-bball.svgz differ diff --git a/kdeplasma-addons/applets/bball/plasma-applet-bball.desktop b/kdeplasma-addons/applets/bball/plasma-applet-bball.desktop new file mode 100644 index 00000000..3737f76b --- /dev/null +++ b/kdeplasma-addons/applets/bball/plasma-applet-bball.desktop @@ -0,0 +1,125 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Bouncy Ball +Name[ar]=كرة نطّاطة +Name[bs]=Bouncy Ball +Name[ca]=Una pilota que bota +Name[ca@valencia]=Una pilota que bota +Name[cs]=Poskakující míč +Name[da]=Hoppebold +Name[de]=Springender Ball +Name[el]=Aναπηδώσα μπάλα +Name[en_GB]=Bouncy Ball +Name[es]=Pelota que rebota +Name[et]=Põrkav pall +Name[eu]=Pilota bizia +Name[fi]=Pomppupallo +Name[fr]=Balle rebondissante +Name[gl]=Bóla a rebotar +Name[hr]=Odskakujuća lopta +Name[hu]=Pattogó labda +Name[it]=Palla rimbalzante +Name[ja]=バウンスボール +Name[kk]=Секірмелі доп +Name[km]=Bouncy Ball +Name[ko]=튀는 공 +Name[lt]=Šokinėjantis kamuolys +Name[lv]=Atlecoša bumba +Name[mr]=बाऊन्सी बॉल +Name[nb]=Sprettball +Name[nds]=Jumpen Ball +Name[nl]=Stuiterende bal +Name[nn]=Sprettball +Name[pa]=ਕੁੱਦਦੀ ਗੇਂਦ +Name[pl]=Skacząca piłka +Name[pt]=Bola Saltitante +Name[pt_BR]=Bola saltitante +Name[ro]=Minge săritoare +Name[ru]=Попрыгунчик +Name[sk]=Poskakujúca lopta +Name[sl]=Odbijajoča se žoga +Name[sr]=скочилопта +Name[sr@ijekavian]=скочилопта +Name[sr@ijekavianlatin]=skočilopta +Name[sr@latin]=skočilopta +Name[sv]=Studsande boll +Name[th]=ลูกบอลกระเด้งกระดอน +Name[tr]=Zıplayan Top +Name[ug]=Bouncy Ball +Name[uk]=М’ячик-стрибунець +Name[wa]=Ridjiblante bole +Name[x-test]=xxBouncy Ballxx +Name[zh_CN]=弹球 +Name[zh_TW]=彈跳球 +Comment=A bouncy ball for plasma +Comment[ar]=كرة نطاطة للبلازما +Comment[ast]=Una pelota que rebota pa plasma +Comment[bs]=Odskačuća lopta za Plazmu +Comment[ca]=Una pilota que bota per al plasma +Comment[ca@valencia]=Una pilota que bota per al plasma +Comment[cs]=Poskakující míč pro Plasmu +Comment[da]=En hoppende bold til Plasma +Comment[de]=Ein Springball für Plasma +Comment[el]=Μια αναπηδώσα μπάλα για το plasma +Comment[en_GB]=A bouncy ball for plasma +Comment[es]=Una pelota que rebota para plasma +Comment[et]=Põrkavad pallid Plasmale +Comment[eu]=Plasmarentzako pilota bizi bat +Comment[fi]=Pomppiva pallo Plasmaan +Comment[fr]=Une balle rebondissante pour KDE +Comment[ga]=Liathróid phreabarnach le haghaidh plasma +Comment[gl]=Unha bóla a rebotar para plasma +Comment[he]=כדור קופצני עבור plasma +Comment[hr]=Odskakujuća lopta za Plasmu +Comment[hu]=Pattogó labda +Comment[is]=Hoppandi plasmabolti +Comment[it]=Una palla rimbalzante per Plasma +Comment[ja]=Plasma のバウンスボール +Comment[kk]=Plasma-ның секірмелі добы +Comment[km]=បាល់​លោត​សម្រាប់​ប្លាស្មា +Comment[ko]=바탕 화면에서 튀는 공 +Comment[ku]=Topa lotikî ji bo plasma +Comment[lt]=Šokinėjantis kamuolys plazmai +Comment[lv]=Atlecoša bumba +Comment[mr]=प्लाज्मा करिता एक उडी मारणारा बॉल +Comment[nb]=En sprettball for plasma +Comment[nds]=En jumpen Ball för Plasma +Comment[nl]=Een stuiterende bal voor plasma +Comment[nn]=Sprettball til Plasma +Comment[pa]=ਪਲਾਜ਼ਮਾ ਲਈ ਕੁੱਦਦੀ ਗੇਂਦ +Comment[pl]=Skacząca piłka +Comment[pt]=Uma bola saltitante para o Plasma +Comment[pt_BR]=Uma bola saltitante para o Plasma +Comment[ro]=O minge săritoare pentru Plasma +Comment[ru]=Попрыгунчик для Plasma +Comment[sk]=Poskakujúca lopta pre Plasmu +Comment[sl]=Odbijajoča se žoga za Plasmo +Comment[sr]=Одскачућа лопта за Плазму +Comment[sr@ijekavian]=Одскачућа лопта за Плазму +Comment[sr@ijekavianlatin]=Odskačuća lopta za Plasmu +Comment[sr@latin]=Odskačuća lopta za Plasmu +Comment[sv]=En studsande boll för Plasma +Comment[th]=ลูกบอลกระเด้งกระดอนสำหรับพลาสมา +Comment[tr]=Plasma için bir zıplayan top +Comment[uk]=М’ячик-стрибунець для плазми +Comment[wa]=Ene bole ki ridjibele po plasma +Comment[x-test]=xxA bouncy ball for plasmaxx +Comment[zh_CN]=一个 plasma 的弹球 +Comment[zh_TW]=Plasma 上的彈跳球遊戲 +Type=Service +ServiceTypes=Plasma/Applet +Icon=bball + +X-KDE-Library=plasma_applet_bball +X-KDE-PluginInfo-Author=Thomas Gillespie +X-KDE-PluginInfo-Email=tomjamesgillespie@googlemail.com +X-KDE-PluginInfo-Name=BbalL +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website= +X-KDE-PluginInfo-Category=Fun and Games +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true + +X-Plasma-Requires-FileDialog=Unused +X-Plasma-Requires-LaunchApp=Unused diff --git a/kdeplasma-addons/applets/binary-clock/CMakeLists.txt b/kdeplasma-addons/applets/binary-clock/CMakeLists.txt new file mode 100644 index 00000000..b42a6e76 --- /dev/null +++ b/kdeplasma-addons/applets/binary-clock/CMakeLists.txt @@ -0,0 +1,12 @@ +project(binaryclock) + +set(binaryclock_SRCS binaryclock.cpp) + +kde4_add_ui_files(binaryclock_SRCS clockConfig.ui) +kde4_add_plugin(plasma_applet_binaryclock ${binaryclock_SRCS}) + +target_link_libraries(plasma_applet_binaryclock ${KDE4WORKSPACE_PLASMACLOCK_LIBRARY} ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS}) + +install(TARGETS plasma_applet_binaryclock DESTINATION ${PLUGIN_INSTALL_DIR}) + +install(FILES plasma-applet-binaryclock.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/kdeplasma-addons/applets/binary-clock/Messages.sh b/kdeplasma-addons/applets/binary-clock/Messages.sh new file mode 100755 index 00000000..40a3686f --- /dev/null +++ b/kdeplasma-addons/applets/binary-clock/Messages.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash +$EXTRACTRC *.ui >> rc.cpp +$XGETTEXT *.cpp -o $podir/plasma_applet_binaryclock.pot diff --git a/kdeplasma-addons/applets/binary-clock/binaryclock.cpp b/kdeplasma-addons/applets/binary-clock/binaryclock.cpp new file mode 100644 index 00000000..75c45485 --- /dev/null +++ b/kdeplasma-addons/applets/binary-clock/binaryclock.cpp @@ -0,0 +1,316 @@ +/*************************************************************************** + * Copyright 2007 by Riccardo Iaconelli * + * Copyright 2007 by Davide Bettio * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "binaryclock.h" + +#include + +#include + +#include +#include + +BinaryClock::BinaryClock(QObject *parent, const QVariantList &args) + : ClockApplet(parent, args), + m_showSeconds(true), + m_showOffLeds(true), + m_showGrid(true), + m_time(0, 0) +{ + KGlobal::locale()->insertCatalog(QLatin1String("libplasmaclock")); + KGlobal::locale()->insertCatalog(QLatin1String("timezones4")); + + setHasConfigurationInterface(true); + resize(getWidthFromHeight(128), 128); +} + +void BinaryClock::init() +{ + ClockApplet::init(); + clockConfigChanged(); + + connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(updateColors())); + + connectToEngine(); + + updateColors(); +} + +BinaryClock::~BinaryClock() +{ +} + +int BinaryClock::getHeightFromWidth(int w) const +{ + int dots = m_showSeconds ? 6 : 4; + int rectSize = (w - 5) * 4; + + return (rectSize / dots) + 3; +} + +int BinaryClock::getWidthFromHeight(int h) const +{ + int dots = m_showSeconds ? 6 : 4; + int rectSize = (h - 3) / 4; + + return (rectSize * dots) + (dots - 1); +} + +void BinaryClock::constraintsEvent(Plasma::Constraints constraints) +{ + if (constraints & Plasma::SizeConstraint) { + qreal top, bottom, left, right; + getContentsMargins(&left, &top, &right, &bottom); + qreal borderHeight = top + bottom; + qreal borderWidth = left + right; + + if (formFactor() == Plasma::Vertical) { + setMinimumHeight(getHeightFromWidth((int) contentsRect().width()) + borderHeight); + setMinimumWidth(0); + } else if (formFactor() == Plasma::Horizontal) { + setMinimumWidth(getWidthFromHeight((int) contentsRect().height()) + borderWidth); + setMinimumHeight(0); + } else { + setMinimumWidth(getWidthFromHeight(40)); + setMinimumHeight(40); + } + } +} + +void BinaryClock::connectToEngine() +{ + Plasma::DataEngine* timeEngine = dataEngine(QLatin1String("time")); + + if (m_showSeconds) { + timeEngine->connectSource(currentTimezone(), this, 500); + } else { + timeEngine->connectSource(currentTimezone(), this, 6000, Plasma::AlignToMinute); + } +} + +void BinaryClock::dataUpdated(const QString& source, const Plasma::DataEngine::Data &data) +{ + Q_UNUSED(source); + + m_time = data[QLatin1String("Time")].toTime(); + + if (m_time.minute() == m_lastTimeSeen.minute() && + m_time.second() == m_lastTimeSeen.second()) { + // avoid unnecessary repaints + return; + } + + if (Plasma::ToolTipManager::self()->isVisible(this)) { + updateTipContent(); + } + updateClockApplet(data); + + m_lastTimeSeen = m_time; + + update(); +} + +void BinaryClock::createClockConfigurationInterface(KConfigDialog *parent) +{ + QWidget *widget = new QWidget(); + ui.setupUi(widget); + parent->addPage(widget, i18n("Appearance"), QLatin1String("view-media-visualization")); + + ui.showSecondHandCheckBox->setChecked(m_showSeconds); + ui.showGridCheckBox->setChecked(m_showGrid); + ui.showOffLedsCheckBox->setChecked(m_showOffLeds); + + QButtonGroup *onLedsGroup = new QButtonGroup(widget); + onLedsGroup->addButton(ui.onLedsDefaultColorRadioButton); + onLedsGroup->addButton(ui.onLedsCustomColorRadioButton); + + QButtonGroup *offLedsGroup = new QButtonGroup(widget); + offLedsGroup->addButton(ui.offLedsDefaultColorRadioButton); + offLedsGroup->addButton(ui.offLedsCustomColorRadioButton); + + ui.onLedsDefaultColorRadioButton->setChecked(!m_customOnLedsColor); + ui.offLedsDefaultColorRadioButton->setChecked(!m_customOffLedsColor); + ui.gridDefaultColorRadioButton->setChecked(!m_customGridColor); + + ui.onLedsCustomColorRadioButton->setChecked(m_customOnLedsColor); + ui.offLedsCustomColorRadioButton->setChecked(m_customOffLedsColor); + ui.gridCustomColorRadioButton->setChecked(m_customGridColor); + + KConfigGroup cg = config(); + ui.onLedsCustomColorButton->setColor(cg.readEntry("onLedsColor", m_onLedsColor)); + ui.offLedsCustomColorButton->setColor(cg.readEntry("offLedsColor", m_offLedsColor)); + ui.gridCustomColorButton->setColor(cg.readEntry("gridColor", m_gridColor)); + + connect(ui.showSecondHandCheckBox, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); + connect(ui.showGridCheckBox, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); + connect(ui.showOffLedsCheckBox, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); + connect(onLedsGroup, SIGNAL(buttonReleased(int)), parent, SLOT(settingsModified())); + connect(offLedsGroup, SIGNAL(buttonReleased(int)), parent, SLOT(settingsModified())); + connect(ui.showOffLedsCheckBox, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); + connect(ui.showGridCheckBox, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); +} + +void BinaryClock::clockConfigAccepted() +{ + KConfigGroup cg = config(); + m_showSeconds = ui.showSecondHandCheckBox->isChecked(); + m_showGrid = ui.showGridCheckBox->isChecked(); + m_showOffLeds = ui.showOffLedsCheckBox->isChecked(); + + m_customOnLedsColor = ui.onLedsCustomColorRadioButton->isChecked(); + m_customOffLedsColor = ui.offLedsCustomColorRadioButton->isChecked(); + m_customGridColor = ui.gridCustomColorRadioButton->isChecked(); + + if (m_customOnLedsColor){ + m_onLedsColor = ui.onLedsCustomColorButton->color(); + } + + if (m_customOffLedsColor){ + m_offLedsColor = ui.offLedsCustomColorButton->color(); + } + + if (m_customGridColor){ + m_gridColor = ui.gridCustomColorButton->color(); + } + + cg.writeEntry("showSeconds", m_showSeconds); + cg.writeEntry("showGrid", m_showGrid); + cg.writeEntry("showOffLeds", m_showOffLeds); + + cg.writeEntry("customOnLedsColor", m_customOnLedsColor); + cg.writeEntry("customOffLedsColor", m_customOffLedsColor); + cg.writeEntry("customGridColor", m_customGridColor); + + cg.writeEntry("onLedsColor", ui.onLedsCustomColorButton->color()); + cg.writeEntry("offLedsColor", ui.offLedsCustomColorButton->color()); + cg.writeEntry("gridColor", ui.gridCustomColorButton->color()); + + dataEngine(QLatin1String("time"))->disconnectSource(currentTimezone(), this); + connectToEngine(); + + update(); + emit configNeedsSaving(); +} + +void BinaryClock::clockConfigChanged() +{ + KConfigGroup cg = config(); + m_showSeconds = cg.readEntry("showSeconds", m_showSeconds); + m_showGrid = cg.readEntry("showGrid", m_showGrid); + m_showOffLeds = cg.readEntry("showOffLeds", m_showOffLeds); + + m_customOnLedsColor = cg.readEntry("customOnLedsColor", false); + m_customOffLedsColor = cg.readEntry("customOffLedsColor", false); + m_customGridColor = cg.readEntry("customGridColor", false); + + updateColors(); +} + +void BinaryClock::changeEngineTimezone(const QString &oldTimezone, const QString &newTimezone) +{ + dataEngine(QLatin1String("time"))->disconnectSource(oldTimezone, this); + + Plasma::DataEngine* timeEngine = dataEngine(QLatin1String("time")); + if (m_showSeconds) { + timeEngine->connectSource(newTimezone, this, 500); + } else { + timeEngine->connectSource(newTimezone, this, 6000, Plasma::AlignToMinute); + } +} + +void BinaryClock::updateColors() +{ + KConfigGroup cg = config(); + + m_onLedsColor = QColor(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor)); + + if (m_customOnLedsColor){ + m_onLedsColor = cg.readEntry("onLedsColor", m_onLedsColor); + } + + m_offLedsColor = QColor(m_onLedsColor); + m_offLedsColor.setAlpha(40); + + if (m_customOffLedsColor){ + m_offLedsColor = cg.readEntry("offLedsColor", m_offLedsColor); + } + + m_gridColor = QColor(m_onLedsColor); + m_gridColor.setAlpha(60); + + if (m_customGridColor){ + m_gridColor = cg.readEntry("gridColor", m_gridColor); + } + + update(); +} + +void BinaryClock::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, + const QRect &contentsRect) +{ + Q_UNUSED(option); + + if (! m_time.isValid()) { + return; + } + + QSizeF m_size = contentsRect.size(); + int appletHeight = (int) contentsRect.height(); + int appletWidth = (int) contentsRect.width(); + int dots = m_showSeconds ? 6 : 4; + + int rectSize = qMax(1, qMin((appletHeight - 3) / 4, (appletWidth - 3) / dots)); + int yPos = ((appletHeight - 4 * rectSize) / 2) + contentsRect.topLeft().y(); + int xPos = ((appletWidth - (rectSize * dots) - 5) / 2) + contentsRect.topLeft().x(); + + int timeDigits[6] = {m_time.hour() / 10, m_time.hour() % 10, + m_time.minute() / 10, m_time.minute() % 10, + m_time.second() / 10, m_time.second() % 10}; + + for (int i = 0; i < dots; i++) { + for (int j = 0; j < 4; j++) { + if (timeDigits[i] & (1 << (3 - j))) { + p->fillRect(xPos + (i * (rectSize + 1)), yPos + (j * (rectSize + 1)), rectSize, rectSize, m_onLedsColor); + } else if (m_showOffLeds) { + p->fillRect(xPos + (i * (rectSize + 1)), yPos + (j * (rectSize + 1)), rectSize, rectSize, m_offLedsColor); + } + } + } + + if (m_showGrid) { + p->setPen(m_gridColor); + p->drawRect((xPos - 1), (yPos - 1), + (dots * (rectSize + 1)), (4 * (rectSize + 1)) ); + + for (int i = 1; i < dots; i++) { + for (int j = 0; j < 4; j++) { + p->drawLine((xPos + (i * (rectSize + 1)) - 1), (yPos + (j * (rectSize + 1))), + (xPos + (i * (rectSize + 1)) - 1), (yPos + (j * (rectSize + 1)) + rectSize - 1) ); + } + } + + for (int j = 1; j < 4; j++) { + p->drawLine(xPos, (yPos + (j * (rectSize + 1)) - 1), + (xPos + (dots * (rectSize + 1)) - 2), (yPos + (j * (rectSize + 1)) - 1) ); + } + } +} + +#include "binaryclock.moc" diff --git a/kdeplasma-addons/applets/binary-clock/binaryclock.h b/kdeplasma-addons/applets/binary-clock/binaryclock.h new file mode 100644 index 00000000..5ae83dff --- /dev/null +++ b/kdeplasma-addons/applets/binary-clock/binaryclock.h @@ -0,0 +1,87 @@ +/*************************************************************************** + * Copyright 2007 by Riccardo Iaconelli * + * Copyright 2007 by Davide Bettio * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef BINARYCLOCK_H +#define BINARYCLOCK_H + +#include + +#include + +#include "ui_clockConfig.h" + +class QTime; +class QColor; + +namespace Plasma { + class DataEngine; +} + +class BinaryClock : public ClockApplet +{ + Q_OBJECT + public: + BinaryClock(QObject *parent, const QVariantList &args); + ~BinaryClock(); + + void init(); + void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect& contentsRect); + void constraintsEvent(Plasma::Constraints constraints); + + public slots: + void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data); + + protected: + void createClockConfigurationInterface(KConfigDialog *parent); + void clockConfigAccepted(); + void clockConfigChanged(); + void changeEngineTimezone(const QString &oldTimezone, const QString &newTimezone); + + private slots: + void updateColors(); + + private: + void connectToEngine(); + + int getWidthFromHeight(int h) const; + int getHeightFromWidth(int w) const; + + bool m_showSeconds; + bool m_showOffLeds; + bool m_showGrid; + + bool m_customOnLedsColor; + bool m_customOffLedsColor; + bool m_customGridColor; + + QColor m_onLedsColor; + QColor m_offLedsColor; + QColor m_gridColor; + + QTime m_lastTimeSeen; + QTime m_time; + int m_updateIndex; + + Ui::clockConfig ui; +}; + +K_EXPORT_PLASMA_APPLET(binaryclock, BinaryClock) + +#endif diff --git a/kdeplasma-addons/applets/binary-clock/clockConfig.ui b/kdeplasma-addons/applets/binary-clock/clockConfig.ui new file mode 100644 index 00000000..0c2cec79 --- /dev/null +++ b/kdeplasma-addons/applets/binary-clock/clockConfig.ui @@ -0,0 +1,423 @@ + + clockConfig + + + + 0 + 0 + 586 + 349 + + + + + 400 + 300 + + + + + + + + 75 + true + + + + Appearance + + + + + + + Active LEDs: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + Use custom color for active LEDs: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 7 + + + + + + + + Inactive LEDs: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Show the inactive LEDs + + + Check this if you want to see the inactive LEDs. + + + Show + + + true + + + + + + + Use theme color + + + + + + + + + + 0 + 0 + + + + Use custom color for inactive LEDs: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 7 + + + + + + + + Grid: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Show the grid + + + Check this if you want to see a grid around leds. + + + Show + + + true + + + + + + + Use theme color + + + + + + + + + Use custom grid color: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 13 + + + + + + + + + 75 + true + + + + Information + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Use theme color + + + + + + + Seconds: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Show the seconds LEDs + + + Check this if you want to display seconds LEDs in order to see the seconds. + + + Show + + + + + + + + KColorButton + QPushButton +
kcolorbutton.h
+
+
+ + + + onLedsDefaultColorRadioButton + toggled(bool) + onLedsCustomColorButton + setDisabled(bool) + + + 558 + 55 + + + 423 + 82 + + + + + offLedsDefaultColorRadioButton + toggled(bool) + offLedsCustomColorButton + setDisabled(bool) + + + 566 + 148 + + + 424 + 172 + + + + + gridDefaultColorRadioButton + toggled(bool) + gridCustomColorButton + setDisabled(bool) + + + 547 + 243 + + + 395 + 267 + + + + + showOffLedsCheckBox + toggled(bool) + offLedsDefaultColorRadioButton + setEnabled(bool) + + + 164 + 124 + + + 184 + 147 + + + + + showOffLedsCheckBox + toggled(bool) + offLedsCustomColorRadioButton + setEnabled(bool) + + + 296 + 120 + + + 296 + 176 + + + + + showGridCheckBox + toggled(bool) + gridDefaultColorRadioButton + setEnabled(bool) + + + 165 + 217 + + + 191 + 238 + + + + + showGridCheckBox + toggled(bool) + gridCustomColorRadioButton + setEnabled(bool) + + + 264 + 210 + + + 256 + 268 + + + + +
diff --git a/kdeplasma-addons/applets/binary-clock/plasma-applet-binaryclock.desktop b/kdeplasma-addons/applets/binary-clock/plasma-applet-binaryclock.desktop new file mode 100644 index 00000000..fcd33c42 --- /dev/null +++ b/kdeplasma-addons/applets/binary-clock/plasma-applet-binaryclock.desktop @@ -0,0 +1,129 @@ +[Desktop Entry] +Name=Binary Clock +Name[ar]=ساعة ثنائية +Name[ast]=Reló binariu +Name[bs]=binarni sat +Name[ca]=Rellotge binari +Name[ca@valencia]=Rellotge binari +Name[cs]=Binární hodiny +Name[da]=Binært ur +Name[de]=Binäre Uhr +Name[el]=Δυαδικό ρολόι +Name[en_GB]=Binary Clock +Name[es]=Reloj binario +Name[et]=Binaarkell +Name[eu]=Ordulari bitarra +Name[fi]=Binaarikello +Name[fr]=Horloge binaire +Name[ga]=Clog Dénártha +Name[gl]=Reloxo binario +Name[he]=שעון בִּינָרִי +Name[hr]=Binarni sat +Name[hu]=Bináris óra +Name[is]=Tvíundarklukka +Name[it]=Orologio binario +Name[ja]=バイナリ時計 +Name[kk]=Бинарлы сағат +Name[km]=នាឡិកា​គោល​ពីរ +Name[ko]=바이너리 시계 +Name[ku]=Demjimêra Cot +Name[lt]=Dvejetainis laikrodis +Name[lv]=Binārs pulkstenis +Name[mr]=बायनरी घड्याळ +Name[nb]=Binær klokke +Name[nds]=Bineerklock +Name[nl]=Binaire klok +Name[nn]=Binærklokke +Name[pa]=ਬਾਈਨਰੀ ਘੜੀ +Name[pl]=Zegar dwójkowy +Name[pt]=Relógio Binário +Name[pt_BR]=Relógio binário +Name[ro]=Ceas binar +Name[ru]=Двоичные часы +Name[sk]=Binárne hodiny +Name[sl]=Dvojiška ura +Name[sq]=Orë Bianre +Name[sr]=бинарни сат +Name[sr@ijekavian]=бинарни сат +Name[sr@ijekavianlatin]=binarni sat +Name[sr@latin]=binarni sat +Name[sv]=Binärklocka +Name[th]=นาฬิกาไบนารี +Name[tr]=İkili Saat +Name[uk]=Двійковий годинник +Name[wa]=Ôrlodje binaire +Name[x-test]=xxBinary Clockxx +Name[zh_CN]=二进制时钟 +Name[zh_TW]=二進制時鐘 +Comment=Time displayed in binary format +Comment[ar]=الوقت يظهر بالتنسيق الثنائي +Comment[ast]=Hora amosada en formatu binariu +Comment[bs]=Vrijeme prikazano u binarnom obliku +Comment[ca]=L'hora mostrada en format binari +Comment[ca@valencia]=L'hora mostrada en format binari +Comment[cs]=Zobrazení času v binárním formátu +Comment[da]=Tiden vist i binært format +Comment[de]=Zeitanzeige im Binärformat +Comment[el]=Εμφάνιση της ώρας σε δυαδική μορφή +Comment[en_GB]=Time displayed in binary format +Comment[es]=Hora mostrada en formato binario +Comment[et]=Aja näitamine binaarkujul +Comment[eu]=Ordua formatu bitarrean bistaratuta +Comment[fi]=Binaarimuotoinen ajanesitys +Comment[fr]=Heure affichée au format numérique +Comment[ga]=An t-am i bhformáid dhénártha +Comment[gl]=Mostra a hora no formato binario +Comment[he]=השעה מוצגת בפורמט בִּינָרִי +Comment[hr]=Vrijeme je prikazano u binarnom formatu +Comment[hu]=Bináris formátumban megjelenített idő +Comment[is]=Sýnir tímann á tvíundarformi +Comment[it]=Ora mostrata in formato binario +Comment[ja]=時間をバイナリ形式で表示します +Comment[kk]=Бинарлы пішімдегі уақыт +Comment[km]=បាន​បង្ហាញ​ពេលវេលា​គិត​ជា​ទ្រង់ទ្រាយ​គោល​ពីរ +Comment[ko]=이진수로 시각 표시 +Comment[ku]=Dem di teşeya cot-bûyî de dê bê nîşandan +Comment[lt]=Laikas rodomas skaitmeniniu formatu +Comment[lv]=Rāda laiku binārā formātā +Comment[mr]=बायनरी पद्धतिने वेळ दर्शविली जाते +Comment[nb]=Tiden vist i binærformat +Comment[nds]=Tiet in Bineerformaat wiest +Comment[nl]=De tijd in binair formaat +Comment[nn]=Klokka vist i binærformat +Comment[pa]=ਬਾਈਨਰੀ ਫਾਰਮੈਟ ਵਿੱਚ ਸਮਾਂ ਵੇਖੋ +Comment[pl]=Czas wyświetlany w formacie dwójkowym +Comment[pt]=Hora mostrada no formato binário +Comment[pt_BR]=Hora exibida em formato binário +Comment[ro]=Ora afișată în format binar +Comment[ru]=Время в двоичной записи +Comment[sk]=Čas zobrazený v binárnom formáte +Comment[sl]=Čas je prikazan v dvojiški obliki +Comment[sr]=Време приказано у бинарном облику +Comment[sr@ijekavian]=Вријеме приказано у бинарном облику +Comment[sr@ijekavianlatin]=Vrijeme prikazano u binarnom obliku +Comment[sr@latin]=Vreme prikazano u binarnom obliku +Comment[sv]=Tid visad med binärformat +Comment[th]=แสดงเวลาในรูปแบบไบนารี +Comment[tr]=Saati ikili biçimde görüntüle +Comment[uk]=Час, показаний у двійковому форматі +Comment[wa]=Eure håynêye e cogne binaire +Comment[x-test]=xxTime displayed in binary formatxx +Comment[zh_CN]=以二进制格式显示的时间 +Comment[zh_TW]=以二進位格式顯示時間 +Icon=clock +Type=Service +ServiceTypes=Plasma/Applet + +X-KDE-Library=plasma_applet_binaryclock +X-KDE-PluginInfo-Author=Davide Bettio +X-KDE-PluginInfo-Email=davide.bettio@kdemail.net +X-KDE-PluginInfo-Name=binaryclock +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-Category=Date and Time +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true + +X-Plasma-Requires-FileDialog=Unused +X-Plasma-Requires-LaunchApp=Unused diff --git a/kdeplasma-addons/applets/blackboard/CMakeLists.txt b/kdeplasma-addons/applets/blackboard/CMakeLists.txt new file mode 100644 index 00000000..b9f085d5 --- /dev/null +++ b/kdeplasma-addons/applets/blackboard/CMakeLists.txt @@ -0,0 +1,29 @@ + +# Project needs a name of course +project(blackboard) + +# Find the required Libaries +find_package(KDE4 REQUIRED) +include(KDE4Defaults) + + +add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) +include_directories( + ${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${KDE4_INCLUDES} + ) + +# We add our source code here +set(blackboard_SRCS blackboard.cpp blackboardwidget.cpp) + +# Now make sure all files get to the right place +kde4_add_plugin(plasma_applet_blackboard ${blackboard_SRCS}) +target_link_libraries(plasma_applet_blackboard + ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS}) + +install(TARGETS plasma_applet_blackboard + DESTINATION ${PLUGIN_INSTALL_DIR}) + +install(FILES plasma-applet-blackboard.desktop + DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/kdeplasma-addons/applets/blackboard/blackboard.cpp b/kdeplasma-addons/applets/blackboard/blackboard.cpp new file mode 100644 index 00000000..0f77d83d --- /dev/null +++ b/kdeplasma-addons/applets/blackboard/blackboard.cpp @@ -0,0 +1,95 @@ +/*************************************************************************** + * Copyright 2009 by Davide Bettio * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "blackboard.h" + +#include + +#include +#include + +#include +#include + +BlackBoard::BlackBoard(QObject *parent, const QVariantList &args) + : Plasma::Applet(parent, args), + blackBoard(0) +{ + setAspectRatioMode(Plasma::IgnoreAspectRatio); + resize(200, 200); + setHasConfigurationInterface(false); + //setBackgroundHints(NoBackground); +} + +BlackBoard::~BlackBoard() +{ + if (blackBoard) { + blackBoard->saveImage(); + } +} + +void BlackBoard::init() +{ + QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(Qt::Vertical); + blackBoard = new BlackBoardWidget(this); + blackBoard->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); + mainLayout->addItem(blackBoard); + + buttonsLayout = new QGraphicsLinearLayout(Qt::Horizontal); + + addColorButton(QColor(Qt::red)); + addColorButton(QColor(Qt::yellow)); + addColorButton(QColor(Qt::green)); + addColorButton(QColor(Qt::blue)); + addColorButton(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor)); + + Plasma::ToolButton *eraseB = new Plasma::ToolButton(this); + eraseB->setIcon(KIcon(QLatin1String("edit-delete"))); + buttonsLayout->addItem(eraseB); + connect(eraseB, SIGNAL(clicked()), blackBoard, SLOT(erase())); + + mainLayout->addItem(buttonsLayout); + + setLayout(mainLayout); +} + +void BlackBoard::addColorButton(QColor color) +{ + QPixmap colorPixmap(22, 22); + colorPixmap.fill(color); + + Plasma::ToolButton *tB = new Plasma::ToolButton(this); + tB->setProperty("color", color); + tB->setIcon(colorPixmap); + buttonsLayout->addItem(tB); + connect(tB, SIGNAL(clicked()), this, SLOT(changeColor())); +} + +void BlackBoard::changeColor() +{ + QObject *sender = QObject::sender(); + + if (!sender || sender->property("color").type() != QVariant::Color) { + return; + } + + blackBoard->setBrushColor(sender->property("color").value()); +} + +#include "blackboard.moc" diff --git a/kdeplasma-addons/applets/blackboard/blackboard.h b/kdeplasma-addons/applets/blackboard/blackboard.h new file mode 100644 index 00000000..2ea066db --- /dev/null +++ b/kdeplasma-addons/applets/blackboard/blackboard.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright 2009 by Davide Bettio * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef BLACKBOARD_H +#define BLACKBOARD_H + +#include + +#include "blackboardwidget.h" + +class QGraphicsLinearLayout; + +class BlackBoard : public Plasma::Applet +{ + Q_OBJECT + + public: + BlackBoard(QObject *parent, const QVariantList &args); + ~BlackBoard(); + + void init(); + + void addColorButton(QColor color); + + private slots: + void changeColor(); + + private: + BlackBoardWidget *blackBoard; + QGraphicsLinearLayout *buttonsLayout; +}; + +K_EXPORT_PLASMA_APPLET(blackboard, BlackBoard) + +#endif diff --git a/kdeplasma-addons/applets/blackboard/blackboardwidget.cpp b/kdeplasma-addons/applets/blackboard/blackboardwidget.cpp new file mode 100644 index 00000000..58e47548 --- /dev/null +++ b/kdeplasma-addons/applets/blackboard/blackboardwidget.cpp @@ -0,0 +1,182 @@ +/*************************************************************************** + * Copyright 2009 by Davide Bettio * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "blackboardwidget.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +BlackBoardWidget::BlackBoardWidget(Plasma::Applet *parent) + : QGraphicsWidget(parent) +{ + m_changed = false; + setAcceptTouchEvents(true); + m_parentApplet = parent; + + m_color = QColor(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor)); + m_oldPoint = QPointF(-1, 0); + + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(saveImage())); + timer->start(600000); + + QTimer::singleShot(500, this, SLOT(loadImage())); +} + +BlackBoardWidget::~BlackBoardWidget() +{ +} + +void BlackBoardWidget::saveImage() +{ + if (m_parentApplet->destroyed()){ + KIO::del(imagePath()); + }else{ + if (m_changed){ + KSaveFile imageFile(imagePath()); + imageFile.open(); + m_pixmap.save(&imageFile, "PNG"); + imageFile.finalize(); + imageFile.close(); + } + } +} + +void BlackBoardWidget::loadImage() +{ + m_painter.end(); + m_pixmap.load(imagePath(), "PNG"); + update(contentsRect()); + m_painter.begin(&m_pixmap); + m_painter.setPen(QPen(m_color, 3)); +} + +void BlackBoardWidget::mousePressEvent(QGraphicsSceneMouseEvent *) +{ + update(contentsRect()); +} + +void BlackBoardWidget::drawSegment(QPointF point0, QPointF point1, qreal penRadius) +{ + m_painter.setPen(QPen(m_color, penRadius)); + m_painter.drawLine(point0, point1); + + qreal x = qMin(point0.x(), point1.x()) -(penRadius + 1); + qreal y = qMin(point0.y(), point1.y()) -(penRadius + 1); + qreal w = qMax(point0.x(), point1.x()) + penRadius + 1 - x; + qreal h = qMax(point0.y(), point1.y()) + penRadius + 1 - y; + + update(x,y,w,h); + m_changed = true; +} + +bool BlackBoardWidget::event(QEvent *event) +{ + switch (event->type()) { + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: { + QList touchPoints = static_cast(event)->touchPoints(); + foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints) { + switch (touchPoint.state()) { + case Qt::TouchPointStationary: + // don't do anything if this touch point hasn't moved + continue; + default: + drawSegment(touchPoint.lastPos(), touchPoint.pos(), 3*touchPoint.pressure()); + break; + } + } + break; + } + default: + return QGraphicsWidget::event(event); + } + return true; +} + +void BlackBoardWidget::mouseMoveEvent(QGraphicsSceneMouseEvent * event) +{ + QPointF lastPos = event->lastPos(); + + if (m_oldPoint.x() != -1){ + drawSegment(m_oldPoint, lastPos, 1); + } + + m_oldPoint = lastPos; +} + +void BlackBoardWidget::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) +{ + mouseMoveEvent(event); + m_oldPoint.setX(-1); +} + +void BlackBoardWidget::resizeEvent(QGraphicsSceneResizeEvent *event) +{ + Q_UNUSED(event) + + if (m_painter.isActive()) + m_painter.end(); + + QPixmap tmpPixmap = m_pixmap; + m_pixmap = QPixmap(contentsRect().width(), contentsRect().height()); + m_pixmap.fill(Qt::transparent); + + m_painter.begin(&m_pixmap); + m_painter.drawPixmap(0, 0, tmpPixmap); + m_painter.setPen(QPen(m_color, 3)); +} + +void BlackBoardWidget::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(widget) + + p->drawPixmap(option->exposedRect, m_pixmap, option->exposedRect); +} + +void BlackBoardWidget::setBrushColor(QColor color) +{ + m_color = color; + m_painter.setPen(QPen(m_color, 3)); +} + +void BlackBoardWidget::erase() +{ + m_pixmap.fill(Qt::transparent); + update(contentsRect()); + KIO::del(imagePath()); +} + +QString BlackBoardWidget::imagePath() +{ + return KStandardDirs::locateLocal("data", QLatin1String("plasma-desktop-datastorage/blackboard-") + QString::number(m_parentApplet->id()) + QLatin1String(".png")); +} + +#include "blackboardwidget.moc" diff --git a/kdeplasma-addons/applets/blackboard/blackboardwidget.h b/kdeplasma-addons/applets/blackboard/blackboardwidget.h new file mode 100644 index 00000000..7464542f --- /dev/null +++ b/kdeplasma-addons/applets/blackboard/blackboardwidget.h @@ -0,0 +1,75 @@ +/*************************************************************************** + * Copyright 2009 by Davide Bettio * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef BLACKBOARDWIDGET_H +#define BLACKBOARDWIDGET_H + +#include +#include +#include +#include + +class QGraphicsSceneMouseEvent; +class QStyleOptionGraphicsItem; + +namespace Plasma +{ + class Applet; +} + +class BlackBoardWidget : public QGraphicsWidget +{ + Q_OBJECT + + public: + BlackBoardWidget(Plasma::Applet *parent); + ~BlackBoardWidget(); + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent ( QGraphicsSceneMouseEvent *event ); + void mouseReleaseEvent ( QGraphicsSceneMouseEvent *event ); + void resizeEvent(QGraphicsSceneResizeEvent *event); + + void setBrushColor(QColor color); + + protected: + bool event(QEvent *event); + + public Q_SLOTS: + void saveImage(); + void erase(); + + private Q_SLOTS: + void loadImage(); + + private: + QString imagePath(); + + void drawSegment(QPointF point0, QPointF point1, qreal penRadius); + bool m_changed; + Plasma::Applet *m_parentApplet; + QString m_id; + QColor m_color; + QPixmap m_pixmap; + QPointF m_oldPoint; + QPainter m_painter; +}; + +#endif diff --git a/kdeplasma-addons/applets/blackboard/plasma-applet-blackboard.desktop b/kdeplasma-addons/applets/blackboard/plasma-applet-blackboard.desktop new file mode 100644 index 00000000..d892374f --- /dev/null +++ b/kdeplasma-addons/applets/blackboard/plasma-applet-blackboard.desktop @@ -0,0 +1,110 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Black Board +Name[ar]=لوح طباشير +Name[bs]=tabla +Name[ca]=Pissarra +Name[ca@valencia]=Pissarra +Name[cs]=Tabule +Name[da]=Tavle +Name[de]=Tafel +Name[el]=Μαυροπίνακας +Name[en_GB]=Black Board +Name[es]=Pizarra +Name[et]=Tahvel +Name[eu]=Arbela +Name[fi]=Liitutaulu +Name[fr]=Tableau noir +Name[ga]=Clár Dubh +Name[gl]=Encerado +Name[hr]=Školska ploča +Name[hu]=Fekete tábla +Name[it]=Lavagna +Name[ja]=黒板 +Name[kk]=Тақта +Name[km]=ក្ដារ​ពណ៌​ខ្មៅ +Name[ko]=칠판 +Name[lt]=Lenta +Name[lv]=Tāfele +Name[mr]=काळा फळा +Name[nb]=Tavle +Name[nds]=Swatt Brett +Name[nl]=Black Board +Name[nn]=Tavle +Name[pa]=ਬਲੈਕ ਬੋਰਡ +Name[pl]=Czarna tablica +Name[pt]=Quadro Preto +Name[pt_BR]=Quadro negro +Name[ro]=Tablă de scris +Name[ru]=Доска +Name[sk]=Čierna tabuľa +Name[sl]=Tabla +Name[sr]=табла +Name[sr@ijekavian]=табла +Name[sr@ijekavianlatin]=tabla +Name[sr@latin]=tabla +Name[sv]=Svarta tavlan +Name[th]=กระดานดำ +Name[tr]=Kara Tahta +Name[uk]=Дошка +Name[wa]=Noer Platea +Name[x-test]=xxBlack Boardxx +Name[zh_CN]=黑板 +Name[zh_TW]=黑板 +Comment=Draw a quick note or a colorful image +Comment[ar]=ارسم ملاحظة سريعة أو صورة ملونة +Comment[bs]=Napiši brzu napomenu ili obojenu sliku +Comment[ca]=Per dibuixar una nota ràpida o una imatge a tot color +Comment[ca@valencia]=Per dibuixar una nota ràpida o una imatge a tot color +Comment[cs]=Nakreslete rychlou poznámku nebo barevný obrázek +Comment[da]=Tegn en kviknote eller et farverigt billede +Comment[de]=Zeigt eine kurze Notiz oder ein farbiges Bild +Comment[el]=Σχεδιάστε μια γρήγορη σημείωση ή μια χρωματιστή εικόνα +Comment[en_GB]=Draw a quick note or a colourful image +Comment[es]=Dibujar una nota rápida o una imagen a color +Comment[et]=Kiiresti märkuse või värvilise pildi kirjutamine/joonistamine +Comment[fi]=Piirrä pikainen muistiinpano tai värikäs kuva +Comment[fr]=Réaliser une note rapide ou une image colorée +Comment[gl]=Debuxe unha nota rápida ou unha imaxe con moita cor. +Comment[hu]=Gyors jegyzet vagy színes kép rajzolása +Comment[it]=Crea una breve nota o un'immagine colorata +Comment[kk]=Шұғыл жазуды не түрлі-түсті кескінде салу +Comment[ko]=빠른 메모나 그림 그리기 +Comment[mr]=रंगीत प्रतिमा काढा किंवा नोंद लिहा +Comment[nb]=Tegn et raskt notat eller et fargerikt bilde +Comment[nds]=En Kortnotiz oder en klöörriek Bild wiesen +Comment[nl]=Teken een snelle notitie of een kleurrijke afbeelding +Comment[pl]=Rysowanie szybkich notatek lub kolorowych obrazów +Comment[pt]=Desenhar uma nota rápida ou uma imagem colorida +Comment[pt_BR]=Desenha uma nota rápida ou uma imagem colorida +Comment[ro]=Desenează o notă rapidă pe o imagine colorată +Comment[ru]=Быстрая заметка или цветной рисунок +Comment[sk]=Kresliť rýchlu poznámku alebo farebný obrázok +Comment[sl]=Narišite kratko sporočilo ali barvito sliko +Comment[sr]=Нажврљајте брзу белешку или шарену слику +Comment[sr@ijekavian]=Нажврљајте брзу белешку или шарену слику +Comment[sr@ijekavianlatin]=Nažvrljajte brzu belešku ili šarenu sliku +Comment[sr@latin]=Nažvrljajte brzu belešku ili šarenu sliku +Comment[sv]=Skriv en snabb anmärkning eller rita en färgrik bild +Comment[tr]=Hızlı bir not veya renkli bir görüntü çizin +Comment[uk]=Малювання нотатки або кольорового зображення +Comment[x-test]=xxDraw a quick note or a colorful imagexx +Comment[zh_CN]=绘制便笺或者画图 +Comment[zh_TW]=繪製一份快速備忘或彩色影像 +Type=Service +Icon=applications-education +ServiceTypes=Plasma/Applet +X-Plasma-ContainmentCategories=desktop +X-KDE-Library=plasma_applet_blackboard +X-KDE-PluginInfo-Author=Davide Bettio +X-KDE-PluginInfo-Email=davide.bettio@kdemail.net +X-KDE-PluginInfo-Name=blackboard +X-KDE-PluginInfo-Version=0.1 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-Category=Utilities +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true + +X-Plasma-Requires-FileDialog=Unused +X-Plasma-Requires-LaunchApp=Unused diff --git a/kdeplasma-addons/applets/bookmarks/CMakeLists.txt b/kdeplasma-addons/applets/bookmarks/CMakeLists.txt new file mode 100644 index 00000000..bdc3300c --- /dev/null +++ b/kdeplasma-addons/applets/bookmarks/CMakeLists.txt @@ -0,0 +1,18 @@ +project( plasma-bookmarks ) + +set( bookmarks_SRCS + generalconfigeditor.cpp + bookmarksplasmoid.cpp + main.cpp +) + +kde4_add_plugin( plasma_applet_bookmarks ${bookmarks_SRCS}) + +target_link_libraries( plasma_applet_bookmarks + ${KDE4_PLASMA_LIBS} + ${KDE4_KDEUI_LIBS} + ${KDE4_KIO_LIBS} +) + +install( TARGETS plasma_applet_bookmarks DESTINATION ${PLUGIN_INSTALL_DIR}) +install( FILES plasma-applet-bookmarks.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) diff --git a/kdeplasma-addons/applets/bookmarks/Messages.sh b/kdeplasma-addons/applets/bookmarks/Messages.sh new file mode 100644 index 00000000..e88f7dc2 --- /dev/null +++ b/kdeplasma-addons/applets/bookmarks/Messages.sh @@ -0,0 +1,2 @@ +#! /usr/bin/env bash +$XGETTEXT *.cpp -o $podir/plasma_applet_bookmarks.pot diff --git a/kdeplasma-addons/applets/bookmarks/bookmarkowner.h b/kdeplasma-addons/applets/bookmarks/bookmarkowner.h new file mode 100644 index 00000000..298a00f6 --- /dev/null +++ b/kdeplasma-addons/applets/bookmarks/bookmarkowner.h @@ -0,0 +1,53 @@ +/* + This file is part of the Bookmarks plasmoid, part of the KDE project. + + Copyright 2009 Friedrich W. H. Kossebau + + 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) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + 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, see . +*/ + +#ifndef BOOKMARKOWNER_H +#define BOOKMARKOWNER_H + +// KDE +#include +#include + + +class BookmarkOwner : public KBookmarkOwner +{ +public: + BookmarkOwner(); + +public: // KBookmarkOwner API + virtual bool enableOption(BookmarkOption) const; + virtual void openBookmark(const KBookmark& bookmark, Qt::MouseButtons, Qt::KeyboardModifiers); +}; + + +inline BookmarkOwner::BookmarkOwner() : KBookmarkOwner() {} + +inline bool BookmarkOwner::enableOption(BookmarkOption) const +{ + return false; +} +inline void BookmarkOwner::openBookmark(const KBookmark& bookmark, Qt::MouseButtons, Qt::KeyboardModifiers) +{ + new KRun(bookmark.url(), (QWidget*)0); +} + +#endif diff --git a/kdeplasma-addons/applets/bookmarks/bookmarksplasmoid.cpp b/kdeplasma-addons/applets/bookmarks/bookmarksplasmoid.cpp new file mode 100644 index 00000000..2be64e7d --- /dev/null +++ b/kdeplasma-addons/applets/bookmarks/bookmarksplasmoid.cpp @@ -0,0 +1,199 @@ +/* + This file is part of the Bookmarks plasmoid, part of the KDE project. + + Copyright 2009-2010 Friedrich W. H. Kossebau + + 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) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + 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, see . +*/ + +#include "bookmarksplasmoid.h" + +// Plasmoid +#include "generalconfigeditor.h" +#include "bookmarkowner.h" +// Plasma +#include +#include +// KDE +#include +#include +#include +#include +#include +#include +// Qt +#include +#include + + +namespace Plasma +{ + +static const char bookmarkFolderAddressConfigKey[] = "BookmarkFolderAddress"; + + +BookmarksPlasmoid::BookmarksPlasmoid(QObject* parent, const QVariantList& args) + : Applet(parent, args), + mIcon(0), + mBookmarkManager(0), + mBookmarkMenu(0), + mBookmarkOwner(0) +{ +} + + +void BookmarksPlasmoid::init() +{ + mBookmarkManager = KBookmarkManager::userBookmarksManager(); + mBookmarkManager->setEditorOptions(name(), true); + connect(mBookmarkManager, SIGNAL(changed(QString,QString)), SLOT(onBookmarksChanged(QString))); + + // general + setHasConfigurationInterface(true); + connect(this, SIGNAL(activate()), SLOT(toggleMenu())); + Plasma::ToolTipManager::self()->registerWidget(this); + + // context menu + KAction* editorOpener = KStandardAction::editBookmarks(this, SLOT(editBookmarks()), this); + mContextualActions.append(editorOpener); + + // view + setAspectRatioMode(ConstrainedSquare); + setBackgroundHints(NoBackground); + + QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + layout->setSpacing(0); + + mIcon = new IconWidget(KIcon("bookmarks"),"",this); + mIcon->setFlag(ItemIsMovable, false); + connect(mIcon, SIGNAL(pressed(bool)), SLOT(toggleMenu(bool))); + layout->addItem(mIcon); + + + configChanged(); +} + +QList BookmarksPlasmoid::contextualActions() +{ + return mContextualActions; +} + +void BookmarksPlasmoid::updateFolderData() +{ + const KBookmark bookmark = mBookmarkManager->findByAddress(mBookmarkFolderAddress); + + KBookmarkGroup bookmarkFolder = + (bookmark.isNull() || ! bookmark.isGroup()) ? mBookmarkManager->root() : bookmark.toGroup(); + + const bool isRoot = (! bookmarkFolder.hasParent()); + + const QString iconName = isRoot ? QString::fromLatin1("bookmarks") : bookmarkFolder.icon(); + const QString folderName = isRoot ? i18nc("name of the container of all browser bookmarks", + "Bookmarks") : + bookmarkFolder.text(); + const QString comment = isRoot ? i18n("Quick access to your bookmarks.") : bookmarkFolder.description(); + + // icon + mIcon->setIcon(iconName); + // tooltip + Plasma::ToolTipContent toolTipContent(folderName, comment, KIcon(iconName)); + Plasma::ToolTipManager::self()->setContent(this, toolTipContent); +} + +void BookmarksPlasmoid::toggleMenu(bool toggle) +{ + if (! toggle) + return; + + Plasma::ToolTipManager::self()->hide(this); + mIcon->setPressed(); + + const bool isFirstTime = (mBookmarkOwner == 0); + if (isFirstTime) + mBookmarkOwner = new BookmarkOwner(); + + delete mBookmarkMenu; + + KMenu* menu = new KMenu(); + menu->setAttribute(Qt::WA_DeleteOnClose); + connect(menu, SIGNAL(aboutToHide()), mIcon, SLOT(setUnpressed())); + // TODO: only renew if manager emits changed + mBookmarkMenu = new KBookmarkMenu(mBookmarkManager, mBookmarkOwner, menu, mBookmarkFolderAddress); + + menu->popup(popupPosition(menu->size())); + menu->move(popupPosition(menu->size())); + +} + +void BookmarksPlasmoid::toggleMenu() +{ + toggleMenu(true); +} + +void BookmarksPlasmoid::createConfigurationInterface(KConfigDialog* parent) +{ + mGeneralConfigEditor = new GeneralConfigEditor(mBookmarkManager, parent); + mGeneralConfigEditor->setBookmarkFolderAddress(mBookmarkFolderAddress); + const QString pageName = i18nc("@title:tab name of settings page with general parameters","General"); + parent->addPage(mGeneralConfigEditor, pageName, icon()); + connect(parent, SIGNAL(applyClicked()), SLOT(applyConfigChanges())); + connect(parent, SIGNAL(okClicked()), SLOT(applyConfigChanges())); +} + +void BookmarksPlasmoid::applyConfigChanges() +{ + const QString& bookmarkFolderAddress = mGeneralConfigEditor->bookmarkFolderAddress(); + + if (mBookmarkFolderAddress != bookmarkFolderAddress) { + KConfigGroup configGroup = config(); + configGroup.writeEntry(bookmarkFolderAddressConfigKey, bookmarkFolderAddress); + emit configNeedsSaving(); + } +} + +void BookmarksPlasmoid::configChanged() +{ + // read config + KConfigGroup configGroup = config(); + const QString bookmarkFolderAddress = configGroup.readEntry(bookmarkFolderAddressConfigKey, mBookmarkFolderAddress); + + if (mBookmarkFolderAddress != bookmarkFolderAddress) { + mBookmarkFolderAddress = bookmarkFolderAddress; + updateFolderData(); + } +} + +void BookmarksPlasmoid::editBookmarks() +{ + mBookmarkManager->slotEditBookmarksAtAddress(mBookmarkFolderAddress); +} + +void BookmarksPlasmoid::onBookmarksChanged(const QString& address) +{ + Q_UNUSED(address); + + updateFolderData(); +} + +BookmarksPlasmoid::~BookmarksPlasmoid() +{ + delete mBookmarkMenu; + delete mBookmarkOwner; +} + +} diff --git a/kdeplasma-addons/applets/bookmarks/bookmarksplasmoid.h b/kdeplasma-addons/applets/bookmarks/bookmarksplasmoid.h new file mode 100644 index 00000000..ae93df45 --- /dev/null +++ b/kdeplasma-addons/applets/bookmarks/bookmarksplasmoid.h @@ -0,0 +1,85 @@ +/* + This file is part of the Bookmarks plasmoid, part of the KDE project. + + Copyright 2009 Friedrich W. H. Kossebau + + 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) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + 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, see . +*/ + +#ifndef BOOKMARKSPLASMOID_H +#define BOOKMARKSPLASMOID_H + +// Plasma +#include + +class GeneralConfigEditor; +class BookmarkOwner; + +class KBookmarkMenu; +class KBookmarkManager; + + +namespace Plasma +{ +class IconWidget; + + +class BookmarksPlasmoid : public Applet +{ + Q_OBJECT + +public: + BookmarksPlasmoid(QObject* parent, const QVariantList& args); + + virtual ~BookmarksPlasmoid(); + +public: // Plasma::Applet API + virtual void init(); + virtual QList contextualActions(); + virtual void createConfigurationInterface(KConfigDialog* parent); + +public Q_SLOTS: + virtual void configChanged(); + +protected: + void updateFolderData(); + +protected Q_SLOTS: + void toggleMenu(bool toggle); + void toggleMenu(); + void editBookmarks(); + void applyConfigChanges(); + + void onBookmarksChanged(const QString& address); + +private: + QString mBookmarkFolderAddress; + + IconWidget* mIcon; + + QList mContextualActions; + + KBookmarkManager* mBookmarkManager; + KBookmarkMenu* mBookmarkMenu; + BookmarkOwner* mBookmarkOwner; + + GeneralConfigEditor* mGeneralConfigEditor; +}; + +} + +#endif diff --git a/kdeplasma-addons/applets/bookmarks/generalconfigeditor.cpp b/kdeplasma-addons/applets/bookmarks/generalconfigeditor.cpp new file mode 100644 index 00000000..d73f8e6c --- /dev/null +++ b/kdeplasma-addons/applets/bookmarks/generalconfigeditor.cpp @@ -0,0 +1,125 @@ +/* + This file is part of the Bookmarks plasmoid, part of the KDE project. + + Copyright 2009-2010 Friedrich W. H. Kossebau + + 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) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + 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, see . +*/ + +#include "generalconfigeditor.h" + +// KDE +#include +#include +#include +#include +#include +// Qt +#include +#include +#include + + +GeneralConfigEditor::GeneralConfigEditor(KBookmarkManager* bookmarkManager, QWidget* parent) + : QWidget(parent), + mBookmarkFolderAddress(bookmarkManager->root().address()), + mBookmarkManager(bookmarkManager) +{ + QVBoxLayout* pageLayout = new QVBoxLayout(this); + pageLayout->setMargin(0); + + // folder selection + QHBoxLayout* folderSelectLayout = new QHBoxLayout; + + const QString folderSelectLabelText = + i18nc("@label:edit the bookmark folder to show", + "Folder:"); + QLabel* label = new QLabel(folderSelectLabelText); + + mFolderSelectButton = new KPushButton; + label->setBuddy(mFolderSelectButton); + connect(mFolderSelectButton, SIGNAL(clicked(bool)), SLOT(selectBookmarkFolder())); + + const QString folderToolTip = + i18nc("@info:tooltip", + "The folder which will be used as the base for the menu."); + label->setToolTip(folderToolTip); + mFolderSelectButton->setToolTip(folderToolTip); +// const QString folderWhatsThis = +// i18nc( "@info:whatsthis", +// "Select the folder which should be used to in the menu." ); +// mFolderSelectButton->setWhatsThis( groupSizeWhatsThis ); + + folderSelectLayout->addWidget(label); + folderSelectLayout->addWidget(mFolderSelectButton); + folderSelectLayout->addStretch(); + + pageLayout->addLayout(folderSelectLayout); + pageLayout->addStretch(); + + connect(mBookmarkManager, SIGNAL(changed(QString,QString)), SLOT(onBookmarksChanged(QString))); + connect(mFolderSelectButton, SIGNAL(clicked(bool)), parent, SLOT(settingsModified())); + + updateFolder(); +} + +void GeneralConfigEditor::setBookmarkFolderAddress(const QString& bookmarkFolderAddress) +{ + if (mBookmarkFolderAddress == bookmarkFolderAddress) + return; + + mBookmarkFolderAddress = bookmarkFolderAddress; + + updateFolder(); +} + +void GeneralConfigEditor::selectBookmarkFolder() +{ + const KBookmark bookmarkFolder = mBookmarkManager->findByAddress(mBookmarkFolderAddress); + + KBookmarkDialog* dialog = new KBookmarkDialog(mBookmarkManager, this); + KBookmarkGroup selectedFolder = dialog->selectFolder(bookmarkFolder); + delete dialog; + + if (! selectedFolder.isNull()) { + mBookmarkFolderAddress = selectedFolder.address(); + updateFolder(); + } +} + +void GeneralConfigEditor::updateFolder() +{ + const KBookmark bookmarkFolder = mBookmarkManager->findByAddress(mBookmarkFolderAddress); + + const bool isRoot = (! bookmarkFolder.hasParent()); + + const QString iconName = isRoot ? QString::fromLatin1("bookmarks") : bookmarkFolder.icon(); + const QString folderName = isRoot ? i18nc("name of the container of all browser bookmarks", + "Bookmarks") : + bookmarkFolder.text(); + + mFolderSelectButton->setIcon(KIcon(iconName)); + mFolderSelectButton->setText(folderName); +} + + +void GeneralConfigEditor::onBookmarksChanged(const QString& address) +{ + Q_UNUSED(address); + + updateFolder(); +} diff --git a/kdeplasma-addons/applets/bookmarks/generalconfigeditor.h b/kdeplasma-addons/applets/bookmarks/generalconfigeditor.h new file mode 100644 index 00000000..edf29dc8 --- /dev/null +++ b/kdeplasma-addons/applets/bookmarks/generalconfigeditor.h @@ -0,0 +1,69 @@ +/* + This file is part of the Bookmarks plasmoid, part of the KDE project. + + Copyright 2009 Friedrich W. H. Kossebau + + 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) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + 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, see . +*/ + +#ifndef GENERALCONFIGEDITOR_H +#define GENERALCONFIGEDITOR_H + +// Qt +#include +#include + +class KBookmarkManager; +class KPushButton; + + +class GeneralConfigEditor : public QWidget +{ + Q_OBJECT + +public: + GeneralConfigEditor(KBookmarkManager* bookmarkManager, QWidget* parent); + +public: // getter + const QString& bookmarkFolderAddress() const; + +public: // setter + void setBookmarkFolderAddress(const QString& bookmarkFolderAddress); + +protected: + void updateFolder(); + +protected Q_SLOTS: + void selectBookmarkFolder(); + + void onBookmarksChanged(const QString& address); + +protected: + QString mBookmarkFolderAddress; + + KBookmarkManager* mBookmarkManager; + + KPushButton* mFolderSelectButton; +}; + + +inline const QString& GeneralConfigEditor::bookmarkFolderAddress() const +{ + return mBookmarkFolderAddress; +} + +#endif diff --git a/kdeplasma-addons/applets/bookmarks/main.cpp b/kdeplasma-addons/applets/bookmarks/main.cpp new file mode 100644 index 00000000..14e92980 --- /dev/null +++ b/kdeplasma-addons/applets/bookmarks/main.cpp @@ -0,0 +1,26 @@ +/* + This file is part of the Bookmarks plasmoid, part of the KDE project. + + Copyright 2009 Friedrich W. H. Kossebau + + 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) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + 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, see . +*/ + +// Plasmoid +#include "bookmarksplasmoid.h" + +K_EXPORT_PLASMA_APPLET(bookmarks, Plasma::BookmarksPlasmoid) diff --git a/kdeplasma-addons/applets/bookmarks/plasma-applet-bookmarks.desktop b/kdeplasma-addons/applets/bookmarks/plasma-applet-bookmarks.desktop new file mode 100644 index 00000000..446a6a8e --- /dev/null +++ b/kdeplasma-addons/applets/bookmarks/plasma-applet-bookmarks.desktop @@ -0,0 +1,122 @@ +[Desktop Entry] +Name=Bookmarks +Name[ar]=العلامات +Name[ast]=Marcadores +Name[bs]=obilježivači +Name[ca]=Adreces d'interès +Name[ca@valencia]=Adreces d'interés +Name[cs]=Záložky +Name[da]=Bogmærker +Name[de]=Lesezeichen +Name[el]=Σελιδοδείκτες +Name[en_GB]=Bookmarks +Name[eo]=Legosignoj +Name[es]=Marcadores +Name[et]=Järjehoidjad +Name[eu]=Liburu markak +Name[fi]=Kirjanmerkit +Name[fr]=Signets +Name[ga]=Leabharmharcanna +Name[gl]=Marcadores +Name[hr]=Oznake +Name[hu]=Könyvjelzők +Name[it]=Segnalibri +Name[ja]=ブックマーク +Name[kk]=Бетбелгілер +Name[km]=ចំណាំ +Name[ko]=책갈피 +Name[lt]=Žymelės +Name[lv]=Grāmatzīmes +Name[mr]=ओळखचिन्हे +Name[nb]=Bokmerker +Name[nds]=Leestekens +Name[nl]=Bladwijzers +Name[nn]=Bokmerke +Name[pa]=ਬੁੱਕਮਾਰਕ +Name[pl]=Zakładki +Name[pt]=Favoritos +Name[pt_BR]=Favoritos +Name[ro]=Semne de carte +Name[ru]=Закладки +Name[sk]=Záložky +Name[sl]=Zaznamki +Name[sr]=обележивачи +Name[sr@ijekavian]=обележивачи +Name[sr@ijekavianlatin]=obeleživači +Name[sr@latin]=obeleživači +Name[sv]=Bokmärken +Name[th]=ที่คั่นหน้า +Name[tr]=Yer İmleri +Name[ug]=خەتكۈشلەر +Name[uk]=Закладки +Name[wa]=Rimarkes +Name[x-test]=xxBookmarksxx +Name[zh_CN]=书签 +Name[zh_TW]=書籤 +Comment=Quick Access to the Bookmarks +Comment[ar]=وصول سريع للعلامات +Comment[ast]=Accesu rápidu a Marcadores +Comment[bs]=Brz pristup do obilježivača +Comment[ca]=Accés ràpid a les adreces d'interès +Comment[ca@valencia]=Accés ràpid a les adreces d'interés +Comment[cs]=Rychlý přístup k záložkám +Comment[da]=Hurtig adgang til bogmærker +Comment[de]=Schnellzugriff auf die Lesezeichen +Comment[el]=Γρήγορη πρόσβαση στους σελιδοδείκτες +Comment[en_GB]=Quick Access to the Bookmarks +Comment[es]=Acceso rápido a los marcadores +Comment[et]=Kiire ligipääs järjehoidjatele +Comment[eu]=Liburu marketara sarbide azkarra +Comment[fi]=Nopea pääsy kirjanmerkkeihin +Comment[fr]=Accès rapide aux signets +Comment[gl]=Acceso rápido aos marcadores. +Comment[hr]=Brzi pristup oznakama +Comment[hu]=Gyors hozzáférés a könyvjelzőkhöz +Comment[it]=Accesso rapido ai segnalibri +Comment[ja]=ブックマークへ素早くアクセス +Comment[kk]=Бетбелгілерге тез қатынау +Comment[km]=ចូល​ដំណើរ​ការ​រហ័ស​ទៅ​កាន់​ចំណាំ +Comment[ko]=책갈피에 빨리 접근하기 +Comment[lt]=Greita prieiga prie žymių +Comment[lv]=Ātra piekļuve grāmatzīmēm +Comment[mr]=ओळखचिन्हांकरिता जलद हाताळणी +Comment[nb]=Kjapp tilgang til bokmerkene dine +Comment[nds]=Fixtogriep op de Leestekens +Comment[nl]=Snelle toegang tot de bladwijzers +Comment[nn]=Kjapp tilgang til bokmerka +Comment[pa]=ਬੁੱਕਮਾਰਕ ਲਈ ਤੁਰੰਤ ਅਸੈੱਸ +Comment[pl]=Szybki dostęp do zakładek +Comment[pt]=Acesso Rápido aos Favoritos +Comment[pt_BR]=Acesso rápido aos favoritos +Comment[ro]=Acces rapid la semnele de carte +Comment[ru]=Быстрый доступ к закладкам +Comment[sk]=Rýchly prístup k záložkám +Comment[sl]=Hiter dostop do zaznamkov +Comment[sr]=Брз приступ обележивачима +Comment[sr@ijekavian]=Брз приступ обиљеживачима +Comment[sr@ijekavianlatin]=Brz pristup obilježivačima +Comment[sr@latin]=Brz pristup obeleživačima +Comment[sv]=Snabbåtkomst till bokmärken +Comment[th]=เข้าใช้งานที่คั่นหน้าด่วน +Comment[tr]=Yer İmlerinize Hızlı Erişim +Comment[uk]=Швидкий доступ до закладок +Comment[wa]=Potchî rade dins les rmarkes +Comment[x-test]=xxQuick Access to the Bookmarksxx +Comment[zh_CN]=快速访问书签 +Comment[zh_TW]=快速存取書籤 +Type=Service +Icon=bookmarks +ServiceTypes=Plasma/Applet + +X-KDE-Library=plasma_applet_bookmarks +X-KDE-PluginInfo-Author=Friedrich W. H. Kossebau +X-KDE-PluginInfo-Email=kossebau@kde.org +X-KDE-PluginInfo-Name=bookmarks +X-KDE-PluginInfo-Version=0.1 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-Category=File System +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true +X-Plasma-Requires-FileDialog=Unused +X-Plasma-Requires-LaunchApp=Required diff --git a/kdeplasma-addons/applets/bubblemon/CMakeLists.txt b/kdeplasma-addons/applets/bubblemon/CMakeLists.txt new file mode 100644 index 00000000..ad550eb4 --- /dev/null +++ b/kdeplasma-addons/applets/bubblemon/CMakeLists.txt @@ -0,0 +1,6 @@ +project(plasma-applet-bubblemon) + +add_subdirectory(src) +add_subdirectory(images) + +install(FILES plasma-applet-bubblemon.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/kdeplasma-addons/applets/bubblemon/images/CMakeLists.txt b/kdeplasma-addons/applets/bubblemon/images/CMakeLists.txt new file mode 100644 index 00000000..762d6bf7 --- /dev/null +++ b/kdeplasma-addons/applets/bubblemon/images/CMakeLists.txt @@ -0,0 +1 @@ +install(FILES bubble.svg DESTINATION ${DATA_INSTALL_DIR}/desktoptheme/default/bubblemon) diff --git a/kdeplasma-addons/applets/bubblemon/images/bubble.svg b/kdeplasma-addons/applets/bubblemon/images/bubble.svg new file mode 100644 index 00000000..748c0141 --- /dev/null +++ b/kdeplasma-addons/applets/bubblemon/images/bubble.svg @@ -0,0 +1,443 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kdeplasma-addons/applets/bubblemon/plasma-applet-bubblemon.desktop b/kdeplasma-addons/applets/bubblemon/plasma-applet-bubblemon.desktop new file mode 100644 index 00000000..4720f384 --- /dev/null +++ b/kdeplasma-addons/applets/bubblemon/plasma-applet-bubblemon.desktop @@ -0,0 +1,114 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Bubblemon +Name[ar]=Bubblemon +Name[ast]=Bubblemon +Name[bs]=Bubblemon +Name[ca]=Monitor bombolla +Name[ca@valencia]=Monitor bombolla +Name[cs]=Bubblemon +Name[da]=Bobbelmon +Name[de]=Bubblemon +Name[el]=Bubblemon +Name[en_GB]=Bubblemon +Name[eo]=Bubblemon +Name[es]=Bubblemon +Name[et]=Bubblemon +Name[eu]=Bubblemon +Name[fi]=Valvontakupla +Name[fr]=Bubblemon +Name[ga]=Bubblemon +Name[gl]=Bubblemon +Name[hu]=Bubblemon +Name[is]=Bubblemon +Name[it]=Bubblemon +Name[ja]=Bubblemon +Name[kk]=Көпіршік-монитор +Name[km]=Bubblemon +Name[ko]=거품 모니터 +Name[lt]=Bubblemon +Name[lv]=Bubblemon +Name[mr]=बबलमॉन +Name[nb]=Bubblemon +Name[nds]=Bubblemon +Name[nl]=Bubblemon +Name[nn]=Bobleovervaking +Name[pa]=ਬੁਲਬੁਲਾਮੈਮੋਰੀ +Name[pl]=Monitor bąbelkowy +Name[pt]=Bubblemon +Name[pt_BR]=Bubblemon +Name[ro]=Bubblemon +Name[ru]=Пузырьковый монитор +Name[sk]=Bubblemon +Name[sl]=Bubblemon +Name[sq]=Bubblemon +Name[sr]=облакмон +Name[sr@ijekavian]=облакмон +Name[sr@ijekavianlatin]=oblakmon +Name[sr@latin]=oblakmon +Name[sv]=Bubblemon +Name[tr]=Bubblemon +Name[uk]=Bubblemon +Name[wa]=Bubblemon +Name[x-test]=xxBubblemonxx +Name[zh_CN]=Bubblemon +Name[zh_TW]=泡泡監視器 +Comment=A pretty bubble that monitors your system +Comment[ar]=فقاعة جميلة تراقب نظامك +Comment[bs]=Prijatni balon koji nadzire sistem. +Comment[ca]=Una bombolla graciosa que vigila el sistema +Comment[ca@valencia]=Una bombolla graciosa que vigila el sistema +Comment[cs]=Pěkná bublina monitorující váš systém +Comment[da]=En pæn boble der overvåger dit system +Comment[de]=Eine schicke Blase, die Ihr System überwacht. +Comment[el]=Μια όμορφη φυσαλίδα που εποπτεύει το σύστημά σας. +Comment[en_GB]=A pretty bubble that monitors your system +Comment[es]=Una bonita burbuja que observa su sistema +Comment[et]=Kena mull, mis jälgib süsteemi +Comment[fi]=Sievä järjestelmänvalvontakupla +Comment[fr]=Une jolie bulle supervisant votre système. +Comment[gl]=Unha burbulla que vixía o sistema +Comment[hu]=Rendszerfigyelő buborék +Comment[it]=Una graziosa bolla che controlla il sistema +Comment[kk]=Жүйеңізді бақылайтын ғажайып көпіршік +Comment[ko]=시스템 상태를 보여주는 자그마한 거품 +Comment[nb]=En pen boble som overvåker systemet ditt +Comment[nds]=En smuck Blaas, de Dien Systeem bekieken deit +Comment[nl]=Een prachtige bubbel die uw systeem monitort +Comment[pl]=Uroczy bąbelek, który monitoruje twój system +Comment[pt]=Uma bolha bonita que vigia o seu sistema +Comment[pt_BR]=Uma bonita bolha que monitora o seu sistema +Comment[ro]=Un balon drăguț ce vă monitorizează sistemul +Comment[ru]=Представление загрузки системы в виде пузырьков +Comment[sk]=Pekná bublina, ktorá monitoruje váš systém +Comment[sl]=Lep mehurček, ki nadzira vaš sistem +Comment[sr]=Пријатни балон који надзире систем +Comment[sr@ijekavian]=Пријатни балон који надзире систем +Comment[sr@ijekavianlatin]=Prijatni balon koji nadzire sistem +Comment[sr@latin]=Prijatni balon koji nadzire sistem +Comment[sv]=En snygg bubbla som övervakar systemet +Comment[tr]=Sisteminizi izleyen sevimli bir baloncuk +Comment[uk]=Гарненька бульбашка, яка спостерігає за вашою системою +Comment[x-test]=xxA pretty bubble that monitors your systemxx +Comment[zh_CN]=监视您系统的可爱泡泡 +Comment[zh_TW]=漂亮的泡泡,監視您的系統 +ServiceTypes=Plasma/Applet +Type=Service +Icon=utilities-system-monitor + +X-KDE-Library=plasma_applet_bubblemon +X-KDE-PluginInfo-Author=Trever Fischer +X-KDE-PluginInfo-Email=tdfischer@fedoraproject.org +X-KDE-PluginInfo-Name=bubblemon +X-KDE-PluginInfo-Version=0.1 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-Category=System Information +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true + +X-Plasma-Requires-FileDialog=Unused +X-Plasma-Requires-LaunchApp=Unused +X-Plasma-NotificationArea=true + +X-Plasma-DefaultSize=200,200 diff --git a/kdeplasma-addons/applets/bubblemon/src/CMakeLists.txt b/kdeplasma-addons/applets/bubblemon/src/CMakeLists.txt new file mode 100644 index 00000000..89568960 --- /dev/null +++ b/kdeplasma-addons/applets/bubblemon/src/CMakeLists.txt @@ -0,0 +1,9 @@ +set(bubblemon_SRCS + bubble.cpp + ) + +kde4_add_ui_files(bubblemon_SRCS settings.ui) +kde4_add_plugin(plasma_applet_bubblemon ${bubblemon_SRCS}) +target_link_libraries(plasma_applet_bubblemon ${KDE4_PLASMA_LIBS}) + +install(TARGETS plasma_applet_bubblemon DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/kdeplasma-addons/applets/bubblemon/src/Messages.sh b/kdeplasma-addons/applets/bubblemon/src/Messages.sh new file mode 100755 index 00000000..3addbe73 --- /dev/null +++ b/kdeplasma-addons/applets/bubblemon/src/Messages.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash +$EXTRACTRC *.ui >> rc.cpp +$XGETTEXT *.cpp -o $podir/plasma_applet_bubblemon.pot diff --git a/kdeplasma-addons/applets/bubblemon/src/bubble.cpp b/kdeplasma-addons/applets/bubblemon/src/bubble.cpp new file mode 100644 index 00000000..b10d52e8 --- /dev/null +++ b/kdeplasma-addons/applets/bubblemon/src/bubble.cpp @@ -0,0 +1,531 @@ +/* +* Copyright 2009 by Trever Fischer +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Library General Public License as +* published by the Free Software Foundation; either version 2, 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 Library General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#include "bubble.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include + + +K_EXPORT_PLASMA_APPLET(bubblemon, Bubble) + +Bubble::Bubble(QObject *parent, const QVariantList &args) + : Plasma::Applet(parent, args), + m_showText(false), + m_animated(true), + m_val(0), + m_max(0), + m_speed(1000), + m_bubbles(20), + m_bubbleCount(0), + m_labelTransparency(0), + m_rebuildClip(true) +{ + m_svg = new Plasma::Svg(this); + m_svg->setImagePath(Plasma::Theme::defaultTheme()->imagePath("bubblemon/bubble")); + + connect(m_svg, SIGNAL(repaintNeeded()), this, SLOT(repaintNeeded())); + + setAcceptsHoverEvents(true); + setAspectRatioMode(Plasma::Square); + setBackgroundHints(NoBackground); + + m_animation = new QPropertyAnimation(this, "labelTransparency", this); + m_animation->setDuration(200); + m_animation->setStartValue(0.0); + m_animation->setEndValue(1.0); +} + +Bubble::~Bubble() +{ +} + +void +Bubble::repaintNeeded() +{ + update(); +} + +void +Bubble::reloadTheme() +{ + m_svg->setImagePath(Plasma::Theme::defaultTheme()->imagePath("bubblemon/bubble")); +} + +void +Bubble::interpolateValue() +{ + m_rebuildClip = true; + update(); +} + +void +Bubble::init() +{ + m_svg->resize(geometry().width(), geometry().height()); + + m_sensorModel = new QStandardItemModel(this); + + connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(reloadTheme())); + + m_animator = new QTimer(this); + m_animator->setInterval(75); + connect(m_animator, SIGNAL(timeout()), this, SLOT(moveBubbles())); + + m_interpolator = new QTimeLine(m_speed, this); + connect(m_interpolator, SIGNAL(frameChanged(int)), this, SLOT(interpolateValue())); + + m_engine = dataEngine("systemmonitor"); + if (!m_engine->isValid()) { + setFailedToLaunch(true, + i18nc("@info:status The system monitor data engine could not be found or loaded", + "Could not load the System Monitor data engine.")); + } else { + connect(m_engine, SIGNAL(sourceAdded(QString)), this, SLOT(connectSensor())); + } + + configChanged(); + + m_bubbleRect = m_svg->elementSize("bubble"); +} + +void +Bubble::resizeEvent(QGraphicsSceneResizeEvent *evt) +{ + Plasma::Applet::resizeEvent(evt); + qreal size = qMin(contentsRect().size().width(), contentsRect().size().height()); + m_svg->resize(size, size); + m_bubbleRect = m_svg->elementSize("bubble"); + m_rebuildClip = true; +} + +void +Bubble::connectSensor() +{ + m_engine->connectSource(m_sensor, this, m_speed); +} + +void +Bubble::disconnectSensor() +{ + m_engine->disconnectSource(m_sensor, this); +} + +void +Bubble::reconnectSensor() +{ + disconnectSensor(); + connectSensor(); +} + +void +Bubble::constraintsEvent(Plasma::Constraints constraints) +{ + Plasma::Applet::constraintsEvent(constraints); + + if (constraints & Plasma::FormFactorConstraint) { + if (formFactor() == Plasma::Horizontal || formFactor() == Plasma::Vertical) { + setPreferredSize(-1,-1); + } else { + setPreferredSize(150, 150); + } + } + + if (formFactor() == Plasma::Planar || formFactor() == Plasma::MediaCenter) { + setMinimumSize(30,30); + } else { + setMinimumSize(0,0); + } +} + +void +Bubble::hoverEnterEvent(QGraphicsSceneHoverEvent *evt) +{ + Q_UNUSED(evt) + if (m_showText) + showLabel(true); +} + +void +Bubble::hoverLeaveEvent(QGraphicsSceneHoverEvent *evt) +{ + Q_UNUSED(evt) + if (m_showText) + showLabel(false); +} + +qreal +Bubble::labelTransparency() const +{ + return m_labelTransparency; +} + +void +Bubble::setLabelTransparency(qreal trans) +{ + m_labelTransparency = trans; + update(); +} + +void +Bubble::showLabel(bool show) +{ + if (!show) + m_animation->setDirection(QAbstractAnimation::Backward); + else + m_animation->setDirection(QAbstractAnimation::Forward); + m_animation->start(); +} + +void +Bubble::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect) +{ + if (configurationRequired()) { + return; + } + + painter->save(); + painter->translate(contentsRect.topLeft()); + m_svg->paint(painter, m_svg->elementRect("background"), "background"); + + if (m_max>0 && m_val>0) { + float drawValue; + if (m_animated && !shouldConserveResources()) + drawValue = m_interpolator->currentFrame(); + else + drawValue = m_val; + if (m_rebuildClip) { + //Clipping the fill is easy. We just stop after some point. + QRectF clipRect(contentsRect); + clipRect.setTop(contentsRect.height()-(contentsRect.height()*((float)drawValue/m_max))); + m_clip = clipRect; + + //To clip the individual bubbles, we first build a path of the whole bubble. + //Then we take that path and subtract the empty portion. + //This would be easier of QPainterPath could simply subtract primitives, but alas. + QPainterPath bubbleClipPath; + QPainterPath bubblePath; + QPainterPath filledPath; + QRectF unfilledRect(contentsRect); + unfilledRect.setBottom(clipRect.top()); + bubblePath.addEllipse(m_svg->elementRect("fill")); + filledPath.addRect(unfilledRect); + + bubbleClipPath = bubblePath - filledPath; + + m_bubbleClip = bubbleClipPath; + m_rebuildClip = false; + } + painter->setClipRect(m_clip); + m_svg->paint(painter, m_svg->elementRect("fill"), "fill"); + if (m_bubbleCount>0 && m_animated && !shouldConserveResources()) { + painter->setClipPath(m_bubbleClip); + for(int i = 0;im_clip.top()) + m_svg->paint(painter, QRectF(m_bubbles.at(i), m_bubbleRect), "bubble"); + } + } + painter->setClipping(false); + } + m_svg->paint(painter, m_svg->elementRect("glass"), "glass"); + if (m_labelTransparency > 0) + drawLabel(painter, option, contentsRect); + painter->restore(); +} + +void +Bubble::drawLabel(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRectF &contentsRect) +{ + Q_UNUSED(option); + QPointF center = contentsRect.center(); + QFont font = painter->font(); + QFont oldFont = font; + font.setPointSize(font.pointSize()+1); + QRectF labelRect; + do { + font.setPointSize(font.pointSize()-1); + painter->setFont(font); + labelRect = painter->boundingRect(contentsRect, + Qt::TextWordWrap | Qt::AlignCenter | Qt::AlignVCenter, m_label); + labelRect.moveCenter(center); + labelRect.adjust(-3, -3, 3, 3); + } while (labelRect.width() > boundingRect().width() && font.pointSize()>1); + if (font.pointSize()<=1) + return; + painter->setFont(font); + QColor background = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor); + QColor fontColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor); + background.setAlphaF(m_labelTransparency); + painter->setPen(background); + background.setAlphaF(m_labelTransparency*0.5); + painter->setBrush(background); + + fontColor.setAlphaF(m_labelTransparency); + + painter->drawRoundedRect(labelRect, 3, 3); + painter->setPen(fontColor); + painter->drawText(labelRect, Qt::TextWordWrap | Qt::AlignCenter | Qt::AlignVCenter, m_label); + painter->setFont(oldFont); +} + +void +Bubble::moveBubbles() +{ + if (!boundingRect().isEmpty() && int(m_bubbleRect.height() * m_bubbleCount) > 0 && m_max > 0 && m_animated && !shouldConserveResources()) { + QRectF rect = boundingRect(); + QVector::iterator i; + bool needsUpdate = false; + int maxHeight = rect.height()-(m_val/(float)m_max*rect.height()+m_bubbleRect.height()); + for(i=m_bubbles.begin();i!=m_bubbles.end();++i) { + (*i).setY((*i).y()-m_bubbleSpeed); + if ((*i).y()maxHeight) + needsUpdate = true; + } + if (needsUpdate) + update(); + } +} + +QPainterPath +Bubble::shape() const +{ + QPainterPath path; + path.addEllipse(boundingRect()); + return path; +} + +void +Bubble::dataUpdated(QString name, Plasma::DataEngine::Data data) +{ + Q_UNUSED(name); + int prev = m_val; + m_val = data["value"].toDouble(); + + if(prev == m_val) + return; + + if (data["max"].toDouble()>0) + m_max = data["max"].toDouble(); + else + m_max = qMax(m_max, m_val); + + m_label = data["name"].toString(); + + Plasma::ToolTipContent tip; + tip.setMainText(data["name"].toString()); + if (data["units"].toString() == "%") + tip.setSubText(i18nc("@info:status Value as displayed in a percentage format", "%1%", m_val)); + else + tip.setSubText(i18nc("@info:status Value for non-percentage units (such as memory usage.)", + "%1%3/%2%3 (%4%)", + KGlobal::locale()->formatNumber(m_val), + KGlobal::locale()->formatNumber(m_max), + data["units"].toString(), + (int)((float)m_val/m_max*100))); + + QString section = m_sensor.section('/',0,0); + KIcon tipIcon(icon()); + tip.setImage(tipIcon.pixmap(IconSize(KIconLoader::Desktop))); + Plasma::ToolTipManager::self()->setContent(this, tip); + + if (m_animated && !shouldConserveResources()) { + m_bubbleCount = ((float)m_val/(float)m_max)*20; + /*int bubbleCount; + if (m_max>0) + bubbleCount = ((float)m_val/(float)m_max)*20; + else + bubbleCount = 0;*/ + /*while(m_bubbles.size()bubbleCount) + m_bubbles.removeLast();*/ + m_bubbleSpeed = (boundingRect().height()/20)*((float)m_val/m_max)*3; + + m_interpolator->stop(); + m_interpolator->setFrameRange(prev, m_val); + m_interpolator->start(); + } + + int lower = qMin(m_val, prev); + int upper = qMax(m_val, prev); + + //formula taken fron Bubble::paintInterface + QRect toUpdate(0, geometry().height()-(geometry().height()*((float)upper/m_max)), + geometry().width(), geometry().height()-(geometry().height()*((float)lower/m_max)) ); + + m_rebuildClip = true; + update(toUpdate); +} + +QString +Bubble::icon() const +{ + QString section = m_sensor.section('/',0,0); + if (section == "cpu") + return "cpu"; + if (section == "mem") + return "media-flash"; + if (section == "system") + return "computer"; + if (section == "partitions" || section == "disk") + return "drive-harddisk"; + if (section == "network") + return "network-wired"; + if (section == "acpi") + return "battery"; + if (section == "lmsensors") + return "media-flash"; + return "utilities-system-monitor"; +} + +void +Bubble::createConfigurationInterface(KConfigDialog* dlg) +{ + QWidget *page = new QWidget(dlg); + ui.setupUi(page); + + m_sensorModel->clear(); + QStandardItem *sensorItem; + QModelIndex currentSensor; + foreach(const QString &sensor, m_engine->sources()) { + Plasma::DataEngine::Data sensorData = m_engine->query(sensor); + sensorItem = new QStandardItem(sensorData["name"].toString()); + sensorItem->setData(sensor); + sensorItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + m_sensorModel->appendRow(sensorItem); + if (sensor == m_sensor) { + currentSensor = m_sensorModel->indexFromItem(sensorItem); + } + } + + QSortFilterProxyModel *proxy = new QSortFilterProxyModel(m_sensorModel); + proxy->setSourceModel(m_sensorModel); + ui.sensorView->setModel(proxy); + + if (currentSensor.isValid()) { + ui.sensorView->selectionModel()->setCurrentIndex(currentSensor, QItemSelectionModel::ClearAndSelect); + ui.sensorView->scrollTo(currentSensor, QAbstractItemView::PositionAtTop); + } + + ui.searchBox->setProxy(proxy); + + dlg->addPage(page, i18nc("@title:group Title for the bubblemon settings page","General"), icon()); + connect(dlg, SIGNAL(applyClicked()), this, SLOT(writeConfig())); + connect(dlg, SIGNAL(okClicked()), this, SLOT(writeConfig())); + ui.animateBubbles->setChecked(m_animated ? Qt::Checked : Qt::Unchecked); + ui.showText->setChecked(m_showText ? Qt::Checked : Qt::Unchecked); + ui.updateSpeed->setValue(m_speed); + connect(ui.updateSpeed, SIGNAL(valueChanged(int)), dlg, SLOT(settingsModified())); + connect(ui.animateBubbles, SIGNAL(toggled(bool)), dlg, SLOT(settingsModified())); + connect(ui.showText, SIGNAL(toggled(bool)), dlg, SLOT(settingsModified())); + connect(ui.sensorView, SIGNAL(activated(QModelIndex)), dlg, SLOT(settingsModified())); +} + +void +Bubble::writeConfig() +{ + KConfigGroup cg = config(); + bool changed = false; + + if (m_animated != ui.animateBubbles->isChecked()) { + changed = true; + cg.writeEntry("animated", ui.animateBubbles->isChecked()); + } + + if (m_showText != ui.showText->isChecked()) { + changed = true; + cg.writeEntry("showText", ui.showText->isChecked()); + } + + if (m_speed != ui.updateSpeed->value()) { + changed = true; + cg.writeEntry("speed", ui.updateSpeed->value()); + } + + QItemSelectionModel *selection = ui.sensorView->selectionModel(); + const QString sensor = selection->currentIndex().data(Qt::UserRole+1).toString(); + if (m_sensor != sensor) { + changed = true; + cg.writeEntry("sensor", sensor); + setConfigurationRequired(false); + } + + + if (changed) { + emit configNeedsSaving(); + m_rebuildClip = true; + } +} + +void +Bubble::configChanged() +{ + KConfigGroup cg = config(); + m_animated = cg.readEntry("animated", true); + m_showText = cg.readEntry("showText", false); + showLabel(m_showText); + + const int oldSpeed = m_speed; + m_speed = cg.readEntry("speed", m_speed); + m_interpolator->setDuration(m_speed); + + const QString sensor = cg.readEntry("sensor", m_sensor); + if (m_sensor != sensor) { + if (!m_sensor.isEmpty()) { + disconnectSensor(); + } + + m_sensor = sensor; + connectSensor(); + } else if (oldSpeed != m_speed && !m_sensor.isEmpty()) { + reconnectSensor(); + } + + if (m_sensor.isEmpty()) + setConfigurationRequired(true); + + if (m_animated) + m_animator->start(); + else + m_animator->stop(); + + update(); +} + + diff --git a/kdeplasma-addons/applets/bubblemon/src/bubble.h b/kdeplasma-addons/applets/bubblemon/src/bubble.h new file mode 100644 index 00000000..55cf8d33 --- /dev/null +++ b/kdeplasma-addons/applets/bubblemon/src/bubble.h @@ -0,0 +1,103 @@ +/* +* Copyright 2009 by Trever Fischer +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Library General Public License as +* published by the Free Software Foundation; either version 2, 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 Library General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef BUBBLE_H +#define BUBBLE_H + +#include +#include + +#include "ui_settings.h" + +class QTimeLine; +class QGraphicsSceneResizeEvent; +class QTimer; +class QStandardItemModel; +class QPropertyAnimation; + +namespace Plasma { + class Svg; +} + +class Bubble : public Plasma::Applet { + Q_OBJECT + Q_PROPERTY(qreal labelTransparency READ labelTransparency WRITE setLabelTransparency) + + public: + Bubble(QObject *parent, const QVariantList &args); + ~Bubble(); + void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect); + void init(); + void createConfigurationInterface(KConfigDialog *parent); + QString icon() const; + void setLabelTransparency(qreal); + qreal labelTransparency() const; + + public slots: + void dataUpdated(QString name, Plasma::DataEngine::Data data); + void configChanged(); + + protected: + QPainterPath shape() const; + void constraintsEvent(Plasma::Constraints constraints); + void resizeEvent(QGraphicsSceneResizeEvent *evt); + + protected slots: + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + + private slots: + void writeConfig(); + void moveBubbles(); + void showLabel(bool); + void interpolateValue(); + void connectSensor(); + void reconnectSensor(); + void disconnectSensor(); + void reloadTheme(); + void repaintNeeded(); + + private: + void drawLabel(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRectF &contentsRect); + + Ui::Settings ui; + bool m_showText; + bool m_animated; + int m_val; + int m_max; + int m_speed; + QVector m_bubbles; + int m_bubbleCount; + qreal m_labelTransparency; + float m_bubbleSpeed; + QSizeF m_bubbleRect; + QString m_sensor; + Plasma::Svg *m_svg; + QString m_label; + QTimer *m_animator; + QTimeLine *m_interpolator; + Plasma::DataEngine *m_engine; + QStandardItemModel *m_sensorModel; + QPropertyAnimation *m_animation; + QRectF m_clip; + QPainterPath m_bubbleClip; + bool m_rebuildClip; +}; + +#endif diff --git a/kdeplasma-addons/applets/bubblemon/src/settings.ui b/kdeplasma-addons/applets/bubblemon/src/settings.ui new file mode 100644 index 00000000..8856ed09 --- /dev/null +++ b/kdeplasma-addons/applets/bubblemon/src/settings.ui @@ -0,0 +1,206 @@ + + + Settings + + + + 0 + 0 + 391 + 294 + + + + + + + + 75 + true + + + + Data + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 25 + + + + + + + + Update every: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + 100 + + + 50 + + + 1000000 + + + 100 + + + ms + + + + + + + Qt::Horizontal + + + + 118 + 20 + + + + + + + + + + Sensors: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + sensorView + + + + + + + + + + + 0 + 10 + + + + false + + + + + + + + 75 + true + + + + Appearance + + + + + + + Animated: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + animateBubbles + + + + + + + + + + + + + + Show text: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + showText + + + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 5 + + + + + + + + + KFilterProxySearchLine + QWidget +
kfilterproxysearchline.h
+
+ + KIntNumInput + QWidget +
knuminput.h
+
+
+ + +
diff --git a/kdeplasma-addons/applets/calculator/CMakeLists.txt b/kdeplasma-addons/applets/calculator/CMakeLists.txt new file mode 100644 index 00000000..48297077 --- /dev/null +++ b/kdeplasma-addons/applets/calculator/CMakeLists.txt @@ -0,0 +1,8 @@ +project(plasma-calculator) + +install(DIRECTORY package/ + DESTINATION ${DATA_INSTALL_DIR}/plasma/plasmoids/calculator) + +install(FILES package/metadata.desktop + DESTINATION ${SERVICES_INSTALL_DIR} + RENAME plasma-applet-calculator.desktop) diff --git a/kdeplasma-addons/applets/calculator/Messages.sh b/kdeplasma-addons/applets/calculator/Messages.sh new file mode 100755 index 00000000..303190d9 --- /dev/null +++ b/kdeplasma-addons/applets/calculator/Messages.sh @@ -0,0 +1,2 @@ +#! /usr/bin/env bash +$XGETTEXT `find . -name \*.qml` -o $podir/plasma_applet_calculator.pot diff --git a/kdeplasma-addons/applets/calculator/package/contents/ui/calculator.qml b/kdeplasma-addons/applets/calculator/package/contents/ui/calculator.qml new file mode 100644 index 00000000..c027719e --- /dev/null +++ b/kdeplasma-addons/applets/calculator/package/contents/ui/calculator.qml @@ -0,0 +1,394 @@ +/***************************************************************************** + * Copyright (C) 2012 by Davide Bettio * + * Copyright (C) 2012 by Luiz Romário Santana Rios * + * Copyright (C) 2007 by Henry Stanaland * + * Copyright (C) 2008 by Laurent Montel * + * * + * 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 . * + *****************************************************************************/ + +import QtQuick 1.0; +import org.kde.plasma.core 0.1 as PlasmaCore +import org.kde.plasma.components 0.1 as PlasmaComponents +import org.kde.locale 0.1 as Locale + +Item { + id: main; + + property int minimumWidth: 200; + property int minimumHeight: 250; + + property int buttonHeight: (height - displayFrame.height - 6 * buttonsGrid.spacing) / 5; + property int buttonWidth: (width / 4) - buttonsGrid.spacing; + + property real result: 0; + property bool hasResult: false; + property bool showingInput: true; + property bool showingResult: false; + property string operator: undefined; + property real operand: 0; + property bool commaPressed: false; + property int decimals: 0; + property int inputSize: 0; + + property int maxInputLength: 15; // More than that and the number notation turns scientific + // (i.e.: 1.32324e+12) + + Keys.onDigit0Pressed: { digitClicked(0); } + Keys.onDigit1Pressed: { digitClicked(1); } + Keys.onDigit2Pressed: { digitClicked(2); } + Keys.onDigit3Pressed: { digitClicked(3); } + Keys.onDigit4Pressed: { digitClicked(4); } + Keys.onDigit5Pressed: { digitClicked(5); } + Keys.onDigit6Pressed: { digitClicked(6); } + Keys.onDigit7Pressed: { digitClicked(7); } + Keys.onDigit8Pressed: { digitClicked(8); } + Keys.onDigit9Pressed: { digitClicked(9); } + Keys.onEscapePressed: { allClearClicked(); } + Keys.onDeletePressed: { clearClicked(); } + Keys.onPressed: { + switch (event.key) { + case Qt.Key_Plus: + setOperator("+"); + break; + case Qt.Key_Minus: + setOperator("-"); + break; + case Qt.Key_Asterisk: + setOperator("*"); + break; + case Qt.Key_Slash: + setOperator("/"); + break; + case Qt.Key_Period: + decimalClicked(); + break; + case Qt.Key_Equal: + case Qt.Key_Return: + case Qt.Key_Enter: + equalsClicked(); + break; + default: + break; + } + } + + function digitClicked(digit) { + if (inputSize >= maxInputLength) { + return; + } + + if (showingResult) { + allClearClicked(); + } + + if (commaPressed) { + ++decimals; + tenToTheDecimals = Math.pow(10, decimals); + operand = (operand * tenToTheDecimals + digit) / tenToTheDecimals; + } else { + operand = operand * 10 + digit; + } + display.text = operand; + showingInput = true; + ++inputSize; + } + + function decimalClicked() { + if (showingResult) { + allClearClicked(); + } + + commaPressed = true; + showingInput = true; + } + + function doOperation() { + switch (operator) { + case "+": + result += operand; + break; + case "-": + result -= operand; + break; + case "*": + result *= operand; + break; + case "/": + result /= operand; + break; + default: + return; + } + + display.text = algarismCount(result * Math.pow(10, decimals)) > maxInputLength? + "E" : result; + showingInput = false; + } + + function clearOperand() { + operand = 0; + commaPressed = false; + decimals = 0; + inputSize = 0; + } + + function setOperator(op) { + if (!hasResult) { + result = operand; + hasResult = true; + } else if (showingInput) { + doOperation(); + } + + clearOperand(); + operator = op; + showingResult = false; + } + + function equalsClicked() { + showingResult = true; + doOperation(); + } + + function clearClicked() { + clearOperand(); + operator = ""; + display.text = operand; + showingInput = true; + showingResult = false; + } + + function allClearClicked() { + clearClicked(); + result = 0; + hasResult = false; + } + + function algarismCount(number) { + return number == 0? 1 : + Math.floor(Math.log(Math.abs(number))/Math.log(10)) + 1; + } + + Locale.Locale { + id: locale; + } + + PlasmaCore.Theme { + id: plasmaTheme; + } + + Connections { + target: plasmoid; + onPopupEvent: { + main.focus = true; + } + } + + Column { + focus: true; + spacing: 4; + + PlasmaCore.FrameSvgItem { + id: displayFrame; + width: buttonsGrid.width; + height: 2 * display.font.pixelSize; + imagePath: "widgets/frame"; + prefix: "sunken"; + + TextEdit { + id: display; + anchors { + fill: parent; + margins: parent.margins.right; + } + text: "0"; + font.pointSize: 16; + font.weight: Font.Bold; + color: plasmaTheme.viewTextColor; + horizontalAlignment: TextEdit.AlignRight; + verticalAlignment: TextEdit.AlignVCenter; + readOnly: true; + } + } + + Grid { + id: buttonsGrid; + columns: 4; + rows: 5; + spacing: 4; + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: i18nc("Text of the clear button", "C"); + onClicked: clearClicked(); + } + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: i18nc("Text of the division button", "÷"); + onClicked: setOperator("/"); + } + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: i18nc("Text of the multiplication button", "×"); + onClicked: setOperator("*"); + } + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: i18nc("Text of the all clear button", "AC"); + onClicked: allClearClicked(); + } + + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: "7"; + onClicked: digitClicked(7); + } + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: "8"; + onClicked: digitClicked(8); + } + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: "9"; + onClicked: digitClicked(9); + } + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: i18nc("Text of the minus button", "-"); + onClicked: setOperator("-"); + } + + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: "4"; + onClicked: digitClicked(4); + } + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: "5"; + onClicked: digitClicked(5); + } + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: "6"; + onClicked: digitClicked(6); + } + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: i18nc("Text of the plus button", "+"); + onClicked: setOperator("+"); + } + + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: "1"; + onClicked: digitClicked(1); + } + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: "2"; + onClicked: digitClicked(2); + } + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: "3"; + onClicked: digitClicked(3); + } + + Item { + id: ansPlaceHolder; + width: buttonWidth; + height: buttonHeight; + } + + Item { + id: zeroPlaceHolder; + width: buttonWidth; + height: buttonHeight; + } + + Item { + id: zeroPlaceHolder2; + width: buttonWidth; + height: buttonHeight; + } + + PlasmaComponents.Button { + width: buttonWidth; + height: buttonHeight; + text: locale.decimalSymbol; + onClicked: decimalClicked(); + } + + Item { + id: ansPlaceHolder2; + width: buttonWidth; + height: buttonHeight; + } + } + } + + PlasmaComponents.Button { + width: buttonWidth * 2 + buttonsGrid.spacing; + height: buttonHeight; + x: zeroPlaceHolder.x + buttonsGrid.x; + y: zeroPlaceHolder.y + buttonsGrid.y; + text: "0"; + onClicked: digitClicked(0); + } + + PlasmaComponents.Button { + id: ansButton; + width: buttonWidth; + height: buttonHeight * 2 + buttonsGrid.spacing; + x: ansPlaceHolder.x + buttonsGrid.x; + y: ansPlaceHolder.y + buttonsGrid.y; + text: i18nc("Text of the equals button", "="); + onClicked: equalsClicked(); + } +} + diff --git a/kdeplasma-addons/applets/calculator/package/metadata.desktop b/kdeplasma-addons/applets/calculator/package/metadata.desktop new file mode 100644 index 00000000..62228d20 --- /dev/null +++ b/kdeplasma-addons/applets/calculator/package/metadata.desktop @@ -0,0 +1,135 @@ +[Desktop Entry] +Name=Calculator +Name[ar]=آلة حاسبة +Name[ast]=Calculadora +Name[bs]=kalkulator +Name[ca]=Calculadora +Name[ca@valencia]=Calculadora +Name[cs]=Kalkulačka +Name[da]=Lommeregner +Name[de]=Rechner +Name[el]=Αριθμομηχανή +Name[en_GB]=Calculator +Name[eo]=Kalkulilo +Name[es]=Calculadora +Name[et]=Kalkulaator +Name[eu]=Kalkulagailua +Name[fi]=Laskin +Name[fr]=Calculatrice +Name[ga]=Áireamhán +Name[gl]=Calculadora +Name[he]=מחשבון +Name[hr]=Kalkulator +Name[hu]=Számológép +Name[is]=Reiknivél +Name[it]=Calcolatrice +Name[ja]=計算機 +Name[kk]=Калькулятор +Name[km]=ម៉ាស៊ីន​គិតលេខ +Name[ko]=계산기 +Name[ku]=Makîneya Hesaban +Name[lt]=Skaičiuotuvas +Name[lv]=Kalkulators +Name[mr]=गणकयंत्र +Name[nb]=Kalkulator +Name[nds]=Taschenreekner +Name[nl]=Rekenmachine +Name[nn]=Kalkulator +Name[oc]=Calculeta +Name[pa]=ਕੈਲਕੂਲੇਟਰ +Name[pl]=Kalkulator +Name[pt]=Calculadora +Name[pt_BR]=Calculadora +Name[ro]=Calculator +Name[ru]=Калькулятор +Name[sk]=Kalkulačka +Name[sl]=Računalo +Name[sq]=Makina Llogaritëse +Name[sr]=калкулатор +Name[sr@ijekavian]=калкулатор +Name[sr@ijekavianlatin]=kalkulator +Name[sr@latin]=kalkulator +Name[sv]=Miniräknare +Name[th]=เครื่องคิดเลข +Name[tr]=Hesap Makinesi +Name[ug]=ھېسابلىغۇچ +Name[uk]=Калькулятор +Name[wa]=Carculete +Name[x-test]=xxCalculatorxx +Name[zh_CN]=计算器 +Name[zh_TW]=計算機 +Comment=Calculate simple sums +Comment[ar]=احسب عمليات جمع بسيطة +Comment[ast]=Calcular sumes simples +Comment[bs]=Izračunajte jednostavne izraze +Comment[ca]=Calcula sumes senzilles +Comment[ca@valencia]=Calcula sumes senzilles +Comment[cs]=Jednoduché sčítání +Comment[da]=Beregn simple summer. +Comment[de]=Für kleine Rechenaufgaben +Comment[el]=Υπολογισμός απλών πράξεων +Comment[en_GB]=Calculate simple sums +Comment[es]=Calcular sumas sencillas +Comment[et]=Lihtne kalkulaator +Comment[eu]=Gehiketa errazak kalkulatu +Comment[fi]=Laske yksinkertaisia laskuja +Comment[fr]=Calcule des sommes simples +Comment[ga]=Áirigh suimeanna simplí +Comment[gl]=Calcula sumas simples +Comment[he]=מחשב סכומים פשוטים +Comment[hr]=Izračunaj jednostavne sume +Comment[hu]=Egyszerű számológép +Comment[is]=Reiknar einfaldar aðgerðir +Comment[it]=Calcola semplici somme +Comment[ja]=簡単な合計計算ができます +Comment[kk]=Қарапайым есептерді шығару +Comment[km]=គណនា​ផល​បូក​ធម្មតា +Comment[ko]=간단한 계산기 +Comment[ku]=Berhevkirinên hêsan hesab bike +Comment[lt]=Skaičiuoti paprastas sumas +Comment[lv]=Aprēķina vienkāršas summas +Comment[mr]=सोपी गणना करतो +Comment[nb]=Regn ut enkle regnestykker +Comment[nds]=Eenfache Saken utreken +Comment[nl]=Eenvoudige berekeningen +Comment[nn]=Grafisk kalkulator +Comment[pa]=ਸਧਾਰਨ ਜੋੜ ਕੱਢੋ +Comment[pl]=Obliczanie prostych sum +Comment[pt]=Calcular somas simples +Comment[pt_BR]=Calcula funções matemáticas básicas +Comment[ro]=Calculează sume simple +Comment[ru]=Вычисление простых выражений +Comment[sk]=Výpočet jednoduchých súm +Comment[sl]=Izračuna preproste vsote +Comment[sr]=Израчунајте једноставне изразе +Comment[sr@ijekavian]=Израчунајте једноставне изразе +Comment[sr@ijekavianlatin]=Izračunajte jednostavne izraze +Comment[sr@latin]=Izračunajte jednostavne izraze +Comment[sv]=Beräkna enkla summor +Comment[th]=คำนวณหาค่าที่ง่าย ๆ +Comment[tr]=Basit hesaplamalar yapın +Comment[uk]=Обчисліть прості суми +Comment[wa]=Cårculez des ptits carculs +Comment[x-test]=xxCalculate simple sumsxx +Comment[zh_CN]=计算简单的求和 +Comment[zh_TW]=計算簡單的算式 +Icon=accessories-calculator +Type=Service +ServiceTypes=Plasma/Applet,Plasma/PopupApplet + +X-KDE-Library=plasma_applet_calculator +X-KDE-PluginInfo-Author=Henry Stanaland +X-KDE-PluginInfo-Email=stanaland@gmail.com +X-KDE-PluginInfo-Name=calculator +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-Category=Utilities +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true + +X-Plasma-API=declarativeappletscript +X-Plasma-DefaultSize=200,250 +X-Plasma-MainScript=ui/calculator.qml +X-Plasma-Requires-FileDialog=Unused +X-Plasma-Requires-LaunchApp=Unused diff --git a/kdeplasma-addons/applets/charselect/CMakeLists.txt b/kdeplasma-addons/applets/charselect/CMakeLists.txt new file mode 100644 index 00000000..3b6a0f12 --- /dev/null +++ b/kdeplasma-addons/applets/charselect/CMakeLists.txt @@ -0,0 +1,12 @@ +project(charselect) + +set(charselect_SRCS charselect.cpp) + +kde4_add_plugin(plasma_applet_charselect ${charselect_SRCS}) +target_link_libraries(plasma_applet_charselect ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS}) + +install(TARGETS plasma_applet_charselect + DESTINATION ${PLUGIN_INSTALL_DIR}) + +install(FILES plasma-applet-charselect.desktop + DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/kdeplasma-addons/applets/charselect/Messages.sh b/kdeplasma-addons/applets/charselect/Messages.sh new file mode 100755 index 00000000..45615d1c --- /dev/null +++ b/kdeplasma-addons/applets/charselect/Messages.sh @@ -0,0 +1,2 @@ +#! /usr/bin/env bash +$XGETTEXT *.cpp -o $podir/plasma_applet_CharSelectApplet.pot diff --git a/kdeplasma-addons/applets/charselect/charselect.cpp b/kdeplasma-addons/applets/charselect/charselect.cpp new file mode 100644 index 00000000..1bcc9249 --- /dev/null +++ b/kdeplasma-addons/applets/charselect/charselect.cpp @@ -0,0 +1,92 @@ +/*************************************************************************** + * Copyright 2008 by Laurent Montel * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "charselect.h" + +#include +#include +#include +#include +#include +#include +#include + +CharSelectApplet::CharSelectApplet(QObject *parent, const QVariantList &args) + : Plasma::PopupApplet(parent, args), + m_mainWidget(0) +{ + setPopupIcon(QLatin1String("accessories-character-map")); +} + + +CharSelectApplet::~CharSelectApplet() +{ + delete m_mainWidget; +} + +void CharSelectApplet::constraintsEvent(Plasma::Constraints constraints) +{ + if (constraints & Plasma::StartupCompletedConstraint) { + if (size().width() < widget()->size().width() || + size().height() < widget()->size().height()) { + resize(widget()->size()); + emit appletTransformedItself(); + } + } +} + +QWidget *CharSelectApplet::widget() +{ + if (!m_mainWidget) { + m_mainWidget = new QWidget; + m_mainWidget->setAttribute(Qt::WA_NoSystemBackground); + QGridLayout *layout = new QGridLayout(m_mainWidget); + + m_charselect = new KCharSelect(m_mainWidget, 0, KCharSelect::BlockCombos|KCharSelect::CharacterTable|KCharSelect::FontCombo); + m_charselect->setMinimumSize(300, 250); + connect( m_charselect, SIGNAL(charSelected(QChar)), this, SLOT(slotCharSelect(QChar)) ); + layout->addWidget( m_charselect, 0, 0, 1, 2); + + m_lineEdit = new KLineEdit(m_mainWidget); + m_lineEdit->setReadOnly( true ); + layout->addWidget( m_lineEdit, 1, 0 ); + + m_addToClipboard = new KPushButton(m_mainWidget); + m_addToClipboard->setText( i18n( "&Add to Clipboard" ) ); + connect( m_addToClipboard, SIGNAL(clicked()), this, SLOT(slotAddToClipboard()) ); + layout->addWidget( m_addToClipboard, 1, 1 ); + } + + return m_mainWidget; +} + +void CharSelectApplet::slotAddToClipboard() +{ + const QString textLine = m_lineEdit->text(); + QClipboard *cb = QApplication::clipboard(); + cb->setText( textLine,QClipboard::Clipboard ); + cb->setText( textLine,QClipboard::Selection ); +} + +void CharSelectApplet::slotCharSelect( const QChar &c ) +{ + m_lineEdit->setText( c ); +} + +#include "charselect.moc" diff --git a/kdeplasma-addons/applets/charselect/charselect.h b/kdeplasma-addons/applets/charselect/charselect.h new file mode 100644 index 00000000..58eb666c --- /dev/null +++ b/kdeplasma-addons/applets/charselect/charselect.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright 2008 by Laurent Montel * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef CHARSELECT_H +#define CHARSELECT_H + +#include + +class KCharSelect; +class QGraphicsGridLayout; +class KLineEdit; +class KPushButton; + +class CharSelectApplet : public Plasma::PopupApplet +{ + Q_OBJECT +public: + CharSelectApplet(QObject *parent, const QVariantList &args); + virtual ~CharSelectApplet(); + + virtual QWidget *widget(); + +protected: + void constraintsEvent(Plasma::Constraints); + +public slots: + void slotAddToClipboard(); + void slotCharSelect( const QChar &c ); + +private: + QWidget *m_mainWidget; + KCharSelect *m_charselect; + QGraphicsGridLayout *m_layout; + KLineEdit *m_lineEdit; + KPushButton *m_addToClipboard; +}; + +K_EXPORT_PLASMA_APPLET(CharSelectApplet, CharSelectApplet) + +#endif diff --git a/kdeplasma-addons/applets/charselect/plasma-applet-charselect.desktop b/kdeplasma-addons/applets/charselect/plasma-applet-charselect.desktop new file mode 100644 index 00000000..84d8f4d9 --- /dev/null +++ b/kdeplasma-addons/applets/charselect/plasma-applet-charselect.desktop @@ -0,0 +1,131 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Character Selector +Name[ar]=مختار الأحرف +Name[ast]=Seleutor de caráuter +Name[bs]=birač znakova +Name[ca]=Selector de caràcters +Name[ca@valencia]=Selector de caràcters +Name[cs]=Výběr znaků +Name[da]=Tegnvælger +Name[de]=Tabelle zur Zeichenauswahl +Name[el]=Επιλογέας χαρακτήρων +Name[en_GB]=Character Selector +Name[eo]=Elektilo por signoj +Name[es]=Selector de caracteres +Name[et]=Sümbolivalija +Name[eu]=Karaktere hautatzailea +Name[fi]=Merkkivalitsin +Name[fr]=Sélecteur de caractères +Name[ga]=Roghnóir Carachtar +Name[gl]=Selector de caracteres +Name[he]=בוחר התווים +Name[hr]=Birač znakova +Name[hu]=Karakterválasztó +Name[is]=Stafaval +Name[it]=Selettore dei caratteri +Name[ja]=文字選択アプレット +Name[kk]=Таңба таңдағышы +Name[km]=កម្មវិធី​ជ្រើស​តួ​អក្សរ +Name[ko]=문자 선택기 +Name[ku]=Bijarkerê Tîpan +Name[lt]=Simbolių parinkiklis +Name[lv]=Rakstzīmju atlasītājs +Name[mr]=अक्षर निवड +Name[nb]=Tegnvelger +Name[nds]=Tekenköör +Name[nl]=Speciale tekens +Name[nn]=Teiknveljar +Name[pa]=ਅੱਖਰ ਚੋਣਕਾਰ +Name[pl]=Wybór znaków +Name[pt]=Selector de Caracteres +Name[pt_BR]=Seletor de caracteres +Name[ro]=Selector caractere +Name[ru]=Выбор символа +Name[sk]=Výber znakov +Name[sl]=Izbirnik znakov +Name[sq]=Zgjedhës i Gërmave +Name[sr]=бирач знакова +Name[sr@ijekavian]=бирач знакова +Name[sr@ijekavianlatin]=birač znakova +Name[sr@latin]=birač znakova +Name[sv]=Teckenväljare +Name[th]=เครื่องมือเลือกอักขระ +Name[tr]=Karakter Seçici +Name[ug]=ھەرپ تاللىغۇچ +Name[uk]=Таблиця символів +Name[wa]=Tchoezixheu di caracteres +Name[x-test]=xxCharacter Selectorxx +Name[zh_CN]=字符选择器 +Name[zh_TW]=字元選擇器 +Comment=View, select, and copy characters from a font collection +Comment[ar]=أظهر، واختر، و انسخ محارف من مجموعة الخط +Comment[ast]=Ver, esbillar y copiar carauteres d'una colección de fontes de lletra +Comment[bs]=Gledajte, birajte i kopirajte znakove iz zbirke fontova +Comment[ca]=Mostra, selecciona i copia caràcters d'una col·lecció de tipus de lletra +Comment[ca@valencia]=Mostra, selecciona i copia caràcters d'una col·lecció de tipus de lletra +Comment[cs]=Zobrazení, výběr a kopírování znaků ze sbírky písem +Comment[da]=Se, udvælg og kopiér tegn fra en skrifttypesamling. +Comment[de]=Zeichen aus einer Sammlung ansehen, auswählen oder kopieren +Comment[el]=Προβολή, επιλογή και αντιγραφή χαρακτήρων από μια συλλογή γραμματοσειρών +Comment[en_GB]=View, select, and copy characters from a font collection +Comment[es]=Ver, seleccionar y copiar caracteres de una colección de tipos de letra +Comment[et]=Fondikogude märkide näitamine, valimine ja kopeerimine +Comment[eu]=Letra-tipo bilduma batetik karaktereak ikusi, hautatu, eta kopiatu +Comment[fi]=Katso, valitse ja kopioi merkkejä fonttivalikoimasta +Comment[fr]=Permet d'afficher, de sélectionner et de copier des caractères +Comment[ga]=Féach ar, roghnaigh, agus cóipeáil carachtair ó bhailiúchán clónna +Comment[gl]=Ver, escoller e copiar caracteres dunha colección de tipografías +Comment[he]=הצג, בחר והעתק תווים מתוך אוסף גופנים +Comment[hr]=Prikaži, odaberi i kopiraj znakove iz kolekcije pisama +Comment[hu]=Karakterek megjelenítése, kiválasztása és másolása a betűkészlet-gyűjteményből +Comment[is]=Skoða, velja og afrita stafi úr letursafni +Comment[it]=Vedi, seleziona e copia caratteri da una collezione di caratteri +Comment[ja]=フォントのコレクションから文字を選択してコピーします +Comment[kk]=Қаріп жинағынан таңбаларды қарау, таңдау және көшіріп алу +Comment[km]=មើល ជ្រើស និង​ចម្លង​តួ​អក្សរ​ពី​កា​រជ្រើស​ពុម្ពអក្សរ +Comment[ko]=글꼴의 문자를 보고, 선택하고, 복사하기 +Comment[ku]=Jê berhevoka cure-nivîsê tîpan bibîne, hilbijêre û ji ber bigire +Comment[lt]=Žiūrėti, pasirinkti ir kopijuoti simbolius iš šriftų kolekcijos +Comment[lv]=Apskatiet, izvēlieties un kopējiet rakstzīmes no fontu kolekcijas +Comment[mr]=फॉन्ट संग्रहातून अक्षरे बघा, निवडा व प्रत करा +Comment[nb]=Vis, velg og kopier tegn fra en samling skrifter +Comment[nds]=Tekens ut en Schriftoordensammlen ankieken, utsöken un koperen +Comment[nl]=Toon, selecteer en kopieer tekens van een lettertypecollectie +Comment[nn]=Vis, merk og kopier teikn frå skrifter +Comment[pa]=ਫੋਂਟ ਭੰਡਾਰ ਵਿਚੋਂ ਅੱਖਰ ਵੇਖੋ, ਚੁਣੋ ਤੇ ਕਾਪੀ ਕਰੋ +Comment[pl]=Przeglądanie, wybieranie i kopiowanie znaków ze zbioru czcionek +Comment[pt]=Ver, seleccionar e copiar caracteres de uma colecção de tipos de letra +Comment[pt_BR]=Exibe, seleciona e copia caracteres de uma coleção de fontes +Comment[ro]=Vizualizează, alege și copiază caractere dintr-o colecție de fonturi +Comment[ru]=Просмотр, выбор и копирование символов из коллекции шрифтов +Comment[sk]=Zobrazenie, výber a kopírovanie znakov z kolekcie písiem +Comment[sl]=Oglejte si, izberite in kopirajte znake iz zbirke pisav +Comment[sr]=Гледајте, бирајте и копирајте знакове из збирке фонтова +Comment[sr@ijekavian]=Гледајте, бирајте и копирајте знакове из збирке фонтова +Comment[sr@ijekavianlatin]=Gledajte, birajte i kopirajte znakove iz zbirke fontova +Comment[sr@latin]=Gledajte, birajte i kopirajte znakove iz zbirke fontova +Comment[sv]=Visa, markera och kopiera tecken från en samling teckensnitt +Comment[th]=แสดง, เลือก และคัดลอกอักขระต่าง ๆ จากคลังแบบอักษร +Comment[tr]=Bir yazı tipi koleksiyonundan karakterleri seçin, kopyalayın ve görüntüleyin +Comment[uk]=Перегляньте, оберіть і скопіюйте символи зі збірки шрифтів +Comment[wa]=Vey, tchoezi eyet copyî des caracteres a pårti d' ene ramexhnêye di fontes +Comment[x-test]=xxView, select, and copy characters from a font collectionxx +Comment[zh_CN]=从字体集中查看、选择和复制字符 +Comment[zh_TW]=從字型中檢視、選擇與複製字元 +Type=Service +Icon=accessories-character-map +ServiceTypes=Plasma/Applet +X-KDE-Library=plasma_applet_charselect +X-KDE-PluginInfo-Author=Laurent Montel +X-KDE-PluginInfo-Email=montel@kde.org +X-KDE-PluginInfo-Name=charselect +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-Category=Utilities +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true + +X-Plasma-Requires-FileDialog=Unused +X-Plasma-Requires-LaunchApp=Unused diff --git a/kdeplasma-addons/applets/comic/CMakeLists.txt b/kdeplasma-addons/applets/comic/CMakeLists.txt new file mode 100644 index 00000000..55735b32 --- /dev/null +++ b/kdeplasma-addons/applets/comic/CMakeLists.txt @@ -0,0 +1,40 @@ +project(plasma-comic) + +if(HAVE_NEPOMUK) + add_definitions(-DHAVE_NEPOMUK) + add_definitions(-DDISABLE_NEPOMUK_LEGACY) +endif(HAVE_NEPOMUK) + +set(comic_SRCS + comic.cpp + comicmodel.cpp + configwidget.cpp + comicarchivejob.cpp + comicarchivedialog.cpp + checknewstrips.cpp + comicdata.cpp + comicinfo.cpp + comicsaver.cpp + stripselector.cpp + activecomicmodel.cpp +) + +kde4_add_ui_files(comic_SRCS + comicSettings.ui + appearanceSettings.ui + advancedsettings.ui + comicarchivedialog.ui +) + +kde4_add_plugin(plasma_applet_comic ${comic_SRCS}) +target_link_libraries(plasma_applet_comic ${KDE4_KDEUI_LIBS} ${KDE4_PLASMA_LIBS} ${KDE4_SOLID_LIBS} ${KDE4_KIO_LIBS} ${KDE4_KNEWSTUFF3_LIBS} ${QT_QTDECLARATIVE_LIBRARY}) + +if(HAVE_NEPOMUK) + target_link_libraries(plasma_applet_comic ${NEPOMUK_LIBRARIES} ${NEPOMUK_UTILS_LIBRARIES} ${SOPRANO_LIBRARIES}) +endif(HAVE_NEPOMUK) + +install(TARGETS plasma_applet_comic DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES plasma-comic-default.desktop DESTINATION ${SERVICES_INSTALL_DIR}) + +install(FILES comic.knsrc DESTINATION ${CONFIG_INSTALL_DIR}) +install(DIRECTORY package/ DESTINATION ${DATA_INSTALL_DIR}/plasma/packages/org.kde.comic) \ No newline at end of file diff --git a/kdeplasma-addons/applets/comic/Messages.sh b/kdeplasma-addons/applets/comic/Messages.sh new file mode 100755 index 00000000..eaee7280 --- /dev/null +++ b/kdeplasma-addons/applets/comic/Messages.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash +$EXTRACTRC *.ui >> rc.cpp +$XGETTEXT *.cpp `find . -name '*.qml'` -o $podir/plasma_applet_comic.pot diff --git a/kdeplasma-addons/applets/comic/activecomicmodel.cpp b/kdeplasma-addons/applets/comic/activecomicmodel.cpp new file mode 100644 index 00000000..84992aca --- /dev/null +++ b/kdeplasma-addons/applets/comic/activecomicmodel.cpp @@ -0,0 +1,63 @@ +/* + * Copyright 2012 Reza Fatahilah Shah + * + * 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, see . + */ + +#include "activecomicmodel.h" + +ActiveComicModel::ActiveComicModel(QObject *parent) + : QStandardItemModel(0, 1, parent) +{ + QHash newRoleNames = roleNames(); + newRoleNames[ComicKeyRole] = "key"; + newRoleNames[ComicTitleRole] = "title"; + newRoleNames[ComicIconRole] = "icon"; + newRoleNames[ComicHighlightRole] = "highlight"; + + setRoleNames(newRoleNames); + connect(this, SIGNAL(modelReset()), + this, SIGNAL(countChanged())); + connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)), + this, SIGNAL(countChanged())); + connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)), + this, SIGNAL(countChanged())); +} + +void ActiveComicModel::addComic(const QString &key, const QString &title, const QString &iconPath, bool highlight) +{ + QList newRow; + QStandardItem *item = new QStandardItem(title); + + item->setData(key, ComicKeyRole); + item->setData(title, ComicTitleRole); + item->setData(iconPath, ComicIconRole); + item->setData(highlight, ComicHighlightRole); + + newRow << item; + appendRow(newRow); +} + +QVariantHash ActiveComicModel::get(int row) const +{ + QModelIndex idx = index(row, 0); + QVariantHash hash; + + QHash::const_iterator i; + for (i = roleNames().constBegin(); i != roleNames().constEnd(); ++i) { + hash[i.value()] = data(idx, i.key()); + } + + return hash; +} diff --git a/kdeplasma-addons/applets/comic/activecomicmodel.h b/kdeplasma-addons/applets/comic/activecomicmodel.h new file mode 100644 index 00000000..848a98b3 --- /dev/null +++ b/kdeplasma-addons/applets/comic/activecomicmodel.h @@ -0,0 +1,49 @@ +/* + * Copyright 2012 Reza Fatahilah Shah + * + * 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, see . + */ + +#ifndef ACTIVE_COMIC_MODEL_H +#define ACTIVE_COMIC_MODEL_H + +#include +#include + +class ActiveComicModel : public QStandardItemModel +{ + Q_OBJECT + Q_PROPERTY(int count READ count NOTIFY countChanged) + +public: + enum Roles { + ComicKeyRole = Qt::UserRole+1, + ComicTitleRole = Qt::UserRole+2, + ComicIconRole = Qt::UserRole+3, + ComicHighlightRole = Qt::UserRole+4 + }; + + ActiveComicModel(QObject *parent = 0); + + void addComic(const QString &key, const QString &title, const QString &iconPath, bool highlight = true); + + int count() { return rowCount(QModelIndex()); } + + Q_INVOKABLE QVariantHash get(int i) const; + +Q_SIGNALS: + void countChanged(); +}; + +#endif \ No newline at end of file diff --git a/kdeplasma-addons/applets/comic/advancedsettings.ui b/kdeplasma-addons/applets/comic/advancedsettings.ui new file mode 100644 index 00000000..9fc4d211 --- /dev/null +++ b/kdeplasma-addons/applets/comic/advancedsettings.ui @@ -0,0 +1,161 @@ + + + AdvancedSettings + + + + 0 + 0 + 468 + 300 + + + + + + + + 75 + true + + + + Cache + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 5 + + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + 0 + + + strips per comic + + + No size limit + + + + + + + Comic cache: + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 5 + + + + + + + + + 75 + true + + + + Error Handling + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 5 + + + + + + + + + + Display error image when getting comic failed: + + + + + + + + + + true + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/kdeplasma-addons/applets/comic/appearanceSettings.ui b/kdeplasma-addons/applets/comic/appearanceSettings.ui new file mode 100644 index 00000000..5dc1144f --- /dev/null +++ b/kdeplasma-addons/applets/comic/appearanceSettings.ui @@ -0,0 +1,263 @@ + + + AppearanceSettings + + + + 0 + 0 + 280 + 182 + + + + + 0 + 0 + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 5 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 40 + 5 + + + + + + + + QLayout::SetDefaultConstraint + + + QFormLayout::ExpandingFieldsGrow + + + + + Show arrows only on &hover: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + checkBox_arrows + + + + + + + + + + true + + + + + + + + + + 75 + true + + + + Information + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Show comic &title: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + checkBox_title + + + + + + + + + + false + + + + + + + Show comic &identifier: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + checkBox_identifier + + + + + + + + + + false + + + + + + + Show comic &author: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + checkBox_author + + + + + + + + + + false + + + + + + + Show comic &URL: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + checkBox_url + + + + + + + + + + false + + + + + + + + + + + + true + + + + 0 + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + KButtonGroup + QGroupBox +
kbuttongroup.h
+ 1 +
+
+ + checkBox_arrows + checkBox_title + checkBox_identifier + checkBox_author + checkBox_url + + + +
diff --git a/kdeplasma-addons/applets/comic/checknewstrips.cpp b/kdeplasma-addons/applets/comic/checknewstrips.cpp new file mode 100644 index 00000000..8558c9e5 --- /dev/null +++ b/kdeplasma-addons/applets/comic/checknewstrips.cpp @@ -0,0 +1,79 @@ +/*************************************************************************** + * Copyright (C) 2011 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "checknewstrips.h" + +#include + +CheckNewStrips::CheckNewStrips( const QStringList &identifiers, Plasma::DataEngine *engine, int minutes, QObject *parent) + : QObject( parent ), + mMinutes( minutes ), + mIndex( 0 ), + mEngine( engine ), + mIdentifiers( identifiers ) +{ + QTimer *timer = new QTimer( this ); + timer->setInterval( minutes * 60 * 1000 ); + connect( timer, SIGNAL(timeout()), this, SLOT(start()) ); + timer->start(); + + //start at once, that way the user does not have to wait for minutes to get the initial result + start(); +} + +void CheckNewStrips::dataUpdated( const QString &source, const Plasma::DataEngine::Data &data ) +{ + QString lastIdentifierSuffix; + + if ( !data[ "Error" ].toBool() ) { + lastIdentifierSuffix = data[ "Identifier" ].toString(); + lastIdentifierSuffix.remove( source ); + } + + mEngine->disconnectSource( source, this ); + + if ( !lastIdentifierSuffix.isEmpty() ) { + QString temp = source; + temp.remove( ':' ); + emit lastStrip( mIndex, temp, lastIdentifierSuffix ); + } + ++mIndex; + + if ( mIndex < mIdentifiers.count() ) { + const QString newSource = mIdentifiers[mIndex] + ':'; + mEngine->connectSource( newSource, this ); + mEngine->query( newSource ); + } else { + mIndex = 0; + } +} + +void CheckNewStrips::start() +{ + //already running, do nothing + if ( mIndex ) { + return; + } + + if ( mIndex < mIdentifiers.count() ) { + const QString newSource = mIdentifiers[mIndex] + ':'; + mEngine->connectSource( newSource, this ); + mEngine->query( newSource ); + } +} diff --git a/kdeplasma-addons/applets/comic/checknewstrips.h b/kdeplasma-addons/applets/comic/checknewstrips.h new file mode 100644 index 00000000..f975edb2 --- /dev/null +++ b/kdeplasma-addons/applets/comic/checknewstrips.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (C) 2011 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef CHECK_NEW_STRIPS_H +#define CHECK_NEW_STRIPS_H + +#include + +/** + * This class searches for the newest comic strips of predefined comics in a defined intervall. + * Once found it emits lastStrip + */ +class CheckNewStrips : public QObject +{ + Q_OBJECT + + public: + CheckNewStrips( const QStringList &identifiers, Plasma::DataEngine *engine, int minutes, QObject *parent = 0 ); + + signals: + /** + * @param index of the identifier in identifiers + * @param identifier of the comic + * @param suffix of the last comic strip + * @see CheckNewStrips + */ + void lastStrip( int index, const QString &identifier, const QString &suffix ); + + public slots: + void dataUpdated( const QString &name, const Plasma::DataEngine::Data &data ); + + private slots: + void start(); + + private: + int mMinutes; + int mIndex; + Plasma::DataEngine *mEngine; + const QStringList mIdentifiers; +}; + +#endif diff --git a/kdeplasma-addons/applets/comic/comic.cpp b/kdeplasma-addons/applets/comic/comic.cpp new file mode 100644 index 00000000..8352eeea --- /dev/null +++ b/kdeplasma-addons/applets/comic/comic.cpp @@ -0,0 +1,804 @@ +/*************************************************************************** + * Copyright (C) 2007 by Tobias Koenig * + * Copyright (C) 2008 by Marco Martin * + * Copyright (C) 2008-2011 Matthias Fuchs * + * Copyright (C) 2012 Reza Fatahilah Shah * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "comic.h" +#include "comicarchivedialog.h" +#include "comicarchivejob.h" +#include "checknewstrips.h" +#include "stripselector.h" +#include "comicsaver.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "comicmodel.h" +#include "configwidget.h" + +K_GLOBAL_STATIC( ComicUpdater, globalComicUpdater ) + +const int ComicApplet::CACHE_LIMIT = 20; + +ComicApplet::ComicApplet( QObject *parent, const QVariantList &args ) + : Plasma::PopupApplet( parent, args ), + mActiveComicModel(parent), + mDifferentComic( true ), + mShowComicUrl( false ), + mShowComicAuthor( false ), + mShowComicTitle( false ), + mShowComicIdentifier( false ), + mShowErrorPicture( true ), + mArrowsOnHover( true ), + mMiddleClick( true ), + mCheckNewStrips( 0 ), + mDeclarativeWidget( 0 ), + mActionShop( 0 ), + mEngine( 0 ), + mSavingDir(0) +{ + setHasConfigurationInterface( true ); + resize( 600, 250 ); + setAspectRatioMode( Plasma::IgnoreAspectRatio ); + + setPopupIcon( "face-smile-big" ); +} + +void ComicApplet::init() +{ + globalComicUpdater->init( globalConfig() ); + mSavingDir = new SavingDir(config()); + + configChanged(); + //QML + QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(this); + mDeclarativeWidget = new Plasma::DeclarativeWidget(this); + layout->addItem(mDeclarativeWidget); + + mDeclarativeWidget->engine()->rootContext()->setContextProperty("comicApplet", this); + + Plasma::PackageStructure::Ptr structure = Plasma::PackageStructure::load("Plasma/Generic"); + Plasma::Package package(QString(), "org.kde.comic", structure); + mDeclarativeWidget->setQmlPath(package.filePath("mainscript")); + //End of QML + + mEngine = dataEngine( "comic" ); + mModel = new ComicModel( mEngine->query( "providers" ), mTabIdentifier, this ); + mProxy = new QSortFilterProxyModel( this ); + mProxy->setSourceModel( mModel ); + mProxy->setSortCaseSensitivity( Qt::CaseInsensitive ); + mProxy->sort( 1, Qt::AscendingOrder ); + + //set maximum number of cached strips per comic, -1 means that there is no limit + KConfigGroup global = globalConfig(); + //convert old values + if ( global.hasKey( "useMaxComicLimit" ) ) { + const bool use = global.readEntry( "useMaxComicLimit", false ); + if ( !use ) { + global.writeEntry( "maxComicLimit", 0 ); + } + global.deleteEntry( "useMaxComicLimit" ); + } + const int maxComicLimit = global.readEntry( "maxComicLimit", CACHE_LIMIT ); + mEngine->query( QLatin1String( "setting_maxComicLimit:" ) + QString::number( maxComicLimit ) ); + + mCurrentDay = QDate::currentDate(); + mDateChangedTimer = new QTimer( this ); + connect( mDateChangedTimer, SIGNAL(timeout()), this, SLOT(checkDayChanged()) ); + mDateChangedTimer->setInterval( 5 * 60 * 1000 ); // every 5 minutes + + mActionNextNewStripTab = new KAction( KIcon( "go-next-view" ), i18nc( "here strip means comic strip", "&Next Tab with a new Strip" ), this ); + mActionNextNewStripTab->setShortcut( KStandardShortcut::openNew() ); + addAction( "next new strip" , mActionNextNewStripTab ); + mActions.append( mActionNextNewStripTab ); + connect( mActionNextNewStripTab, SIGNAL(triggered(bool)), this, SIGNAL(showNextNewStrip()) ); + + mActionGoFirst = new QAction( KIcon( "go-first" ), i18n( "Jump to &first Strip" ), this ); + mActions.append( mActionGoFirst ); + connect( mActionGoFirst, SIGNAL(triggered(bool)), this, SLOT(slotFirstDay()) ); + + mActionGoLast = new QAction( KIcon( "go-last" ), i18n( "Jump to ¤t Strip" ), this ); + mActions.append( mActionGoLast ); + connect( mActionGoLast, SIGNAL(triggered(bool)), this, SLOT(slotCurrentDay()) ); + + mActionGoJump = new QAction( KIcon( "go-jump" ), i18n( "Jump to Strip ..." ), this ); + mActions.append( mActionGoJump ); + connect( mActionGoJump, SIGNAL(triggered(bool)), this, SLOT(slotGoJump()) ); + + if ( hasAuthorization( "LaunchApp" ) ) { + mActionShop = new QAction( i18n( "Visit the shop &website" ), this ); + mActionShop->setEnabled( false ); + mActions.append( mActionShop ); + connect( mActionShop, SIGNAL(triggered(bool)), this, SLOT(slotShop()) ); + } + + if ( hasAuthorization( "FileDialog" ) ) { + QAction *action = new QAction( KIcon( "document-save-as" ), i18n( "&Save Comic As..." ), this ); + mActions.append( action ); + connect( action, SIGNAL(triggered(bool)), this , SLOT(slotSaveComicAs()) ); + } + + if ( hasAuthorization( "FileDialog" ) ) { + QAction *action = new QAction( KIcon( "application-epub+zip" ), i18n( "&Create Comic Book Archive..." ), this ); + mActions.append( action ); + connect( action, SIGNAL(triggered(bool)), this, SLOT(createComicBook()) ); + } + + mActionScaleContent = new QAction( KIcon( "zoom-original" ), i18nc( "@option:check Context menu of comic image", "&Actual Size" ), this ); + mActionScaleContent->setCheckable( true ); + mActionScaleContent->setChecked( mCurrent.scaleComic() ); + mActions.append( mActionScaleContent ); + connect( mActionScaleContent, SIGNAL(triggered(bool)), this , SLOT(slotScaleToContent()) ); + + mActionStorePosition = new QAction( KIcon( "go-home" ), i18nc( "@option:check Context menu of comic image", "Store current &Position" ), this); + mActionStorePosition->setCheckable( true ); + mActionStorePosition->setChecked(mCurrent.hasStored()); + mActions.append( mActionStorePosition ); + connect( mActionStorePosition, SIGNAL(triggered(bool)), this, SLOT(slotStorePosition()) ); + + //make sure that tabs etc. are displayed even if the comic strip in the first tab does not work + updateView(); + + updateUsedComics(); + changeComic( true ); +} + +ComicApplet::~ComicApplet() +{ + delete mSavingDir; +} + +QGraphicsWidget *ComicApplet::graphicsWidget() +{ + return mDeclarativeWidget; +} + +void ComicApplet::dataUpdated( const QString &source, const Plasma::DataEngine::Data &data ) +{ + //disconnect prefetched comic strips + if ( source != mOldSource ) { + mEngine->disconnectSource( source, this ); + return; + } + + setBusy( false ); + setConfigurationRequired( false ); + + //there was an error, display information as image + const bool hasError = data[ "Error" ].toBool(); + const bool errorAutoFixable = data[ "Error automatically fixable" ].toBool(); + if ( hasError ) { + const QString previousIdentifierSuffix = data[ "Previous identifier suffix" ].toString(); + if ( !mShowErrorPicture && !previousIdentifierSuffix.isEmpty() ) { + mEngine->disconnectSource( source, this ); + updateComic( previousIdentifierSuffix ); + return; + } + } + + mCurrent.setData(data); + + setAssociatedApplicationUrls(mCurrent.websiteUrl()); + + //looking at the last index, thus not mark it as new + KConfigGroup cg = config(); + if (!mCurrent.hasNext() && mCheckNewComicStripsIntervall) { + setTabHighlighted( mCurrent.id(), false ); + mActionNextNewStripTab->setEnabled( hasHighlightedTabs() ); + } + + //call the slot to check if the position needs to be saved + slotStorePosition(); + + //disconnect if there is either no error, or an error that can not be fixed automatically + if ( !errorAutoFixable ) { + mEngine->disconnectSource( source, this ); + } + + //prefetch the previous and following comic for faster navigation + if (mCurrent.hasNext()) { + const QString prefetch = mCurrent.id() + ':' + mCurrent.next(); + mEngine->connectSource( prefetch, this ); + mEngine->query( prefetch ); + } + if ( mCurrent.hasPrev()) { + const QString prefetch = mCurrent.id() + ':' + mCurrent.prev(); + mEngine->connectSource( prefetch, this ); + mEngine->query( prefetch ); + } + + updateView(); + + refreshComicData(); +} + +void ComicApplet::updateView() +{ + updateContextMenu(); +} + +void ComicApplet::createConfigurationInterface( KConfigDialog *parent ) +{ + mConfigWidget = new ConfigWidget( dataEngine( "comic" ), mModel, mProxy, parent ); + mConfigWidget->setShowComicUrl( mShowComicUrl ); + mConfigWidget->setShowComicAuthor( mShowComicAuthor ); + mConfigWidget->setShowComicTitle( mShowComicTitle ); + mConfigWidget->setShowComicIdentifier( mShowComicIdentifier ); + mConfigWidget->setShowErrorPicture( mShowErrorPicture ); + mConfigWidget->setArrowsOnHover( mArrowsOnHover ); + mConfigWidget->setMiddleClick( mMiddleClick ); + mConfigWidget->setCheckNewComicStripsIntervall( mCheckNewComicStripsIntervall ); + + //not storing this value, since other applets might have changed it inbetween + KConfigGroup global = globalConfig(); + const int maxComicLimit = global.readEntry( "maxComicLimit", CACHE_LIMIT ); + mConfigWidget->setMaxComicLimit( maxComicLimit ); + const int updateIntervall = global.readEntry( "updateIntervall", 3 ); + mConfigWidget->setUpdateIntervall( updateIntervall ); + + parent->setButtons( KDialog::Ok | KDialog::Cancel | KDialog::Apply ); + parent->addPage( mConfigWidget->comicSettings, i18n( "General" ), icon() ); + parent->addPage( mConfigWidget->appearanceSettings, i18n( "Appearance" ), "image" ); + parent->addPage( mConfigWidget->advancedSettings, i18n( "Advanced" ), "system-run" ); + + connect( parent, SIGNAL(applyClicked()), this, SLOT(applyConfig()) ); + connect( parent, SIGNAL(okClicked()), this, SLOT(applyConfig()) ); + connect(mConfigWidget, SIGNAL(enableApply()), parent, SLOT(settingsModified())); +} + +void ComicApplet::applyConfig() +{ + setShowComicUrl(mConfigWidget->showComicUrl()); + setShowComicAuthor(mConfigWidget->showComicAuthor()); + setShowComicTitle(mConfigWidget->showComicTitle()); + setShowComicIdentifier(mConfigWidget->showComicIdentifier()); + setShowErrorPicture(mConfigWidget->showErrorPicture()); + setArrowsOnHover(mConfigWidget->arrowsOnHover()); + setMiddleClick(mConfigWidget->middleClick()); + mCheckNewComicStripsIntervall = mConfigWidget->checkNewComicStripsIntervall(); + + //not storing this value, since other applets might have changed it inbetween + KConfigGroup global = globalConfig(); + const int oldMaxComicLimit = global.readEntry( "maxComicLimit", CACHE_LIMIT ); + const int maxComicLimit = mConfigWidget->maxComicLimit(); + if ( oldMaxComicLimit != maxComicLimit ) { + global.writeEntry( "maxComicLimit", maxComicLimit ); + mEngine->query( QLatin1String( "setting_maxComicLimit:" ) + QString::number( maxComicLimit ) ); + } + + + globalComicUpdater->applyConfig( mConfigWidget ); + + updateUsedComics(); + saveConfig(); + + //make sure that tabs etc. are displayed even if the comic strip in the first tab does not work + updateView(); + + changeComic( mDifferentComic ); +} + +void ComicApplet::changeComic( bool differentComic ) +{ + if ( differentComic ) { + KConfigGroup cg = config(); + mActionStorePosition->setChecked(mCurrent.storePosition()); + + // assign mScaleComic the moment the new strip has been loaded (dataUpdated) as up to this point + // the old one should be still shown with its scaling settings + mActionScaleContent->setChecked( mCurrent.scaleComic() ); + + updateComic( mCurrent.stored() ); + } else { + updateComic( mCurrent.current() ); + } +} + +void ComicApplet::updateUsedComics() +{ + const QString oldIdentifier = mCurrent.id(); + + mActiveComicModel.clear(); + mTabIdentifier.clear(); + mCurrent = ComicData(); + + bool isFirst = true; + QModelIndex data; + KConfigGroup cg = config(); + int tab = 0; + for ( int i = 0; i < mProxy->rowCount(); ++i ) { + if ( mProxy->index( i, 0 ).data( Qt::CheckStateRole) == Qt::Checked ) { + data = mProxy->index( i, 1 ); + + if ( isFirst ) { + isFirst = false; + const QString id = data.data( Qt::UserRole ).toString(); + mDifferentComic = ( oldIdentifier != id ); + const QString title = data.data().toString(); + mCurrent.init(id, config()); + mCurrent.setTitle(title); + } + + const QString name = data.data().toString(); + const QString identifier = data.data( Qt::UserRole ).toString(); + const QString iconPath = data.data( Qt::DecorationRole ).value().name(); + //found a newer strip last time, which was not visited + if ( mCheckNewComicStripsIntervall && !cg.readEntry( "lastStripVisited_" + identifier, true ) ) { + mActiveComicModel.addComic(identifier, name, iconPath, true); + } else { + mActiveComicModel.addComic(identifier, name, iconPath); + } + + mTabIdentifier << identifier; + ++tab; + } + } + + mActionNextNewStripTab->setVisible( mCheckNewComicStripsIntervall ); + mActionNextNewStripTab->setEnabled( hasHighlightedTabs() ); + + delete mCheckNewStrips; + mCheckNewStrips = 0; + if ( mCheckNewComicStripsIntervall ) { + mCheckNewStrips = new CheckNewStrips( mTabIdentifier, mEngine, mCheckNewComicStripsIntervall, this ); + connect( mCheckNewStrips, SIGNAL(lastStrip(int,QString,QString)), this, SLOT(slotFoundLastStrip(int,QString,QString)) ); + } + + emit comicModelChanged(); +} + +void ComicApplet::slotTabChanged(const QString &identifier) +{ + bool differentComic = (mCurrent.id() != identifier); + mCurrent = ComicData(); + mCurrent.init(identifier, config()); + changeComic( differentComic ); +} + +void ComicApplet::checkDayChanged() +{ + if ( ( mCurrentDay != QDate::currentDate() ) || !mCurrent.hasImage() ) + updateComic( mCurrent.stored() ); + + mCurrentDay = QDate::currentDate(); +} + +void ComicApplet::configChanged() +{ + KConfigGroup cg = config(); + mTabIdentifier = cg.readEntry( "tabIdentifier", QStringList( QString() ) ); + + const QString id = mTabIdentifier.count() ? mTabIdentifier.at( 0 ) : QString(); + mCurrent = ComicData(); + mCurrent.init(id, cg); + + mShowComicUrl = cg.readEntry( "showComicUrl", false ); + mShowComicAuthor = cg.readEntry( "showComicAuthor", false ); + mShowComicTitle = cg.readEntry( "showComicTitle", false ); + mShowComicIdentifier = cg.readEntry( "showComicIdentifier", false ); + mShowErrorPicture = cg.readEntry( "showErrorPicture", true ); + mArrowsOnHover = cg.readEntry( "arrowsOnHover", true ); + mMiddleClick = cg.readEntry( "middleClick", true ); + mCheckNewComicStripsIntervall = cg.readEntry( "checkNewComicStripsIntervall", 30 ); + + //use a decent default size + const QSizeF tempMaxSize = isInPanel() ? QSizeF( 600, 250 ) : this->size(); + mMaxSize = cg.readEntry( "maxSize", tempMaxSize ); + mLastSize = mMaxSize; + + globalComicUpdater->load(); +} + +void ComicApplet::saveConfig() +{ + KConfigGroup cg = config(); + cg.writeEntry( "comic", mCurrent.id() ); + cg.writeEntry( "showComicUrl", mShowComicUrl ); + cg.writeEntry( "showComicAuthor", mShowComicAuthor ); + cg.writeEntry( "showComicTitle", mShowComicTitle ); + cg.writeEntry( "showComicIdentifier", mShowComicIdentifier ); + cg.writeEntry( "showErrorPicture", mShowErrorPicture ); + cg.writeEntry( "arrowsOnHover", mArrowsOnHover ); + cg.writeEntry( "middleClick", mMiddleClick ); + cg.writeEntry( "tabIdentifier", mTabIdentifier ); + cg.writeEntry( "checkNewComicStripsIntervall", mCheckNewComicStripsIntervall ); + + globalComicUpdater->save(); +} + +void ComicApplet::slotNextDay() +{ + updateComic(mCurrent.next()); +} + +void ComicApplet::slotPreviousDay() +{ + updateComic(mCurrent.prev()); +} + +void ComicApplet::slotFirstDay() +{ + updateComic(mCurrent.first()); +} + +void ComicApplet::slotCurrentDay() +{ + updateComic(QString()); +} + +void ComicApplet::slotFoundLastStrip( int index, const QString &identifier, const QString &suffix ) +{ + KConfigGroup cg = config(); + if ( suffix != cg.readEntry( "lastStrip_" + identifier, QString() ) ) { + kDebug() << identifier << "has a newer strip."; + setTabHighlighted( identifier, true ); + cg.writeEntry( "lastStripVisited_" + identifier, false ); + } + + mActionNextNewStripTab->setEnabled( hasHighlightedTabs() ); +} + +void ComicApplet::slotGoJump() +{ + StripSelector *selector = StripSelectorFactory::create(mCurrent.type()); + connect(selector, SIGNAL(stripChosen(QString)), this, SLOT(updateComic(QString))); + + selector->select(mCurrent); +} + +void ComicApplet::slotStorePosition() +{ + mCurrent.storePosition(mActionStorePosition->isChecked()); +} + +void ComicApplet::slotShop() +{ + KRun::runUrl(mCurrent.shopUrl(), "text/html", 0); +} + +bool ComicApplet::isInPanel() const +{ + return ( this->geometry().width() < 70 ) || ( this->geometry().height() < 50 ); +} + +void ComicApplet::createComicBook() +{ + ComicArchiveDialog *dialog = new ComicArchiveDialog(mCurrent.id(), mCurrent.title(), mCurrent.type(), mCurrent.current(), + mCurrent.first(), mSavingDir->getDir()); + dialog->setAttribute(Qt::WA_DeleteOnClose);//to have destroyed emitted upon closing + connect( dialog, SIGNAL(archive(int,KUrl,QString,QString)), this, SLOT(slotArchive(int,KUrl,QString,QString)) ); + dialog->show(); +} + +void ComicApplet::slotArchive( int archiveType, const KUrl &dest, const QString &fromIdentifier, const QString &toIdentifier ) +{ + mSavingDir->setDir(dest.directory()); + + const QString id = mCurrent.id(); + kDebug() << "Archiving:" << id << archiveType << dest << fromIdentifier << toIdentifier; + ComicArchiveJob *job = new ComicArchiveJob(dest, mEngine, static_cast< ComicArchiveJob::ArchiveType >( archiveType ), mCurrent.type(), id, this); + job->setFromIdentifier(id + ':' + fromIdentifier); + job->setToIdentifier(id + ':' + toIdentifier); + if (job->isValid()) { + connect(job, SIGNAL(finished(KJob*)), this, SLOT(slotArchiveFinished(KJob*))); + KIO::getJobTracker()->registerJob(job); + job->start(); + } else { + kWarning() << "Archiving job is not valid."; + delete job; + } +} + +void ComicApplet::slotArchiveFinished (KJob *job ) +{ + if ( job->error() ) { + KNotification::event( KNotification::Warning, i18n( "Archiving comic failed" ), job->errorText(), KIcon( "dialog-warning" ).pixmap( KIconLoader::SizeMedium ) ); + } +} + +QList ComicApplet::contextualActions() +{ + return mActions; +} + +QSizeF ComicApplet::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const +{ + if (which != Qt::PreferredSize) { + return Applet::sizeHint(which, constraint); + } else { + QSize imageSize = mCurrent.image().size(); + if (!imageSize.isEmpty()) { + return imageSize; + } else { + return Applet::sizeHint(which, constraint); + } + } +} + +void ComicApplet::updateComic( const QString &identifierSuffix ) +{ + mEngine = dataEngine( "comic" ); + const QString id = mCurrent.id(); + setConfigurationRequired( id.isEmpty() ); + if ( !id.isEmpty() && mEngine && mEngine->isValid() ) { + + setBusy( true ); + const QString identifier = id + ':' + identifierSuffix; + + //disconnecting of the oldSource is needed, otherwise you could get data for comics you are not looking at if you use tabs + //if there was an error only disconnect the oldSource if it had nothing to do with the error or if the comic changed, that way updates of the error can come in + if ( !mIdentifierError.isEmpty() && !mIdentifierError.contains( id ) ) { + mEngine->disconnectSource( mIdentifierError, this ); + mIdentifierError.clear(); + } + if ( ( mIdentifierError != mOldSource ) && ( mOldSource != identifier ) ) { + mEngine->disconnectSource( mOldSource, this ); + } + mOldSource = identifier; + mEngine->disconnectSource( identifier, this ); + mEngine->connectSource( identifier, this ); + const Plasma::DataEngine::Data data = mEngine->query( identifier ); + + if ( data[ "Error" ].toBool() ) { + dataUpdated( QString(), data ); + } + } else { + kError() << "Either no identifier was specified or the engine could not be created:" << "id" << id << "engine valid:" << ( mEngine && mEngine->isValid() ); + setConfigurationRequired( true ); + } +} + +void ComicApplet::updateContextMenu() +{ + mActionGoFirst->setVisible(mCurrent.hasFirst()); + mActionGoFirst->setEnabled(mCurrent.hasPrev()); + mActionGoLast->setEnabled(true);//always enable to have some kind of refresh action + if (mActionShop) { + mActionShop->setEnabled(mCurrent.shopUrl().isValid()); + } +} + +void ComicApplet::slotSaveComicAs() +{ + ComicSaver saver(mSavingDir); + saver.save(mCurrent); +} + +void ComicApplet::slotScaleToContent() +{ + setShowActualSize(mActionScaleContent->isChecked()); +} + +//QML +QObject *ComicApplet::comicsModel() +{ + return &mActiveComicModel; +} + +bool ComicApplet::showComicUrl() const +{ + return mShowComicUrl; +} + +void ComicApplet::setShowComicUrl(bool show) +{ + if (show == mShowComicUrl) + return; + + mShowComicUrl = show; + + emit showComicUrlChanged(); +} + +bool ComicApplet::showComicAuthor() const +{ + return mShowComicAuthor; +} + +void ComicApplet::setShowComicAuthor(bool show) +{ + if (show == mShowComicAuthor) + return; + + mShowComicAuthor = show; + + emit showComicAuthorChanged(); +} + +bool ComicApplet::showComicTitle() const +{ + return mShowComicTitle; +} + +void ComicApplet::setShowComicTitle(bool show) +{ + if (show == mShowComicTitle) + return; + + mShowComicTitle = show; + + emit showComicTitleChanged(); +} + +bool ComicApplet::showComicIdentifier() const +{ + return mShowComicIdentifier; +} + +void ComicApplet::setShowComicIdentifier(bool show) +{ + if (show == mShowComicIdentifier) + return; + + mShowComicIdentifier = show; + + emit showComicIdentifierChanged(); +} + +bool ComicApplet::showErrorPicture() const +{ + return mShowErrorPicture; +} + +void ComicApplet::setShowErrorPicture(bool show) +{ + if (show == mShowErrorPicture) + return; + + mShowErrorPicture = show; + + emit showErrorPictureChanged(); +} + +bool ComicApplet::arrowsOnHover() const +{ + return mArrowsOnHover; +} + +void ComicApplet::setArrowsOnHover(bool show) +{ + if (show == mArrowsOnHover) + return; + + mArrowsOnHover = show; + + emit arrowsOnHoverChanged(); +} + +bool ComicApplet::middleClick() const +{ + return mMiddleClick; +} + +void ComicApplet::setMiddleClick(bool show) +{ + if (show == mMiddleClick) + return; + + mMiddleClick = show; + + emit middleClickChanged(); +} + +QVariantHash ComicApplet::comicData() +{ + return mComicData; +} + +void ComicApplet::refreshComicData() +{ + mComicData["image"] = mCurrent.image(); + mComicData["prev"] = mCurrent.prev(); + mComicData["next"] = mCurrent.next(); + mComicData["additionalText"] = mCurrent.additionalText(); + + mComicData["websiteUrl"] = mCurrent.websiteUrl().prettyUrl(); + mComicData["websiteHost"] = mCurrent.websiteUrl().host(); + mComicData["imageUrl"] = mCurrent.websiteUrl().prettyUrl(); + mComicData["shopUrl"] = mCurrent.websiteUrl().prettyUrl(); + mComicData["first"] = mCurrent.first(); + mComicData["stripTitle"] = mCurrent.stripTitle(); + mComicData["author"] = mCurrent.author(); + mComicData["title"] = mCurrent.title(); + + mComicData["suffixType"] = "Date"; + mComicData["current"] = mCurrent.current(); + //mComicData["last"] = mCurrent.last(); + mComicData["currentReadable"] = mCurrent.currentReadable(); + mComicData["firstStripNum"] = mCurrent.firstStripNum(); + mComicData["maxStripNum"] = mCurrent.maxStripNum(); + mComicData["isLeftToRight"] = mCurrent.isLeftToRight(); + mComicData["isTopToBottom"] = mCurrent.isTopToBottom(); + + emit comicDataChanged(); +} + +bool ComicApplet::showActualSize() const +{ + return mCurrent.scaleComic(); +} + +void ComicApplet::setShowActualSize(bool show) +{ + if (show == mCurrent.scaleComic()) + return; + + mCurrent.setScaleComic(show); + + emit showActualSizeChanged(); +} +//Endof QML +void ComicApplet::setTabHighlighted(const QString &id, bool highlight) +{ + //Search for matching id + for (int index = 0; index < mActiveComicModel.rowCount(); ++index) { + QStandardItem * item = mActiveComicModel.item(index); + + QString currentId = item->data(ActiveComicModel::ComicKeyRole).toString(); + if (id == currentId){ + if (highlight != item->data(ActiveComicModel::ComicHighlightRole).toBool()) { + item->setData(highlight, ActiveComicModel::ComicHighlightRole); + emit tabHighlightRequest(id, highlight); + } + } + } +} + +bool ComicApplet::hasHighlightedTabs() +{ + for (int i = 0; i < mActiveComicModel.rowCount(); ++i) { + if (isTabHighlighted(i)) { + return true; + } + } + + return false; +} + +bool ComicApplet::isTabHighlighted(int index) const +{ + if (index < 0 || index >= mActiveComicModel.rowCount()) { + return false; + } + + QStandardItem * item = mActiveComicModel.item(index); + + return item->data(ActiveComicModel::ComicHighlightRole).toBool(); +} +#include "comic.moc" diff --git a/kdeplasma-addons/applets/comic/comic.h b/kdeplasma-addons/applets/comic/comic.h new file mode 100644 index 00000000..d460b112 --- /dev/null +++ b/kdeplasma-addons/applets/comic/comic.h @@ -0,0 +1,209 @@ +/*************************************************************************** + * Copyright (C) 2007 by Tobias Koenig * + * Copyright (C) 2008 by Marco Martin * + * Copyright (C) 2008-2010 Matthias Fuchs * + * Copyright (C) 2012 Reza Fatahilah Shah * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef COMIC_H +#define COMIC_H + +#include "comicdata.h" + +#include + +#include +#include +#include + +#include "activecomicmodel.h" + +namespace Plasma { + class DeclarativeWidget; +} + +class CheckNewStrips; +class ComicModel; +class ConfigWidget; +class KAction; +class KJob; +class QAction; +class QGraphicsLayout; +class QSortFilterProxyModel; +class QTimer; +class SavingDir; + +class ComicApplet : public Plasma::PopupApplet +{ + Q_OBJECT + Q_PROPERTY(QObject * comicsModel READ comicsModel NOTIFY comicModelChanged) + Q_PROPERTY(bool showComicUrl READ showComicUrl WRITE setShowComicUrl NOTIFY showComicUrlChanged) + Q_PROPERTY(bool showComicAuthor READ showComicAuthor WRITE setShowComicAuthor NOTIFY showComicAuthorChanged) + Q_PROPERTY(bool showComicTitle READ showComicTitle WRITE setShowComicTitle NOTIFY showComicTitleChanged) + Q_PROPERTY(bool showComicIdentifier READ showComicIdentifier WRITE setShowComicIdentifier NOTIFY showComicIdentifierChanged) + Q_PROPERTY(bool showErrorPicture READ showErrorPicture WRITE setShowErrorPicture NOTIFY showErrorPictureChanged) + Q_PROPERTY(bool arrowsOnHover READ arrowsOnHover WRITE setArrowsOnHover NOTIFY arrowsOnHoverChanged) + Q_PROPERTY(bool middleClick READ middleClick WRITE setMiddleClick NOTIFY middleClickChanged) + Q_PROPERTY(QVariantHash comicData READ comicData NOTIFY comicDataChanged) + Q_PROPERTY(bool showActualSize READ showActualSize WRITE setShowActualSize NOTIFY showActualSizeChanged) + + public: + ComicApplet( QObject *parent, const QVariantList &args ); + ~ComicApplet(); + + void init(); + virtual QList contextualActions(); + + QGraphicsWidget *graphicsWidget(); + + //For QML + QObject *comicsModel(); + QVariantHash comicData(); + + bool showComicUrl() const; + void setShowComicUrl(bool show); + + bool showComicAuthor() const; + void setShowComicAuthor(bool show); + + bool showComicTitle() const; + void setShowComicTitle(bool show); + + bool showComicIdentifier() const; + void setShowComicIdentifier(bool show); + + bool showErrorPicture() const; + void setShowErrorPicture(bool show); + + bool arrowsOnHover() const; + void setArrowsOnHover(bool show); + + bool middleClick() const; + void setMiddleClick(bool show); + + bool showActualSize() const; + void setShowActualSize(bool show); + + Q_INVOKABLE bool checkAuthorization(const QString &permissionName) { return hasAuthorization(permissionName); } + //End for QML +Q_SIGNALS: + void comicModelChanged(); + void showComicUrlChanged(); + void showComicAuthorChanged(); + void showComicTitleChanged(); + void showComicIdentifierChanged(); + void showErrorPictureChanged(); + void arrowsOnHoverChanged(); + void middleClickChanged(); + void comicDataChanged(); + void tabHighlightRequest(const QString &id, bool highlight); + void showNextNewStrip(); + void showActualSizeChanged(); + + public Q_SLOTS: + void dataUpdated( const QString &name, const Plasma::DataEngine::Data &data ); + void createConfigurationInterface( KConfigDialog *parent ); + + private Q_SLOTS: + void slotTabChanged( const QString &newIdentifier ); + void slotNextDay(); + void slotPreviousDay(); + void slotFirstDay(); + void slotCurrentDay(); + void slotFoundLastStrip( int index, const QString &identifier, const QString &suffix ); + void slotGoJump(); + void slotSaveComicAs(); + void slotScaleToContent(); + void slotShop(); + void slotStorePosition(); + void applyConfig(); + void checkDayChanged(); + void createComicBook(); + void slotArchive( int archiveType, const KUrl &dest, const QString &fromIdentifier, const QString &toIdentifier ); + void slotArchiveFinished( KJob *job ); + + public slots: + void configChanged(); + Q_INVOKABLE void updateComic(const QString &identifierSuffix = QString()); + Q_INVOKABLE void goJump() { slotGoJump();} + Q_INVOKABLE void shop() { slotShop();} + Q_INVOKABLE void tabChanged(const QString &newIdentifier) { slotTabChanged(newIdentifier);} + + protected: + QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; + + private: + void changeComic( bool differentComic ); + void updateUsedComics(); + void updateContextMenu(); + void updateView(); + void saveConfig(); + bool isInPanel() const; + void refreshComicData(); + void setTabHighlighted(const QString &id, bool highlight); + bool hasHighlightedTabs(); + bool isTabHighlighted(int index) const; + + private: + static const int CACHE_LIMIT; + ComicModel *mModel; + QSortFilterProxyModel *mProxy; + ActiveComicModel mActiveComicModel; + QVariantHash mComicData; + + QDate mCurrentDay; + + QString mIdentifierError; + QString mOldSource; + ConfigWidget *mConfigWidget; + bool mDifferentComic; + bool mShowComicUrl; + bool mShowComicAuthor; + bool mShowComicTitle; + bool mShowComicIdentifier; + bool mShowErrorPicture; + bool mArrowsOnHover; + bool mMiddleClick; + int mCheckNewComicStripsIntervall; + CheckNewStrips *mCheckNewStrips; + QTimer *mDateChangedTimer; + QList mActions; + Plasma::DeclarativeWidget *mDeclarativeWidget; + QAction *mActionGoFirst; + QAction *mActionGoLast; + QAction *mActionGoJump; + QAction *mActionScaleContent; + QAction *mActionShop; + QAction *mActionStorePosition; + KAction *mActionNextNewStripTab; + QSizeF mMaxSize; + QSizeF mLastSize; + QSizeF mIdealSize; + Plasma::DataEngine *mEngine; + + //Tabs + bool mTabAdded; + QStringList mTabIdentifier; + + ComicData mCurrent; + SavingDir *mSavingDir; +}; + +K_EXPORT_PLASMA_APPLET( comic, ComicApplet ) + +#endif diff --git a/kdeplasma-addons/applets/comic/comic.knsrc b/kdeplasma-addons/applets/comic/comic.knsrc new file mode 100644 index 00000000..e9ddbf7b --- /dev/null +++ b/kdeplasma-addons/applets/comic/comic.knsrc @@ -0,0 +1,8 @@ +[KNewStuff3] +ProvidersUrl=http://download.kde.org/ocs/providers.xml +Categories=Plasma Comic +TargetDir=plasma/comics +Uncompress=never +InstallationCommand=plasmapkg -t comic -i %f +UninstallCommand=plasmapkg -t comic -r %f + diff --git a/kdeplasma-addons/applets/comic/comicSettings.ui b/kdeplasma-addons/applets/comic/comicSettings.ui new file mode 100644 index 00000000..fd73d477 --- /dev/null +++ b/kdeplasma-addons/applets/comic/comicSettings.ui @@ -0,0 +1,238 @@ + + + ComicSettings + + + + 0 + 0 + 500 + 394 + + + + + 0 + 0 + + + + + + + + + + + 75 + true + + + + Comic + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + QAbstractItemView::NoEditTriggers + + + false + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + true + + + true + + + false + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 5 + + + + + + + + + + Download new comics + + + &Get New Comics... + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 0 + 0 + + + + &Middle-click on the comic to show it at its original size + + + true + + + + + + + + 75 + true + + + + Update + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Automatically update comic plugins: + + + + + + + 0 + + + 0 + + + 120 + + + days + + + every + + + never + + + + + + + Check for new comic strips: + + + + + + + 0 + + + 0 + + + 1200 + + + minutes + + + every + + + never + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 40 + 5 + + + + + + + + + + pushButton_GHNS + + + + diff --git a/kdeplasma-addons/applets/comic/comicarchivedialog.cpp b/kdeplasma-addons/applets/comic/comicarchivedialog.cpp new file mode 100644 index 00000000..35902d83 --- /dev/null +++ b/kdeplasma-addons/applets/comic/comicarchivedialog.cpp @@ -0,0 +1,200 @@ +/*************************************************************************** + * Copyright (C) 2011 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "comicarchivedialog.h" +#include "comicarchivejob.h" + +#include + +ComicArchiveDialog::ComicArchiveDialog( const QString &pluginName, const QString &comicName, IdentifierType identifierType, const QString ¤tIdentifierSuffix, const QString &firstIdentifierSuffix, const QString &savingDir, QWidget *parent ) + : KDialog( parent ), + mIdentifierType( identifierType ), + mPluginName( pluginName ) +{ + QWidget *widget = new QWidget(this); + ui.setupUi(widget); + setCaption( i18n( "Create %1 Comic Book Archive", comicName ) ); + setMainWidget( widget ); + + switch ( mIdentifierType ) { + case Date: { + const QDate current = QDate::fromString( currentIdentifierSuffix, "yyyy-MM-dd" ); + const QDate first = QDate::fromString( firstIdentifierSuffix, "yyyy-MM-dd" ); + const QDate today = QDate::currentDate(); + QDate maxDate = today; + if ( current.isValid() ) { + ui.fromDate->setDate( current ); + ui.toDate->setDate( current ); + maxDate = ( today > current ? today : current ); + } + if ( first.isValid() ) { + ui.fromDate->setMinimumDate( first ); + ui.toDate->setMinimumDate( first ); + } + + connect( ui.fromDate, SIGNAL(dateChanged(QDate)), this, SLOT(fromDateChanged(QDate)) ); + connect( ui.toDate, SIGNAL(dateChanged(QDate)), this, SLOT(toDateChanged(QDate)) ); + break; + } + case Number: { + bool ok; + const int current = currentIdentifierSuffix.toInt( &ok ); + if ( ok ) { + ui.fromNumber->setValue( current ); + ui.toNumber->setValue( current ); + } + const int first = firstIdentifierSuffix.toInt( &ok ); + if ( ok ) { + ui.fromNumber->setMinimum( first ); + ui.toNumber->setMinimum( first ); + } + break; + } + case String: { + ui.fromString->setText( currentIdentifierSuffix ); + ui.toString->setText( currentIdentifierSuffix ); + connect( ui.fromString, SIGNAL(textEdited(QString)), this, SLOT(updateOkButton()) ); + connect( ui.toString, SIGNAL(textEdited(QString)), this, SLOT(updateOkButton()) ); + break; + } + } + + ui.types->setCurrentIndex( mIdentifierType ); + + archiveTypeChanged( ComicArchiveJob::ArchiveAll ); + + //TODO suggest file name! + ui.dest->fileDialog()->setOperationMode( KFileDialog::Saving ); + if ( !savingDir.isEmpty() ) { + ui.dest->setStartDir( savingDir ); + } + + connect( ui.archiveType, SIGNAL(currentIndexChanged(int)), this, SLOT(archiveTypeChanged(int)) ); + connect( ui.dest, SIGNAL(textChanged(QString)), this, SLOT(updateOkButton()) ); + connect( this, SIGNAL(okClicked()), this, SLOT(slotOkClicked()) ); +} + +void ComicArchiveDialog::archiveTypeChanged( int newType ) +{ + switch ( newType ) { + case ComicArchiveJob::ArchiveAll: + setFromVisible( false ); + setToVisibile( false ); + break; + break; + case ComicArchiveJob::ArchiveEndTo: + case ComicArchiveJob::ArchiveStartTo: + setFromVisible( false ); + setToVisibile( true ); + break; + case ComicArchiveJob::ArchiveFromTo: + setFromVisible( true ); + setToVisibile( true ); + break; + } + + updateOkButton(); +} + +void ComicArchiveDialog::fromDateChanged( const QDate &newDate ) +{ + if ( ui.toDate->date() < newDate ) { + ui.toDate->setDate( newDate ); + } + updateOkButton(); +} + +void ComicArchiveDialog::toDateChanged( const QDate &newDate ) +{ + if ( ui.fromDate->date() > newDate ) { + ui.fromDate->setDate( newDate ); + } + updateOkButton(); +} + +void ComicArchiveDialog::updateOkButton() +{ + const int archiveType = ui.archiveType->currentIndex(); + bool okEnabled = true; + + //string is handled here, as it is the only identifier which can be invalid (empty) + if ( mIdentifierType == String ) { + if ( archiveType == ComicArchiveJob::ArchiveAll ) { + okEnabled = true ; + } else if ( ui.archiveType->currentIndex() == ComicArchiveJob::ArchiveFromTo ) { + okEnabled = !ui.fromString->text().isEmpty() && !ui.toString->text().isEmpty(); + } else { + okEnabled = !ui.toString->text().isEmpty(); + } + } + + okEnabled = ( okEnabled && !ui.dest->url().isEmpty() ); + enableButtonOk( okEnabled ); +} + +void ComicArchiveDialog::slotOkClicked() +{ + const int archiveType = ui.archiveType->currentIndex(); + QString fromIdentifier; + QString toIdentifier; + + switch ( mIdentifierType ) { + case Date: + fromIdentifier = ui.fromDate->date().toString( "yyyy-MM-dd" ); + toIdentifier = ui.toDate->date().toString( "yyyy-MM-dd" ); + break; + case Number: { + fromIdentifier = QString::number( ui.fromNumber->value() ); + toIdentifier = QString::number( ui.toNumber->value() ); + //the user entered from and to wrong, swap them + if ( ( archiveType == ComicArchiveJob::ArchiveFromTo) && ( ui.toNumber->value() < ui.fromNumber->value() ) ) { + QString temp = fromIdentifier; + fromIdentifier = toIdentifier; + toIdentifier = temp; + } + break; + } + case String: + fromIdentifier = ui.fromString->text(); + toIdentifier = ui.toString->text(); + break; + } + + emit archive( archiveType, ui.dest->url(), fromIdentifier, toIdentifier ); +} + +void ComicArchiveDialog::setFromVisible( bool visible ) +{ + ui.fromDateLabel->setVisible( visible ); + ui.fromDate->setVisible( visible ); + ui.fromNumberLabel->setVisible( visible ); + ui.fromNumber->setVisible( visible ); + ui.fromStringLabel->setVisible( visible ); + ui.fromString->setVisible( visible ); +} + +void ComicArchiveDialog::setToVisibile( bool visible ) +{ + ui.toDateLabel->setVisible( visible ); + ui.toDate->setVisible( visible ); + ui.toNumberLabel->setVisible( visible ); + ui.toNumber->setVisible( visible ); + ui.toStringLabel->setVisible( visible ); + ui.toString->setVisible( visible ); +} diff --git a/kdeplasma-addons/applets/comic/comicarchivedialog.h b/kdeplasma-addons/applets/comic/comicarchivedialog.h new file mode 100644 index 00000000..2bd6551f --- /dev/null +++ b/kdeplasma-addons/applets/comic/comicarchivedialog.h @@ -0,0 +1,57 @@ +/*************************************************************************** + * Copyright (C) 2011 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef COMIC_ARCHIVE_DIALOG_H +#define COMIC_ARCHIVE_DIALOG_H + +#include "comicinfo.h" + +#include "ui_comicarchivedialog.h" + +#include + + +class ComicArchiveDialog : public KDialog +{ + Q_OBJECT + + public: + ComicArchiveDialog( const QString &pluginName, const QString &comicName, IdentifierType identifierType, const QString ¤tIdentifierSuffix, const QString &firstIdentifierSuffix, const QString &savingDir = QString(), QWidget *parent = 0 ); + + signals: + void archive( int archiveType, const KUrl &dest, const QString &fromIdentifier, const QString &toIdentifier ); + + private slots: + void archiveTypeChanged( int newType ); + void fromDateChanged( const QDate &newDate ); + void toDateChanged( const QDate &newDate ); + void slotOkClicked(); + void updateOkButton(); + + private: + void setFromVisible( bool visible ); + void setToVisibile( bool visible ); + + private: + Ui::ComicArchiveDialog ui; + IdentifierType mIdentifierType; + QString mPluginName; +}; + +#endif diff --git a/kdeplasma-addons/applets/comic/comicarchivedialog.ui b/kdeplasma-addons/applets/comic/comicarchivedialog.ui new file mode 100644 index 00000000..64911793 --- /dev/null +++ b/kdeplasma-addons/applets/comic/comicarchivedialog.ui @@ -0,0 +1,218 @@ + + + ComicArchiveDialog + + + + 0 + 0 + 469 + 143 + + + + + + + + 75 + true + + + + Destination: + + + + + + + *.cbz|Comic Book Archive (Zip) + + + KFile::File|KFile::LocalOnly + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 5 + + + + + + + + The range of comic strips to archive. + + + Range: + + + + + + + + All + + + + + From beginning to ... + + + + + From end to ... + + + + + Manual range + + + + + + + + 0 + + + + + 0 + + + + + From: + + + + + + + To: + + + + + + + dd.MM.yyyy + + + true + + + + + + + dd.MM.yyyy + + + true + + + + + + + + + 0 + + + + + From: + + + + + + + To: + + + + + + + 100000 + + + + + + + 100000 + + + + + + + + + 0 + + + + + From: + + + + + + + To: + + + + + + + + + + + + + + + + + + KUrlRequester + QFrame +
kurlrequester.h
+
+ + KLineEdit + QLineEdit +
klineedit.h
+
+ + KComboBox + QComboBox +
kcombobox.h
+
+
+ + +
diff --git a/kdeplasma-addons/applets/comic/comicarchivejob.cpp b/kdeplasma-addons/applets/comic/comicarchivejob.cpp new file mode 100644 index 00000000..68b42d2d --- /dev/null +++ b/kdeplasma-addons/applets/comic/comicarchivejob.cpp @@ -0,0 +1,435 @@ +/*************************************************************************** + * Copyright (C) 2011 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "comicarchivejob.h" + +#include +#include +#include +#include + +#ifdef HAVE_NEPOMUK +#include +#include +#include +#include +#include +#include + +using namespace Nepomuk::Vocabulary; +#endif + +ComicArchiveJob::ComicArchiveJob( const KUrl &dest, Plasma::DataEngine *engine, ComicArchiveJob::ArchiveType archiveType, IdentifierType identifierType, const QString &pluginName, QObject *parent ) + : KJob( parent ), + mType( archiveType ), + mDirection( Undefined ), + mIdentifierType( identifierType ), + mSuspend( false ), + mFindAmount( true ), + mHasVariants( false ), + mDone( false ), + mComicNumber( 0 ), + mProcessedFiles( 0 ), + mTotalFiles( -1 ), + mEngine( engine ), + mZipFile( new KTemporaryFile ), + mZip( 0 ), + mPluginName( pluginName ), + mDest( dest ) +{ + if ( mZipFile->open() ) { + mZip = new KZip( mZipFile->fileName() ); + mZip->open( QIODevice::ReadWrite ); + mZip->setCompression( KZip::NoCompression ); + setCapabilities( Killable | Suspendable ); + } else { + kError() << "Could not create a temporary file for the zip file."; + } +} + +ComicArchiveJob::~ComicArchiveJob() +{ + emitResultIfNeeded(); + delete mZip; + delete mZipFile; + qDeleteAll( mBackwardFiles ); +} + +bool ComicArchiveJob::isValid() const +{ + if ( mPluginName.isEmpty() ) { + kWarning() << "No plugin name specified."; + return false; + } + + switch ( mType ) { + case ArchiveFromTo: + if ( mToIdentifier.isEmpty() || mFromIdentifier.isEmpty() ) { + kWarning() << "Not enought data provided to archive a range."; + return false; + } + break; + case ArchiveStartTo: + case ArchiveEndTo: + if ( mToIdentifier.isEmpty() ) { + kWarning() << "Not enough data provied to archive StartTo/EndTo."; + return false; + } + break; + default: + break; + } + + return mEngine->isValid() && mZip && mZip->isOpen(); +} + +void ComicArchiveJob::setToIdentifier( const QString &toIdentifier ) +{ + mToIdentifier = toIdentifier; + mToIdentifierSuffix = mToIdentifier; + mToIdentifierSuffix.remove( mPluginName + ':' ); +} + +void ComicArchiveJob::setFromIdentifier( const QString &fromIdentifier ) +{ + mFromIdentifier = fromIdentifier; + mFromIdentifierSuffix = mFromIdentifier; + mFromIdentifierSuffix.remove( mPluginName + ':' ); +} + +void ComicArchiveJob::start() +{ + switch ( mType ) { + case ArchiveAll: + requestComic( suffixToIdentifier( QString() ) ); + break; + case ArchiveStartTo: + requestComic( mToIdentifier ); + break; + case ArchiveEndTo: { + setFromIdentifier( mToIdentifier ); + mToIdentifier.clear(); + mToIdentifierSuffix.clear(); + requestComic( suffixToIdentifier( QString() ) ); + break; + } + case ArchiveFromTo: + mDirection = Foward; + defineTotalNumber(); + requestComic( mFromIdentifier ); + break; + } +} + +void ComicArchiveJob::dataUpdated( const QString &source, const Plasma::DataEngine::Data &data ) +{ + if ( !mZip ) { + kWarning() << "No zip file, aborting."; + setErrorText( i18n( "No zip file is existing, aborting." ) ); + setError( KilledJobError ); + emitResultIfNeeded(); + return; + } + + const QString currentIdentifier = data[ "Identifier" ].toString(); + QString currentIdentifierSuffix = currentIdentifier; + currentIdentifierSuffix.remove( mPluginName + ':' ); + + const QImage image = data[ "Image" ].value(); + const bool hasError = data[ "Error" ].toBool() || image.isNull(); + const QString previousIdentifierSuffix = data[ "Previous identifier suffix" ].toString(); + const QString nextIdentifierSuffix = data[ "Next identifier suffix" ].toString(); + const QString firstIdentifierSuffix = data[ "First strip identifier suffix" ].toString(); + + mAuthors << data[ "Comic Author" ].toString().split( ',', QString::SkipEmptyParts ); + mAuthors.removeDuplicates(); + + if ( mComicTitle.isEmpty() ) { + mComicTitle = data[ "Title" ].toString(); + } + + mEngine->disconnectSource( source, this ); + + if ( hasError ) { + kWarning() << "An error occured at" << source << "stopping."; + setErrorText( i18n( "An error happened for identifier %1.", source ) ); + setError( KilledJobError ); + copyZipFileToDestination(); + return; + } + + if ( mDirection == Undefined ) { + if ( ( mType == ArchiveAll ) || ( mType == ArchiveStartTo ) ) { + if ( !firstIdentifierSuffix.isEmpty() ) { + setFromIdentifier( suffixToIdentifier( firstIdentifierSuffix ) ); + } + if ( mType == ArchiveAll ) { + setToIdentifier( currentIdentifier ); + } + mDirection = ( firstIdentifierSuffix.isEmpty() ? Backward : Foward ); + if ( mDirection == Foward ) { + requestComic( suffixToIdentifier( firstIdentifierSuffix ) ); + return; + } else { + //backward, i.e. the to identifier is unknown + mToIdentifier.clear(); + mToIdentifierSuffix.clear(); + } + } else if ( mType == ArchiveEndTo ) { + mDirection = Foward; + setToIdentifier( currentIdentifier ); + requestComic( mFromIdentifier ); + return; + } + } + + bool worked = false; + ++mProcessedFiles; + if ( mDirection == Foward ) { + KTemporaryFile tempFile; + worked = tempFile.open(); + worked = worked && tempFile.flush(); + worked = ( worked ? image.save( tempFile.fileName(), "PNG" ) : worked ); + worked = ( worked ? addFileToZip( tempFile.fileName() ) : worked ); + + if ( worked ) { + if ( ( currentIdentifier == mToIdentifier ) || ( currentIdentifierSuffix == nextIdentifierSuffix) || nextIdentifierSuffix.isEmpty() ) { + kDebug() << "Done downloading at:" << source; + copyZipFileToDestination(); + } else { + requestComic( suffixToIdentifier( nextIdentifierSuffix ) ); + } + } + } else if ( mDirection == Backward ) { + KTemporaryFile *tempFile = new KTemporaryFile; + mBackwardFiles << tempFile; + worked = tempFile->open(); + worked = worked && tempFile->flush(); + worked = ( worked ? image.save( tempFile->fileName(), "PNG" ) : worked ); + + if ( worked ) { + if ( ( currentIdentifier == mToIdentifier ) || ( currentIdentifierSuffix == previousIdentifierSuffix ) || previousIdentifierSuffix.isEmpty() ) { + kDebug() << "Done downloading at:" << source; + createBackwardZip(); + } else { + requestComic( suffixToIdentifier( previousIdentifierSuffix) ); + } + } + } + + defineTotalNumber( currentIdentifierSuffix ); + setProcessedAmount( Files, mProcessedFiles ); + if ( mTotalFiles != -1 ) { + setPercent( ( 100 * mProcessedFiles ) / mTotalFiles ); + } + + if ( !worked ) { + kError() << "Could not write the file, identifier:" << source; + setErrorText( i18n( "Failed creating the file with identifier %1.", source ) ); + setError( KilledJobError ); + emitResultIfNeeded(); + } +} + +bool ComicArchiveJob::doKill() +{ + mSuspend = true; + return KJob::doKill(); +} + +bool ComicArchiveJob::doSuspend() +{ + mSuspend = true; + return true; +} + +bool ComicArchiveJob::doResume() +{ + mSuspend = false; + if ( !mRequest.isEmpty() ) { + requestComic( mRequest ); + } + return true; +} + +void ComicArchiveJob::defineTotalNumber( const QString ¤tSuffix ) +{ + findTotalNumberFromTo(); + if ( mTotalFiles == -1 ) { + kDebug() << "Unable to find the total number for" << mPluginName; + return; + } + + //calculate a new value for total files, can be different from the previous one, + //if there are no strips for certain days/numbers + if ( !currentSuffix.isEmpty() ) { + if ( mIdentifierType == Date ) { + const QDate current = QDate::fromString( currentSuffix, "yyyy-MM-dd" ); + const QDate to = QDate::fromString( mToIdentifierSuffix, "yyyy-MM-dd" ); + if ( current.isValid() && to.isValid() ) { + //processed files + files still to download + mTotalFiles = mProcessedFiles + qAbs( current.daysTo( to ) ); + } + } else if ( mIdentifierType == Number ) { + bool result = true; + bool ok; + const int current = currentSuffix.toInt( &ok ); + result = ( result && ok ); + const int to = mToIdentifierSuffix.toInt( &ok ); + result = ( result && ok ); + if ( result ) { + //processed files + files still to download + mTotalFiles = mProcessedFiles + qAbs( to - current ); + } + } + } + + if ( mTotalFiles != -1 ) { + setTotalAmount( Files, mTotalFiles ); + } +} + +void ComicArchiveJob::findTotalNumberFromTo() +{ + if ( mTotalFiles != -1 ) { + return; + } + + if ( mIdentifierType == Date ) { + const QDate from = QDate::fromString( mFromIdentifierSuffix, "yyyy-MM-dd" ); + const QDate to = QDate::fromString( mToIdentifierSuffix, "yyyy-MM-dd" ); + if ( from.isValid() && to.isValid() ) { + mTotalFiles = qAbs( from.daysTo( to ) ) + 1; + } + } else if ( mIdentifierType == Number ) { + bool result = true; + bool ok; + const int from = mFromIdentifierSuffix.toInt( &ok ); + result = ( result && ok ); + const int to = mToIdentifierSuffix.toInt( &ok ); + result = ( result && ok ); + if ( result ) { + mTotalFiles = qAbs( to - from ) + 1; + } + } +} + +QString ComicArchiveJob::suffixToIdentifier( const QString &suffix ) const +{ + return mPluginName + ':' + suffix; +} + +void ComicArchiveJob::requestComic( QString identifier ) //krazy:exclude=passbyvalue +{ + mRequest.clear(); + if ( mSuspend ) { + mRequest = identifier; + return; + } + + emit description( this, i18n( "Creating Comic Book Archive" ), + qMakePair( QString( "source" ), identifier ), + qMakePair( QString( "destination" ), mDest.prettyUrl() ) ); + + mEngine->connectSource( identifier, this ); + mEngine->query( identifier ); +} + +bool ComicArchiveJob::addFileToZip( const QString &path ) +{ + //We use 6 signs, e.g. number 1 --> 000001.png, 123 --> 000123.png + //this way the comics should always be correctly sorted (otherwise evince e.g. has problems) + static const int numSigns = 6; + static const QString zero = QLatin1String( "0" ); + QString number = QString::number( ++mComicNumber ); + const int length = number.length(); + if ( length < numSigns ) { + number = zero.repeated( numSigns - length ) + number; + } + + return mZip->addLocalFile( path, number + QLatin1String( ".png" ) ); +} + +void ComicArchiveJob::createBackwardZip() +{ + for ( int i = mBackwardFiles.count() - 1; i >= 0; --i ) { + if ( !addFileToZip( mBackwardFiles[i]->fileName() ) ) { + kWarning() << "Failed adding a file to the archive."; + setErrorText( i18n( "Failed adding a file to the archive." ) ); + setError( KilledJobError ); + emitResultIfNeeded(); + return; + } + } + + copyZipFileToDestination(); +} + +void ComicArchiveJob::copyZipFileToDestination() +{ + mZip->close(); + const bool worked = KIO::NetAccess::file_copy( KUrl( mZipFile->fileName() ), mDest ); + //store additional data using Nepomuk + if (!worked) { + kWarning() << "Could not copy the zip file to the specified destination:" << mDest; + setErrorText( i18n( "Could not create the archive at the specified location." ) ); + setError( KilledJobError ); + emitResultIfNeeded(); + return; + } + +#ifdef HAVE_NEPOMUK + //store additional data using Nepomuk + Nepomuk::Resource res( mDest, NFO::FileDataObject() ); + + Nepomuk::Resource comicTopic( "Comic", PIMO::Topic() ); + comicTopic.setLabel( i18n( "Comic" ) ); + + if ( !mComicTitle.isEmpty() ) { + Nepomuk::Resource topic( mComicTitle, PIMO::Topic() ); + topic.setLabel( mComicTitle ); + topic.setProperty( PIMO::superTopic(), comicTopic ); + res.addTag( topic ); + } else { +// res.addTag( comicTopic );//TODO activate this, see below + ; + } + + //FIXME also set the comic topic as tag, this is redundant, as topic has this as super topic + //though at this point the gui (Dolphin) does not manage to show the correct tags + res.addTag( comicTopic ); + + foreach ( QString author, mAuthors ) { + author = author.trimmed(); + Nepomuk::Resource authorRes( author, NCO::PersonContact() ); + authorRes.setProperty( NCO::fullname(), author ); + res.addProperty( NCO::creator(), authorRes ); + } +#endif + + emitResultIfNeeded(); +} + +void ComicArchiveJob::emitResultIfNeeded() +{ + if ( !mDone ) { + mDone = true; + emitResult(); + } +} diff --git a/kdeplasma-addons/applets/comic/comicarchivejob.h b/kdeplasma-addons/applets/comic/comicarchivejob.h new file mode 100644 index 00000000..2ee1428f --- /dev/null +++ b/kdeplasma-addons/applets/comic/comicarchivejob.h @@ -0,0 +1,144 @@ +/*************************************************************************** + * Copyright (C) 2011 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef COMIC_ARCHIVE_JOB_H +#define COMIC_ARCHIVE_JOB_H + +#include "comicinfo.h" + +#include +#include + +class KTemporaryFile; +class KZip; + +class ComicArchiveJob : public KJob +{ + Q_OBJECT + + public: + enum ArchiveType { + ArchiveAll = 0, + ArchiveStartTo, + ArchiveEndTo, + ArchiveFromTo + }; + + /** + * Creates a comic archive job. + * The engine has to be a working comic dataengine. + * The archiveType defines what kind of input is given, e.g. if ArchiveAll is + * used no other parameters need to be defined, while ArchiveFromTo needs + * both toIdentifier and fromIdentifier (from <= to!), the other two types need only the toIdentifier. + * You need to define the plugin name in any case, this is part of the identifier e.g. + * "garfield:2010-03-04", here "garfield" is the plugin name + * @see setToIdentifier, setFromIdentifier + */ + ComicArchiveJob( const KUrl &dest, Plasma::DataEngine *engine, ArchiveType archiveType, IdentifierType identifierType, const QString &pluginName, QObject *parent = 0 ); + ~ComicArchiveJob(); + + /** + * Checks if all the needed data has been set + */ + bool isValid() const; + + /** + * Sets the end to toIdentifier. + * Keep in mind that depending on the ArchiveType this might be ignored + */ + void setToIdentifier( const QString &toIdentifier ); + + /** + * Sets the beginning to toIdentifier. + * Keep in mind that depending on the ArchiveType this might be ignored + */ + void setFromIdentifier( const QString &fromIdentifier ); + + virtual void start(); + + public slots: + void dataUpdated( const QString &source, const Plasma::DataEngine::Data& data ); + + protected: + virtual bool doKill(); + virtual bool doSuspend(); + virtual bool doResume(); + + private: + /** + * Sets the total number of comics to download. + * @param currentSuffix if empty the from and to identifier suffix will be used. + * If a currentSuffix is defined it will check if the total number is different + * e.g. not a comic defined for every day etc. + */ + void defineTotalNumber( const QString ¤tSuffix = QString() ); + + /** + * Sets mTotalFiles if that is -1 and it can calculate at total number + * base on the from and to identifier suffix + */ + void findTotalNumberFromTo(); + + QString suffixToIdentifier( const QString &suffix ) const; + void requestComic( QString identifier ); + bool addFileToZip( const QString &path ); + + /** + * If the ArchiveDirection is Backward, this will fill the zip + * with mBackwardFiles (beginning from the back), and will call + * copyZipFileToDestination afterwards + */ + void createBackwardZip(); + void copyZipFileToDestination(); + + void emitResultIfNeeded(); + + private: + enum ArchiveDirection { + Undefined, + Foward, + Backward + }; + + ArchiveType mType; + ArchiveDirection mDirection; + IdentifierType mIdentifierType; + bool mSuspend; + bool mFindAmount; + bool mHasVariants; + bool mDone; + int mComicNumber; + int mProcessedFiles; + int mTotalFiles; + Plasma::DataEngine *mEngine; + KTemporaryFile *mZipFile; + KZip *mZip; + QString mPluginName; + QString mToIdentifier; + QString mToIdentifierSuffix; + QString mFromIdentifier; + QString mFromIdentifierSuffix; + QString mComicTitle; + QString mRequest; + const KUrl mDest; + QStringList mAuthors; + QList< KTemporaryFile* > mBackwardFiles; +}; + +#endif diff --git a/kdeplasma-addons/applets/comic/comicdata.cpp b/kdeplasma-addons/applets/comic/comicdata.cpp new file mode 100644 index 00000000..f61be2fe --- /dev/null +++ b/kdeplasma-addons/applets/comic/comicdata.cpp @@ -0,0 +1,159 @@ +/*************************************************************************** + * Copyright (C) 2012 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "comicdata.h" + +#include + +#include + +ComicData::ComicData() +{ +} + +void ComicData::init(const QString &id, const KConfigGroup &config) +{ + mId = id; + mCfg = config; + mFirstStripNum = 0; + mMaxStripNum = 0; + mScaleComic = false; + mIsLeftToRight = true; + mIsTopToBottom = true; + + load(); +} + +void ComicData::load() +{ + mScaleComic = mCfg.readEntry("scaleToContent_" + mId, false); + mMaxStripNum = mCfg.readEntry("maxStripNum_" + mId, 0); + mStored = mCfg.readEntry("storedPosition_" + mId, QString()); +} + +void ComicData::save() +{ + mCfg.writeEntry("scaleToContent_" + mId, mScaleComic); + mCfg.writeEntry("maxStripNum_" + mId, mMaxStripNum); + mCfg.writeEntry("storedPosition_" + id(), mStored); + + // no next, thus the most recent strip + if (!hasNext()) { + mCfg.writeEntry("lastStripVisited_" + mId, true); + mCfg.writeEntry("lastStrip_" + mId, mLast); + } +} + +void ComicData::setScaleComic(bool scale) +{ + mScaleComic = scale; + save(); +} + +void ComicData::storePosition(bool store) +{ + mStored = (store ? mCurrent : QString()); + save(); +} + +void ComicData::setData(const Plasma::DataEngine::Data &data) +{ + const bool hasError = data[ "Error" ].toBool(); + if (!hasError) { + mImage = data["Image"].value(); + mPrev = data["Previous identifier suffix"].toString(); + mNext = data["Next identifier suffix"].toString(); + mAdditionalText = data["Additional text"].toString(); + } + + mWebsiteUrl = data[ "Website Url" ].value(); + mImageUrl = data["Image Url"].value(); + mShopUrl = data[ "Shop Url" ].value(); + mFirst = data[ "First strip identifier suffix" ].toString(); + mStripTitle = data[ "Strip title" ].toString(); + mAuthor = data[ "Comic Author" ].toString(); + mTitle = data[ "Title" ].toString(); + + const QString suffixType = data[ "SuffixType" ].toString(); + if ( suffixType == "Date" ) { + mType = Date; + } else if ( suffixType == "Number" ) { + mType = Number; + } else { + mType = String; + } + + QString temp = data["Identifier"].toString(); + mCurrent = temp.remove(mId + ':'); + + //found a new last identifier + if (!hasNext()) { + mLast = mCurrent; + } + + mCurrentReadable = ""; + if ( mType == Number ) { + mCurrentReadable = i18nc("an abbreviation for Number", "# %1", mCurrent); + int tempNum = mCurrent.toInt(); + if ( mMaxStripNum < tempNum ) { + mMaxStripNum = tempNum; + } + + temp = mFirst.remove(mId + ':'); + mFirstStripNum = temp.toInt(); + } else if ( mType == Date && QDate::fromString( temp, "yyyy-MM-dd" ).isValid() ) { + mCurrentReadable = mCurrent; + } else if ( mType == String ) { + mCurrentReadable = mCurrent; + } + + mIsLeftToRight = data["isLeftToRight"].toBool(); + mIsTopToBottom = data["isTopToBottom"].toBool(); + + save(); +} + +void ComicData::createErrorPicture(const Plasma::DataEngine::Data &data) +{ + QPixmap errorPic( 500, 400 ); + errorPic.fill(); + QPainter p( &errorPic ); + QFont font = Plasma::Theme::defaultTheme()->font( Plasma::Theme::DefaultFont ); + font.setPointSize( 24 ); + p.setPen( QColor( 0, 0, 0 ) ); + p.setFont( font ); + QString title = i18n( "Getting comic strip failed:" ); + p.drawText( QRect( 10, 10 , 480, 100 ), Qt::TextWordWrap | Qt::AlignHCenter | Qt::AlignVCenter, title ); + QString text = i18n( "Maybe there is no Internet connection.\nMaybe the comic plugin is broken.\nAnother reason might be that there is no comic for this day/number/string, so choosing a different one might work." ); + + mPrev = data["Previous identifier suffix"].toString(); + if (hasPrev()) { + if (!data["Identifier"].toString().isEmpty() ) { + mErrorStrip = data["Identifier"].toString(); + } + text.append( i18n( "\n\nChoose the previous strip to go to the last cached strip." ) ); + } + + font.setPointSize( 16 ); + p.setFont( font ); + p.drawText( QRect( 10, 120 , 480, 270 ), Qt::TextWordWrap | Qt::AlignLeft, text ); + + mImage = errorPic.toImage(); + mAdditionalText = title + text; +} diff --git a/kdeplasma-addons/applets/comic/comicdata.h b/kdeplasma-addons/applets/comic/comicdata.h new file mode 100644 index 00000000..696dc8ad --- /dev/null +++ b/kdeplasma-addons/applets/comic/comicdata.h @@ -0,0 +1,157 @@ +/*************************************************************************** + * Copyright (C) 2012 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef COMIC_DATA_H +#define COMIC_DATA_H + +#include "comicinfo.h" + +#include +#include + +#include + +class ComicData +{ + public: + ComicData(); + + void init(const QString &id, const KConfigGroup &config); + + void setData(const Plasma::DataEngine::Data &data); + + IdentifierType type() const { return mType; } + + /** + * The identifier of the comic, e.g. "garfield" + */ + QString id() const { return mId; } + + /** + * The stored comic e.g. "2007-12-21" for a comic of the Date type + */ + QString stored() const { return mStored; } + + void storePosition(bool store); + + /** + * The previous comic e.g. "2007-12-21" for a comic of the Date type + */ + QString prev() const { return mPrev; } + + /** + * The current comic e.g. "2007-12-21" for a comic of the Date type + */ + QString current() const { return mCurrent; } + + /** + * The next comic e.g. "2007-12-21" for a comic of the Date type + */ + QString next() const { return mNext; } + + QString currentReadable() const { return mCurrentReadable; } + + /** + * The first comic e.g. "2007-12-21" for a comic of the Date type + */ + QString first() const { return mFirst; } + + bool hasNext() const { return !mNext.isEmpty(); } + + bool hasPrev() const { return !mPrev.isEmpty(); } + + bool hasFirst() const { return !mFirst.isEmpty(); } + + bool hasStored() const { return !mStored.isEmpty(); } + + bool hasImage() const { return !mImage.isNull(); } + + QString additionalText() const { return mAdditionalText; } + + QString title() const { return mTitle; } + void setTitle(const QString &title) { mTitle = title; } + + + QString stripTitle() const { return mStripTitle; } + + KUrl websiteUrl() const { return mWebsiteUrl; } + + KUrl imageUrl() const { return mImageUrl; } + + KUrl shopUrl() const { return mShopUrl; } + + QString author() const { return mAuthor; } + + QImage image() const { return mImage; } + + bool scaleComic() const { return mScaleComic; } + bool isLeftToRight() const { return mIsLeftToRight; } + bool isTopToBottom() const { return mIsTopToBottom; } + bool storePosition() const { return !mStored.isEmpty(); } + + void setScaleComic(bool scale); + + + QString errorStrip() const { return mErrorStrip; } + + int firstStripNum() const { return mFirstStripNum; } + int maxStripNum() const { return mMaxStripNum; } + + void save(); + + private: + void load(); + void createErrorPicture(const Plasma::DataEngine::Data &data); + + private: + + IdentifierType mType; + QString mId; + QString mFirst; + QString mLast; + QString mCurrent; + QString mNext; + QString mPrev; + QString mStored; + QString mCurrentReadable; + + QString mErrorStrip; + + QString mAuthor; + QString mTitle; + QString mStripTitle; + QString mAdditionalText; + KUrl mWebsiteUrl; + KUrl mImageUrl; + KUrl mShopUrl; + + QImage mImage; + + // only applicable if the comic is of type Number + int mFirstStripNum; + int mMaxStripNum; + + bool mScaleComic; + bool mIsLeftToRight; + bool mIsTopToBottom; + + KConfigGroup mCfg; +}; + +#endif diff --git a/kdeplasma-addons/applets/comic/comicinfo.cpp b/kdeplasma-addons/applets/comic/comicinfo.cpp new file mode 100644 index 00000000..c7372ae6 --- /dev/null +++ b/kdeplasma-addons/applets/comic/comicinfo.cpp @@ -0,0 +1,115 @@ +/*************************************************************************** + * Copyright (C) 2012 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "comicinfo.h" + +#include +#include + +#include + +class SavingDir::SavingDirPrivate +{ + public: + SavingDirPrivate(const KConfigGroup &cfg); + + void init(); + + QString getDir() const; + void setDir(const QString &dir); + + private: + void load(); + void save(); + bool isValid(); + + private: + KConfigGroup mCfg; + QString mDir; +}; + + +SavingDir::SavingDirPrivate::SavingDirPrivate(const KConfigGroup &cfg) + : mCfg(cfg) +{ +} + + +void SavingDir::SavingDirPrivate::init() +{ + load(); + save(); +} + +QString SavingDir::SavingDirPrivate::getDir() const +{ + return mDir; +} + +void SavingDir::SavingDirPrivate::setDir(const QString &dir) +{ + mDir = dir; + save(); +} + +void SavingDir::SavingDirPrivate::load() +{ + mDir = mCfg.readEntry("savingDir", QString()); + if (!isValid()) { + mDir = KGlobalSettings::picturesPath(); + } + if (!isValid()) { + mDir = KGlobalSettings::downloadPath(); + } + if (!isValid()) { + mDir = QDir::homePath(); + } +} + +void SavingDir::SavingDirPrivate::save() +{ + mCfg.writeEntry("savingDir", mDir); +} + +bool SavingDir::SavingDirPrivate::isValid() +{ + QDir dir; + return (!mDir.isEmpty() && dir.exists(mDir)); +} + +SavingDir::SavingDir(const KConfigGroup &cfg) + : d(new SavingDirPrivate(cfg)) +{ + d->init(); +} + +SavingDir::~SavingDir() +{ + delete d; +} + +QString SavingDir::getDir() const +{ + return d->getDir(); +} + +void SavingDir::setDir(const QString &dir) +{ + d->setDir(dir); +} diff --git a/kdeplasma-addons/applets/comic/comicinfo.h b/kdeplasma-addons/applets/comic/comicinfo.h new file mode 100644 index 00000000..99cc53e3 --- /dev/null +++ b/kdeplasma-addons/applets/comic/comicinfo.h @@ -0,0 +1,66 @@ +/*************************************************************************** + * Copyright (C) 2011-2012 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef COMIC_TYPE_H +#define COMIC_TYPE_H + +class KConfigGroup; +class QString; + +enum IdentifierType { + Date = 0, + Number, + String +}; + +/** + * Provides access (read/write) to the directory that should be used + * whenever the user is presented with a file selection dialog. + */ +class SavingDir +{ + public: + /** + * @param config the config that should be used to retrieve + * the saving directory and to store it to in case of changes + */ + SavingDir(const KConfigGroup &config); + + ~SavingDir(); + + /** + * @return the directory to be displayed to the user + */ + QString getDir() const; + + /** + * Set the directory that should be displayed to the user first + * when choosing a destination. Automatically writes the directory + * to the config, if one was specified in init. + * @param dir the directory to display the user first + * @see init + */ + void setDir(const QString &dir); + + private: + class SavingDirPrivate; + SavingDirPrivate *d; +}; + +#endif diff --git a/kdeplasma-addons/applets/comic/comicmodel.cpp b/kdeplasma-addons/applets/comic/comicmodel.cpp new file mode 100644 index 00000000..349019d8 --- /dev/null +++ b/kdeplasma-addons/applets/comic/comicmodel.cpp @@ -0,0 +1,137 @@ +/*************************************************************************** + * Copyright (C) 2007 by Tobias Koenig * + * Copyright (C) 2008-2010 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "comicmodel.h" + +#include + +ComicModel::ComicModel( const Plasma::DataEngine::Data &comics, const QStringList &usedComics, QObject *parent ) + : QAbstractTableModel( parent ), mNumSelected( 0 ) +{ + setComics( comics, usedComics ); +} + +void ComicModel::setComics( const Plasma::DataEngine::Data &comics, const QStringList &usedComics ) +{ + beginResetModel(); + + mNumSelected = 0; + mComics = comics; + mState.clear(); + Plasma::DataEngine::Data::const_iterator it; + Plasma::DataEngine::Data::const_iterator itEnd = mComics.constEnd(); + for ( it = mComics.constBegin(); it != itEnd; ++it ) { + const bool isChecked = usedComics.contains( it.key() ); + mState[ it.key() ] = ( isChecked ? Qt::Checked : Qt::Unchecked ); + if ( isChecked ) { + ++mNumSelected; + } + } + + endResetModel(); +} + +int ComicModel::rowCount( const QModelIndex &index ) const +{ + if ( !index.isValid() ) { + return mComics.count(); + } + + return 0; +} + +int ComicModel::columnCount( const QModelIndex &index ) const +{ + Q_UNUSED( index ) + return 2; +} + +QVariant ComicModel::data( const QModelIndex &index, int role ) const +{ + if ( !index.isValid() || index.row() >= mComics.keys().count() ) { + return QVariant(); + } + + const QString data = mComics.keys()[ index.row() ]; + if ( index.column() == 0 ) { + if ( role == Qt::CheckStateRole ) { + return mState[ data ]; + } + } else if ( index.column() == 1 ) { + switch( role ) { + case Qt::DisplayRole: + return mComics[ data ].toStringList()[ 0 ]; + case Qt::DecorationRole: + return KIcon( mComics[ data ].toStringList()[ 1 ] ); + case Qt::UserRole: + return data; + } + } + + return QVariant(); +} + +Qt::ItemFlags ComicModel::flags( const QModelIndex &index ) const +{ + if ( index.isValid() && ( index.column() == 0 ) ) { + return QAbstractItemModel::flags( index ) | Qt::ItemIsUserCheckable; + } + + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +bool ComicModel::setData( const QModelIndex &index, const QVariant &value, int role ) +{ + if ( index.isValid() && ( role == Qt::CheckStateRole ) ) { + Qt::CheckState oldState = mState[ mComics.keys()[ index.row() ] ]; + Qt::CheckState newState = static_cast< Qt::CheckState >( value.toInt() ); + mState[ mComics.keys()[ index.row() ] ] = newState; + if ( newState != oldState ) { + if ( newState == Qt::Checked ) { + ++mNumSelected; + } else if ( newState == Qt::Unchecked ) { + --mNumSelected; + } + } + emit dataChanged( index, index ); + return true; + } + + return false; +} + +int ComicModel::numSelected() const +{ + return mNumSelected; +} + +QStringList ComicModel::selected() const +{ + QStringList list; + QHash< QString, Qt::CheckState >::const_iterator it; + QHash< QString, Qt::CheckState >::const_iterator itEnd = mState.constEnd(); + for ( it = mState.constBegin(); it != itEnd; ++it ) { + if ( it.value() == Qt::Checked ) { + list << it.key(); + } + } + + return list; +} diff --git a/kdeplasma-addons/applets/comic/comicmodel.h b/kdeplasma-addons/applets/comic/comicmodel.h new file mode 100644 index 00000000..87b5a0fd --- /dev/null +++ b/kdeplasma-addons/applets/comic/comicmodel.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2007 by Tobias Koenig * + * Copyright (C) 2008-2010 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef COMICMODEL_H +#define COMICMODEL_H + +#include + +#include + +class ComicModel : public QAbstractTableModel +{ + public: + ComicModel( const Plasma::DataEngine::Data &comics, const QStringList &usedComics, QObject *parent = 0 ); + + void setComics( const Plasma::DataEngine::Data &comics, const QStringList &usedComics ); + + int rowCount( const QModelIndex &index = QModelIndex() ) const; + int columnCount( const QModelIndex &index = QModelIndex() ) const; + QVariant data( const QModelIndex &index, int role = Qt::CheckStateRole ) const; + Qt::ItemFlags flags( const QModelIndex &index ) const; + bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ); + + int numSelected() const; + QStringList selected() const; + + private: + Plasma::DataEngine::Data mComics; + QHash mState; + int mNumSelected; +}; + +#endif diff --git a/kdeplasma-addons/applets/comic/comicsaver.cpp b/kdeplasma-addons/applets/comic/comicsaver.cpp new file mode 100644 index 00000000..cf92c762 --- /dev/null +++ b/kdeplasma-addons/applets/comic/comicsaver.cpp @@ -0,0 +1,132 @@ +/*************************************************************************** + * Copyright (C) 2008-2012 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "comicsaver.h" +#include "comicdata.h" +#include "comicinfo.h" + +#include +#include +#include + +#ifdef HAVE_NEPOMUK +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Nepomuk::Vocabulary; +#endif + +ComicSaver::ComicSaver(SavingDir *savingDir) + : mSavingDir(savingDir) +{ +#ifdef HAVE_NEPOMUK + static bool isInit = false; + if (!isInit) { + isInit = true; + // for manually saving the comics + Nepomuk::ResourceManager::instance()->init(); + } +#endif +} + +bool ComicSaver::save(const ComicData &comic) +{ + KTemporaryFile tempFile; + + if (!tempFile.open()) { + return false; + } + + // save image to temporary file + comic.image().save(tempFile.fileName(), "PNG"); + + KUrl srcUrl( tempFile.fileName() ); + + const QString title = comic.title(); + + const QString name = title + " - " + comic.current() + ".png"; + KUrl destUrl = KUrl(mSavingDir->getDir()); + destUrl.addPath( name ); + + destUrl = KFileDialog::getSaveUrl( destUrl, "*.png" ); + if ( !destUrl.isValid() ) { + return false; + } + + mSavingDir->setDir(destUrl.directory()); + +#ifdef HAVE_NEPOMUK + bool worked = KIO::NetAccess::file_copy(srcUrl, destUrl); + //store additional data using Nepomuk + if (worked) { + Nepomuk::Resource res(destUrl, NFO::FileDataObject()); + + Nepomuk::Resource comicTopic("Comic", PIMO::Topic()); + comicTopic.setLabel(i18n("Comic")); + + if (!comic.additionalText().isEmpty()) { + res.setProperty(NIE::description(), comic.additionalText()); + } + if ((comic.type() == Date) && !comic.current().isEmpty()) { + res.setProperty(NIE::contentCreated(), QDateTime::fromString(comic.current(), Qt::ISODate)); + } + if (!title.isEmpty()) { + Nepomuk::Resource topic(title, PIMO::Topic()); + topic.setLabel(title); + topic.setProperty(PIMO::superTopic(), comicTopic); + res.addTag(topic); + } else { +// res.addTag(comicTopic);//TODO activate this, see below + ; + } + + //FIXME also set the comic topic as tag, this is redundant, as topic has this as super topic + //though at this point the gui does not manage to show the correct tags + res.addTag(comicTopic); + + if (!comic.stripTitle().isEmpty()) { + res.setProperty(NIE::title(), comic.stripTitle()); + } + if (!comic.websiteUrl().isEmpty()) { + Nepomuk::Resource copyEvent = Nepomuk::Utils::createCopyEvent(comic.imageUrl(), destUrl, QDateTime(), comic.websiteUrl()); + } + + const QStringList authors = comic.author().split(',', QString::SkipEmptyParts); + foreach (const QString &author, authors) { + Nepomuk::Resource authorRes(author, NCO::PersonContact()); + authorRes.setProperty(NCO::fullname(), author.trimmed()); + res.addProperty(NCO::creator(), authorRes); + } + return true; + } + + return false; +#else + KIO::NetAccess::file_copy( srcUrl, destUrl ); + + return true; +#endif +} diff --git a/kdeplasma-addons/applets/comic/comicsaver.h b/kdeplasma-addons/applets/comic/comicsaver.h new file mode 100644 index 00000000..1e867217 --- /dev/null +++ b/kdeplasma-addons/applets/comic/comicsaver.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2008-2012 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef COMIC_SAVER_H +#define COMIC_SAVER_H + +class ComicData; +class SavingDir; + +/** + * ComicSaver takes care of saving a comic strip to a user chosen + * destination. + * Further if available Nepomuk is used to store the title, author + * etc. + */ +class ComicSaver +{ + public: + ComicSaver(SavingDir *savingDir); + + /** + * Asks the user for a destination to save the specified + * comic to. If possible writes it to that destination. + * @param comic the comic to save + * @return true if saving worked, false if there was a problem + */ + bool save(const ComicData &comic); + + private: + SavingDir *mSavingDir; +}; + +#endif diff --git a/kdeplasma-addons/applets/comic/config-nepomuk.h.cmake b/kdeplasma-addons/applets/comic/config-nepomuk.h.cmake new file mode 100644 index 00000000..fe7364f6 --- /dev/null +++ b/kdeplasma-addons/applets/comic/config-nepomuk.h.cmake @@ -0,0 +1 @@ +#cmakedefine HAVE_NEPOMUK diff --git a/kdeplasma-addons/applets/comic/configwidget.cpp b/kdeplasma-addons/applets/comic/configwidget.cpp new file mode 100644 index 00000000..0d7b1491 --- /dev/null +++ b/kdeplasma-addons/applets/comic/configwidget.cpp @@ -0,0 +1,268 @@ +/*************************************************************************** + * Copyright (C) 2007 by Tobias Koenig * + * Copyright (C) 2008-2010 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "configwidget.h" +#include "comicmodel.h" + +#include +#include + +#include +#include +#include + +ComicUpdater::ComicUpdater( QObject *parent ) + : QObject( parent ), + mDownloadManager( 0 ), + mUpdateIntervall( 3 ), + m_updateTimer( 0 ) +{ +} + +ComicUpdater::~ComicUpdater() +{ +} + +void ComicUpdater::init(const KConfigGroup &group) +{ + mGroup = group; +} + +void ComicUpdater::load() +{ + //check when the last update happened and update if necessary + mUpdateIntervall = mGroup.readEntry( "updateIntervall", 3 ); + if ( mUpdateIntervall ) { + mLastUpdate = mGroup.readEntry( "lastUpdate", QDateTime() ); + checkForUpdate(); + } +} + +void ComicUpdater::save() +{ + mGroup.writeEntry( "updateIntervall", mUpdateIntervall ); +} + +void ComicUpdater::applyConfig( ConfigWidget *widget ) +{ + mUpdateIntervall = widget->updateIntervall(); +} + +void ComicUpdater::checkForUpdate() +{ + //start a timer to check each hour, if KNS3 should look for updates + if ( !m_updateTimer ) { + m_updateTimer = new QTimer(this); + connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(checkForUpdate())); + m_updateTimer->start( 1 * 60 * 60 * 1000 ); + } + + if ( !mLastUpdate.isValid() || ( mLastUpdate.addDays( mUpdateIntervall ) < QDateTime::currentDateTime() ) ) { + mGroup.writeEntry( "lastUpdate", QDateTime::currentDateTime() ); + downloadManager()->checkForUpdates(); + } +} + +void ComicUpdater::slotUpdatesFound( const KNS3::Entry::List &entries ) +{ + for ( int i = 0; i < entries.count(); ++i ) { + downloadManager()->installEntry( entries[ i ] ); + } +} + +KNS3::DownloadManager *ComicUpdater::downloadManager() +{ + if ( !mDownloadManager ) { + mDownloadManager = new KNS3::DownloadManager( "comic.knsrc", this ); + connect(mDownloadManager, SIGNAL(searchResult(KNS3::Entry::List)), this, SLOT(slotUpdatesFound(KNS3::Entry::List))); + } + + return mDownloadManager; +} + + +ConfigWidget::ConfigWidget( Plasma::DataEngine *engine, ComicModel *model, QSortFilterProxyModel *proxy, KConfigDialog *parent ) + : QWidget( parent ), mEngine( engine ), mModel( model ), mProxyModel( proxy ), mNewStuffDialog( 0 ) +{ + comicSettings = new QWidget( this ); + comicUi.setupUi( comicSettings ); + comicUi.pushButton_GHNS->setIcon( KIcon( "get-hot-new-stuff" ) ); + + appearanceSettings = new QWidget(); + appearanceUi.setupUi( appearanceSettings ); + + advancedSettings = new QWidget(); + advancedUi.setupUi( advancedSettings ); + + connect( comicUi.pushButton_GHNS, SIGNAL(clicked()), this, SLOT(getNewStuff()) ); + + comicUi.listView_comic->setModel( mProxyModel ); + comicUi.listView_comic->resizeColumnToContents( 0 ); + + // "Apply" button connections + connect(comicUi.listView_comic , SIGNAL(clicked(QModelIndex)), this , SIGNAL(enableApply())); + connect(comicUi.pushButton_GHNS , SIGNAL(clicked(bool)), this , SIGNAL(enableApply())); + connect(comicUi.checkBox_middle , SIGNAL(toggled(bool)), this , SIGNAL(enableApply())); + connect(comicUi.updateIntervall, SIGNAL(valueChanged(int)), this, SIGNAL(enableApply())); + connect(comicUi.updateIntervallComicStrips, SIGNAL(valueChanged(int)), this, SIGNAL(enableApply())); + connect(appearanceUi.checkBox_arrows, SIGNAL(toggled(bool)), this , SIGNAL(enableApply())); + connect(appearanceUi.checkBox_title, SIGNAL(toggled(bool)), this , SIGNAL(enableApply())); + connect(appearanceUi.checkBox_identifier, SIGNAL(toggled(bool)), this , SIGNAL(enableApply())); + connect(appearanceUi.checkBox_author, SIGNAL(toggled(bool)), this , SIGNAL(enableApply())); + connect(appearanceUi.checkBox_url, SIGNAL(toggled(bool)), this , SIGNAL(enableApply())); + connect(appearanceUi.kbuttongroup, SIGNAL(changed(int)), this , SIGNAL(enableApply())); + connect(advancedUi.maxComicLimit, SIGNAL(valueChanged(int)), this, SIGNAL(enableApply())); + connect(advancedUi.errorPicture, SIGNAL(toggled(bool)), this , SIGNAL(enableApply())); + + mEngine->connectSource( QLatin1String( "providers" ), this ); +} + +ConfigWidget::~ConfigWidget() +{ + mEngine->disconnectSource( QLatin1String( "providers" ), this ); +} + +void ConfigWidget::getNewStuff() +{ + if (!mNewStuffDialog) { + mNewStuffDialog = new KNS3::DownloadDialog( "comic.knsrc", this ); + } + mNewStuffDialog->show(); +} + +void ConfigWidget::dataUpdated(const QString &name, const Plasma::DataEngine::Data &data) +{ + Q_UNUSED(name); + mModel->setComics( data, mModel->selected() ); + comicUi.listView_comic->resizeColumnToContents( 0 ); +} + +void ConfigWidget::setShowComicUrl( bool show ) +{ + appearanceUi.checkBox_url->setChecked( show ); +} + +bool ConfigWidget::showComicUrl() const +{ + return appearanceUi.checkBox_url->isChecked(); +} + +void ConfigWidget::setShowComicAuthor( bool show ) +{ + appearanceUi.checkBox_author->setChecked( show ); +} + +bool ConfigWidget::showComicAuthor() const +{ + return appearanceUi.checkBox_author->isChecked(); +} + +void ConfigWidget::setShowComicTitle( bool show ) +{ + appearanceUi.checkBox_title->setChecked( show ); +} + +bool ConfigWidget::showComicTitle() const +{ + return appearanceUi.checkBox_title->isChecked(); +} + +void ConfigWidget::setShowComicIdentifier( bool show ) +{ + appearanceUi.checkBox_identifier->setChecked( show ); +} + +bool ConfigWidget::showComicIdentifier() const +{ + return appearanceUi.checkBox_identifier->isChecked(); +} + +void ConfigWidget::setShowErrorPicture( bool show ) +{ + advancedUi.errorPicture->setChecked( show ); +} + +bool ConfigWidget::showErrorPicture() const +{ + return advancedUi.errorPicture->isChecked(); +} + + +void ConfigWidget::setArrowsOnHover( bool arrows ) +{ + return appearanceUi.checkBox_arrows->setChecked( arrows ); +} + +bool ConfigWidget::arrowsOnHover() const +{ + return appearanceUi.checkBox_arrows->isChecked(); +} + +void ConfigWidget::setMiddleClick( bool checked ) +{ + comicUi.checkBox_middle->setChecked( checked ); +} + +bool ConfigWidget::middleClick() const +{ + return comicUi.checkBox_middle->isChecked(); +} + +void ConfigWidget::setTabView(int tabView) +{ + appearanceUi.kbuttongroup->setSelected( tabView ); +} + +int ConfigWidget::tabView() const +{ + return appearanceUi.kbuttongroup->selected(); +} + +int ConfigWidget::maxComicLimit() const +{ + return advancedUi.maxComicLimit->value(); +} + +void ConfigWidget::setMaxComicLimit( int limit ) +{ + advancedUi.maxComicLimit->setValue( limit ); +} + +void ConfigWidget::setUpdateIntervall( int days ) +{ + comicUi.updateIntervall->setValue( days ); +} + +int ConfigWidget::updateIntervall() const +{ + return comicUi.updateIntervall->value(); +} + +void ConfigWidget::setCheckNewComicStripsIntervall( int minutes ) +{ + comicUi.updateIntervallComicStrips->setValue( minutes ); +} + +int ConfigWidget::checkNewComicStripsIntervall() const +{ + return comicUi.updateIntervallComicStrips->value(); +} + +#include "configwidget.moc" diff --git a/kdeplasma-addons/applets/comic/configwidget.h b/kdeplasma-addons/applets/comic/configwidget.h new file mode 100644 index 00000000..0bf450f7 --- /dev/null +++ b/kdeplasma-addons/applets/comic/configwidget.h @@ -0,0 +1,139 @@ +/*************************************************************************** + * Copyright (C) 2007 by Tobias Koenig * + * Copyright (C) 2008-2010 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef CONFIGWIDGET_H +#define CONFIGWIDGET_H + +#include "ui_appearanceSettings.h" +#include "ui_advancedsettings.h" +#include "ui_comicSettings.h" + +#include +#include + +#include +#include + +class ComicModel; +class KConfigDialog; +class QCheckBox; +class QComboBox; +class QSortFilterProxyModel; + +namespace KNS3 { + class DownloadDialog; + class DownloadManager; +} + +namespace Plasma { + class DataEngine; +} + +class ConfigWidget; + +class ComicUpdater : public QObject +{ + Q_OBJECT + + public: + explicit ComicUpdater( QObject *parent = 0 ); + ~ComicUpdater(); + + void init( const KConfigGroup &group ); + + void load(); + void save(); + void applyConfig( ConfigWidget *widget ); + + private slots: + /** + * Will check if an update is needed, if so will search + * for updates and do them automatically + */ + void checkForUpdate(); + void slotUpdatesFound( const KNS3::Entry::List &entries ); + + private: + KNS3::DownloadManager *downloadManager(); + + private: + KNS3::DownloadManager *mDownloadManager; + KConfigGroup mGroup; + int mUpdateIntervall; + QDateTime mLastUpdate; + QTimer *m_updateTimer; + +}; + +class ConfigWidget : public QWidget +{ + Q_OBJECT + public: + ConfigWidget( Plasma::DataEngine *engine, ComicModel *model, QSortFilterProxyModel *proxy, KConfigDialog *parent ); + ~ConfigWidget(); + + void setShowComicUrl( bool show ); + bool showComicUrl() const; + void setShowComicAuthor( bool show ); + bool showComicAuthor() const; + void setShowComicTitle( bool show ); + bool showComicTitle() const; + void setShowComicIdentifier( bool show ); + bool showComicIdentifier() const; + void setShowErrorPicture( bool show ); + bool showErrorPicture() const; + void setArrowsOnHover( bool arrows ); + bool arrowsOnHover() const; + void setMiddleClick( bool checked ); + bool middleClick() const; + void setTabView( int tabView ); + int tabView() const; + int maxComicLimit() const; + void setMaxComicLimit( int limit ); + void setUpdateIntervall( int days ); + int updateIntervall() const; + void setCheckNewComicStripsIntervall( int minutes ); + int checkNewComicStripsIntervall() const; + + QWidget *comicSettings; + QWidget *appearanceSettings; + QWidget *advancedSettings; + + Q_SIGNALS: + void maxSizeClicked(); + void enableApply(); + + public slots: + void dataUpdated( const QString &name, const Plasma::DataEngine::Data &data ); + + protected slots: + void getNewStuff(); + + private: + Ui::ComicSettings comicUi; + Ui::AppearanceSettings appearanceUi; + Ui::AdvancedSettings advancedUi; + Plasma::DataEngine *mEngine; + ComicModel *mModel; + QSortFilterProxyModel *mProxyModel; + KNS3::DownloadDialog* mNewStuffDialog; +}; + +#endif diff --git a/kdeplasma-addons/applets/comic/package/contents/ui/ButtonBar.qml b/kdeplasma-addons/applets/comic/package/contents/ui/ButtonBar.qml new file mode 100644 index 00000000..d10b9154 --- /dev/null +++ b/kdeplasma-addons/applets/comic/package/contents/ui/ButtonBar.qml @@ -0,0 +1,75 @@ +/* + * Copyright 2012 Reza Fatahilah Shah + * + * 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, see . + */ + +import QtQuick 1.1 +import org.kde.plasma.core 0.1 as PlasmaCore +import org.kde.plasma.components 0.1 as PlasmaComponents + +Item { + id: root + + implicitWidth: rowButton.width + background.margins.left + background.margins.right + implicitHeight: rowButton.height + background.margins.top + background.margins.bottom + + signal prevClicked + signal nextClicked + signal zoomClicked + + PlasmaCore.FrameSvgItem { + id: background + + anchors.fill: parent + + imagePath: "widgets/toolbar" + prefix: "raised" + } + + Row { + id: rowButton + + x: background.margins.left + y: background.margins.top + + spacing: 4 + //ToolButton or Button in C++ use PushButton? + PlasmaComponents.Button { + id: prevButton + + iconSource: "arrow-left" + enabled: (comicData.prev != undefined && comicData.prev.length > 0) + } + + PlasmaComponents.Button { + id: zoomButton + + iconSource: "zoom-original" + } + + PlasmaComponents.Button { + id: nextButton + + iconSource: "arrow-right" + enabled: (comicData.next != undefined && comicData.next.length > 0) + } + } + + Component.onCompleted: { + prevButton.clicked.connect(root.prevClicked); + nextButton.clicked.connect(root.nextClicked); + zoomButton.clicked.connect(root.zoomClicked); + } +} \ No newline at end of file diff --git a/kdeplasma-addons/applets/comic/package/contents/ui/ComicBottomInfo.qml b/kdeplasma-addons/applets/comic/package/contents/ui/ComicBottomInfo.qml new file mode 100644 index 00000000..ac7e0746 --- /dev/null +++ b/kdeplasma-addons/applets/comic/package/contents/ui/ComicBottomInfo.qml @@ -0,0 +1,116 @@ +/* + * Copyright 2012 Reza Fatahilah Shah + * + * 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, see . + */ + +import QtQuick 1.1 +import org.kde.plasma.core 0.1 as PlasmaCore +import org.kde.plasma.components 0.1 as PlasmaComponents +import org.kde.qtextracomponents 0.1 + +Item { + id: root + + implicitWidth: 10 + implicitHeight: comicIdentifier.height + + property bool showUrl: false + property bool showIdentifier: false + property variant comicData + + visible: (comicIdentifier.text.length > 0 || comicUrl.text.length > 0) + + PlasmaComponents.Label { + id: comicIdentifier + + anchors { + left: root.left + top: root.top + bottom: root.bottom + right: comicUrl.left + leftMargin: 2 + } + + color: theme.textColor + visible: (showIdentifier && comicIdentifier.text.length > 0) + text: (showIdentifier && comicData.currentReadable != undefined) ? comicData.currentReadable : "" + + MouseArea { + id: idLabelArea + + anchors.fill: parent + + hoverEnabled: true + + onEntered: { + parent.color = theme.highlightColor; + } + + onExited: { + parent.color = theme.textColor; + } + + onClicked: { + comicApplet.goJump(); + } + + PlasmaCore.ToolTip { + target: idLabelArea + mainText: i18n( "Jump to Strip ..." ) + } + } + } + + PlasmaComponents.Label { + id:comicUrl + + anchors { + top: root.top + bottom: root.bottom + right: root.right + rightMargin: 2 + } + + color: theme.textColor + visible: (showUrl && comicUrl.text.length > 0) + text: (showUrl && comicData.websiteHost.length > 0) ? comicData.websiteHost : "" + + MouseArea { + id: idUrlLabelArea + + anchors.fill: parent + + hoverEnabled: true + visible: comicApplet.checkAuthorization("LaunchApp") + + onEntered: { + parent.color = theme.highlightColor; + } + + onExited: { + parent.color = theme.textColor; + } + + onClicked: { + comicApplet.shop(); + } + + PlasmaCore.ToolTip { + target: idUrlLabelArea + mainText: i18n( "Visit the comic website" ) + } + } + } +} \ No newline at end of file diff --git a/kdeplasma-addons/applets/comic/package/contents/ui/ComicCentralView.qml b/kdeplasma-addons/applets/comic/package/contents/ui/ComicCentralView.qml new file mode 100644 index 00000000..92356e9c --- /dev/null +++ b/kdeplasma-addons/applets/comic/package/contents/ui/ComicCentralView.qml @@ -0,0 +1,143 @@ +/* + * Copyright 2012 Reza Fatahilah Shah + * + * 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, see . + */ + +import QtQuick 1.1 +import org.kde.plasma.core 0.1 as PlasmaCore +import org.kde.plasma.components 0.1 as PlasmaComponents +import org.kde.qtextracomponents 0.1 + +Item { + id: root + + width: 10 + height: 10 + + property variant comicData + + PlasmaComponents.ToolButton { + id: arrowLeft + + anchors { + left: root.left + verticalCenter: root.verticalCenter + } + + iconSource: "go-previous" + visible: (!comicApplet.arrowsOnHover && (comicData.prev !== undefined)) + + onClicked: { + comicApplet.updateComic(comicData.prev); + } + } + + MouseArea { + id: comicImageArea + + anchors { + left: arrowLeft.visible ? arrowLeft.right : root.left + right: arrowRight.visible ? arrowRight.left : root.right + leftMargin: arrowLeft.visible ? 4 : 0 + rightMargin: arrowRight.visible ? 4 : 0 + top: root.top + bottom: root.bottom + } + + hoverEnabled: true + preventStealing: false + acceptedButtons: Qt.LeftButton | Qt.MiddleButton + + onClicked: { + if (mouse.button == Qt.MiddleButton && comicApplet.middleClick) { + fullDialog.open(); + } + } + + PlasmaCore.ToolTip { + id: tooltip + target: comicImageArea + mainText: comicApplet.comicData.additionalText + } + + ImageWidget { + id: comicImage + + anchors.fill: parent + + image: comicApplet.comicData.image + actualSize: comicApplet.showActualSize + isLeftToRight: comicApplet.comicData.isLeftToRight + isTopToBottom: comicApplet.comicData.isTopToBottom + } + + ButtonBar { + id: buttonBar + + anchors { + horizontalCenter: parent.horizontalCenter + bottom: parent.bottom + bottomMargin: 10 + } + + visible: comicApplet.arrowsOnHover && comicImageArea.containsMouse//(comicApplet.arrowsOnHover && (comicImageArea.containsMouse || (comicImageArea.containsMouse && buttonBar.visible)) ) + opacity: 0 + + onPrevClicked: { + comicApplet.updateComic(comicData.prev); + } + + onNextClicked: { + comicApplet.updateComic(comicData.next); + } + + onZoomClicked: { + fullDialog.open(); + } + + states: State { + name: "show"; when: (comicApplet.arrowsOnHover && comicImageArea.containsMouse) + PropertyChanges { target: buttonBar; opacity: 1; } + } + + transitions: Transition { + from: ""; to: "show"; reversible: true + NumberAnimation { properties: "opacity"; duration: 250; easing.type: Easing.InOutQuad } + } + } + } + + PlasmaComponents.ToolButton { + id: arrowRight + + anchors { + right: root.right + verticalCenter: root.verticalCenter + } + + iconSource: "go-next" + visible: (!comicApplet.arrowsOnHover && (comicData.next !== undefined)) + + onClicked: { + comicApplet.updateComic(comicData.next); + } + } + + FullViewWidget { + id: fullDialog + + image: comicApplet.comicData.image + } +} diff --git a/kdeplasma-addons/applets/comic/package/contents/ui/FullViewWidget.qml b/kdeplasma-addons/applets/comic/package/contents/ui/FullViewWidget.qml new file mode 100644 index 00000000..f76bd4c4 --- /dev/null +++ b/kdeplasma-addons/applets/comic/package/contents/ui/FullViewWidget.qml @@ -0,0 +1,85 @@ +/* + * Copyright 2012 Reza Fatahilah Shah + * + * 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, see . + */ + +import QtQuick 1.1 +import org.kde.plasma.core 0.1 as PlasmaCore +import org.kde.plasma.components 0.1 as PlasmaComponents +import org.kde.plasma.extras 0.1 as PlasmaExtras +import org.kde.qtextracomponents 0.1 + +PlasmaCore.Dialog { + id: root + + property alias image: comicPicture.image + + windowFlags: Qt.Popup + visible: false + + function open() + { + var pos = root.popupPosition(null, Qt.AlignCenter); + + root.x = pos.x; + root.y = pos.y; + + root.visible = true; + root.activateWindow(); + } + + function close() { + root.visible = false; + } + + mainItem: PlasmaExtras.ScrollArea { + id: mainScrollArea + + anchors.fill: parent + + width: comicPicture.nativeWidth + height: comicPicture.nativeHeight + + Flickable { + id: viewContainer + + anchors.fill:parent + + contentWidth: comicPicture.nativeWidth + contentHeight: comicPicture.nativeHeight + + //clip: true + + QImageItem { + id: comicPicture + + anchors.fill: parent + + smooth: true + fillMode: QImageItem.PreserveAspectFit + + MouseArea { + id: dialogMouseArea + + anchors.fill: comicPicture + + onClicked: { + root.close(); + } + } + } + } + } +} \ No newline at end of file diff --git a/kdeplasma-addons/applets/comic/package/contents/ui/ImageWidget.qml b/kdeplasma-addons/applets/comic/package/contents/ui/ImageWidget.qml new file mode 100644 index 00000000..e450db60 --- /dev/null +++ b/kdeplasma-addons/applets/comic/package/contents/ui/ImageWidget.qml @@ -0,0 +1,78 @@ +/* + * Copyright 2012 Reza Fatahilah Shah + * + * 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, see . + */ + +import QtQuick 1.1 +import org.kde.plasma.core 0.1 as PlasmaCore +import org.kde.plasma.components 0.1 as PlasmaComponents +import org.kde.plasma.extras 0.1 as PlasmaExtras +import org.kde.qtextracomponents 0.1 + +PlasmaExtras.ScrollArea { + id: root + + width: comicPicture.nativeWidth + height: comicPicture.nativeHeight + + property bool actualSize: false + property bool isLeftToRight: true + property bool isTopToBottom: true + + property alias image: comicPicture.image + + function calculateContentWidth() { + return actualSize ? (comicPicture.nativeWidth > viewContainer.width ? comicPicture.nativeWidth : viewContainer.width) : viewContainer.width; + } + + function calculateContentHeight() { + return actualSize ? (comicPicture.nativeHeight > viewContainer.height ? comicPicture.nativeHeight : viewContainer.height) : viewContainer.height; + } + + Flickable { + id: viewContainer + + anchors.fill:parent + + contentWidth: comicPictureHolder.width + contentHeight: comicPictureHolder.height + + clip: true + + Item { + id: comicPictureHolder + + width: Math.max(comicPicture.width, viewContainer.width); + height: Math.max(comicPicture.height, viewContainer.height); + + QImageItem { + id: comicPicture + + anchors.centerIn: parent + + width: actualSize ? comicPicture.nativeWidth : viewContainer.width + height: actualSize ? comicPicture.nativeHeight : viewContainer.height + + onImageChanged: { + viewContainer.contentX = (root.isLeftToRight) ? 0 : ( viewContainer.contentWidth - viewContainer.width); + viewContainer.contentY = (root.isTopToBottom) ? 0 : ( viewContainer.contentHeight - viewContainer.height); + } + + smooth: true + fillMode: QImageItem.PreserveAspectFit + } + } + } +} diff --git a/kdeplasma-addons/applets/comic/package/contents/ui/main.qml b/kdeplasma-addons/applets/comic/package/contents/ui/main.qml new file mode 100644 index 00000000..7b48fd95 --- /dev/null +++ b/kdeplasma-addons/applets/comic/package/contents/ui/main.qml @@ -0,0 +1,228 @@ +/* + * Copyright 2012 Reza Fatahilah Shah + * + * 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, see . + */ + +import QtQuick 1.1 +import org.kde.plasma.core 0.1 as PlasmaCore +import org.kde.plasma.components 0.1 as PlasmaComponents +import org.kde.qtextracomponents 0.1 + +Item { + id: mainWindow + + width: minimumWidth + height: minimumHeight + + property int minimumWidth: theme.defaultFont.mSize.width * 35 + property int minimumHeight: theme.defaultFont.mSize.height * 12 + property bool showComicAuthor: comicApplet.showComicAuthor + property bool showComicTitle: comicApplet.showComicTitle + property bool showErrorPicture: comicApplet.showErrorPicture + property bool middleClick: comicApplet.middleClick + + Connections { + target: comicApplet + + onComicsModelChanged: { + comicTabbar.currentTab = comicTabbar.layout.children[1]; + } + + onTabHighlightRequest: { + for (var i = 0; i < comicTabbar.layout.children.length; ++i) { + var button = comicTabbar.layout.children[i]; + + if (button.key !== undefined && button.key == id) { + button.highlighted = highlight; + } + } + } + + onShowNextNewStrip: { + var firstButton = undefined; + + for (var i = 0; i < comicTabbar.layout.children.length; ++i) { + var button = comicTabbar.layout.children[i]; + if (button.key !== undefined && button.highlighted == true) { + //key is ordered + if (button.key > comicTabbar.currentTab.key) { + comicTabbar.currentTab = button; + return; + } else if (firstButton === undefined){ + firstButton = button; + } + } + } + + if (firstButton !== undefined) { + comicTabbar.currentTab = firstButton; + } + } + } + + PlasmaCore.Theme { + id: theme + } + + PlasmaCore.Svg { + id: arrowsSvg + imagePath: "widgets/arrows" + } + + PlasmaComponents.TabBar{ + id: comicTabbar + + anchors { + left: parent.left + right: parent.right + } + + visible: (comicApplet.comicsModel.count > 1) + + onCurrentTabChanged: { + console.log("onCurrentTabChanged:" + comicTabbar.currentTab.key); + comicApplet.tabChanged(comicTabbar.currentTab.key); + } + + Repeater { + model: comicApplet.comicsModel + delegate: PlasmaComponents.TabButton { + id: tabButton + + property string key: model.key + property bool highlighted: model.highlight + + text: model.title + iconSource: model.icon + + Rectangle { + id: highlightMask + + anchors { + bottom: parent.bottom + left: parent.left + } + + width: Math.max(theme.smallIconSize, tabButton.height) + height: Math.max(theme.smallIconSize, tabButton.height) + + color: "white" + opacity: model.highlight ? 0 : 0.5 + } + } + } + } + + PlasmaComponents.Label { + id: topInfo + + anchors { + top: comicTabbar.visible ? comicTabbar.bottom : mainWindow.top + left: mainWindow.left + right: mainWindow.right + } + + visible: (topInfo.text.length > 0) + horizontalAlignment: Text.AlignHCenter + text: (showComicAuthor || showComicTitle) ? getTopInfo() : "" + + function getTopInfo() { + var tempTop = ""; + + if ( showComicTitle ) { + tempTop = comicApplet.comicData.title; + tempTop += ( ( (comicApplet.comicData.stripTitle.length > 0) && (comicApplet.comicData.title.length > 0) ) ? " - " : "" ) + comicApplet.comicData.stripTitle; + } + + if ( showComicAuthor && + (comicApplet.comicData.author != undefined || comicApplet.comicData.author.length > 0) ) { + tempTop = ( tempTop.length > 0 ? comicApplet.comicData.author + ": " + tempTop : comicApplet.comicData.author ); + } + + return tempTop; + } + } + + ComicCentralView { + id: centerLayout + + anchors { + left: mainWindow.left + right: mainWindow.right + bottom: (bottomInfo.visible) ? bottomInfo.top : mainWindow.bottom + top: (topInfo.visible) ? topInfo.bottom : (comicTabbar.visible ? comicTabbar.bottom : mainWindow.top) + topMargin: (comicTabbar.visible) ? 3 : 0 + } + + comicData: comicApplet.comicData + } + + ComicBottomInfo { + id:bottomInfo + + anchors { + left: mainWindow.left + right: mainWindow.right + bottom: mainWindow.bottom + } + + comicData: comicApplet.comicData + showUrl: comicApplet.showComicUrl + showIdentifier: comicApplet.showComicIdentifier + } + + PlasmaComponents.BusyIndicator { + id: busyIndicator + anchors.centerIn: parent + running: visible + visible: false + } + + states: [ + State { + name: "topInfoVisible" + when: topInfo.visible && !bottomInfo.visible + AnchorChanges { + target: centerLayout + anchors.top: topInfo.bottom + } + }, + State { + name: "bottomInfoVisible" + when: bottomInfo.visible && !topInfo.visible + AnchorChanges { + target: centerLayout + anchors.bottom: bottomInfo.top + } + }, + State { + name: "topBottomInfoVisible" + when: bottomInfo.visible && topInfo.visible + AnchorChanges { + target: centerLayout + anchors.top: topInfo.bottom + anchors.bottom: bottomInfo.top + } + } + ] + + transitions: + Transition { + AnchorAnimation { + duration: 500 + easing.type: Easing.InOutQuad + } + } +} diff --git a/kdeplasma-addons/applets/comic/package/metadata.desktop b/kdeplasma-addons/applets/comic/package/metadata.desktop new file mode 100644 index 00000000..ca94dfc3 --- /dev/null +++ b/kdeplasma-addons/applets/comic/package/metadata.desktop @@ -0,0 +1,128 @@ +[Desktop Entry] +Name=Comic Strip +Name[ar]=شريط هزلي +Name[ast]=Tira de cómic +Name[bs]=stripovi +Name[ca]=Tira còmica +Name[ca@valencia]=Tira còmica +Name[cs]=Komiksový proužek +Name[csb]=Kòmiksowi sztrépk +Name[da]=Tegneseriestribe +Name[de]=Comic +Name[el]=Σειρά κόμικ +Name[en_GB]=Comic Strip +Name[es]=Tira de cómic +Name[et]=Koomiks +Name[eu]=Komiki zerrenda +Name[fi]=Sarjakuvastrippi +Name[fr]=Bande dessinée +Name[ga]=Stiallchartún +Name[gl]=Banda deseñada +Name[he]=קומיקס +Name[hr]=Strip +Name[hu]=Képregény +Name[is]=Myndasögur +Name[it]=Striscia di fumetti +Name[ja]=コミック・ストリップ +Name[kk]=Комикс +Name[km]=យក​កំប្លែង​ចេញ +Name[ko]=만화 조각 +Name[ku]=Pirtûka Qerfî +Name[lv]=Komikss +Name[mr]=कॉमिक पट्टी +Name[nb]=Comic Strip +Name[nds]=Comic +Name[nl]=Stripboek +Name[nn]=Teikneserie +Name[pa]=ਧੂਮਕੇਤੂ ਪੱਟੀ +Name[pl]=Komiks +Name[pt]=Banda Desenhada +Name[pt_BR]=Tirinha +Name[ro]=Benzi desenate +Name[ru]=Комиксы +Name[sk]=Komiks +Name[sl]=Smešen strip +Name[sr]=стрипови +Name[sr@ijekavian]=стрипови +Name[sr@ijekavianlatin]=stripovi +Name[sr@latin]=stripovi +Name[sv]=Tecknad serie +Name[th]=ดูหนังสือการ์ตูน +Name[tr]=Çizgi Roman +Name[uk]=Комічна стрічка +Name[wa]=Binde d' imådje +Name[x-test]=xxComic Stripxx +Name[zh_CN]=连环画 +Name[zh_TW]=漫畫 +Comment=View comic strips from the Internet +Comment[ar]=اعرض شرائط هزلية من الإنترنت +Comment[ast]=Amuesa tires de cómic d'Internet +Comment[bs]=Pogledajte stripove sa Interneta +Comment[ca]=Mostra una tira còmica des d'Internet +Comment[ca@valencia]=Mostra una tira còmica des d'Internet +Comment[cs]=Ukáže komiksový proužek z internetu +Comment[da]=Se tegneseriestriber fra internettet. +Comment[de]=Comics aus dem Internet anzeigen +Comment[el]=Εμφάνιση σειρών κόμικ από το διαδίκτυο +Comment[en_GB]=View comic strips from the Internet +Comment[es]=Muestra tiras de cómic de Internet +Comment[et]=Internetist hangitud koomiksite näitamine +Comment[eu]=Interneteko komiki zerrendak ikusi +Comment[fi]=Katso sarjakuvia internetistä +Comment[fr]=Affiche une bande dessinée provenant d'Internet +Comment[ga]=Taispeáin stiallchartún ón Idirlíon +Comment[gl]=Mostra bandas deseñadas de internet +Comment[he]=מציג קומיקסים נבחרים מהאינטרנט +Comment[hr]=Prikaži stripove na Internetu +Comment[hu]=Képregények megjelenítése az internetről +Comment[is]=Skoða myndasögur af netinu +Comment[it]=Vedi una striscia di fumetti da Internet. +Comment[ja]=インターネット上のコミック・ストリップを表示します +Comment[kk]=Интернеттен комиксті қарау +Comment[km]=មើល​រឿង​កំប្លែង​ពី​អ៊ីនធឺណិត +Comment[ko]=인터넷 만화 보기 +Comment[ku]=Ji Torê pirtûkên qerfî bibîne +Comment[lv]=Rāda komiksus no interneta +Comment[mr]=महाजाळापासून कॉमिक पट्ट्या बघा +Comment[nb]=Vis tegneserier fra Internett +Comment[nds]=Comics ut dat Internet ankieken +Comment[nl]=Toont stripboeken van het internet +Comment[nn]=Vis teikneseriar frå Internett +Comment[pa]=ਇੰਟਰਨੈੱਟ ਤੋਂ ਧੂਮਕੇਤੂ ਪੱਟੀ ਵੇਖੋ +Comment[pl]=Przeglądanie komiksów z Internetu +Comment[pt]=Mostra bandas desenhadas da Internet +Comment[pt_BR]=Exibe uma tirinha da Internet +Comment[ro]=Afișează benzi desenate din Internet +Comment[ru]=Просмотр комиксов из Интернета +Comment[sk]=Zobrazenie komiksov z internetu +Comment[sl]=Oglejte si smešne stripe z interneta +Comment[sr]=Погледајте стрипове са Интернета +Comment[sr@ijekavian]=Погледајте стрипове са Интернета +Comment[sr@ijekavianlatin]=Pogledajte stripove sa Interneta +Comment[sr@latin]=Pogledajte stripove sa Interneta +Comment[sv]=Visa tecknade serier från Internet +Comment[th]=ดูหนังสือการ์ตูนผ่านทางอินเทอร์เน็ต +Comment[tr]=İnternet'ten çizgi roman karikatürleri göster +Comment[uk]=Показує стрічку з жартами з Інтернету +Comment[wa]=Vey ene binde d' imådje di l' Etrernet +Comment[x-test]=xxView comic strips from the Internetxx +Comment[zh_CN]=查看来自互联网的连环画 +Comment[zh_TW]=從網路上顯示漫畫 +Icon=face-smile-big +Type=Service +X-KDE-ServiceTypes=Plasma/Applet + +X-Plasma-API=declarativeappletscript +X-Plasma-MainScript=ui/main.qml +X-Plasma-DefaultSize=600,250 +X-KDE-PluginInfo-Author=Reza Fatahilah Shah +X-KDE-PluginInfo-Email=rshah0385@kireihana.com +X-KDE-PluginInfo-Name=comic +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-Category=Graphics +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true +X-Plasma-Requires-FileDialog=Optional +X-Plasma-Requires-LaunchApp=Optional diff --git a/kdeplasma-addons/applets/comic/plasma-comic-default.desktop b/kdeplasma-addons/applets/comic/plasma-comic-default.desktop new file mode 100644 index 00000000..12371434 --- /dev/null +++ b/kdeplasma-addons/applets/comic/plasma-comic-default.desktop @@ -0,0 +1,126 @@ +[Desktop Entry] +Name=Comic Strip +Name[ar]=شريط هزلي +Name[ast]=Tira de cómic +Name[bs]=stripovi +Name[ca]=Tira còmica +Name[ca@valencia]=Tira còmica +Name[cs]=Komiksový proužek +Name[csb]=Kòmiksowi sztrépk +Name[da]=Tegneseriestribe +Name[de]=Comic +Name[el]=Σειρά κόμικ +Name[en_GB]=Comic Strip +Name[es]=Tira de cómic +Name[et]=Koomiks +Name[eu]=Komiki zerrenda +Name[fi]=Sarjakuvastrippi +Name[fr]=Bande dessinée +Name[ga]=Stiallchartún +Name[gl]=Banda deseñada +Name[he]=קומיקס +Name[hr]=Strip +Name[hu]=Képregény +Name[is]=Myndasögur +Name[it]=Striscia di fumetti +Name[ja]=コミック・ストリップ +Name[kk]=Комикс +Name[km]=យក​កំប្លែង​ចេញ +Name[ko]=만화 조각 +Name[ku]=Pirtûka Qerfî +Name[lv]=Komikss +Name[mr]=कॉमिक पट्टी +Name[nb]=Comic Strip +Name[nds]=Comic +Name[nl]=Stripboek +Name[nn]=Teikneserie +Name[pa]=ਧੂਮਕੇਤੂ ਪੱਟੀ +Name[pl]=Komiks +Name[pt]=Banda Desenhada +Name[pt_BR]=Tirinha +Name[ro]=Benzi desenate +Name[ru]=Комиксы +Name[sk]=Komiks +Name[sl]=Smešen strip +Name[sr]=стрипови +Name[sr@ijekavian]=стрипови +Name[sr@ijekavianlatin]=stripovi +Name[sr@latin]=stripovi +Name[sv]=Tecknad serie +Name[th]=ดูหนังสือการ์ตูน +Name[tr]=Çizgi Roman +Name[uk]=Комічна стрічка +Name[wa]=Binde d' imådje +Name[x-test]=xxComic Stripxx +Name[zh_CN]=连环画 +Name[zh_TW]=漫畫 +Comment=View comic strips from the Internet +Comment[ar]=اعرض شرائط هزلية من الإنترنت +Comment[ast]=Amuesa tires de cómic d'Internet +Comment[bs]=Pogledajte stripove sa Interneta +Comment[ca]=Mostra una tira còmica des d'Internet +Comment[ca@valencia]=Mostra una tira còmica des d'Internet +Comment[cs]=Ukáže komiksový proužek z internetu +Comment[da]=Se tegneseriestriber fra internettet. +Comment[de]=Comics aus dem Internet anzeigen +Comment[el]=Εμφάνιση σειρών κόμικ από το διαδίκτυο +Comment[en_GB]=View comic strips from the Internet +Comment[es]=Muestra tiras de cómic de Internet +Comment[et]=Internetist hangitud koomiksite näitamine +Comment[eu]=Interneteko komiki zerrendak ikusi +Comment[fi]=Katso sarjakuvia internetistä +Comment[fr]=Affiche une bande dessinée provenant d'Internet +Comment[ga]=Taispeáin stiallchartún ón Idirlíon +Comment[gl]=Mostra bandas deseñadas de internet +Comment[he]=מציג קומיקסים נבחרים מהאינטרנט +Comment[hr]=Prikaži stripove na Internetu +Comment[hu]=Képregények megjelenítése az internetről +Comment[is]=Skoða myndasögur af netinu +Comment[it]=Vedi una striscia di fumetti da Internet. +Comment[ja]=インターネット上のコミック・ストリップを表示します +Comment[kk]=Интернеттен комиксті қарау +Comment[km]=មើល​រឿង​កំប្លែង​ពី​អ៊ីនធឺណិត +Comment[ko]=인터넷 만화 보기 +Comment[ku]=Ji Torê pirtûkên qerfî bibîne +Comment[lv]=Rāda komiksus no interneta +Comment[mr]=महाजाळापासून कॉमिक पट्ट्या बघा +Comment[nb]=Vis tegneserier fra Internett +Comment[nds]=Comics ut dat Internet ankieken +Comment[nl]=Toont stripboeken van het internet +Comment[nn]=Vis teikneseriar frå Internett +Comment[pa]=ਇੰਟਰਨੈੱਟ ਤੋਂ ਧੂਮਕੇਤੂ ਪੱਟੀ ਵੇਖੋ +Comment[pl]=Przeglądanie komiksów z Internetu +Comment[pt]=Mostra bandas desenhadas da Internet +Comment[pt_BR]=Exibe uma tirinha da Internet +Comment[ro]=Afișează benzi desenate din Internet +Comment[ru]=Просмотр комиксов из Интернета +Comment[sk]=Zobrazenie komiksov z internetu +Comment[sl]=Oglejte si smešne stripe z interneta +Comment[sr]=Погледајте стрипове са Интернета +Comment[sr@ijekavian]=Погледајте стрипове са Интернета +Comment[sr@ijekavianlatin]=Pogledajte stripove sa Interneta +Comment[sr@latin]=Pogledajte stripove sa Interneta +Comment[sv]=Visa tecknade serier från Internet +Comment[th]=ดูหนังสือการ์ตูนผ่านทางอินเทอร์เน็ต +Comment[tr]=İnternet'ten çizgi roman karikatürleri göster +Comment[uk]=Показує стрічку з жартами з Інтернету +Comment[wa]=Vey ene binde d' imådje di l' Etrernet +Comment[x-test]=xxView comic strips from the Internetxx +Comment[zh_CN]=查看来自互联网的连环画 +Comment[zh_TW]=從網路上顯示漫畫 +Icon=face-smile-big +Type=Service +X-KDE-ServiceTypes=Plasma/Applet + +X-KDE-Library=plasma_applet_comic +X-KDE-PluginInfo-Author=Tobias Koenig +X-KDE-PluginInfo-Email=tokoe@kde.org +X-KDE-PluginInfo-Name=comic +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-Category=Graphics +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true +X-Plasma-Requires-FileDialog=Optional +X-Plasma-Requires-LaunchApp=Optional diff --git a/kdeplasma-addons/applets/comic/stripselector.cpp b/kdeplasma-addons/applets/comic/stripselector.cpp new file mode 100644 index 00000000..cd88ea34 --- /dev/null +++ b/kdeplasma-addons/applets/comic/stripselector.cpp @@ -0,0 +1,179 @@ +/*************************************************************************** + * Copyright (C) 2012 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "stripselector.h" +#include "stripselector_p.h" +#include "comicdata.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + +//NOTE based on GotoPageDialog KDE/kdegraphics/okular/part.cpp +//BEGIN choose a strip dialog +class ChooseStripNumDialog : public KDialog +{ + public: + ChooseStripNumDialog(QWidget *parent, int current, int min, int max) + : KDialog( parent ) + { + setCaption(i18n("Go to Strip")); + setButtons(Ok | Cancel); + setDefaultButton(Ok); + + QWidget *widget = new QWidget(this); + setMainWidget(widget); + + QVBoxLayout *topLayout = new QVBoxLayout(widget); + topLayout->setMargin(0); + topLayout->setSpacing(spacingHint()); + numInput = new KIntNumInput(current, widget); + numInput->setRange(min, max); + numInput->setEditFocus(true); + numInput->setSliderEnabled(true); + + QLabel *label = new QLabel(i18n("&Strip Number:"), widget); + label->setBuddy(numInput); + topLayout->addWidget(label); + topLayout->addWidget(numInput) ; + // A little bit extra space + topLayout->addSpacing(spacingHint()); + topLayout->addStretch(10); + numInput->setFocus(); + } + + int getStripNumber() const + { + return numInput->value(); + } + + protected: + KIntNumInput *numInput; +}; +//END choose a strip dialog + +StripSelector::StripSelector(QObject *parent) + : QObject(parent) +{ +} + +StripSelector::~StripSelector() +{ +} + +StripSelector *StripSelectorFactory::create(IdentifierType type) +{ + switch (type) { + case Number: + return new NumberStripSelector(); + case Date: + return new DateStripSelector(); + case String: + return new StringStripSelector(); + } + + return 0; +} + + +StringStripSelector::StringStripSelector(QObject *parent) + : StripSelector(parent) +{ +} + +StringStripSelector::~StringStripSelector() +{ +} + +void StringStripSelector::select(const ComicData ¤tStrip) +{ + bool ok; + const QString strip = KInputDialog::getText(i18n("Go to Strip"), i18n("Strip identifier:"), + currentStrip.current(), &ok); + if (ok) { + emit stripChosen(strip); + } + deleteLater(); +} + +NumberStripSelector::NumberStripSelector(QObject *parent) + : StripSelector(parent) +{ +} + +NumberStripSelector::~NumberStripSelector() +{ +} + +void NumberStripSelector::select(const ComicData ¤tStrip) +{ + QScopedPointer pageDialog(new ChooseStripNumDialog(0, currentStrip.current().toInt(), + currentStrip.firstStripNum(), currentStrip.maxStripNum())); + if (pageDialog->exec() == QDialog::Accepted) { + emit stripChosen(QString::number(pageDialog->getStripNumber())); + } + deleteLater(); +} + +DateStripSelector::DateStripSelector(QObject *parent) + : StripSelector(parent) +{ +} + +DateStripSelector::~DateStripSelector() +{ +} + +void DateStripSelector::select(const ComicData ¤tStrip) +{ + mFirstIdentifierSuffix = currentStrip.first(); + + KDatePicker *calendar = new KDatePicker; + calendar->setAttribute(Qt::WA_DeleteOnClose);//to have destroyed emitted upon closing + calendar->setMinimumSize(calendar->sizeHint()); + calendar->setDate(QDate::fromString(currentStrip.current(), "yyyy-MM-dd")); + + connect(calendar, SIGNAL(dateSelected(QDate)), this, SLOT(slotChosenDay(QDate))); + connect(calendar, SIGNAL(dateEntered(QDate)), this, SLOT(slotChosenDay(QDate))); + + // only delete this if the dialog got closed + connect(calendar, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater())); + calendar->show(); +} + +void DateStripSelector::slotChosenDay(const QDate &date) +{ + if (date <= QDate::currentDate()) { + QDate temp = QDate::fromString(mFirstIdentifierSuffix, "yyyy-MM-dd"); + // only update if date >= first strip date, or if there is no first + // strip date + if (temp.isValid() || date >= temp) { + emit stripChosen(date.toString("yyyy-MM-dd")); + } + } +} + +#include "stripselector.moc" +#include "stripselector_p.moc" diff --git a/kdeplasma-addons/applets/comic/stripselector.h b/kdeplasma-addons/applets/comic/stripselector.h new file mode 100644 index 00000000..f42012ec --- /dev/null +++ b/kdeplasma-addons/applets/comic/stripselector.h @@ -0,0 +1,72 @@ +/*************************************************************************** + * Copyright (C) 2012 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef STRIP_SELECTOR_H +#define STRIP_SELECTOR_H + +#include + +#include "comicinfo.h" + +class ComicData; +class QDate; + +/** + * Enables users to visually select a strip they want to navigate to. + * Subclasses implement different Selectors for the different comic + * types. + * @note use the StripSelectorFactory to retrieve an appropriate + * StripSelector + */ +class StripSelector : public QObject +{ + Q_OBJECT + + public: + virtual ~StripSelector(); + + /** + * Select a strip depending on the subclass + * @param currentStrip the currently active strip + * @note StripSelector takes care to delete itself + */ + virtual void select(const ComicData ¤tStrip) = 0; + + signals: + /** + * @param strip the selected strip, can be empty + * + */ + void stripChosen(const QString &strip); + + protected: + explicit StripSelector(QObject *parent = 0); +}; + +/** + * Class to retrrieve the correct StripSelector depending on the + * specified IdentifierType + */ +class StripSelectorFactory +{ + public: + static StripSelector *create(IdentifierType type); +}; + +#endif diff --git a/kdeplasma-addons/applets/comic/stripselector_p.h b/kdeplasma-addons/applets/comic/stripselector_p.h new file mode 100644 index 00000000..516e1e1c --- /dev/null +++ b/kdeplasma-addons/applets/comic/stripselector_p.h @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (C) 2012 Matthias Fuchs * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef STRIP_SELECTOR_P_H +#define STRIP_SELECTOR_P_H + +#include "stripselector.h" + +#include + +class StringStripSelector : public StripSelector +{ + public: + explicit StringStripSelector(QObject *parent = 0); + virtual ~StringStripSelector(); + + virtual void select(const ComicData ¤tStrip); +}; + +class NumberStripSelector : public StripSelector +{ + public: + explicit NumberStripSelector(QObject *parent = 0); + virtual ~NumberStripSelector(); + + virtual void select(const ComicData ¤tStrip); +}; + +class DateStripSelector : public StripSelector +{ + Q_OBJECT + + public: + explicit DateStripSelector(QObject *parent = 0); + virtual ~DateStripSelector(); + + virtual void select(const ComicData ¤tStrip); + + private slots: + void slotChosenDay(const QDate &date); + + private: + QString mFirstIdentifierSuffix; +}; + +#endif diff --git a/kdeplasma-addons/applets/community/CMakeLists.txt b/kdeplasma-addons/applets/community/CMakeLists.txt new file mode 100644 index 00000000..bfc28b50 --- /dev/null +++ b/kdeplasma-addons/applets/community/CMakeLists.txt @@ -0,0 +1,43 @@ +project(plasma-opendesktop) + +set(opendesktop_SRCS + actionstack.cpp + loginwidget.cpp + friendlist.cpp + contactcontainer.cpp + friendmanagementcontainer.cpp + friendmanagementwidget.cpp + messagecounter.cpp + requestfriendshipwidget.cpp + messagelist.cpp + messagewatchlist.cpp + messagewidget.cpp + personwatch.cpp + personwatchlist.cpp + sourcewatchlist.cpp + utils.cpp + sendmessagewidget.cpp + opendesktop.cpp + contactwidget.cpp + userwidget.cpp + contactimage.cpp + stylesheet.cpp + contactlist.cpp +) + +kde4_add_ui_files(opendesktop_SRCS opendesktopConfig.ui opendesktopLocationConfig.ui ) +kde4_add_plugin(plasma_applet_opendesktop ${opendesktop_SRCS}) + +target_link_libraries( + plasma_applet_opendesktop + ${KDE4_KIO_LIBS} + ${KDE4_PLASMA_LIBS} + ${KDE4_KCMUTILS_LIBS} + ${QT_QTWEBKIT_LIBRARY} +) + +install(TARGETS plasma_applet_opendesktop DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES plasma-applet-opendesktop.desktop DESTINATION ${SERVICES_INSTALL_DIR}) + +install(FILES user.css DESTINATION ${DATA_INSTALL_DIR}/plasma-applet-opendesktop/) + diff --git a/kdeplasma-addons/applets/community/Messages.sh b/kdeplasma-addons/applets/community/Messages.sh new file mode 100755 index 00000000..c32f88d3 --- /dev/null +++ b/kdeplasma-addons/applets/community/Messages.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash +$EXTRACTRC *.ui >> rc.cpp +$XGETTEXT *.cpp -o $podir/plasma_applet_opendesktop.pot diff --git a/kdeplasma-addons/applets/community/actionstack.cpp b/kdeplasma-addons/applets/community/actionstack.cpp new file mode 100644 index 00000000..fcfa26fc --- /dev/null +++ b/kdeplasma-addons/applets/community/actionstack.cpp @@ -0,0 +1,114 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "actionstack.h" + +#include +#include +#include "contactlist.h" +#include "requestfriendshipwidget.h" +#include "sendmessagewidget.h" +#include "userwidget.h" + + +using namespace Plasma; + + +ActionStack::ActionStack(DataEngine* engine, QGraphicsWidget* mainWidget, QGraphicsWidget* parent) + : QGraphicsWidget(parent) +{ + m_details = new UserWidget(engine); + m_requestFriendship = new RequestFriendshipWidget(engine); + m_sendMessage = new SendMessageWidget(engine); + + m_tabs = new TabBar; + m_tabs->setTabBarShown(false); + m_tabs->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_tabs->addTab(QString(), mainWidget); + m_tabs->addTab(QString(), m_details); + m_tabs->addTab(QString(), m_sendMessage); + m_tabs->addTab(QString(), m_requestFriendship); + + QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Horizontal); + layout->setContentsMargins(0, 0, 0, 0); + setContentsMargins(0, 0, 0, 0); + mainWidget->setContentsMargins(0, 0, 0, 0); + m_tabs->setContentsMargins(0, 0, 0, 0); + layout->addItem(m_tabs); + + setLayout(layout); + + connect(this, SIGNAL(providerChanged(QString)), m_details, SLOT(setProvider(QString))); + connect(this, SIGNAL(providerChanged(QString)), m_requestFriendship, SLOT(setProvider(QString))); + connect(this, SIGNAL(providerChanged(QString)), m_sendMessage, SLOT(setProvider(QString))); + + connect(m_details, SIGNAL(sendMessage(QString)), this, SLOT(sendMessage(QString))); + + connect(m_details, SIGNAL(done()), SLOT(showMainWidget())); + + connect(m_requestFriendship, SIGNAL(done()), SLOT(showMainWidget())); + + connect(m_sendMessage, SIGNAL(endWork()), SIGNAL(endWork())); + connect(m_sendMessage, SIGNAL(done()), SLOT(showMainWidget())); + connect(m_sendMessage, SIGNAL(startWork()), SIGNAL(startWork())); +} + + +void ActionStack::addFriend(const QString& id) +{ + m_requestFriendship->setId(id); + m_tabs->setCurrentIndex(3); +} + + +void ActionStack::sendMessage(const QString& id) +{ + m_sendMessage->setId(id); + m_tabs->setCurrentIndex(2); +} + + +void ActionStack::setOwnId(const QString& ownId) +{ + m_details->setOwnId(ownId); + emit ownIdChanged(ownId); +} + + +void ActionStack::setProvider(const QString& provider) +{ + emit providerChanged(provider); +} + + +void ActionStack::showDetails(const QString& id) +{ + m_details->setId(id); + m_tabs->setCurrentIndex(1); +} + + +void ActionStack::showMainWidget() +{ + m_tabs->setCurrentIndex(0); +} + +#include "actionstack.moc" diff --git a/kdeplasma-addons/applets/community/actionstack.h b/kdeplasma-addons/applets/community/actionstack.h new file mode 100644 index 00000000..379a7c0b --- /dev/null +++ b/kdeplasma-addons/applets/community/actionstack.h @@ -0,0 +1,67 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef ACTIONSTACK_H +#define ACTIONSTACK_H + +#include + + +class SendMessageWidget; +class RequestFriendshipWidget; +class UserWidget; + +namespace Plasma { + class DataEngine; + class TabBar; +} + +class ActionStack : public QGraphicsWidget +{ + Q_OBJECT + +public: + explicit ActionStack(Plasma::DataEngine* engine, QGraphicsWidget* mainWidget, QGraphicsWidget* parent = 0); + +public Q_SLOTS: + void addFriend(const QString& id); + void setOwnId(const QString& ownId); + void setProvider(const QString& provider); + void sendMessage(const QString& id); + void showDetails(const QString& id); + void showMainWidget(); + +Q_SIGNALS: + void endWork(); + void ownIdChanged(const QString& ownId); + void providerChanged(const QString& provider); + void sourceChanged(const QString& source); + void startWork(); + +private: + UserWidget* m_details; + RequestFriendshipWidget* m_requestFriendship; + SendMessageWidget* m_sendMessage; + Plasma::TabBar* m_tabs; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/contactcontainer.cpp b/kdeplasma-addons/applets/community/contactcontainer.cpp new file mode 100644 index 00000000..6b8cd3fb --- /dev/null +++ b/kdeplasma-addons/applets/community/contactcontainer.cpp @@ -0,0 +1,120 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "contactcontainer.h" + +#include + +#include + +#include "contactwidget.h" +#include "utils.h" + + +using namespace Plasma; + +ContactContainer::ContactContainer(DataEngine* engine, Plasma::ScrollWidget* parent) + : QGraphicsWidget(parent), + m_scrollWidget(parent), + m_engine(engine), + m_friendWatcher(engine), + m_layout(new QGraphicsLinearLayout(Qt::Vertical)), + m_personWatcher(engine) +{ + setLayout(m_layout); + connect(&m_addFriendMapper, SIGNAL(mapped(QString)), SIGNAL(addFriend(QString))); + connect(&m_friendWatcher, SIGNAL(personAdded(QString)), SLOT(friendAdded(QString))); + connect(&m_friendWatcher, SIGNAL(personRemoved(QString)), SLOT(friendRemoved(QString))); + connect(&m_personWatcher, SIGNAL(personAdded(QString)), SLOT(personAdded(QString))); + connect(&m_personWatcher, SIGNAL(personRemoved(QString)), SLOT(personRemoved(QString))); + connect(&m_sendMessageMapper, SIGNAL(mapped(QString)), SIGNAL(sendMessage(QString))); + connect(&m_showDetailsMapper, SIGNAL(mapped(QString)), SIGNAL(showDetails(QString))); +} + + +void ContactContainer::friendAdded(const QString& person) +{ + if (m_idToWidget.contains(person)) { + m_idToWidget.value(person)->setIsFriend(true); + } +} + + +void ContactContainer::friendRemoved(const QString& person) { + if (m_idToWidget.contains(person)) { + m_idToWidget.value(person)->setIsFriend(false); + } +} + + +void ContactContainer::personAdded(const QString& person) +{ + ContactWidget* widget = new ContactWidget(m_engine, this); + + widget->setProvider(m_provider); + widget->setId(person); + widget->setIsFriend(m_friendWatcher.contains(person)); + m_layout->addItem(widget); + m_idToWidget.insert(person, widget); + m_addFriendMapper.setMapping(widget, person); + m_sendMessageMapper.setMapping(widget, person); + m_showDetailsMapper.setMapping(widget, person); + connect(widget, SIGNAL(addFriend()), &m_addFriendMapper, SLOT(map())); + connect(widget, SIGNAL(sendMessage()), &m_sendMessageMapper, SLOT(map())); + connect(widget, SIGNAL(showDetails()), &m_showDetailsMapper, SLOT(map())); +} + + +void ContactContainer::personRemoved(const QString& person) +{ + ContactWidget* widget = m_idToWidget.take(person); + if (widget) { + m_layout->removeItem(widget); + widget->deleteLater(); + } +} + + +void ContactContainer::setOwnId(const QString& ownId) +{ + m_ownId = ownId; + m_friendWatcher.setSource(friendsQuery(m_provider, m_ownId)); +} + + +void ContactContainer::setProvider(const QString& provider) +{ + m_provider = provider; + m_friendWatcher.setSource(friendsQuery(m_provider, m_ownId)); + foreach (ContactWidget* widget, m_idToWidget) { + widget->setProvider(m_provider); + } +} + + +void ContactContainer::setSource(const QString& source) +{ + m_source = source; + m_personWatcher.setSource(m_source); +} + + +#include "contactcontainer.moc" diff --git a/kdeplasma-addons/applets/community/contactcontainer.h b/kdeplasma-addons/applets/community/contactcontainer.h new file mode 100644 index 00000000..c6692391 --- /dev/null +++ b/kdeplasma-addons/applets/community/contactcontainer.h @@ -0,0 +1,80 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef CONTACTCONTAINER_H +#define CONTACTCONTAINER_H + +#include +#include + +#include + +#include "personwatchlist.h" + + +class ContactWidget; +class QGraphicsLinearLayout; + +namespace Plasma +{ + class ScrollWidget; +} + +class ContactContainer : public QGraphicsWidget +{ + Q_OBJECT + +public: + explicit ContactContainer(Plasma::DataEngine* engine, Plasma::ScrollWidget* parent = 0); + +Q_SIGNALS: + void addFriend(const QString& id); + void sendMessage(const QString& id); + void showDetails(const QString& id); + +public Q_SLOTS: + void setOwnId(const QString& ownId); + void setProvider(const QString& provider); + void setSource(const QString& source); + +private Q_SLOTS: + void friendAdded(const QString& person); + void friendRemoved(const QString& person); + void personAdded(const QString& person); + void personRemoved(const QString& person); + +private: + Plasma::ScrollWidget *m_scrollWidget; + QSignalMapper m_addFriendMapper; + Plasma::DataEngine* m_engine; + PersonWatchList m_friendWatcher; + QHash m_idToWidget; + QGraphicsLinearLayout* m_layout; + QString m_ownId; + PersonWatchList m_personWatcher; + QString m_provider; + QSignalMapper m_sendMessageMapper; + QSignalMapper m_showDetailsMapper; + QString m_source; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/contactimage.cpp b/kdeplasma-addons/applets/community/contactimage.cpp new file mode 100644 index 00000000..68f36f66 --- /dev/null +++ b/kdeplasma-addons/applets/community/contactimage.cpp @@ -0,0 +1,124 @@ +/* + Copyright 2008-2009 by Sebastian Kügler + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "contactimage.h" + +//Qt +#include +#include +#include + +// KDE +#include + +// Plasma +#include +#include + + +using namespace Plasma; + +ContactImage::ContactImage(DataEngine* engine, QGraphicsWidget* parent) + : QGraphicsWidget(parent), m_engine(engine) +{ + border = 1; // should be a power of two, otherwise we get blurry lines + fg = Theme::defaultTheme()->color(Theme::TextColor); + bg = Theme::defaultTheme()->color(Theme::BackgroundColor); + pixmapUpdated(); +} + + +void ContactImage::setUrl(const QUrl& url) +{ + if (!m_engine) { + return; + } + if (!m_source.isEmpty()) { + m_engine->disconnectSource(m_source, this); + } + m_source = url.isValid() ? "Pixmap\\url:" + url.toString() : QString(); + dataUpdated(m_source, DataEngine::Data()); + if (!m_source.isEmpty()) { + m_engine->connectSource(m_source, this); + } +} + + +void ContactImage::dataUpdated(const QString& source, const DataEngine::Data& data) +{ + Q_UNUSED(source) + m_pixmap = data.value("Pixmap").value(); + pixmapUpdated(); + update(); +} + + +void ContactImage::pixmapUpdated() +{ + QSize newSize = QSize(contentsRect().width() - (border * 2), contentsRect().height() - (border * 2)); + if (newSize.isEmpty()) { + m_scaledPixmap = QPixmap(); + return; + } + if (!m_pixmap.isNull()) { + if (newSize.width() > m_pixmap.width()) { + newSize.setWidth(m_pixmap.width()); + } + if (newSize.height() > m_pixmap.height()) { + newSize.setHeight(m_pixmap.height()); + } + m_scaledPixmap = m_pixmap.scaled(newSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); + } else { + m_scaledPixmap = KIcon("system-users").pixmap(newSize); + } +} + + +void ContactImage::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + Q_UNUSED(option) + Q_UNUSED(widget) + + painter->setRenderHint(QPainter::SmoothPixmapTransform); + painter->setRenderHint(QPainter::Antialiasing); + + bg.setAlphaF(.3); + fg.setAlphaF(.2); + painter->setBrush(bg); + painter->setPen(fg); + painter->translate(.5, .5); // unblur (align to full pixel) + + // compute rect of the pixmap to paint the frame + QRectF r = QRect(contentsRect().left(), contentsRect().top(), m_scaledPixmap.width() + border*2, m_scaledPixmap.height() + border*2); + painter->drawRoundedRect(r, border*2, border*2); + + // paint our cached scaled version of the pixmap on top of that + painter->drawPixmap(QPoint(border, border), m_scaledPixmap); +} + + +void ContactImage::resizeEvent(QGraphicsSceneResizeEvent* event) +{ + Q_UNUSED(event) + + pixmapUpdated(); +} + + +#include "contactimage.moc" diff --git a/kdeplasma-addons/applets/community/contactimage.h b/kdeplasma-addons/applets/community/contactimage.h new file mode 100644 index 00000000..a87aa09e --- /dev/null +++ b/kdeplasma-addons/applets/community/contactimage.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright 2009 by Sebastian Kügler * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef CONTACTIMAGE_H +#define CONTACTIMAGE_H + +//Qt +#include +#include + +#include + + +class ContactImage : public QGraphicsWidget +{ + Q_OBJECT + +public: + explicit ContactImage(Plasma::DataEngine* engine, QGraphicsWidget* parent = 0); + void setUrl(const QUrl& url); + +private Q_SLOTS: + void dataUpdated(const QString& source, const Plasma::DataEngine::Data& data); + +private: + void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); + void resizeEvent(QGraphicsSceneResizeEvent* event); + void pixmapUpdated(); + + Plasma::DataEngine* m_engine; + + int border; + QColor fg; + QColor bg; + + QPixmap m_pixmap; + QPixmap m_scaledPixmap; + + QString m_source; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/contactlist.cpp b/kdeplasma-addons/applets/community/contactlist.cpp new file mode 100644 index 00000000..b2be2df9 --- /dev/null +++ b/kdeplasma-addons/applets/community/contactlist.cpp @@ -0,0 +1,57 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "contactlist.h" + +#include "contactcontainer.h" + + +ContactList::ContactList(Plasma::DataEngine* engine, QGraphicsWidget* parent) + : ScrollWidget(parent) +{ + m_widget = new ContactContainer(engine, this); + setWidget(m_widget); + + connect(m_widget, SIGNAL(addFriend(QString)), SIGNAL(addFriend(QString))); + connect(m_widget, SIGNAL(sendMessage(QString)), SIGNAL(sendMessage(QString))); + connect(m_widget, SIGNAL(showDetails(QString)), SIGNAL(showDetails(QString))); +} + + +void ContactList::setProvider(const QString& provider) +{ + m_widget->setProvider(provider); +} + + +void ContactList::setQuery(const QString& query) +{ + m_widget->setSource(query); +} + + +void ContactList::setOwnId(const QString& id) +{ + m_widget->setOwnId(id); +} + + +#include "contactlist.moc" diff --git a/kdeplasma-addons/applets/community/contactlist.h b/kdeplasma-addons/applets/community/contactlist.h new file mode 100644 index 00000000..ff608153 --- /dev/null +++ b/kdeplasma-addons/applets/community/contactlist.h @@ -0,0 +1,91 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef CONTACTLIST_H +#define CONTACTLIST_H + +#include +#include + +#include + + +class ContactContainer; + +namespace Plasma { + class DataEngine; +} + +/** + * The ContactList class provides a Plasma widget for displaying lists of contactwidget + */ +class ContactList : public Plasma::ScrollWidget +{ + Q_OBJECT + + public: + /** + * Creates a new ContactList widget without entries + * @param engine the Plasma data engine to use + * @param parent the parent of this widget + */ + explicit ContactList(Plasma::DataEngine* engine, QGraphicsWidget* parent = 0); + + public Q_SLOTS: + /** + * Sets the id of the user (i.e. the id that is taken into account when computing friendships) + * @param id the new id + */ + void setOwnId(const QString& id); + + void setProvider(const QString& provider); + + /** + * Sets the query whose results should be displayed + * @param query a source of the data engine that can be interpreted as a list of contacts (where each person is identified by a Person-[id] key) + */ + void setQuery(const QString& query); + + Q_SIGNALS: + /** + * This signal is emitted when the user requests to add a friend + * @param id the identification of the new friend + */ + void addFriend(const QString& id); + + /** + * This signal is emitted when the user requests the details of a contact + * @param id the identification of the requested contact details + */ + void showDetails(const QString& id); + + /** + * This signal is emitted when the user requests to write a message to a contact + * @param id the identification of the recipient + */ + void sendMessage(const QString& id); + + private: + ContactContainer* m_widget; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/contactwidget.cpp b/kdeplasma-addons/applets/community/contactwidget.cpp new file mode 100644 index 00000000..70df99c2 --- /dev/null +++ b/kdeplasma-addons/applets/community/contactwidget.cpp @@ -0,0 +1,350 @@ +/* + Copyright 2008-2009 by Sebastian Kügler + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "contactwidget.h" + +//Qt +#include +#include +#include + +//KDE +#include +#include +#include +#include +#include + +// Plasma +#include +#include +#include +#include + +// own +#include "contactimage.h" +#include "utils.h" + +using namespace Plasma; + +ContactWidget::ContactWidget(DataEngine* engine, QGraphicsWidget* parent) + : Frame(parent), + m_isHovered(false), + m_isFriend(false), + m_image(0), + m_nameLabel(0), + m_sendMessage(0), + m_addFriend(0), + m_showDetails(0), + m_engine(engine) +{ + setAcceptHoverEvents(true); + buildDialog(); + connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(updateColors())); + connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), SLOT(updateColors())); + setMinimumHeight(40); + setMinimumWidth(120); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); +} + +ContactWidget::~ContactWidget() +{ +} + + +void ContactWidget::setId(const QString& id) +{ + if (!m_provider.isEmpty() && !m_id.isEmpty()) { + m_engine->disconnectSource(personSummaryQuery(m_provider, m_id), this); + } + m_id = id; + if (!m_provider.isEmpty() && !m_id.isEmpty()) { + m_engine->connectSource(personSummaryQuery(m_provider, m_id), this); + } +} + + +QString ContactWidget::id() const +{ + return m_id; +} + + +void ContactWidget::setProvider(const QString& provider) +{ + if (!m_provider.isEmpty() && !m_id.isEmpty()) { + m_engine->disconnectSource(personSummaryQuery(m_provider, m_id), this); + } + m_provider = provider; + if (!m_provider.isEmpty() && !m_id.isEmpty()) { + m_engine->connectSource(personSummaryQuery(m_provider, m_id), this); + } +} + + +QString ContactWidget::provider() const +{ + return m_provider; +} + + +void ContactWidget::dataUpdated(const QString& source, const Plasma::DataEngine::Data& data) +{ + Q_UNUSED(source); + + m_ocsData = data.value(personAddPrefix(m_id)).value(); + QString _id = m_ocsData["Id"].toString(); + + QString name = m_ocsData["Name"].toString(); + if (name.isEmpty()) { + setName(_id); + } else { + setName(QString("%1 (%2)").arg(name, _id)); + } + + QString city = m_ocsData["City"].toString(); + QString country = m_ocsData["Country"].toString(); + QString location; + if (!city.isEmpty() && !country.isEmpty()) { + location = QString("%1, %2").arg(city, country); + } else if (country.isEmpty() && !city.isEmpty()) { + location = city; + } else if (city.isEmpty() && !country.isEmpty()) { + location = country; + } + + if (!location.isEmpty()) { + setInfo(location); + } + m_image->setUrl(m_ocsData.value("AvatarUrl").toUrl()); +} + + +void ContactWidget::buildDialog() +{ + updateColors(); + + int m = KIconLoader::SizeMedium; + + m_layout = new QGraphicsGridLayout(this); + m_layout->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_layout->setColumnFixedWidth(0, int(m*1.2)); + m_layout->setHorizontalSpacing(4); + + m_image = new ContactImage(m_engine, this); + m_image->setMinimumHeight(m); + m_image->setMinimumWidth(m); + m_layout->addItem(m_image, 0, 0, 2, 1, Qt::AlignTop); + + m_nameLabel = new Plasma::Label(this); + m_nameLabel->nativeWidget()->setWordWrap(false); + m_nameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + m_nameLabel->setMinimumWidth(m*2); + m_layout->addItem(m_nameLabel, 0, 1, 1, 1, Qt::AlignTop); + + int s = KIconLoader::SizeSmallMedium; // The size for the action icons + + m_actions = new QGraphicsLinearLayout(m_layout); + m_actions->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + + m_infoLabel = new Plasma::Label(this); + m_infoLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + m_infoLabel->nativeWidget()->setFont(KGlobalSettings::smallestReadableFont()); + m_infoLabel->nativeWidget()->setWordWrap(false); + m_actions->addItem(m_infoLabel); + + m_sendMessage = new Plasma::IconWidget(this); + m_sendMessage->setIcon("mail-send"); + m_sendMessage->setToolTip(i18n("Send Message")); + m_sendMessage->setMinimumHeight(s); + m_sendMessage->setMaximumHeight(s); + m_sendMessage->setMinimumWidth(s); + m_sendMessage->setMaximumWidth(s); + + m_addFriend = new Plasma::IconWidget(this); + m_addFriend->setIcon("list-add-user"); + m_addFriend->setToolTip(i18n("Add as Friend")); + m_addFriend->setMinimumHeight(s); + m_addFriend->setMaximumHeight(s); + m_addFriend->setMinimumWidth(s); + m_addFriend->setMaximumWidth(s); + + m_showDetails = new Plasma::IconWidget(this); + m_showDetails->setIcon("user-properties"); + m_showDetails->setToolTip(i18n("User Details")); + m_showDetails->setMinimumHeight(s); + m_showDetails->setMaximumHeight(s); + m_showDetails->setMinimumWidth(s); + m_showDetails->setMaximumWidth(s); + + connect(m_sendMessage, SIGNAL(clicked()), SIGNAL(sendMessage())); + connect(m_addFriend, SIGNAL(clicked()), SIGNAL(addFriend())); + connect(m_showDetails, SIGNAL(clicked()), SLOT(slotShowDetails())); + + m_actions->addItem(m_addFriend); + m_actions->addItem(m_sendMessage); + m_actions->addItem(m_showDetails); + + m_layout->addItem(m_actions, 1, 1, 1, 1, Qt::AlignBottom | Qt::AlignRight); + + setLayout(m_layout); + + updateActions(); + updateColors(); +} + +void ContactWidget::setIsFriend(bool isFriend) +{ + if (m_isFriend != isFriend) { + m_isFriend = isFriend; + updateActions(); + } +} + +void ContactWidget::updateActions() +{ + m_addFriend->setVisible(m_isHovered && !m_isFriend); + m_sendMessage->setVisible(m_isHovered); + m_showDetails->setVisible(m_isHovered); +} + + +void ContactWidget::slotShowDetails() +{ + kDebug() << "user details" << user(); + // When sliding out, we'll usually miss the hoverLeaveEvent, + // so do it manually + m_isHovered = false; + updateActions(); + emit showDetails(); +} + +void ContactWidget::updateColors() +{ + QPalette p = palette(); + + // Set background to transparent and use the theme to provide contrast with the text + p.setColor(QPalette::Base, Qt::transparent); // new in Qt 4.5 + p.setColor(QPalette::Window, Qt::transparent); // For Qt 4.4, remove when we depend on 4.5 + + QColor text = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor); + QColor link = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor); + link.setAlphaF(qreal(.8)); + QColor linkvisited = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor); + linkvisited.setAlphaF(qreal(.6)); + + p.setColor(QPalette::Text, text); + p.setColor(QPalette::Link, link); + p.setColor(QPalette::LinkVisited, linkvisited); + + setPalette(p); + + // FIXME: Re-activate or delete + /*if (m_image) { + m_image->fg = text; + m_image->bg = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor); + }*/ + + qreal fontsize = KGlobalSettings::smallestReadableFont().pointSize(); + m_stylesheet = QString("\ + body { \ + color: %1; \ + font-size: %4pt; \ + width: 100%, \ + margin-left: 0px; \ + margin-top: 0px; \ + margin-right: 0px; \ + margin-bottom: 0px; \ + padding: 0px; \ + } \ +\ + a:visited { color: %1; }\ + a:link { color: %2; opacity: .8; }\ + a:visited { color: %3; opacity: .6; }\ + a:hover { text-decoration: none; opacity: .4; } \ +\ + ").arg(text.name()).arg(link.name()).arg(linkvisited.name()).arg(fontsize); + + if (m_nameLabel) { + m_nameLabel->setPalette(p); + m_nameLabel->setStyleSheet(m_stylesheet); + } +} + + +void ContactWidget::setName(const QString &name) +{ + m_nameLabel->setText(name); +} + +QString ContactWidget::name() const +{ + return m_ocsData["Name"].toString(); +} + +QString ContactWidget::user() const +{ + return m_ocsData["Id"].toString(); +} + +void ContactWidget::setInfo(const QString &text) +{ + if (text.isEmpty()) { + m_infoLabel->setEnabled(false); + m_infoLabel->setText(i18n("Unknown location")); + } else { + m_infoLabel->setEnabled(true); + m_infoLabel->setText(text); + } +} + +void ContactWidget::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED( event ); + m_isHovered = true; + updateActions(); +} + +void ContactWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED( event ); + m_isHovered = false; + updateActions(); +} + + +void ContactWidget::mousePressEvent(QGraphicsSceneMouseEvent* event) +{ + return; + Q_UNUSED(event); +} + +void ContactWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + Q_UNUSED(event); +} + +void ContactWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) +{ + Q_UNUSED(event); + emit showDetails(); +} + + +#include "contactwidget.moc" diff --git a/kdeplasma-addons/applets/community/contactwidget.h b/kdeplasma-addons/applets/community/contactwidget.h new file mode 100644 index 00000000..4cde7c7b --- /dev/null +++ b/kdeplasma-addons/applets/community/contactwidget.h @@ -0,0 +1,104 @@ +/*************************************************************************** + * Copyright 2008-2009 by Sebastian Kügler * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef CONTACTWIDGET_H +#define CONTACTWIDGET_H + +//Qt +#include +#include +#include + +#include +#include +#include + +namespace Plasma +{ + class IconWidget; + class Dialog; + class Label; +} + +class ContactImage; + +class ContactWidget : public Plasma::Frame +{ + Q_OBJECT + + public: + explicit ContactWidget(Plasma::DataEngine* engine, QGraphicsWidget *parent = 0); + virtual ~ContactWidget(); + + QString id() const; + QString name() const; + QString provider() const; + QString user() const; + + void setName(const QString &name); + void setInfo(const QString &name); + void setIsFriend(bool isFriend); + void setId(const QString& id); + void setProvider(const QString& provider); + + Plasma::PopupApplet* m_applet; + + Q_SIGNALS: + void addFriend(); + void sendMessage(); + void showDetails(); + + public Q_SLOTS: + void updateColors(); + + protected: + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + void mousePressEvent(QGraphicsSceneMouseEvent* event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + + protected Q_SLOTS: + void slotShowDetails(); + void dataUpdated(const QString& source, const Plasma::DataEngine::Data& data); + + private : + void buildDialog(); + void updateActions(); + + Plasma::DataEngine::Data m_ocsData; + QString m_stylesheet; + bool m_isHovered; + bool m_isFriend; + // The applet attached to this item + QGraphicsGridLayout* m_layout; + QGraphicsLinearLayout* m_actions; + ContactImage* m_image; + Plasma::Label* m_nameLabel; + Plasma::Label* m_infoLabel; + Plasma::IconWidget* m_sendMessage; + Plasma::IconWidget* m_addFriend; + Plasma::IconWidget* m_showDetails; + Plasma::DataEngine* m_engine; + QString m_id; + QString m_provider; +}; + +#endif + diff --git a/kdeplasma-addons/applets/community/friendlist.cpp b/kdeplasma-addons/applets/community/friendlist.cpp new file mode 100644 index 00000000..3d65fdda --- /dev/null +++ b/kdeplasma-addons/applets/community/friendlist.cpp @@ -0,0 +1,74 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "friendlist.h" + +#include + +#include "contactcontainer.h" +#include "friendmanagementcontainer.h" +#include "utils.h" + + +FriendList::FriendList(Plasma::DataEngine* engine, QGraphicsWidget* parent) +: QGraphicsWidget(parent) +{ + m_invitations = new FriendManagementContainer(engine); + + setContentsMargins(0,0,0,0); + QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical); + layout->addItem(m_invitations); + layout->setContentsMargins(0,0,0,0); + + Plasma::ScrollWidget* friendScroll = new Plasma::ScrollWidget(this); + m_friendListWidget = new ContactContainer(engine, friendScroll); + friendScroll->setWidget(m_friendListWidget); + + layout->addItem(friendScroll); + + setLayout(layout); + + connect(m_friendListWidget, SIGNAL(addFriend(QString)), SIGNAL(addFriend(QString))); + connect(m_friendListWidget, SIGNAL(sendMessage(QString)), SIGNAL(sendMessage(QString))); + connect(m_friendListWidget, SIGNAL(showDetails(QString)), SIGNAL(showDetails(QString))); +} + + +void FriendList::setProvider(const QString& provider) +{ + kDebug() << "provider" << provider; + m_provider = provider; + m_invitations->setProvider(provider); + m_friendListWidget->setProvider(provider); + m_friendListWidget->setSource(friendsQuery(m_provider, m_ownId)); +} + + +void FriendList::setOwnId(const QString& id) +{ + kDebug() << id; + m_ownId = id; + m_friendListWidget->setOwnId(id); + m_friendListWidget->setSource(friendsQuery(m_provider, m_ownId)); +} + + +#include "friendlist.moc" diff --git a/kdeplasma-addons/applets/community/friendlist.h b/kdeplasma-addons/applets/community/friendlist.h new file mode 100644 index 00000000..ad0c360f --- /dev/null +++ b/kdeplasma-addons/applets/community/friendlist.h @@ -0,0 +1,62 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef FRIENDLIST_H +#define FRIENDLIST_H + +#include +#include + +#include + + +class ContactContainer; +class FriendManagementContainer; + +namespace Plasma { + class DataEngine; +} + +class FriendList : public QGraphicsWidget +{ + Q_OBJECT + + public: + explicit FriendList(Plasma::DataEngine* engine, QGraphicsWidget* parent = 0); + + public Q_SLOTS: + void setOwnId(const QString& id); + void setProvider(const QString& provider); + + Q_SIGNALS: + void addFriend(const QString& id); + void sendMessage(const QString& id); + void showDetails(const QString& id); + + private: + FriendManagementContainer* m_invitations; + QString m_ownId; + QString m_provider; + ContactContainer* m_friendListWidget; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/friendmanagementcontainer.cpp b/kdeplasma-addons/applets/community/friendmanagementcontainer.cpp new file mode 100644 index 00000000..2a4be0c8 --- /dev/null +++ b/kdeplasma-addons/applets/community/friendmanagementcontainer.cpp @@ -0,0 +1,72 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "friendmanagementcontainer.h" + +#include + +#include "friendmanagementwidget.h" +#include "utils.h" + + +using namespace Plasma; + + +FriendManagementContainer::FriendManagementContainer(DataEngine* engine, QGraphicsWidget* parent) + : QGraphicsWidget(parent), m_engine(engine), m_layout(new QGraphicsLinearLayout(Qt::Vertical)), m_personWatcher(engine) +{ + setLayout(m_layout); + connect(&m_personWatcher, SIGNAL(personAdded(QString)), SLOT(personAdded(QString))); + connect(&m_personWatcher, SIGNAL(personRemoved(QString)), SLOT(personRemoved(QString))); +} + + +void FriendManagementContainer::personAdded(const QString& person) +{ + FriendManagementWidget* widget = new FriendManagementWidget(m_engine); + widget->setProvider(m_provider); + widget->setId(person); + m_layout->addItem(widget); + m_idToWidget.insert(person, widget); +} + + +void FriendManagementContainer::personRemoved(const QString& person) +{ + FriendManagementWidget* widget = m_idToWidget.take(person); + if (widget) { + m_layout->removeItem(widget); + widget->deleteLater(); + } +} + + +void FriendManagementContainer::setProvider(const QString& provider) +{ + m_provider = provider; + m_personWatcher.setSource(receivedInvitationsQuery(m_provider)); + foreach (FriendManagementWidget* widget, m_idToWidget) { + widget->setProvider(m_provider); + } +} + + +#include "friendmanagementcontainer.moc" diff --git a/kdeplasma-addons/applets/community/friendmanagementcontainer.h b/kdeplasma-addons/applets/community/friendmanagementcontainer.h new file mode 100644 index 00000000..efaccd83 --- /dev/null +++ b/kdeplasma-addons/applets/community/friendmanagementcontainer.h @@ -0,0 +1,59 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef FRIENDMANAGEMENTCONTAINER_H +#define FRIENDMANAGEMENTCONTAINER_H + +#include + +#include + +#include "personwatchlist.h" + + +class FriendManagementWidget; +class QGraphicsLinearLayout; + +class FriendManagementContainer : public QGraphicsWidget +{ + Q_OBJECT + +public: + explicit FriendManagementContainer(Plasma::DataEngine* engine, QGraphicsWidget* parent = 0); + +public Q_SLOTS: + void setProvider(const QString& provider); + +private Q_SLOTS: + void personAdded(const QString& person); + void personRemoved(const QString& person); + +private: + Plasma::DataEngine* m_engine; + QHash m_idToWidget; + QGraphicsLinearLayout* m_layout; + PersonWatchList m_personWatcher; + QString m_provider; + QHash m_widgetToId; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/friendmanagementwidget.cpp b/kdeplasma-addons/applets/community/friendmanagementwidget.cpp new file mode 100644 index 00000000..98266ca9 --- /dev/null +++ b/kdeplasma-addons/applets/community/friendmanagementwidget.cpp @@ -0,0 +1,180 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "friendmanagementwidget.h" + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include "contactimage.h" +#include "utils.h" + + +using namespace Plasma; + +FriendManagementWidget::FriendManagementWidget(DataEngine* engine, QGraphicsWidget* parent) + : Frame(parent), m_isHovered(false), m_personWatch(engine), m_engine(engine) +{ + setAcceptHoverEvents(true); + buildDialog(); + updateActions(); + setMinimumHeight(40); + setMinimumWidth(120); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); + connect(&m_personWatch, SIGNAL(updated()), SLOT(updated())); +} + + +void FriendManagementWidget::buildDialog() +{ + int avatarSize = KIconLoader::SizeMedium; + int actionsSize = KIconLoader::SizeSmallMedium; + + m_infoLabel = new Plasma::Label; + m_infoLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + m_infoLabel->setMinimumWidth(avatarSize * 2); + + m_statusLabel = new Plasma::Label; + m_statusLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + m_statusLabel->setMinimumWidth(avatarSize * 2); + m_statusLabel->setText(i18n("Accepting friendship...")); + + m_avatar = new ContactImage(0); + m_avatar->setMinimumHeight(avatarSize); + m_avatar->setMinimumWidth(avatarSize); + m_avatar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + m_actionAccept = new IconWidget; + m_actionAccept->setIcon("dialog-ok"); + m_actionAccept->setToolTip(i18n("Accept friendship")); + m_actionAccept->setMinimumHeight(actionsSize); + m_actionAccept->setMaximumHeight(actionsSize); + m_actionAccept->setMinimumWidth(actionsSize); + m_actionAccept->setMaximumWidth(actionsSize); + + m_actionDecline = new IconWidget; + m_actionDecline->setIcon("dialog-cancel"); + m_actionDecline->setToolTip(i18n("Decline friendship")); + m_actionDecline->setMinimumHeight(actionsSize); + m_actionDecline->setMaximumHeight(actionsSize); + m_actionDecline->setMinimumWidth(actionsSize); + m_actionDecline->setMaximumWidth(actionsSize); + + m_actions = new QGraphicsLinearLayout; + m_actions->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + m_actions->addItem(m_actionAccept); + m_actions->addItem(m_actionDecline); + + layout = new QGraphicsGridLayout; + layout->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + layout->setColumnFixedWidth(0, int(avatarSize * 1.2)); + layout->setHorizontalSpacing(4); + layout->addItem(m_avatar, 0, 0, 2, 1, Qt::AlignTop); + layout->addItem(m_infoLabel, 0, 1, 1, 1, Qt::AlignCenter | Qt::AlignHCenter); + layout->addItem(m_actions, 1, 1, 1, 1, Qt::AlignBottom | Qt::AlignRight); + + setLayout(layout); + + connect(m_actionAccept, SIGNAL(clicked()), SLOT(accept())); + connect(m_actionDecline, SIGNAL(clicked()), SLOT(accept())); +} + + +void FriendManagementWidget::accept() +{ + Service* service = m_engine->serviceForSource(personQuery(m_provider, m_id)); + KConfigGroup cg = service->operationDescription("approveFriendship"); + KJob *job = service->startOperationCall(cg); + connect(job, SIGNAL(finished(KJob*)), service, SLOT(deleteLater())); + delete service; +} + + +void FriendManagementWidget::decline() +{ + Service* service = m_engine->serviceForSource(personQuery(m_provider, m_id)); + KConfigGroup cg = service->operationDescription("declineFriendship"); + KJob *job = service->startOperationCall(cg); + connect(job, SIGNAL(finished(KJob*)), service, SLOT(deleteLater())); + delete service; +} + + +void FriendManagementWidget::hoverEnterEvent(QGraphicsSceneHoverEvent* event) +{ + Q_UNUSED(event) + m_isHovered = true; + updateActions(); +} + + +void FriendManagementWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent* event) +{ + Q_UNUSED(event) + m_isHovered = false; + updateActions(); +} + + +void FriendManagementWidget::setId(const QString& id) +{ + m_id = id; + m_personWatch.setId(m_id); +} + + +void FriendManagementWidget::setProvider(const QString& provider) +{ + m_provider = provider; + m_personWatch.setProvider(provider); +} + + +void FriendManagementWidget::updateActions() +{ + m_actionAccept->setVisible(m_isHovered); + m_actionDecline->setVisible(m_isHovered); +} + + +void FriendManagementWidget::updated() +{ + QString firstName = m_personWatch.data().value("FirstName").toString(); + QString lastName = m_personWatch.data().value("LastName").toString(); + if (!firstName.isEmpty() || !lastName.isEmpty()) { + m_infoLabel->setText(i18n("%1 %2 (%3) wants to be your friend", firstName, lastName, m_id)); + } else { + m_infoLabel->setText(i18n("%1 wants to be your friend", m_id)); + } + m_avatar->setUrl(m_personWatch.data().value("AvatarUrl").toUrl()); +} + + +#include "friendmanagementwidget.moc" diff --git a/kdeplasma-addons/applets/community/friendmanagementwidget.h b/kdeplasma-addons/applets/community/friendmanagementwidget.h new file mode 100644 index 00000000..96809eb8 --- /dev/null +++ b/kdeplasma-addons/applets/community/friendmanagementwidget.h @@ -0,0 +1,80 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef FRIENDMANAGEMENTWIDGET_H +#define FRIENDMANAGEMENTWIDGET_H + +#include + +#include "personwatch.h" + + +class ContactImage; +class QGraphicsGridLayout; +class QGraphicsLinearLayout; + +namespace Plasma { + class IconWidget; + class Label; +} + +class FriendManagementWidget : public Plasma::Frame +{ + Q_OBJECT + +public: + explicit FriendManagementWidget(Plasma::DataEngine* engine, QGraphicsWidget* parent = 0); + +public Q_SLOTS: + void setId(const QString& id); + void setProvider(const QString& provider); + +Q_SIGNALS: + void showDetails(); + +protected Q_SLOTS: + void accept(); + void decline(); + void updated(); + void hoverEnterEvent(QGraphicsSceneHoverEvent* event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent* event); + +private: + void buildDialog(); + void updateActions(); + + bool m_isHovered; + + QGraphicsGridLayout* layout; + QGraphicsLinearLayout* m_actions; + ContactImage* m_avatar; + Plasma::Label* m_infoLabel; + Plasma::Label* m_statusLabel; + Plasma::IconWidget* m_actionAccept; + Plasma::IconWidget* m_actionDecline; + QString m_id; + QString m_provider; + PersonWatch m_personWatch; + Plasma::DataEngine* m_engine; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/loginwidget.cpp b/kdeplasma-addons/applets/community/loginwidget.cpp new file mode 100644 index 00000000..62813f9b --- /dev/null +++ b/kdeplasma-addons/applets/community/loginwidget.cpp @@ -0,0 +1,139 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Frederik Gladhorn + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "loginwidget.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "contactimage.h" +#include "utils.h" + + +using namespace Plasma; + +LoginWidget::LoginWidget(DataEngine* engine, QGraphicsWidget* parent) + : QGraphicsWidget(parent), + m_engine(engine) +{ + //int avatarSize = KIconLoader::SizeMedium; + //int actionSize = KIconLoader::SizeSmallMedium; + + m_serverLabel = new Label; + m_serverLabel->setText(i18n("Login to \"openDesktop.org\"")); + + m_userLabel = new Label; + m_passwordLabel = new Label; + m_userLabel->setText(i18n("Username:")); + m_passwordLabel->setText(i18n("Password:")); + + m_userEdit = new LineEdit; + m_passwordEdit = new LineEdit; + m_passwordEdit->nativeWidget()->setPasswordMode(true); + + QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical, this); + layout->addItem(m_serverLabel); + layout->addItem(m_userLabel); + layout->addItem(m_userEdit); + layout->addItem(m_passwordLabel); + layout->addItem(m_passwordEdit); + + + int buttonsize = KIconLoader::SizeMedium + 4; + Plasma::IconWidget* loginButton = new Plasma::IconWidget; + loginButton->setIcon("dialog-ok"); + loginButton->setText(i18n("Login")); + loginButton->setOrientation(Qt::Horizontal); + loginButton->setMaximumHeight(buttonsize); + loginButton->setDrawBackground(true); + loginButton->setTextBackgroundColor(QColor(Qt::transparent)); + loginButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + layout->addItem(loginButton); + + Plasma::IconWidget* registerButton = new Plasma::IconWidget; + registerButton->setIcon("list-add-user"); + registerButton->setText(i18n("Register new account...")); + registerButton->setOrientation(Qt::Horizontal); + registerButton->setMaximumHeight(buttonsize); + registerButton->setDrawBackground(true); + registerButton->setTextBackgroundColor(QColor(Qt::transparent)); + registerButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + layout->addItem(registerButton); + + connect(loginButton, SIGNAL(clicked()), SLOT(login())); + connect(registerButton, SIGNAL(clicked()), SLOT(registerNewAccount())); +} + +void LoginWidget::setProvider(const QString& provider) +{ + m_provider = provider; +} + +void LoginWidget::login() +{ + if (!m_userEdit->text().isEmpty()) { + kDebug() << "set credentials: " << m_provider << m_userEdit->text() << m_passwordEdit->text(); + Service* service = m_engine->serviceForSource(settingsQuery(m_provider, "setCredentials")); + KConfigGroup cg = service->operationDescription("setCredentials"); + cg.writeEntry("username", m_userEdit->text()); + cg.writeEntry("password", m_passwordEdit->text()); + ServiceJob* job = service->startOperationCall(cg); + connect(job, SIGNAL(finished(KJob*)), this, SLOT(loginJobFinished(KJob*))); + connect(job, SIGNAL(finished(KJob*)), service, SLOT(deleteLater())); + delete service; + } +} + +void LoginWidget::loginJobFinished(KJob* job) +{ + kDebug() << "Login Job finished: " << job->error(); + if (!job->error()) { + emit loginFinished(); + } +} + +void LoginWidget::registerNewAccount() +{ + KToolInvocation::invokeBrowser("https://www.opendesktop.org/usermanager/new.php"); + + /* TODO: use the kcm instead + KCMultiDialog KCM; + KCM.setWindowTitle( i18n( "Open Collaboration Providers" ) ); + KCM.addModule( "kcm_attica" ); + + KCM.exec(); + */ +} + + +#include "loginwidget.moc" diff --git a/kdeplasma-addons/applets/community/loginwidget.h b/kdeplasma-addons/applets/community/loginwidget.h new file mode 100644 index 00000000..bbbe7729 --- /dev/null +++ b/kdeplasma-addons/applets/community/loginwidget.h @@ -0,0 +1,72 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Frederik Gladhorn + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef LOGINWIDGET_H +#define LOGINWIDGET_H + +#include + + +#include +#include +#include +#include +#include +#include + +#include "personwatch.h" + + +class KJob; + +class LoginWidget : public QGraphicsWidget +{ + Q_OBJECT + + public: + LoginWidget(Plasma::DataEngine* engine, QGraphicsWidget* parent = 0); + + public Q_SLOTS: + void setProvider(const QString& provider); + + Q_SIGNALS: + void loginFinished(); + + private Q_SLOTS: + void login(); + void registerNewAccount(); + void loginJobFinished(KJob* job); + + private: + + Plasma::Label* m_serverLabel; + Plasma::Label* m_userLabel; + Plasma::Label* m_passwordLabel; + Plasma::LineEdit* m_userEdit; + Plasma::LineEdit* m_passwordEdit; + + Plasma::DataEngine* m_engine; + QString m_id; + QString m_provider; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/messagecounter.cpp b/kdeplasma-addons/applets/community/messagecounter.cpp new file mode 100644 index 00000000..182ac34c --- /dev/null +++ b/kdeplasma-addons/applets/community/messagecounter.cpp @@ -0,0 +1,57 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include + +#include "messagecounter.h" +#include "utils.h" + + +MessageCounter::MessageCounter(Plasma::DataEngine* engine, QObject* parent) + : QObject(parent), m_count(0), m_watcher(engine) +{ + m_watcher.setUpdateInterval(10 * 60 * 1000); + connect(&m_watcher, SIGNAL(keysAdded(QSet)), SLOT(keysAdded(QSet))); + connect(&m_watcher, SIGNAL(keysRemoved(QSet)), SLOT(keysRemoved(QSet))); +} + + +void MessageCounter::keysAdded(const QSet& keys) +{ + m_count += keys.size(); + emit messageCountChanged(m_count); +} + + +void MessageCounter::keysRemoved(const QSet& keys) +{ + m_count -= keys.size(); + emit messageCountChanged(m_count); +} + + +void MessageCounter::setProvider(const QString& provider) +{ + m_watcher.setQuery(messageListUnreadQuery(provider, "0")); +} + + +#include "messagecounter.moc" diff --git a/kdeplasma-addons/applets/community/messagecounter.h b/kdeplasma-addons/applets/community/messagecounter.h new file mode 100644 index 00000000..7173ead6 --- /dev/null +++ b/kdeplasma-addons/applets/community/messagecounter.h @@ -0,0 +1,58 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef MESSAGECOUNTER_H +#define MESSAGECOUNTER_H + +#include + +#include "sourcewatchlist.h" + + +namespace Plasma { + class DataEngine; +} + +class MessageCounter : public QObject +{ + Q_OBJECT + +public: + explicit MessageCounter(Plasma::DataEngine* engine, QObject* parent = 0); + +public Q_SLOTS: + void setProvider(const QString& provider); + +Q_SIGNALS: + void messageCountChanged(int count); + +private Q_SLOTS: + void keysAdded(const QSet& keys); + void keysRemoved(const QSet& keys); + +private: + int m_count; + QString m_query; + SourceWatchList m_watcher; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/messagelist.cpp b/kdeplasma-addons/applets/community/messagelist.cpp new file mode 100644 index 00000000..e1b81a7c --- /dev/null +++ b/kdeplasma-addons/applets/community/messagelist.cpp @@ -0,0 +1,82 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "messagelist.h" + +#include "messagewidget.h" +#include "utils.h" + + +MessageList::MessageList(Plasma::DataEngine* engine, QGraphicsWidget* parent) + : ScrollWidget(parent), + m_engine(engine), + m_messageWatcher(engine) +{ + m_container = new QGraphicsWidget(this); + m_layout = new QGraphicsLinearLayout(Qt::Vertical, m_container); + setWidget(m_container); + connect(&m_messageWatcher, SIGNAL(messageAdded(QString)), SLOT(messageAdded(QString))); + connect(&m_messageWatcher, SIGNAL(messageRemoved(QString)), SLOT(messageRemoved(QString))); +} + + +void MessageList::setFolder(const QString& folder) +{ + m_folder = folder; + m_messageWatcher.setSource(messageListQuery(m_provider, m_folder)); + foreach (MessageWidget* widget, m_idToWidget) { + widget->setFolder(m_folder); + } +} + + +void MessageList::setProvider(const QString& provider) +{ + m_provider = provider; + m_messageWatcher.setSource(messageListQuery(m_provider, m_folder)); + foreach (MessageWidget* widget, m_idToWidget) { + widget->setProvider(m_provider); + } +} + + +void MessageList::messageAdded(const QString& id) +{ + MessageWidget* widget = new MessageWidget(m_engine); + widget->setProvider(m_provider); + widget->setFolder(m_folder); + widget->setMessage(id); + m_layout->addItem(widget); + m_idToWidget.insert(id, widget); +} + + +void MessageList::messageRemoved(const QString& id) +{ + MessageWidget* widget = m_idToWidget.take(id); + if (widget) { + m_layout->removeItem(widget); + widget->deleteLater(); + } +} + + +#include "messagelist.moc" diff --git a/kdeplasma-addons/applets/community/messagelist.h b/kdeplasma-addons/applets/community/messagelist.h new file mode 100644 index 00000000..5d0ecf7c --- /dev/null +++ b/kdeplasma-addons/applets/community/messagelist.h @@ -0,0 +1,62 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef MESSAGELIST_H +#define MESSAGELIST_H + +#include +#include + +#include +#include + +#include "messagewatchlist.h" + + +class MessageWidget; + +class MessageList : public Plasma::ScrollWidget +{ + Q_OBJECT + + public: + explicit MessageList(Plasma::DataEngine* engine, QGraphicsWidget* parent = 0); + + public Q_SLOTS: + void setFolder(const QString& folder); + void setProvider(const QString& provider); + + private Q_SLOTS: + void messageAdded(const QString& id); + void messageRemoved(const QString& id); + + private: + QGraphicsWidget* m_container; + Plasma::DataEngine* m_engine; + QHash m_idToWidget; + QGraphicsLinearLayout* m_layout; + QString m_provider; + QString m_folder; + MessageWatchList m_messageWatcher; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/messagewatchlist.cpp b/kdeplasma-addons/applets/community/messagewatchlist.cpp new file mode 100644 index 00000000..38559e6b --- /dev/null +++ b/kdeplasma-addons/applets/community/messagewatchlist.cpp @@ -0,0 +1,67 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + + +#include "messagewatchlist.h" + +#include "utils.h" + + +MessageWatchList::MessageWatchList(Plasma::DataEngine* engine, QObject* parent) + : QObject(parent), + m_list(engine) +{ + connect(&m_list, SIGNAL(keysAdded(QSet)), SLOT(slotKeysAdded(QSet))); + connect(&m_list, SIGNAL(keysRemoved(QSet)), SLOT(slotKeysRemoved(QSet))); +} + + +bool MessageWatchList::contains(const QString& id) const { + return m_list.contains(messageAddPrefix(id)); +} + + +void MessageWatchList::setSource(const QString& source) { + m_list.setQuery(source); +} + + +void MessageWatchList::slotKeysAdded(const QSet& keys) { + foreach(const QString& key, keys) { + QString message = messageRemovePrefix(key); + if (!message.isEmpty()) { + emit messageAdded(message); + } + } +} + + +void MessageWatchList::slotKeysRemoved(const QSet& keys) { + foreach(const QString& key, keys) { + QString message = messageRemovePrefix(key); + if (!message.isEmpty()) { + emit messageRemoved(message); + } + } +} + + +#include "messagewatchlist.moc" diff --git a/kdeplasma-addons/applets/community/messagewatchlist.h b/kdeplasma-addons/applets/community/messagewatchlist.h new file mode 100644 index 00000000..3ca58511 --- /dev/null +++ b/kdeplasma-addons/applets/community/messagewatchlist.h @@ -0,0 +1,55 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef MESSAGEWATCHLIST_H +#define MESSAGEWATCHLIST_H + +#include +#include +#include + +#include "sourcewatchlist.h" + + +class MessageWatchList : public QObject +{ + Q_OBJECT + +public: + explicit MessageWatchList(Plasma::DataEngine* engine, QObject* parent = 0); + bool contains(const QString& id) const; + void setSource(const QString& source); + +Q_SIGNALS: + void messageAdded(const QString& id); + void messageRemoved(const QString& id); + +private Q_SLOTS: + void slotKeysAdded(const QSet& keys); + void slotKeysRemoved(const QSet& keys); + +private: + SourceWatchList m_list; + QString m_source; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/messagewidget.cpp b/kdeplasma-addons/applets/community/messagewidget.cpp new file mode 100644 index 00000000..6ff7a47b --- /dev/null +++ b/kdeplasma-addons/applets/community/messagewidget.cpp @@ -0,0 +1,163 @@ +/*************************************************************************** + * Copyright (c) 2009 by Eckhart Wörner * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "messagewidget.h" + +#include +#include + +#include + +#include +#include + +#include "contactimage.h" +#include "utils.h" + + +using namespace Plasma; + +MessageWidget::MessageWidget(DataEngine* engine, QGraphicsWidget* parent) + : Frame(parent), + m_engine(engine), + m_personWatch(engine) +{ + buildDialog(); + setMinimumHeight(40); + setMinimumWidth(120); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); + connect(&m_personWatch, SIGNAL(updated()), SLOT(fromChanged())); +} + + +void MessageWidget::fromChanged() +{ + QString id = m_personWatch.data().value("Id").toString(); + QString firstName = m_personWatch.data().value("FirstName").toString(); + QString lastName = m_personWatch.data().value("LastName").toString(); + QString avatarUrl = m_personWatch.data().value("AvatarUrl").toString(); + if (!firstName.isEmpty() || !lastName.isEmpty()) { + m_fromLabel->setText(i18n("From %1 %2 (%3)", firstName, lastName, id)); + } else { + m_fromLabel->setText(i18n("From %1", id)); + } + m_image->setUrl(avatarUrl); +} + + +void MessageWidget::setFolder(const QString& folderId) +{ + setSourceParameter(m_folderId, folderId); +} + + +void MessageWidget::setMessage(const QString& messageId) +{ + setSourceParameter(m_messageId, messageId); +} + + +void MessageWidget::setProvider(const QString& provider) +{ + setSourceParameter(m_provider, provider); + m_personWatch.setProvider(m_provider); +} + + +void MessageWidget::setSourceParameter(QString& variable, const QString& value) +{ + if (!m_source.isEmpty()) { + m_engine->disconnectSource(m_source, this); + } + variable = value; + m_source = messageSummaryQuery(m_provider, m_folderId, m_messageId); + if (!m_source.isEmpty()) { + m_engine->connectSource(m_source, this); + } +} + + +void MessageWidget::dataUpdated(const QString& source, const DataEngine::Data& data) +{ + if (source != m_source) { + return; + } + + DataEngine::Data m_ocsData = data.value(messageAddPrefix(m_messageId)).value(); + m_subjectLabel->setText(QString("%1").arg(m_ocsData.value("Subject").toString())); + m_personWatch.setId(m_ocsData.value("From-Id").toString()); + m_bodyLabel->setText(m_ocsData.value("Body").toString()); + + m_image->setUrl(m_ocsData.value("AvatarUrl").toUrl()); + m_setRead->setVisible(m_ocsData.value("Status").toString() == "unread"); +} + + +void MessageWidget::buildDialog() +{ + int avatarSize = KIconLoader::SizeMedium; + int actionSize = KIconLoader::SizeSmallMedium; + + + m_image = new ContactImage(m_engine); + m_image->setMinimumHeight(avatarSize); + m_image->setMinimumWidth(avatarSize); + m_image->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + m_subjectLabel = new Label; + m_subjectLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + m_subjectLabel->setMinimumWidth(avatarSize * 2); + + m_fromLabel = new Label; + m_fromLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + + m_bodyLabel = new Label; + m_bodyLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + + m_setRead = new Plasma::IconWidget; + m_setRead->setIcon("mail-unread-new"); + m_setRead->setToolTip(i18n("Mail is unread, mark as read")); + m_setRead->setMinimumHeight(actionSize); + m_setRead->setMaximumHeight(actionSize); + m_setRead->setMinimumWidth(actionSize); + m_setRead->setMaximumWidth(actionSize); + m_setRead->setVisible(false); + + m_layout = new QGraphicsGridLayout; + m_layout->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_layout->setColumnFixedWidth(0, int(avatarSize * 1.2)); + m_layout->setHorizontalSpacing(4); + m_layout->addItem(m_image, 0, 0, 3, 1, Qt::AlignTop); + m_layout->addItem(m_setRead, 0, 1, 1, 1, Qt::AlignTop); + m_layout->addItem(m_subjectLabel, 0, 2, 1, 2, Qt::AlignTop); + m_layout->addItem(m_fromLabel, 1, 2, 1, 1, Qt::AlignTop); + m_layout->addItem(m_bodyLabel, 2, 2, 1, 2, Qt::AlignTop); + + setLayout(m_layout); + + connect(m_setRead, SIGNAL(clicked()), SLOT(markMessageRead())); +} + +void MessageWidget::markMessageRead() +{ + m_engine->query(messageQuery(m_provider, m_folderId, m_messageId)); +} + + +#include "messagewidget.moc" diff --git a/kdeplasma-addons/applets/community/messagewidget.h b/kdeplasma-addons/applets/community/messagewidget.h new file mode 100644 index 00000000..abf5b40d --- /dev/null +++ b/kdeplasma-addons/applets/community/messagewidget.h @@ -0,0 +1,72 @@ +/*************************************************************************** + * Copyright (c) 2009 by Eckhart Wörner * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef MESSAGEWIDGET_H +#define MESSAGEWIDGET_H + +#include +#include + +#include "personwatch.h" + + +class ContactImage; +class QGraphicsGridLayout; + +namespace Plasma { + class IconWidget; + class Label; +} + +class MessageWidget : public Plasma::Frame +{ + Q_OBJECT + +public: + explicit MessageWidget(Plasma::DataEngine* engine, QGraphicsWidget* parent = 0); + + void setFolder(const QString& folderId); + void setMessage(const QString& messageId); + void setProvider(const QString& provider); + +private Q_SLOTS: + void dataUpdated(const QString& source, const Plasma::DataEngine::Data& data); + void fromChanged(); + void markMessageRead(); + +private: + void buildDialog(); + void setSourceParameter(QString& variable, const QString& value); + + Plasma::DataEngine* m_engine; + QString m_folderId; + QString m_messageId; + QString m_provider; + QGraphicsGridLayout* m_layout; + ContactImage* m_image; + Plasma::Label* m_subjectLabel; + Plasma::Label* m_bodyLabel; + Plasma::Label* m_fromLabel; + Plasma::IconWidget* m_setRead; + QString m_source; + PersonWatch m_personWatch; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/opendesktop.cpp b/kdeplasma-addons/applets/community/opendesktop.cpp new file mode 100644 index 00000000..be9773df --- /dev/null +++ b/kdeplasma-addons/applets/community/opendesktop.cpp @@ -0,0 +1,441 @@ +/*************************************************************************** + * Copyright 2009 by Sebastian Kügler * + * Copyright 2009 by Frederik Gladhorn * + * * + * 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 . * + ***************************************************************************/ + +//own +#include "opendesktop.h" + + +//KDE +#include +#include +#include +#include + +//plasma +#include +#include +#include +#include +#include +#include +#include +#include + +#include "actionstack.h" +#include "contactlist.h" +#include "friendlist.h" +#include "loginwidget.h" +#include "messagecounter.h" +#include "messagelist.h" +#include "utils.h" + + +K_EXPORT_PLASMA_APPLET(opendesktop, OpenDesktop) + +using namespace Plasma; + +OpenDesktop::OpenDesktop(QObject *parent, const QVariantList &args) + : Plasma::PopupApplet(parent, args), + m_tabs(0), + m_loginWidget(0), + m_friendList(0), + m_friendStack(0), + m_nearList(0), + m_provider("https://api.opendesktop.org/v1/"), + m_credentialsSource(QString("Credentials\\provider:%1").arg(m_provider)), + m_kcmDialog(0) +{ + KGlobal::locale()->insertCatalog("plasma_applet_opendesktop"); + setBackgroundHints(StandardBackground); + setAspectRatioMode(IgnoreAspectRatio); + setHasConfigurationInterface(true); + setPassivePopup(true); + + setPopupIcon("system-users"); +} + +OpenDesktop::~OpenDesktop() +{ +} + +void OpenDesktop::init() +{ + (void)graphicsWidget(); + + kDebug() << "init: opendesktop"; + + m_engine->connectSource("Providers", this); + + configChanged(); + + connectGeolocation(); +} + +void OpenDesktop::connectGeolocation() +{ + dataEngine("geolocation")->connectSource("location", this); +} + +QGraphicsWidget* OpenDesktop::graphicsWidget() +{ + if (!m_tabs) { + m_engine = dataEngine("ocs"); + + // People near me + m_nearList = new ContactList(m_engine); + m_nearStack = new ActionStack(m_engine, m_nearList); + + m_nearStack->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + m_tabs = new Plasma::TabBar; + + m_tabs->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + m_tabs->addTab(i18n("Nearby"), m_nearStack); + + connect(this, SIGNAL(providerChanged(QString)), m_nearList, SLOT(setProvider(QString))); + connect(this, SIGNAL(providerChanged(QString)), m_nearStack, SLOT(setProvider(QString))); + + connect(m_nearList, SIGNAL(addFriend(QString)), m_nearStack, SLOT(addFriend(QString))); + connect(m_nearList, SIGNAL(sendMessage(QString)), m_nearStack, SLOT(sendMessage(QString))); + connect(m_nearList, SIGNAL(showDetails(QString)), m_nearStack, SLOT(showDetails(QString))); + + connect(m_nearStack, SIGNAL(endWork()), SLOT(endWork())); + connect(m_nearStack, SIGNAL(startWork()), SLOT(startWork())); + + connect(this, SIGNAL(usernameChanged(QString)), m_nearList, SLOT(setOwnId(QString))); + connect(this, SIGNAL(usernameChanged(QString)), m_nearStack, SLOT(setOwnId(QString))); + + emit providerChanged(m_provider); + } + return m_tabs; +} + + +void OpenDesktop::showLoginWidget(bool show) +{ + if (!show) { + if (m_loginWidget) { + m_tabs->removeTab(1); + delete m_loginWidget; + m_loginWidget = 0; + } + return; + } + + if (!m_loginWidget) { + m_loginWidget = new LoginWidget(m_engine); + m_tabs->addTab(i18n("Login"), m_loginWidget); + connect(m_loginWidget, SIGNAL(loginFinished()), this, SLOT(loginFinished())); + connect(this, SIGNAL(providerChanged(QString)), m_loginWidget, SLOT(setProvider(QString))); + + m_loginWidget->setProvider(m_provider); + } +} + + +void OpenDesktop::loginFinished() +{ + showLoginWidget(false); + showFriendsWidget(); + emit providerChanged(m_provider); + emit usernameChanged(m_user); +} + + +void OpenDesktop::showFriendsWidget() +{ + if (m_friendStack) { + return; + } + + // Messages + m_messageCounter = new MessageCounter(m_engine, this); + + // Friends + m_friendList = new FriendList(m_engine); + m_friendStack = new ActionStack(m_engine, m_friendList); + + m_messageList = new MessageList(m_engine); + m_messageList->setFolder("0"); + + m_tabs->addTab(i18n("Friends"), m_friendStack); + m_tabs->addTab(i18n("Messages"), m_messageList); + + connect(m_friendList, SIGNAL(addFriend(QString)), m_friendStack, SLOT(addFriend(QString))); + connect(m_friendList, SIGNAL(sendMessage(QString)), m_friendStack, SLOT(sendMessage(QString))); + connect(m_friendList, SIGNAL(showDetails(QString)), m_friendStack, SLOT(showDetails(QString))); + + connect(m_friendStack, SIGNAL(endWork()), SLOT(endWork())); + connect(m_friendStack, SIGNAL(startWork()), SLOT(startWork())); + + connect(this, SIGNAL(usernameChanged(QString)), m_friendList, SLOT(setOwnId(QString))); + connect(this, SIGNAL(usernameChanged(QString)), m_friendStack, SLOT(setOwnId(QString))); + + connect(this, SIGNAL(providerChanged(QString)), m_friendList, SLOT(setProvider(QString))); + connect(this, SIGNAL(providerChanged(QString)), m_friendStack, SLOT(setProvider(QString))); + connect(this, SIGNAL(providerChanged(QString)), m_messageList, SLOT(setProvider(QString))); + connect(this, SIGNAL(providerChanged(QString)), m_messageCounter, SLOT(setProvider(QString))); + + m_friendList->setOwnId(m_user); + m_friendStack->setOwnId(m_user); + m_friendList->setProvider(m_provider); + m_friendStack->setProvider(m_provider); + + m_messageList->setProvider(m_provider); + m_messageCounter->setProvider(m_provider); +} + + +void OpenDesktop::connectNearby(qreal latitude, qreal longitude) +{ + QString src = QString("Near\\provider:%1\\latitude:%2\\longitude:%3\\distance:0") + .arg(m_provider) + .arg(latitude) + .arg(longitude); + + m_nearList->setQuery(src); +} + + +void OpenDesktop::endWork() +{ + // FIXME: Count + setBusy(false); +} + + +void OpenDesktop::startWork() +{ + // FIXME: Count + setBusy(true); +} + + +void OpenDesktop::dataUpdated(const QString &source, const Plasma::DataEngine::Data &data) +{ + kDebug() << "source updated:" << source << data; + + m_tabs->setPreferredSize(-1, -1); + emit sizeHintChanged(Qt::PreferredSize); + + if (source == "location") { + // The location from the geolocation engine arrived! + m_geolocation.city = data["city"].toString(); + m_geolocation.country = data["country"].toString(); + m_geolocation.countryCode = data["country code"].toString(); + m_geolocation.accuracy = data["accuracy"].toInt(); + m_geolocation.latitude = data["latitude"].toDouble(); + m_geolocation.longitude = data["longitude"].toDouble(); + kDebug() << "geolocation:" << m_geolocation.city << m_geolocation.country << + m_geolocation.countryCode << m_geolocation.latitude << m_geolocation.longitude; + connectNearby(m_geolocation.latitude, m_geolocation.longitude); + saveGeoLocation(); + } else if (source == m_credentialsSource) { + m_user = data["UserName"].toString(); + m_password = data["Password"].toString(); + ui.username->setText(m_user); + ui.password->setText(m_password); + } else if (source == "Providers") { + // The provider to use has been loaded... and it tells about a user name to use + if (data.contains(m_provider)) { + QHash hashData = data[m_provider].toHash(); + QString user = hashData.value("UserName").toString(); + kDebug() << "USER" << user; + + m_user = user; + if (user.isEmpty()) { + showLoginWidget(true); + } else { + showFriendsWidget(); + emit usernameChanged(user); + } + } + } +} + + +void OpenDesktop::createConfigurationInterface(KConfigDialog *parent) +{ + QWidget *generalSettingswidget = new QWidget(parent); + ui.setupUi(generalSettingswidget); + parent->addPage(generalSettingswidget, i18n("General"), Applet::icon()); + + m_engine->connectSource(m_credentialsSource, this); + + QVariant providers = m_engine->query("Providers"); + kDebug() << providers; + QVariantHash p = providers.toHash(); + + foreach(const QString& key, p.keys()) { + QString name = p.value(key).toHash().value("Name").toString(); + QString id = key; + ui.provider->addItem(name, id); + } + + // FIXME connect current changed to get different user name + + QWidget *locationWidget = new QWidget(parent); + locationUi.setupUi(locationWidget); + parent->addPage(locationWidget, i18n("Location"), "go-home"); + // TODO: connect finished() signal to null the ui + + connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted())); + connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted())); + connect(ui.registerButton, SIGNAL(clicked()), this, SLOT(registerAccount())); + connect(locationUi.publishLocation, SIGNAL(clicked()), this, SLOT(publishGeoLocation())); + + locationUi.city->setText(m_geolocation.city); + locationUi.latitude->setText(QString::number(m_geolocation.latitude)); + locationUi.longitude->setText(QString::number(m_geolocation.longitude)); + + locationUi.countryCombo->setInsertPolicy(QComboBox::InsertAlphabetically); + foreach ( const QString &cc, KGlobal::locale()->allCountriesList() ) { + locationUi.countryCombo->addItem(KGlobal::locale()->countryCodeToName(cc), cc); + } + locationUi.countryCombo->setCurrentIndex(locationUi.countryCombo->findText(KGlobal::locale()->countryCodeToName(m_geolocation.countryCode))); + + // actually, 0,0 is a valid location, but here we're using it to see if we + // actually have a location, a bit dirty but far less complex, especially given + // that this point is located in the middle of the ocean off the coast of Ghana + if (m_geolocation.latitude == 0 && m_geolocation.longitude == 0) { + locationUi.publishLocation->setEnabled(false); + + connect(ui.provider , SIGNAL(currentIndexChanged(int)), parent , SLOT(settingsModified())); + connect(ui.username , SIGNAL(textChanged(QString)), parent ,SLOT(settingsModified())); + connect(ui.password, SIGNAL(textChanged(QString)), parent, SLOT(settingsModified())); + connect(ui.registerButton, SIGNAL(clicked(bool)), parent, SLOT(settingsModified())); + connect(locationUi.city , SIGNAL(textChanged(QString)), parent , SLOT(settingsModified())); + connect(locationUi.countryCombo, SIGNAL(currentIndexChanged(int)), parent, SLOT(settingsModified())); + connect(locationUi.latitude, SIGNAL(textChanged(QString)), parent, SLOT(settingsModified())); + connect(locationUi.longitude, SIGNAL(textChanged(QString)), parent, SLOT(settingsModified())); + connect(locationUi.publishLocation, SIGNAL(clicked(bool)), parent, SLOT(settingsModified())); + } +} + +void OpenDesktop::configAccepted() +{ + QString provider = ui.provider->itemData(ui.provider->currentIndex()).toString(); + if(provider != m_provider) { + kDebug() << "Provider changed" << provider; + KConfigGroup cg = config(); + cg.writeEntry("provider", m_provider); + emit configNeedsSaving(); + } + if (!ui.username->text().isEmpty()) { + Service* service = m_engine->serviceForSource(settingsQuery(m_provider, "setCredentials")); + KConfigGroup cg = service->operationDescription("setCredentials"); + kDebug() << ui.username->text() << "in config group..."; + cg.writeEntry("username", ui.username->text()); + cg.writeEntry("password", ui.password->text()); + ServiceJob* job = service->startOperationCall(cg); + connect(job, SIGNAL(finished(KJob*)), service, SLOT(deleteLater())); + } + syncGeoLocation(); +} + +void OpenDesktop::configChanged() +{ + KConfigGroup cg = config(); + m_geolocation.city = cg.readEntry("geoCity", QString()); + m_geolocation.country = cg.readEntry("geoCountry", QString()); + m_geolocation.countryCode = cg.readEntry("geoCountryCode", QString()); + m_geolocation.latitude = cg.readEntry("geoLatitude", 0.0); + m_geolocation.longitude = cg.readEntry("geoLongitude", 0.0); + + QString provider = cg.readEntry("provider", QString("https://api.opendesktop.org/v1/")); + if (provider != m_provider) { + m_provider = provider; + m_credentialsSource = QString("Credentials\\provider:%1").arg(m_provider); + emit providerChanged(m_provider); + } +} + +void OpenDesktop::registerAccount() +{ + kDebug() << "register new account"; + if (m_kcmDialog) { + m_kcmDialog->show(); + return; + } + m_kcmDialog = new KCMultiDialog(); + connect(m_kcmDialog, SIGNAL(finished()), this, SLOT(kcm_finished())); + m_kcmDialog->addModule("kcm_attica"); + m_kcmDialog->setWindowTitle(i18nc("title of control center dialog to configure providers for community applet", "Provider Configuration - Community Plasma Applet")); + m_kcmDialog->show(); +} + +void OpenDesktop::kcm_finished() +{ + m_kcmDialog->deleteLater(); + m_kcmDialog = 0; +} + +void OpenDesktop::syncGeoLocation() +{ + // Location tab + m_geolocation.city = locationUi.city->text(); + m_geolocation.countryCode = locationUi.countryCombo->itemData(locationUi.countryCombo->currentIndex()).toString(); + m_geolocation.country = locationUi.countryCombo->currentText(); + m_geolocation.latitude = locationUi.latitude->text().toDouble(); + m_geolocation.longitude = locationUi.longitude->text().toDouble(); + + kDebug() << "New location:" << m_geolocation.city << m_geolocation.country << m_geolocation.countryCode << m_geolocation.latitude << m_geolocation.longitude; + + saveGeoLocation(); +} + +void OpenDesktop::publishGeoLocation() +{ + syncGeoLocation(); + // FIXME: Use service + QString source = QString("PostLocation-%1:%2:%3:%4").arg( + QString("%1").arg(m_geolocation.latitude), + QString("%1").arg(m_geolocation.longitude), + m_geolocation.countryCode, + m_geolocation.city); + kDebug() << "updating location:" << source; + m_engine->connectSource(source, this); +} + +void OpenDesktop::saveGeoLocation() +{ + KConfigGroup cg = config(); + cg.writeEntry("geoCity", m_geolocation.city); + cg.writeEntry("geoCountry", m_geolocation.country); + cg.writeEntry("geoCountryCode", m_geolocation.countryCode); + cg.writeEntry("geoLatitude", m_geolocation.latitude); + cg.writeEntry("geoLongitude", m_geolocation.longitude); + + emit configNeedsSaving(); +} + + +void OpenDesktop::unreadMessageCountChanged(int count) +{ + if (count) { + m_tabs->setTabText(2, i18n("Messages (%1)", count)); + } else { + m_tabs->setTabText(2, i18n("Messages")); + } +} + + +#include "opendesktop.moc" diff --git a/kdeplasma-addons/applets/community/opendesktop.h b/kdeplasma-addons/applets/community/opendesktop.h new file mode 100644 index 00000000..bf53f9e3 --- /dev/null +++ b/kdeplasma-addons/applets/community/opendesktop.h @@ -0,0 +1,134 @@ +/*************************************************************************** + * Copyright 2009 by Sebastian Kügler * + * Copyright 2009 by Frederik Gladhorn * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef OPENDESKTOP_H +#define OPENDESKTOP_H + +//Plasma +#include +#include + +#include "ui_opendesktopConfig.h" +#include "ui_opendesktopLocationConfig.h" + + +namespace Plasma +{ + class DataEngine; + class TabBar; +} +class KCMultiDialog; + +class ActionStack; +class ContactList; +class FriendList; +class LoginWidget; +class KConfigDialog; +class MessageCounter; +class MessageList; +class QGraphicsLinearLayout; + +struct GeoLocation { + QString country; + QString city; + QString countryCode; + int accuracy; + qreal latitude; + qreal longitude; +}; + +class OpenDesktop : public Plasma::PopupApplet +{ + Q_OBJECT + + public: + OpenDesktop(QObject *parent, const QVariantList &args); + ~OpenDesktop(); + void init(); + QGraphicsWidget* graphicsWidget(); + + Q_SIGNALS: + void providerChanged(const QString& provider); + void usernameChanged(const QString& user); + + public Q_SLOTS: + void dataUpdated(const QString &source, const Plasma::DataEngine::Data &data); + void endWork(); + void configAccepted(); + void configChanged(); + void startWork(); + + protected: + void createConfigurationInterface(KConfigDialog *parent); + + private Q_SLOTS: + void publishGeoLocation(); + void registerAccount(); + void unreadMessageCountChanged(int count); + + void showLoginWidget(bool show); + void showFriendsWidget(); + + void loginFinished(); + void kcm_finished(); + + private: + void connectGeolocation(); + void connectNearby(qreal latitude, qreal longitude); + + // Configuration dialog + Ui::opendesktopConfig ui; + Ui::opendesktopLocationConfig locationUi; + + Plasma::TabBar* m_tabs; + + QGraphicsLinearLayout* m_layout; + + // Login tab + LoginWidget* m_loginWidget; + + // Friends tab + FriendList* m_friendList; + ActionStack* m_friendStack; + + // Nearby people tab + ContactList* m_nearList; + ActionStack* m_nearStack; + + // Messages tab + MessageList* m_messageList; + + // Config values + QString m_provider; + GeoLocation m_geolocation; + void saveGeoLocation(); + void syncGeoLocation(); + MessageCounter* m_messageCounter; + + Plasma::DataEngine* m_engine; + QString m_user; + QString m_password; + QString m_credentialsSource; + + // show attica config + KCMultiDialog* m_kcmDialog; +}; + +#endif diff --git a/kdeplasma-addons/applets/community/opendesktopConfig.ui b/kdeplasma-addons/applets/community/opendesktopConfig.ui new file mode 100644 index 00000000..b7bcfb99 --- /dev/null +++ b/kdeplasma-addons/applets/community/opendesktopConfig.ui @@ -0,0 +1,189 @@ + + + Sebastian Kügler <sebas@kde.org> + opendesktopConfig + + + + 0 + 0 + 482 + 240 + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Account</span></p></body></html> + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 13 + 25 + + + + + + + + + 200 + 0 + + + + + + + + Qt::Horizontal + + + + 105 + 25 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 13 + + + + + + + + + + Register + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 68 + 28 + + + + + + + + QLineEdit::Password + + + + + + + Password: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + password + + + + + + + + + + Provider: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + provider + + + + + + + Username: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + username + + + + + + + + KLineEdit + QLineEdit +
klineedit.h
+
+ + KComboBox + QComboBox +
kcombobox.h
+
+
+ + provider + username + password + registerButton + + + +
diff --git a/kdeplasma-addons/applets/community/opendesktopLocationConfig.ui b/kdeplasma-addons/applets/community/opendesktopLocationConfig.ui new file mode 100644 index 00000000..68559f65 --- /dev/null +++ b/kdeplasma-addons/applets/community/opendesktopLocationConfig.ui @@ -0,0 +1,121 @@ + + + Sebastian Kügler <sebas@kde.org> + opendesktopLocationConfig + + + + 0 + 0 + 238 + 180 + + + + + QFormLayout::ExpandingFieldsGrow + + + + + City: + + + city + + + + + + + + 100 + 0 + + + + + + + + Country: + + + countryCombo + + + + + + + + 0 + 0 + + + + + + + + Latitude: + + + latitude + + + + + + + + 100 + 0 + + + + + + + + Longitude: + + + longitude + + + + + + + + 100 + 0 + + + + + + + + Publish my Location + + + + + + + + KLineEdit + QLineEdit +
klineedit.h
+
+ + KComboBox + QComboBox +
kcombobox.h
+
+
+ + +
diff --git a/kdeplasma-addons/applets/community/personwatch.cpp b/kdeplasma-addons/applets/community/personwatch.cpp new file mode 100644 index 00000000..d05f6ed4 --- /dev/null +++ b/kdeplasma-addons/applets/community/personwatch.cpp @@ -0,0 +1,83 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "personwatch.h" + +#include "utils.h" + + +using namespace Plasma; + +PersonWatch::PersonWatch(DataEngine* engine, QObject* parent) + : QObject(parent), + m_engine(engine) +{ +} + + +DataEngine::Data PersonWatch::data() const +{ + return m_data; +} + + +void PersonWatch::dataUpdated(const QString& source, const DataEngine::Data& data) +{ + if (source != m_source) { + return; + } + DataEngine::Data ocsData = data.value(personAddPrefix(m_id)).value(); + if (ocsData != m_data) { + m_data = ocsData; + emit updated(); + } +} + + +void PersonWatch::setId(const QString& id) +{ + setSourceParameter(m_id, id); +} + + +void PersonWatch::setProvider(const QString& provider) +{ + setSourceParameter(m_provider, provider); +} + + +void PersonWatch::setSourceParameter(QString& variable, const QString& value) +{ + if (variable != value) { + if (!m_source.isEmpty()) { + m_engine->disconnectSource(m_source, this); + } + variable = value; + dataUpdated(m_source, DataEngine::Data()); + m_source = personQuery(m_provider, m_id); + if (!m_source.isEmpty()) { + m_engine->connectSource(m_source, this); + } + } +} + + +#include "personwatch.moc" diff --git a/kdeplasma-addons/applets/community/personwatch.h b/kdeplasma-addons/applets/community/personwatch.h new file mode 100644 index 00000000..eb76b4ee --- /dev/null +++ b/kdeplasma-addons/applets/community/personwatch.h @@ -0,0 +1,59 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef PERSONWATCH_H +#define PERSONWATCH_H + +#include + +#include + + +class PersonWatch : public QObject +{ + Q_OBJECT + +public: + explicit PersonWatch(Plasma::DataEngine* engine, QObject* parent = 0); + Plasma::DataEngine::Data data() const; + +public Q_SLOTS: + void setId(const QString& id); + void setProvider(const QString& provider); + +Q_SIGNALS: + void updated(); + +private Q_SLOTS: + void dataUpdated(const QString& source, const Plasma::DataEngine::Data& data); + +private: + void setSourceParameter(QString& variable, const QString& value); + + Plasma::DataEngine::Data m_data; + Plasma::DataEngine* m_engine; + QString m_id; + QString m_provider; + QString m_source; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/personwatchlist.cpp b/kdeplasma-addons/applets/community/personwatchlist.cpp new file mode 100644 index 00000000..52a98123 --- /dev/null +++ b/kdeplasma-addons/applets/community/personwatchlist.cpp @@ -0,0 +1,66 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "personwatchlist.h" + +#include "utils.h" + + +PersonWatchList::PersonWatchList(Plasma::DataEngine* engine, QObject* parent) + : QObject(parent), + m_list(engine) +{ + connect(&m_list, SIGNAL(keysAdded(QSet)), SLOT(slotKeysAdded(QSet))); + connect(&m_list, SIGNAL(keysRemoved(QSet)), SLOT(slotKeysRemoved(QSet))); +} + + +bool PersonWatchList::contains(const QString& id) const { + return m_list.contains(personAddPrefix(id)); +} + + +void PersonWatchList::setSource(const QString& source) { + m_list.setQuery(source); +} + + +void PersonWatchList::slotKeysAdded(const QSet& keys) { + foreach(const QString& key, keys) { + QString person = personRemovePrefix(key); + if (!person.isEmpty()) { + emit personAdded(person); + } + } +} + + +void PersonWatchList::slotKeysRemoved(const QSet& keys) { + foreach(const QString& key, keys) { + QString person = personRemovePrefix(key); + if (!person.isEmpty()) { + emit personRemoved(person); + } + } +} + + +#include "personwatchlist.moc" diff --git a/kdeplasma-addons/applets/community/personwatchlist.h b/kdeplasma-addons/applets/community/personwatchlist.h new file mode 100644 index 00000000..315fe221 --- /dev/null +++ b/kdeplasma-addons/applets/community/personwatchlist.h @@ -0,0 +1,55 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef PERSONWATCHLIST_H +#define PERSONWATCHLIST_H + +#include +#include +#include + +#include "sourcewatchlist.h" + + +class PersonWatchList : public QObject +{ + Q_OBJECT + +public: + explicit PersonWatchList(Plasma::DataEngine* engine, QObject* parent = 0); + bool contains(const QString& id) const; + void setSource(const QString& source); + +Q_SIGNALS: + void personAdded(const QString& id); + void personRemoved(const QString& id); + +private Q_SLOTS: + void slotKeysAdded(const QSet& keys); + void slotKeysRemoved(const QSet& keys); + +private: + SourceWatchList m_list; + QString m_source; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/plasma-applet-opendesktop.desktop b/kdeplasma-addons/applets/community/plasma-applet-opendesktop.desktop new file mode 100644 index 00000000..08d0acd9 --- /dev/null +++ b/kdeplasma-addons/applets/community/plasma-applet-opendesktop.desktop @@ -0,0 +1,159 @@ +[Desktop Entry] +Name=Community +Name[ar]=المجتمع +Name[ast]=Comunidá +Name[bs]=zajednica +Name[ca]=Comunitat +Name[ca@valencia]=Comunitat +Name[cs]=Komunita +Name[da]=Community +Name[de]=Gemeinschaft +Name[el]=Κοινότητα +Name[en_GB]=Community +Name[es]=Comunidad +Name[et]=Kogukond +Name[eu]=Elkartea +Name[fi]=Yhteisö +Name[fr]=Communauté +Name[ga]=Comhphobal +Name[gl]=Comunidade +Name[hr]=Zajednica +Name[hu]=Közösség +Name[it]=Comunità +Name[ja]=コミュニティー +Name[kk]=Қоғам +Name[km]=សហគមន៍ +Name[ko]=커뮤니티 +Name[lt]=Bendruomenė +Name[lv]=Komūna +Name[mr]=सामाजिक +Name[nb]=Fellesskap +Name[nds]=Meenschap +Name[nl]=Gemeenschap +Name[pa]=ਕਮਿਊਨਟੀ +Name[pl]=Społeczność +Name[pt]=Comunidade +Name[pt_BR]=Comunidade +Name[ro]=Comunitate +Name[ru]=Сообщество +Name[sk]=Komunita +Name[sl]=Skupnost +Name[sr]=заједница +Name[sr@ijekavian]=заједница +Name[sr@ijekavianlatin]=zajednica +Name[sr@latin]=zajednica +Name[sv]=Gemenskap +Name[tr]=Topluluk +Name[ug]=جامائەت +Name[uk]=Спільнота +Name[wa]=Cominålté +Name[x-test]=xxCommunityxx +Name[zh_CN]=社区 +Name[zh_TW]=社群 +Comment=Communicate using the Social Desktop +Comment[ar]=تواصبل باستخدام سطح المكتب الاجتماعي +Comment[ast]=Comuníquese usando l'escritoriu social +Comment[bs]=Komuniciranje putem Društvene površi +Comment[ca]=Comuniqueu-vos usant l'escriptori social +Comment[ca@valencia]=Comuniqueu-vos usant l'escriptori social +Comment[cs]=Komunikujte pomocí Sociálního desktopu +Comment[da]=Kommunikér ved hjælp det sociale skrivebord. +Comment[de]=Über den Social Desktop kommunizieren +Comment[el]=Επικοινωνήστε χρησιμοποιώντας την επιφάνεια εργασίας κοινωνικού δικτύου +Comment[en_GB]=Communicate using the Social Desktop +Comment[es]=Comuníquese usando el escritorio social +Comment[et]=Suhtlemine sotsiaalse töölaua vahendusel +Comment[eu]=Komunikatu gizarte mahaigaina erabiliz +Comment[fi]=Viesti sosiaalisella työpöydällä +Comment[fr]=Communiquer en utilisant le bureau social. +Comment[gl]=Comunicacións a través do escritorio social +Comment[hr]=Komuniciraj koristeći Social Desktop +Comment[hu]=Kommunikáció a közösségi asztal használatával +Comment[is]=Eiga samskipti með samskiptaskjáborðinu +Comment[it]=Comunica utilizzando il desktop sociale +Comment[ja]=ソーシャルデスクトップを使って情報を交換します +Comment[kk]=Қоғам Үстелі арқылы хабарласу +Comment[km]=ទាក់ទង​ដោយ​ប្រើ​ផ្ទៃតុ​សង្គម +Comment[ko]=사회적 데스크톱을 사용하는 커뮤니케이션 +Comment[lt]=Bendraukite naudodami socialinį darbastalį +Comment[lv]=Sazināšanās izmantojot sociālo darbvirsmu +Comment[mr]=सामाजिक डेस्कटॉप वापरून संवाद साधा +Comment[nb]=Kommunikasjon ved bruk av det sosiale skrivebordet +Comment[nds]=Klönen över den Meenschap-Schriefdisch +Comment[nl]=Communiceer met het sociale bureaublad +Comment[nn]=Kommuniser via openDesktop +Comment[pa]=ਸਮਾਜਿਕ ਡੈਸਕਟਾਪ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਗੱਲਾਂਬਾਤਾਂ +Comment[pl]=Komunikacja przy użyciu Pulpitu społecznościowego +Comment[pt]=Comunicar com o Ambiente de Trabalho Social +Comment[pt_BR]=Comunique-se usando o Ambiente de Trabalho Social +Comment[ro]=Comunicați utilizînd Biroul Social +Comment[ru]=Общение при помощи openDesktop +Comment[sk]=Komunikovanie prostredníctvom sociálneho pracovného prostredia +Comment[sl]=Družite se prek družabnega namizja +Comment[sr]=Комуницирање путем Друштвене површи +Comment[sr@ijekavian]=Комуницирање путем Друштвене површи +Comment[sr@ijekavianlatin]=Komuniciranje putem Društvene površi +Comment[sr@latin]=Komuniciranje putem Društvene površi +Comment[sv]=Kommunicera med användning av det sociala skrivbordet +Comment[tr]=Sosyal Masaüstünü kullanarak iletişim kur +Comment[uk]=Спілкування за допомогою соціальної стільниці +Comment[wa]=Comuniker e s' siervant do Scribanne sociå +Comment[x-test]=xxCommunicate using the Social Desktopxx +Comment[zh_CN]=使用社会桌面沟通 +Comment[zh_TW]=使用 Social Desktop 聯繫 + +Icon=system-users +Type=Service +X-KDE-ServiceTypes=Plasma/Applet + +X-KDE-Library=plasma_applet_opendesktop +X-KDE-PluginInfo-Author=Sebastian Kügler +X-KDE-PluginInfo-Email=sebas@kde.org +X-KDE-PluginInfo-Name=opendesktop +X-KDE-PluginInfo-Version=0.1 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +Keywords=Utilities; +Keywords[ar]=أدوات؛ +Keywords[bs]=Alatke; +Keywords[ca]=Utilitats; +Keywords[ca@valencia]=Utilitats; +Keywords[cs]=Nástroje; +Keywords[da]=Værktøjer; +Keywords[de]=Dienstprogramme: +Keywords[el]=Εργαλεία; +Keywords[en_GB]=Utilities; +Keywords[es]=Utilidades; +Keywords[et]=Abivahendid; +Keywords[fi]=Työkalut; +Keywords[fr]=Utilitaires ; +Keywords[gl]=Utensilios: +Keywords[hu]=Segédprogramok; +Keywords[it]=Utilità; +Keywords[kk]=Utilities;Утилиталар; +Keywords[ko]=유틸리티;utilities; +Keywords[mr]=उपकार्यक्रम; +Keywords[nb]=Verktøy: +Keywords[nds]=Warktüüch; +Keywords[nl]=Hulpprogramma's; +Keywords[pl]=Narzędzia; +Keywords[pt]=Utilitários; +Keywords[pt_BR]=Utilitários; +Keywords[ro]=Utilitare; +Keywords[ru]=Утилиты; +Keywords[sk]=Nástroje; +Keywords[sl]=Pripomočki; +Keywords[sr]=алатке; +Keywords[sr@ijekavian]=алатке; +Keywords[sr@ijekavianlatin]=alatke; +Keywords[sr@latin]=alatke; +Keywords[sv]=Verktyg: +Keywords[tr]=Yardımcı Araçlar; +Keywords[uk]=Utilities;інструменти;засоби +Keywords[x-test]=xxUtilities;xx +Keywords[zh_CN]=工具; +Keywords[zh_TW]=Utilities; +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true +X-Plasma-Requires-FileDialog=Unused +X-Plasma-Requires-LaunchApp=Optional diff --git a/kdeplasma-addons/applets/community/requestfriendshipwidget.cpp b/kdeplasma-addons/applets/community/requestfriendshipwidget.cpp new file mode 100644 index 00000000..1f5720a2 --- /dev/null +++ b/kdeplasma-addons/applets/community/requestfriendshipwidget.cpp @@ -0,0 +1,189 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "requestfriendshipwidget.h" + +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include "contactimage.h" +#include "utils.h" + + +using namespace Plasma; + +RequestFriendshipWidget::RequestFriendshipWidget(DataEngine* engine, QGraphicsWidget* parent) + : Frame(parent), + m_engine(engine), + m_personWatch(engine) +{ + m_updateTimer.setInterval(1000); + m_updateTimer.setSingleShot(true); + + int avatarSize = KIconLoader::SizeMedium; + int actionSize = KIconLoader::SizeSmallMedium; + + Label* title = new Label; + title->setText(i18n("Add as friend")); + + // Recipient + m_image = new ContactImage(m_engine); + m_image->setMinimumHeight(avatarSize); + m_image->setMinimumWidth(avatarSize); + m_image->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + m_toLabel = new Label; + m_toEdit = new LineEdit; + + QGraphicsGridLayout* toLayout = new QGraphicsGridLayout; + toLayout->setColumnFixedWidth(0, avatarSize * 1.2); + toLayout->addItem(m_image, 0, 0, 2, 1); + toLayout->addItem(m_toLabel, 0, 1); + toLayout->addItem(m_toEdit, 1, 1); + + Label* bodyLabel = new Label; + bodyLabel->setText(i18n("Message:")); + + Frame* bodyFrame = new Frame(this); + bodyFrame->setFrameShadow(Sunken); + bodyFrame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_body = new TextEdit; + (new QGraphicsLinearLayout(bodyFrame))->addItem(m_body); + + Plasma::IconWidget* cancel = new Plasma::IconWidget; + cancel->setIcon("go-previous-view"); + cancel->setToolTip(i18n("Back")); + cancel->setMinimumHeight(actionSize); + cancel->setMaximumHeight(actionSize); + cancel->setMinimumWidth(actionSize); + cancel->setMaximumWidth(actionSize); + + m_submit = new Plasma::IconWidget; + m_submit->setIcon("dialog-ok"); + m_submit->setToolTip(i18n("Send")); + m_submit->setMinimumHeight(actionSize); + m_submit->setMaximumHeight(actionSize); + m_submit->setMinimumWidth(actionSize); + m_submit->setMaximumWidth(actionSize); + m_submit->setEnabled(false); + + QGraphicsLinearLayout* buttonLayout = new QGraphicsLinearLayout(Qt::Horizontal); + buttonLayout->addItem(cancel); + buttonLayout->addStretch(); + buttonLayout->addItem(m_submit); + + QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical, this); + layout->addItem(title); + layout->addItem(toLayout); + layout->addItem(bodyLabel); + layout->addItem(bodyFrame); + layout->addItem(buttonLayout); + + connect(m_submit, SIGNAL(clicked()), SLOT(send())); + connect(cancel, SIGNAL(clicked()), SIGNAL(done())); + connect(&m_updateTimer, SIGNAL(timeout()), SLOT(updateTo())); + connect(m_toEdit, SIGNAL(editingFinished()), SLOT(updateTo())); + connect(m_toEdit, SIGNAL(textEdited(QString)), SLOT(updateSendAction())); + connect(m_toEdit, SIGNAL(textEdited(QString)), SLOT(toChanged(QString))); + connect(m_toEdit, SIGNAL(returnPressed()), SLOT(switchToBody())); + connect(&m_personWatch, SIGNAL(updated()), SLOT(personUpdated())); + connect(m_body, SIGNAL(textChanged()), SLOT(updateSendAction())); +} + + +void RequestFriendshipWidget::personUpdated() +{ + DataEngine::Data personData = m_personWatch.data(); + m_toLabel->setText(personData.value("Name").toString()); + m_image->setUrl(personData.value("AvatarUrl").toUrl()); +} + + +void RequestFriendshipWidget::send() { + Service* service = m_engine->serviceForSource(personQuery(m_provider, m_id)); + KConfigGroup cg = service->operationDescription("invite"); + cg.writeEntry("Message", m_body->nativeWidget()->toPlainText()); + KJob *job = service->startOperationCall(cg); + connect(job, SIGNAL(finished(KJob*)), service, SLOT(deleteLater())); + + // FIXME: We do not wait for the result atm + emit done(); + m_id.clear(); + m_toEdit->setText(QString()); + m_personWatch.setId(QString()); + m_body->setText(QString()); +} + + +void RequestFriendshipWidget::switchToBody() +{ + m_body->setFocus(); +} + + +void RequestFriendshipWidget::toChanged(const QString& to) +{ + m_id.clear(); + updateTo(); + m_id = to; + m_updateTimer.stop(); + m_updateTimer.start(); +} + + +void RequestFriendshipWidget::updateSendAction() +{ + m_submit->setEnabled(!m_toEdit->text().isEmpty() && !m_body->nativeWidget()->toPlainText().isEmpty()); +} + + +void RequestFriendshipWidget::updateTo() +{ + m_personWatch.setId(m_id); +} + + +void RequestFriendshipWidget::setId(const QString& id) +{ + m_id = id; + m_toEdit->setText(m_id); + m_personWatch.setId(m_id); +} + + +void RequestFriendshipWidget::setProvider(const QString& provider) +{ + m_id.clear(); + m_provider = provider; + m_toEdit->setText(m_id); + m_personWatch.setId(m_id); + m_personWatch.setProvider(m_provider); +} + + +#include "requestfriendshipwidget.moc" diff --git a/kdeplasma-addons/applets/community/requestfriendshipwidget.h b/kdeplasma-addons/applets/community/requestfriendshipwidget.h new file mode 100644 index 00000000..391aaa4a --- /dev/null +++ b/kdeplasma-addons/applets/community/requestfriendshipwidget.h @@ -0,0 +1,79 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef REQUESTFRIENDSHIPWIDGET_H +#define REQUESTFRIENDSHIPWIDGET_H + +#include + +#include +#include +#include +#include +#include +#include + +#include "personwatch.h" + + +class ContactImage; + +namespace Plasma { + class IconWidget; +} + +class RequestFriendshipWidget : public Plasma::Frame +{ + Q_OBJECT + + public: + RequestFriendshipWidget(Plasma::DataEngine* engine, QGraphicsWidget* parent = 0); + + public Q_SLOTS: + void setId(const QString& id); + void setProvider(const QString& provider); + + Q_SIGNALS: + void done(); + + private Q_SLOTS: + void personUpdated(); + void send(); + void switchToBody(); + void toChanged(const QString& to); + void updateTo(); + void updateSendAction(); + + private: + Plasma::LineEdit* m_toEdit; + Plasma::TextEdit* m_body; + Plasma::DataEngine* m_engine; + Plasma::Label* m_toLabel; + Plasma::IconWidget* m_submit; + QString m_id; + QString m_provider; + QTimer m_updateTimer; + PersonWatch m_personWatch; + ContactImage* m_image; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/sendmessagewidget.cpp b/kdeplasma-addons/applets/community/sendmessagewidget.cpp new file mode 100644 index 00000000..20b641bb --- /dev/null +++ b/kdeplasma-addons/applets/community/sendmessagewidget.cpp @@ -0,0 +1,209 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "sendmessagewidget.h" + +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include "contactimage.h" +#include "utils.h" + + +using namespace Plasma; + +SendMessageWidget::SendMessageWidget(DataEngine* engine, QGraphicsWidget* parent) + : Frame(parent), + m_engine(engine), + m_personWatch(engine) +{ + m_updateTimer.setInterval(1000); + m_updateTimer.setSingleShot(true); + + int avatarSize = KIconLoader::SizeMedium; + int actionSize = KIconLoader::SizeSmallMedium; + + Label* title = new Label; + title->setText(i18n("Send message")); + + // Recipient + m_image = new ContactImage(m_engine); + m_image->setMinimumHeight(avatarSize); + m_image->setMinimumWidth(avatarSize); + m_image->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + m_toLabel = new Label; + m_toEdit = new LineEdit; + + QGraphicsGridLayout* toLayout = new QGraphicsGridLayout; + toLayout->setColumnFixedWidth(0, avatarSize * 1.2); + toLayout->addItem(m_image, 0, 0, 2, 1); + toLayout->addItem(m_toLabel, 0, 1); + toLayout->addItem(m_toEdit, 1, 1); + + Label* subjectLabel = new Label; + subjectLabel->setText(i18n("Subject:")); + + m_subject = new LineEdit; + + Label* bodyLabel = new Label; + bodyLabel->setText(i18n("Message:")); + + Frame* bodyFrame = new Frame(this); + bodyFrame->setFrameShadow(Sunken); + bodyFrame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_body = new TextEdit; + (new QGraphicsLinearLayout(bodyFrame))->addItem(m_body); + + Plasma::IconWidget* cancel = new Plasma::IconWidget; + cancel->setIcon("go-previous-view"); + cancel->setToolTip(i18n("Back")); + cancel->setMinimumHeight(actionSize); + cancel->setMaximumHeight(actionSize); + cancel->setMinimumWidth(actionSize); + cancel->setMaximumWidth(actionSize); + + m_submit = new Plasma::IconWidget; + m_submit->setIcon("mail-send"); + m_submit->setToolTip(i18n("Send")); + m_submit->setMinimumHeight(actionSize); + m_submit->setMaximumHeight(actionSize); + m_submit->setMinimumWidth(actionSize); + m_submit->setMaximumWidth(actionSize); + m_submit->setEnabled(false); + + QGraphicsLinearLayout* buttonLayout = new QGraphicsLinearLayout(Qt::Horizontal); + buttonLayout->addItem(cancel); + buttonLayout->addStretch(); + buttonLayout->addItem(m_submit); + + QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical, this); + layout->addItem(title); + layout->addItem(toLayout); + layout->addItem(subjectLabel); + layout->addItem(m_subject); + layout->addItem(bodyLabel); + layout->addItem(bodyFrame); + layout->addItem(buttonLayout); + + connect(m_submit, SIGNAL(clicked()), SLOT(send())); + connect(cancel, SIGNAL(clicked()), SIGNAL(done())); + connect(&m_updateTimer, SIGNAL(timeout()), SLOT(updateTo())); + connect(m_toEdit, SIGNAL(editingFinished()), SLOT(updateTo())); + connect(m_toEdit, SIGNAL(textEdited(QString)), SLOT(updateSendAction())); + connect(m_toEdit, SIGNAL(textEdited(QString)), SLOT(toChanged(QString))); + connect(m_toEdit, SIGNAL(returnPressed()), SLOT(switchToSubject())); + connect(&m_personWatch, SIGNAL(updated()), SLOT(personUpdated())); + connect(m_subject, SIGNAL(textEdited(QString)), SLOT(updateSendAction())); + connect(m_subject, SIGNAL(returnPressed()), SLOT(switchToBody())); + connect(m_body, SIGNAL(textChanged()), SLOT(updateSendAction())); +} + + +void SendMessageWidget::personUpdated() +{ + DataEngine::Data personData = m_personWatch.data(); + m_toLabel->setText(personData.value("Name").toString()); + m_image->setUrl(personData.value("AvatarUrl").toUrl()); +} + + +void SendMessageWidget::send() { + emit startWork(); + Service* service = m_engine->serviceForSource(personQuery(m_provider, m_id)); + KConfigGroup cg = service->operationDescription("sendMessage"); + cg.writeEntry("Subject", m_subject->text()); + cg.writeEntry("Body", m_body->nativeWidget()->toPlainText()); + ServiceJob* job = service->startOperationCall(cg); + connect(job, SIGNAL(finished(KJob*)), SIGNAL(endWork())); + connect(job, SIGNAL(finished(KJob*)), service, SLOT(deleteLater())); + delete service; + + // FIXME: We do not wait for the result atm + emit done(); + m_id.clear(); + m_toEdit->setText(QString()); + m_personWatch.setId(QString()); + m_subject->setText(QString()); + m_body->setText(QString()); +} + + +void SendMessageWidget::switchToBody() +{ + m_body->setFocus(); +} + + +void SendMessageWidget::switchToSubject() +{ + m_subject->setFocus(); +} + + +void SendMessageWidget::toChanged(const QString& to) +{ + m_id.clear(); + updateTo(); + m_id = to; + m_updateTimer.stop(); + m_updateTimer.start(); +} + + +void SendMessageWidget::updateSendAction() +{ + m_submit->setEnabled(!m_toEdit->text().isEmpty() && !m_subject->text().isEmpty() && !m_body->nativeWidget()->toPlainText().isEmpty()); +} + + +void SendMessageWidget::updateTo() +{ + m_personWatch.setId(m_id); +} + + +void SendMessageWidget::setId(const QString& id) +{ + m_id = id; + m_toEdit->setText(m_id); + m_personWatch.setId(m_id); +} + + +void SendMessageWidget::setProvider(const QString& provider) +{ + m_id.clear(); + m_provider = provider; + m_toEdit->setText(m_id); + m_personWatch.setId(m_id); + m_personWatch.setProvider(m_provider); +} + + +#include "sendmessagewidget.moc" diff --git a/kdeplasma-addons/applets/community/sendmessagewidget.h b/kdeplasma-addons/applets/community/sendmessagewidget.h new file mode 100644 index 00000000..b255e4cd --- /dev/null +++ b/kdeplasma-addons/applets/community/sendmessagewidget.h @@ -0,0 +1,83 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef SENDMESSAGEWIDGET_H +#define SENDMESSAGEWIDGET_H + +#include + +#include +#include +#include +#include +#include +#include + +#include "personwatch.h" + + +class ContactImage; + +namespace Plasma { + class IconWidget; +} + +class SendMessageWidget : public Plasma::Frame +{ + Q_OBJECT + + public: + SendMessageWidget(Plasma::DataEngine* engine, QGraphicsWidget* parent = 0); + + public Q_SLOTS: + void setId(const QString& id); + void setProvider(const QString& provider); + + Q_SIGNALS: + void endWork(); + void done(); + void startWork(); + + private Q_SLOTS: + void personUpdated(); + void send(); + void switchToBody(); + void switchToSubject(); + void toChanged(const QString& to); + void updateTo(); + void updateSendAction(); + + private: + Plasma::LineEdit* m_toEdit; + Plasma::TextEdit* m_body; + Plasma::DataEngine* m_engine; + Plasma::Label* m_toLabel; + Plasma::LineEdit* m_subject; + Plasma::IconWidget* m_submit; + QString m_id; + QString m_provider; + QTimer m_updateTimer; + PersonWatch m_personWatch; + ContactImage* m_image; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/sourcewatchlist.cpp b/kdeplasma-addons/applets/community/sourcewatchlist.cpp new file mode 100644 index 00000000..8936cf62 --- /dev/null +++ b/kdeplasma-addons/applets/community/sourcewatchlist.cpp @@ -0,0 +1,95 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "sourcewatchlist.h" + + +using namespace Plasma; + +SourceWatchList::SourceWatchList(DataEngine* engine, QObject* parent) + : QObject(parent), + m_engine(engine), + m_updateInterval(0) +{ +} + + +bool SourceWatchList::contains(const QString& key) const +{ + return m_data.contains(key); +} + + +QString SourceWatchList::query() const +{ + return m_query; +} + + +void SourceWatchList::setQuery(const QString& query) +{ + if (query != m_query) { + if (!m_query.isEmpty()) { + m_engine->disconnectSource(m_query, this); + } + dataUpdated(m_query, DataEngine::Data()); + m_query = query; + if (!m_query.isEmpty()) { + m_engine->connectSource(m_query, this, m_updateInterval); + } + } +} + + +void SourceWatchList::setUpdateInterval(uint updateInterval) +{ + m_updateInterval = updateInterval; + if (!m_query.isEmpty()) { + m_engine->connectSource(m_query, this, m_updateInterval); + } +} + + +QVariant SourceWatchList::value(const QString& id) const +{ + return m_data.value(id); +} + + +void SourceWatchList::dataUpdated(const QString& source, const Plasma::DataEngine::Data& data) +{ + Q_UNUSED(source) + + const QSet oldKeys = QSet::fromList(m_data.keys()); + const QSet newKeys = QSet::fromList(data.keys()); + m_data = data; + QSet addedKeys = QSet(newKeys).subtract(oldKeys); + QSet removedKeys = QSet(oldKeys).subtract(newKeys); + if (!removedKeys.isEmpty()) { + emit keysRemoved(removedKeys); + } + if (!addedKeys.isEmpty()) { + emit keysAdded(addedKeys); + } +} + + +#include "sourcewatchlist.moc" diff --git a/kdeplasma-addons/applets/community/sourcewatchlist.h b/kdeplasma-addons/applets/community/sourcewatchlist.h new file mode 100644 index 00000000..83f52128 --- /dev/null +++ b/kdeplasma-addons/applets/community/sourcewatchlist.h @@ -0,0 +1,58 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef SOURCEWATCHLIST_H +#define SOURCEWATCHLIST_H + +#include +#include + +#include + + +class SourceWatchList : public QObject +{ + Q_OBJECT + + public: + explicit SourceWatchList(Plasma::DataEngine* engine, QObject* parent = 0); + bool contains(const QString& key) const; + QString query() const; + void setQuery(const QString& query); + void setUpdateInterval(uint updateInterval); + QVariant value(const QString& id) const; + + Q_SIGNALS: + void keysAdded(const QSet& keys); + void keysRemoved(const QSet& keys); + + private Q_SLOTS: + void dataUpdated(const QString& source, const Plasma::DataEngine::Data& data); + + private: + Plasma::DataEngine::Data m_data; + Plasma::DataEngine* m_engine; + QString m_query; + uint m_updateInterval; +}; + + +#endif diff --git a/kdeplasma-addons/applets/community/stylesheet.cpp b/kdeplasma-addons/applets/community/stylesheet.cpp new file mode 100644 index 00000000..751c289c --- /dev/null +++ b/kdeplasma-addons/applets/community/stylesheet.cpp @@ -0,0 +1,130 @@ +/* + Copyright 2009 by Sebastian Kügler + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "stylesheet.h" + +//Qt +#include +#include +#include + +// KDE +#include +#include +#include +#include + +// Plasma +#include + + +using namespace Plasma; + +StyleSheet::StyleSheet(QObject *parent) + : QObject(parent) +{ + //m_cssFile = "/home/sebas/kdesvn/src/attica/plasma/opendesktop/user.css"; // For debugging quicker + m_cssFile = KStandardDirs::locate("data", "plasma-applet-opendesktop/user.css"); + load(m_cssFile); + m_cssWatch = new KDirWatch(this); + m_cssWatch->addFile(m_cssFile); + connect(m_cssWatch,SIGNAL(dirty(QString)),this,SLOT(load(QString))); + connect(m_cssWatch,SIGNAL(created(QString)),this,SLOT(load(QString))); + connect(m_cssWatch,SIGNAL(deleted(QString)),this,SLOT(load(QString))); + + connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(update())); + connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), SLOT(update())); +} + +StyleSheet::~StyleSheet() +{ +} + +QString StyleSheet::styleSheet() const +{ + return m_styleSheet; +} + +void StyleSheet::setFileName(const QString &cssFile) +{ + if (m_cssFile != cssFile) { + // change watch file watch and load new CSS ... + m_cssWatch->removeFile(m_cssFile); + m_cssFile = cssFile; + load(cssFile); + m_cssWatch->addFile(m_cssFile); + } +} + +void StyleSheet::setStyleSheet(const QString &css) +{ + m_rawStyleSheet = css; + update(); +} + +void StyleSheet::load(const QString &cssFile) +{ + QFile f(this); + + if (cssFile.isEmpty()) { + f.setFileName(m_cssFile); + } else { + f.setFileName(cssFile); + } + kDebug() << "(Re)loading CSS" << cssFile; + if (f.open(QIODevice::ReadOnly)) { + QTextStream t(&f); + m_rawStyleSheet = t.readAll(); + f.close(); + update(); + } else { + kDebug() << "CSS File not loaded, error reading file"; + } +} + +void StyleSheet::update() +{ + QPalette p = QPalette(); + + QColor text = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor); + QColor link = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor); + QColor background = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor); + link.setAlphaF(qreal(.8)); + QColor linkvisited = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor); + linkvisited.setAlphaF(qreal(.6)); + + m_colors["%textcolor"] = text.name(); + m_colors["%background"] = background.name(); + m_colors["%visitedlink"] = linkvisited.name(); + m_colors["%activatedlink"] = linkvisited.name(); + m_colors["%hoveredlink"] = linkvisited.name(); + m_colors["%link"] = link.name(); + m_colors["%smallfontsize"] = QString("%1pt").arg(KGlobalSettings::smallestReadableFont().pointSize()); + m_colors["%fontsize"] = QString("%1pt").arg(KGlobalSettings::generalFont().pointSize()); + + m_styleSheet = m_rawStyleSheet; + foreach(const QString &k, m_colors.keys()) { + m_styleSheet.replace(k, m_colors[k]); + } + //kDebug() << "CSS:" << m_styleSheet; + + emit styleSheetChanged(m_styleSheet); +} + +#include "stylesheet.moc" diff --git a/kdeplasma-addons/applets/community/stylesheet.h b/kdeplasma-addons/applets/community/stylesheet.h new file mode 100644 index 00000000..d9f744ba --- /dev/null +++ b/kdeplasma-addons/applets/community/stylesheet.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright 2009 by Sebastian Kügler * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef STYLESHEET_H +#define STYLESHEET_H + +//Qt +#include + +// KDE +#include + +class StyleSheet : public QObject +{ + Q_OBJECT + + public: + StyleSheet(QObject *parent); + virtual ~StyleSheet(); + + void setFileName(const QString &cssFile); + + QString styleSheet() const; + void setStyleSheet(const QString &css); + + Q_SIGNALS: + void styleSheetChanged(const QString&); + + public Q_SLOTS: + void load(const QString &cssFile); + void update(); + + private: + QString m_cssFile; + QString m_styleSheet; + QString m_rawStyleSheet; + + QHash m_colors; + KDirWatch* m_cssWatch; +}; + +#endif + diff --git a/kdeplasma-addons/applets/community/user.css b/kdeplasma-addons/applets/community/user.css new file mode 100644 index 00000000..753ad22e --- /dev/null +++ b/kdeplasma-addons/applets/community/user.css @@ -0,0 +1,46 @@ +/** Stylesheet for the UserWidget used in the openDesktop applet + + Please use the following placeholders for colors and sizes. + They are replaced by colors matching the theme. + + %textcolor : Foreground color, used for text + %background : background color, defaults to transparant + %visitedlink : visited link color + %activatedlink : activated link color + %hoveredlink : link color when hovered + %smallfontsize : Size of the smallest readable font + %fontsize : Normal size for fonts + */ + +body { + margin: 0px 0px 0px 0px; + color: %textcolor; +} + +h2 { + font-size: 10px; + color: %textcolor; + opacity: .4; +} + +td { + font-size: %smallfontsize; + font-style: normal; +} + +.infoheader { + font-weight: bold; + text-align: right; +} + +.rowheader { + font-size: %smallfontsize; + vertical-align: top; + font-weight: bold; + text-align: right; + opacity: .7; +} + +a:visited { color: %visitedlink; } +a:link { color: %link .8; } +a:hover { text-decoration: none; opacity: .4; } diff --git a/kdeplasma-addons/applets/community/userwidget.cpp b/kdeplasma-addons/applets/community/userwidget.cpp new file mode 100644 index 00000000..a9379d3d --- /dev/null +++ b/kdeplasma-addons/applets/community/userwidget.cpp @@ -0,0 +1,321 @@ +/* + Copyright 2008-2009 by Sebastian Kügler + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "userwidget.h" + +//Qt +#include +#include +#include +#include + +//KDE +#include +#include +#include +#include +#include +#include + +// Plasma +#include +#include +#include +#include + +// own +#include "contactimage.h" +#include "stylesheet.h" +#include "utils.h" + +using namespace Plasma; + +UserWidget::UserWidget(DataEngine* engine, QGraphicsWidget* parent) + : Frame(parent), + m_css(0), + m_image(0), + m_nameLabel(0), + m_infoView(0), + m_friendWatcher(engine), + m_engine(engine), + m_personWatch(engine) +{ + m_info = i18n("No information available."); + + // listen for changes to the stylesheet file + + m_css = new StyleSheet(this); + connect(m_css, SIGNAL(styleSheetChanged(QString)), this, SLOT(setStyleSheet(QString))); + + setMinimumHeight(200); + setMinimumWidth(200); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + buildDialog(); + connect(Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(updateColors())); + connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), SLOT(updateColors())); +} + +UserWidget::~UserWidget() +{ +} + + +void UserWidget::buildDialog() +{ + updateColors(); + + int m = 64; // size of the image + int actionSize = KIconLoader::SizeSmallMedium; + + m_layout = new QGraphicsGridLayout(this); + m_layout->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_layout->setColumnFixedWidth(0, m); // This could probably be a bit more dynamic + m_layout->setColumnMinimumWidth(1, 60); + m_layout->setHorizontalSpacing(4); + + m_image = new ContactImage(m_engine, this); + + m_image->setPreferredWidth(m); + m_image->setPreferredHeight(m); + m_image->setMinimumHeight(m); + m_image->setMinimumWidth(m); + m_layout->addItem(m_image, 0, 0, 1, 1, Qt::AlignTop); + + m_nameLabel = new Label(this); + m_nameLabel->nativeWidget()->setWordWrap(true); + m_nameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + m_nameLabel->setMinimumWidth(60); + m_nameLabel->setMaximumHeight(40); + m_layout->addItem(m_nameLabel, 0, 1, 1, 1, Qt::AlignTop); + + + m_infoView = new WebView(this); + m_infoView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + //m_infoView->nativeWidget()->setFont(KGlobalSettings::smallestReadableFont()); + //m_infoView->nativeWidget()->setWordWrap(true); + + m_layout->addItem(m_infoView, 1, 0, 1, 2, Qt::AlignTop); + + Plasma::IconWidget* back = new Plasma::IconWidget; + back->setIcon("go-previous-view"); + back->setToolTip(i18n("Back")); + back->setMinimumHeight(actionSize); + back->setMaximumHeight(actionSize); + back->setMinimumWidth(actionSize); + back->setMaximumWidth(actionSize); + + m_addFriend = new Plasma::IconWidget; + m_addFriend->setIcon("list-add-user"); + m_addFriend->setToolTip(i18n("Add friend")); + m_addFriend->setMinimumHeight(actionSize); + m_addFriend->setMaximumHeight(actionSize); + m_addFriend->setMinimumWidth(actionSize); + m_addFriend->setMaximumWidth(actionSize); + + m_sendMessage = new Plasma::IconWidget; + m_sendMessage->setIcon("mail-send"); + m_sendMessage->setToolTip(i18n("Send message")); + m_sendMessage->setMinimumHeight(actionSize); + m_sendMessage->setMaximumHeight(actionSize); + m_sendMessage->setMinimumWidth(actionSize); + m_sendMessage->setMaximumWidth(actionSize); + + QGraphicsLinearLayout* actionLayout = new QGraphicsLinearLayout(Qt::Horizontal); + actionLayout->addItem(back); + actionLayout->addStretch(); + actionLayout->addItem(m_addFriend); + actionLayout->addItem(m_sendMessage); + + m_layout->addItem(actionLayout, 2, 0, 1, 2); + setLayout(m_layout); + + m_mapper = new QSignalMapper(this); + + connect(back, SIGNAL(clicked()), SIGNAL(done())); + connect(m_sendMessage, SIGNAL(clicked()), m_mapper, SLOT(map())); + connect(m_addFriend, SIGNAL(clicked()), m_mapper, SLOT(map())); + + connect(m_mapper, SIGNAL(mapped(QString)), + this, SIGNAL(sendMessage(QString))); + + updateColors(); + + connect(&m_personWatch, SIGNAL(updated()), SLOT(dataUpdated())); +} + +void UserWidget::setId(const QString& id) +{ + m_id = id; + m_mapper->setMapping(m_sendMessage, m_id); + m_mapper->setMapping(m_addFriend, m_id); + m_personWatch.setId(id); + m_addFriend->setVisible(!m_friendWatcher.contains(m_id)); +} + +void UserWidget::setOwnId(const QString& ownId) +{ + m_ownId = ownId; + m_friendWatcher.setSource(friendsQuery(m_provider, m_ownId)); + m_addFriend->setVisible(!m_friendWatcher.contains(m_id)); +} + +void UserWidget::setProvider(const QString& provider) +{ + m_personWatch.setProvider(provider); + m_provider = provider; + m_friendWatcher.setSource(friendsQuery(m_provider, m_ownId)); + m_addFriend->setVisible(!m_friendWatcher.contains(m_id)); +} + + +void UserWidget::dataUpdated() +{ + m_image->setUrl(m_personWatch.data().value("AvatarUrl").toUrl()); + + setName(); + setInfo(); + +} + +QString UserWidget::addRow(const QString& title, const QString& text) +{ + if (!text.isEmpty()) { + return QString("%1%2\n").arg(title, text); + } else { + return QString(); + } +} + +void UserWidget::setStyleSheet(const QString &stylesheet) +{ + Q_UNUSED(stylesheet) + // kDebug() << "Setting new stylesheet" << stylesheet; + updateColors(); + setName(); + setInfo(); +} + +void UserWidget::updateColors() +{ + QPalette p = palette(); + + // Set background to transparent and use the theme to provide contrast with the text + p.setColor(QPalette::Base, Qt::transparent); // new in Qt 4.5 + p.setColor(QPalette::Window, Qt::transparent); // For Qt 4.4, remove when we depend on 4.5 + + + QColor text = Theme::defaultTheme()->color(Theme::TextColor); + QColor link = Theme::defaultTheme()->color(Theme::TextColor); + link.setAlphaF(qreal(.8)); + QColor linkvisited = Theme::defaultTheme()->color(Theme::TextColor); + linkvisited.setAlphaF(qreal(.6)); + + p.setColor(QPalette::Text, text); + p.setColor(QPalette::Link, link); + p.setColor(QPalette::LinkVisited, linkvisited); + + setPalette(p); + + if (m_nameLabel) { + m_nameLabel->setPalette(p); + if (m_css) { + m_nameLabel->setStyleSheet(m_css->styleSheet()); + } + m_infoView->page()->setPalette(p); + } + update(); + // kDebug() << "CSS:" << m_css->styleSheet(); +} + +void UserWidget::setName() +{ + DataEngine::Data data = m_personWatch.data(); + QString html; + + QString _name = data["Name"].toString(); + + if (_name.isEmpty()) { + html = QString("%1").arg(m_id); + } else { + html = QString("%1 (%2)").arg(_name, m_id); + } + + QString crole = data["description"].toString(); + + if (!crole.isEmpty()) { + html.append(QString("\n
%1").arg(crole)); + } + + if (m_nameLabel) { + m_nameLabel->setText(QString("%2").arg(m_css->styleSheet(), html)); + } +} + +void UserWidget::setInfo() +{ + DataEngine::Data data = m_personWatch.data(); + QString city = data["City"].toString(); + QString country = data["Country"].toString(); + qreal lat = (qreal)(data["Latitude"].toDouble()); + qreal lon = (qreal)(data["Longitude"].toDouble()); + + QString location; + if (!city.isEmpty() && !country.isEmpty()) { + location = QString("%1, %2").arg(city, country); + } else if (country.isEmpty() && !city.isEmpty()) { + location = city; + } else if (city.isEmpty() && !country.isEmpty()) { + location = country; + } + + if (lat > 0 && lon) { + location = i18nc("city, country, latitude and longitude", "%1 (Lat: %2, Long: %3)", location, KGlobal::locale()->formatNumber(lat, 2), KGlobal::locale()->formatNumber(lon, 2)); + } + + QString birthday = KGlobal::locale()->formatDate(data["Birthday"].toDate(), KLocale::FancyLongDate); + + QStringList userInfo; + + userInfo << ""; + userInfo << addRow(i18n("Birthday:"), birthday); + userInfo << addRow(i18n("Location:"), location); + userInfo << addRow(i18n("IRC Nickname:"), data["ircnick"].toString()); + userInfo << addRow(i18n("Company:"), data["company"].toString()); + userInfo << addRow(i18n("Languages:"), data["languages"].toString()); + userInfo << addRow(i18n("Interests:"), data["interests"].toString()); + userInfo << addRow(i18n("Music:"), data["favouritemusic"].toString()); + userInfo << addRow(i18n("TV Shows:"), data["favouritetvshows"].toString()); + userInfo << addRow(i18n("Games:"), data["favouritegames"].toString()); + userInfo << addRow(i18n("Programming:"), data["programminglanguages"].toString()); + userInfo << addRow(i18n("%1 likes:", m_id), data["likes"].toString()); + userInfo << addRow(i18n("%1 does not like:", m_id), data["dontlikes"].toString()); + userInfo << "
"; + + QString html = userInfo.join(""); + + if (m_infoView) { + if (m_css) { + html = (QString("%2").arg(m_css->styleSheet(), html)); + } + m_infoView->setHtml(html); + } +} + + +#include "userwidget.moc" diff --git a/kdeplasma-addons/applets/community/userwidget.h b/kdeplasma-addons/applets/community/userwidget.h new file mode 100644 index 00000000..134e43c5 --- /dev/null +++ b/kdeplasma-addons/applets/community/userwidget.h @@ -0,0 +1,109 @@ +/*************************************************************************** + * Copyright 2008-2009 by Sebastian Kügler * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef USERWIDGET_H +#define USERWIDGET_H + +//Qt +#include +#include +#include + +// Plasma +#include +#include + +#include "personwatch.h" +#include "personwatchlist.h" + + +namespace Plasma +{ + class IconWidget; + class Label; + class Frame; + class WebView; +} + +class QSignalMapper; + +class ContactImage; +class StyleSheet; + +class UserWidget : public Plasma::Frame +{ + Q_OBJECT + + public: + explicit UserWidget(Plasma::DataEngine* engine, QGraphicsWidget *parent = 0); + virtual ~UserWidget(); + + void setOwnId(const QString& id); + + Q_SIGNALS: + void sendMessage(const QString &); + void done(); + + public Q_SLOTS: + void setId(const QString& id); + void setProvider(const QString& provider); + + void updateColors(); + //void loadStyleSheet(const QString &cssFile = ""); + void setStyleSheet(const QString &stylesheet); + + private Q_SLOTS: + void dataUpdated(); + + private: + void buildDialog(); + void setName(); + void setInfo(); + + QString addRow(const QString& title, const QString& text); + + StyleSheet* m_css; + + // Caches the content part of the widget + QString m_info; + // Caches the title part of the widget + QString m_name; + // The applet attached to this item + QGraphicsGridLayout* m_layout; + ContactImage* m_image; + Plasma::Label* m_nameLabel; + Plasma::WebView* m_infoView; + // The user id to display + QString m_id; + // our id + QString m_ownId; + QString m_provider; + //to be able to emit sendMessage(const QString &) + QSignalMapper *m_mapper; + Plasma::IconWidget* m_sendMessage; + Plasma::IconWidget* m_addFriend; + //to know if the contact displayed is our friend + PersonWatchList m_friendWatcher; + // The data engine used + Plasma::DataEngine* m_engine; + PersonWatch m_personWatch; +}; + +#endif + diff --git a/kdeplasma-addons/applets/community/utils.cpp b/kdeplasma-addons/applets/community/utils.cpp new file mode 100644 index 00000000..34e028b8 --- /dev/null +++ b/kdeplasma-addons/applets/community/utils.cpp @@ -0,0 +1,154 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "utils.h" + + +QString escape(const QString& value) { + return QString(value).replace('\\', "\\\\"); +} + + +QString friendsQuery(const QString& provider, const QString& id) { + if (!provider.isEmpty() && ! id.isEmpty()) { + return QString("Friends\\provider:%1\\id:%2").arg(escape(provider)).arg(escape(id)); + } else { + return QString(); + } +} + + +QString messageAddPrefix(const QString& message) +{ + return QString("Message-%1").arg(message); +} + + +QString messageListQuery(const QString& provider, const QString& folder) +{ + if (!provider.isEmpty() && ! folder.isEmpty()) { + return QString("Messages\\provider:%1\\folder:%2").arg(escape(provider)).arg(escape(folder)); + } else { + return QString(); + } +} + + +QString messageListUnreadQuery(const QString& provider, const QString& folder) +{ + if (!provider.isEmpty() && ! folder.isEmpty()) { + return QString("Messages\\provider:%1\\folder:%2\\status:unread").arg(escape(provider)).arg(escape(folder)); + } else { + return QString(); + } +} + + +QString messageRemovePrefix(const QString& id) { + if (id.startsWith(QLatin1String("Message-"))) { + QString message = QString(id).remove(0, 8); + return message; + } else { + return QString(); + } +} + + +QString messageQuery(const QString& provider, const QString& folder, const QString& message) +{ + if (!provider.isEmpty() && ! folder.isEmpty() && !message.isEmpty()) { + return QString("Message\\provider:%1\\folder:%2\\id:%3").arg(escape(provider)).arg(escape(folder)).arg(escape(message)); + } else { + return QString(); + } +} + + +QString messageSummaryQuery(const QString& provider, const QString& folder, const QString& message) +{ + if (!provider.isEmpty() && ! folder.isEmpty() && !message.isEmpty()) { + return QString("MessageSummary\\provider:%1\\folder:%2\\id:%3").arg(escape(provider)).arg(escape(folder)).arg(escape(message)); + } else { + return QString(); + } +} + + +QString personAddPrefix(const QString& id) { + return QString("Person-%1").arg(id); +} + + +QString personQuery(const QString& provider, const QString& id) { + if (!provider.isEmpty() && ! id.isEmpty()) { + return QString("Person\\provider:%1\\id:%2").arg(escape(provider)).arg(escape(id)); + } else { + return QString(); + } +} + + +QString personRemovePrefix(const QString& id) { + if (id.startsWith(QLatin1String("Person-"))) { + QString person = QString(id).remove(0, 7); + return person; + } else { + return QString(); + } +} + + +QString personSelfQuery(const QString& provider) +{ + if (!provider.isEmpty()) { + return QString("PersonCheck\\provider:%1").arg(escape(provider)); + } else { + return QString(); + } +} + + +QString personSummaryQuery(const QString& provider, const QString& id) { + if (!provider.isEmpty() && ! id.isEmpty()) { + return QString("PersonSummary\\provider:%1\\id:%2").arg(escape(provider)).arg(escape(id)); + } else { + return QString(); + } +} + + +QString receivedInvitationsQuery(const QString& provider) { + if (!provider.isEmpty()) { + return QString("ReceivedInvitations\\provider:%1").arg(escape(provider)); + } else { + return QString(); + } +} + + +QString settingsQuery(const QString& provider, const QString& id) +{ + if (!provider.isEmpty()) { + return QString("Settings\\provider:%1\\id:%2").arg(escape(provider)).arg(escape(id)); + } else { + return QString(); + } +} diff --git a/kdeplasma-addons/applets/community/utils.h b/kdeplasma-addons/applets/community/utils.h new file mode 100644 index 00000000..a900c558 --- /dev/null +++ b/kdeplasma-addons/applets/community/utils.h @@ -0,0 +1,58 @@ +/* + This file is part of KDE. + + Copyright (c) 2009 Eckhart Wörner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef UTILS_H +#define UTILS_H + +#include + + +QString escape(const QString& value); + +QString friendsQuery(const QString& provider, const QString& id); + +QString messageAddPrefix(const QString& message); + +QString messageListQuery(const QString& provider, const QString& folder); + +QString messageListUnreadQuery(const QString& provider, const QString& folder); + +QString messageRemovePrefix(const QString& message); + +QString messageQuery(const QString& provider, const QString& folder, const QString& message); + +QString messageSummaryQuery(const QString& provider, const QString& folder, const QString& message); + +QString personAddPrefix(const QString& id); + +QString personQuery(const QString& provider, const QString& id); + +QString personRemovePrefix(const QString& id); + +QString personSelfQuery(const QString& provider); + +QString personSummaryQuery(const QString& provider, const QString& id); + +QString receivedInvitationsQuery(const QString& provider); + +QString settingsQuery(const QString& provider, const QString& id); + +#endif diff --git a/kdeplasma-addons/applets/dict/CMakeLists.txt b/kdeplasma-addons/applets/dict/CMakeLists.txt new file mode 100644 index 00000000..7a509b94 --- /dev/null +++ b/kdeplasma-addons/applets/dict/CMakeLists.txt @@ -0,0 +1,16 @@ +project(plasma-dict) + +INCLUDE_DIRECTORIES( + ${QT_QTWEBKIT_INCLUDE_DIR}) + +set(dict_SRCS + dict.cpp) + +kde4_add_plugin(plasma_applet_dict ${dict_SRCS}) +target_link_libraries(plasma_applet_dict ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS} +) + +install(TARGETS plasma_applet_dict DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES plasma-dict-default.desktop DESTINATION ${SERVICES_INSTALL_DIR}) + +kde4_install_icons(${ICON_INSTALL_DIR}) diff --git a/kdeplasma-addons/applets/dict/Messages.sh b/kdeplasma-addons/applets/dict/Messages.sh new file mode 100755 index 00000000..e4483a70 --- /dev/null +++ b/kdeplasma-addons/applets/dict/Messages.sh @@ -0,0 +1,2 @@ +#! /usr/bin/env bash +$XGETTEXT *.cpp -o $podir/plasma_applet_qstardict.pot diff --git a/kdeplasma-addons/applets/dict/TODO b/kdeplasma-addons/applets/dict/TODO new file mode 100644 index 00000000..0eb637bd --- /dev/null +++ b/kdeplasma-addons/applets/dict/TODO @@ -0,0 +1,8 @@ +TODO for dict applet + +Looks +Add clear button +Sliding animations +Configurable dictionaries +Migrate to layouts + diff --git a/kdeplasma-addons/applets/dict/dict.cpp b/kdeplasma-addons/applets/dict/dict.cpp new file mode 100644 index 00000000..1defe449 --- /dev/null +++ b/kdeplasma-addons/applets/dict/dict.cpp @@ -0,0 +1,401 @@ +/* + * Copyright (C) 2008 Nick Shaforostoff + * + * based on work by: + * Copyright (C) 2007 Thomas Georgiou and Jeff Cooper + * + * 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, see . + */ + +#include "dict.h" + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define AUTO_DEFINE_TIMEOUT 500 + +using namespace Plasma; + + + +// Style sheet format +const char* translationCSS = + "dl {color: %1;}\n" + "a{color: %2}\n" + "a:visited{color: %3}\n"; + +DictApplet::DictApplet(QObject *parent, const QVariantList &args) + : Plasma::PopupApplet(parent, args) + , m_graphicsWidget(0) + , m_wordEdit(0) +{ + setPopupIcon(QLatin1String( "accessories-dictionary" )); + setAspectRatioMode(Plasma::IgnoreAspectRatio); +} + +void DictApplet::init() +{ + const char* dataEngines[]={"dict","qstardict"}; + bool engineChoice = dataEngine(QString( QLatin1String( dataEngines[1] ) ) )->isValid(); +// bool engineChoice = false; //for testing + m_dataEngine = QLatin1String( dataEngines[int(engineChoice)] ); + + // tooltip stuff + Plasma::ToolTipContent toolTipData; + toolTipData.setAutohide(true); + toolTipData.setMainText(name()); + toolTipData.setImage(KIcon(QLatin1String( "accessories-dictionary" ))); + + Plasma::ToolTipManager::self()->setContent(this, toolTipData); + + // Only register the tooltip in panels + switch (formFactor()) { + case Plasma::Horizontal: + case Plasma::Vertical: + Plasma::ToolTipManager::self()->registerWidget(this); + break; + default: + Plasma::ToolTipManager::self()->unregisterWidget(this); + break; + } +} + +DictApplet::~DictApplet() +{ + m_defBrowser->deleteLater(); +} + +QGraphicsWidget *DictApplet::graphicsWidget() +{ + if (m_graphicsWidget) { + return m_graphicsWidget; + } + + m_wordEdit = new LineEdit(this); + m_wordEdit->nativeWidget()->setClearButtonShown( true ); + m_wordEdit->nativeWidget()->setClickMessage(i18n("Enter word to define here")); + m_wordEdit->show(); + + m_defBrowser = new Plasma::TextBrowser(); + m_defBrowser->nativeWidget()->setNotifyClick(true); + connect(m_defBrowser->nativeWidget(),SIGNAL(urlClick(QString)),this,SLOT(linkDefine(QString))); + syncTheme(); + connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(updateColors())); + m_defBrowser->hide(); + +// Icon in upper-left corner + m_icon = new Plasma::IconWidget(this); + m_icon->setIcon(QLatin1String( "accessories-dictionary" )); + +// Position lineedits + //const int wordEditOffset = 40; + m_icon->setPos(12,3); + //m_wordProxyWidget->setPos(15 + wordEditOffset,7); + //m_wordProxyWidget->show(); + // TODO m_wordEdit->setDefaultTextColor(Plasma::Theme::self()->color(Plasma::Theme::TextColor)); + +// Timer for auto-define + m_timer = new QTimer(this); + m_timer->setInterval(AUTO_DEFINE_TIMEOUT); + m_timer->setSingleShot(true); + connect(m_timer, SIGNAL(timeout()), this, SLOT(define())); + + m_horLayout = new QGraphicsLinearLayout(Qt::Horizontal); + m_horLayout->addItem(m_icon); + m_horLayout->addItem(m_wordEdit); + m_layout = new QGraphicsLinearLayout(Qt::Vertical); + m_layout->addItem(m_horLayout); + m_layout->addItem(m_defBrowser); + + m_source.clear(); + dataEngine(m_dataEngine)->connectSource(m_source, this); + connect(m_wordEdit, SIGNAL(editingFinished()), this, SLOT(define())); + connect(m_wordEdit->nativeWidget(), SIGNAL(textChanged(QString)), this, SLOT(autoDefine(QString))); + + dataEngine(m_dataEngine)->connectSource(QLatin1String( "list-dictionaries" ), this); + + //connect(m_defEdit, SIGNAL(linkActivated(QString)), this, SLOT(linkDefine(QString))); + +// This is the fix for links/selecting text + //QGraphicsItem::GraphicsItemFlags flags = m_defEdit->flags(); + //flags ^= QGraphicsItem::ItemIsMovable; + // m_defEdit->setFlags(flags); + + /*m_flash = new Plasma::Flash(this); + m_flash->setColor(Qt::gray); + QFont fnt = qApp->font(); + fnt.setBold(true); + m_flash->setFont(fnt); + m_flash->setPos(25,-10); + m_flash->resize(QSize(200,20));*/ + + configChanged(); + + m_graphicsWidget = new QGraphicsWidget(this); + m_graphicsWidget->setLayout(m_layout); + m_graphicsWidget->setPreferredSize(500, 200); + + Animation *zoomAnim = + Plasma::Animator::create(Plasma::Animator::ZoomAnimation); + zoomAnim->setTargetWidget(m_wordEdit); + zoomAnim->setProperty("zoom", 1.0); + zoomAnim->setProperty("duration", 350); + zoomAnim->start(QAbstractAnimation::DeleteWhenStopped); + + return m_graphicsWidget; +} + +void DictApplet::syncTheme() +{ + // Gets the color scheme from default theme + KColorScheme colorScheme(QPalette::Active, KColorScheme::View, Plasma::Theme::defaultTheme()->colorScheme()); + + m_defBrowser->nativeWidget()->document()->setDefaultStyleSheet(QString(QLatin1String( translationCSS )) + .arg(colorScheme.foreground().color().name()) + .arg(colorScheme.foreground(KColorScheme::LinkText).color().name()) + .arg(colorScheme.foreground(KColorScheme::VisitedText).color().name())); +} + +void DictApplet::configChanged() +{ + KConfigGroup cg = config(); + m_dicts = cg.readEntry("KnownDictionaries", QStringList()); + QStringList activeDictNames = cg.readEntry("ActiveDictionaries", QStringList()); + for (QStringList::const_iterator i = m_dicts.constBegin(); i != m_dicts.constEnd(); ++i) { + m_activeDicts[*i]=activeDictNames.contains(*i); + } +} + +void DictApplet::linkDefine(const QString &text) +{ + //kDebug() <<"ACTIVATED"; + m_wordEdit->setText(text); + define(); +} + +void DictApplet::dataUpdated(const QString& source, const Plasma::DataEngine::Data &data) +{ + if (source==QLatin1String( "list-dictionaries" )) { + QStringList newDicts = data[QLatin1String( "dictionaries" )].toStringList(); + bool changed = false; + for (QStringList::const_iterator i = newDicts.constBegin(); i != newDicts.constEnd(); ++i) { + if (!m_dicts.contains(*i)) { + m_dicts << *i; + m_activeDicts[*i] = true; + changed = true; + } + } + + QStringList::iterator it = m_dicts.begin(); + while (it != m_dicts.end()) { + if (!newDicts.contains(*it)) { + it = m_dicts.erase(it); + changed = true; + } else { + ++it; + } + } + + if (changed) { + configAccepted(); + } + } + + if (!m_source.isEmpty()) { + m_defBrowser->show(); + } + + if (data.contains(QLatin1String( "text" ))) { + m_defBrowser->nativeWidget()->setHtml(data[QLatin1String("text")].toString()); + } + + updateGeometry(); +} + +void DictApplet::define() +{ + if (m_timer->isActive()) { + m_timer->stop(); + } + + QString newSource = m_wordEdit->text(); + QStringList dictsList; + + for (QStringList::const_iterator i = m_dicts.constBegin(); i != m_dicts.constEnd(); ++i) { + if (m_activeDicts.contains(*i) && m_activeDicts.value(*i)) { + dictsList << *i; + } + } + + if (!newSource.isEmpty() && !dictsList.isEmpty()) { + newSource.prepend(dictsList.join(QLatin1String( "," ) )+QLatin1Char( ':' )); + } + + if (newSource == m_source) { + return; + } + + dataEngine(m_dataEngine)->disconnectSource(m_source, this); + + if (!newSource.isEmpty()) { + //get new definition + //m_flash->flash(i18n("Looking up ") + m_word); + m_source = newSource; + dataEngine(m_dataEngine)->connectSource(m_source, this); + } else { + //make the definition box disappear + m_defBrowser->hide(); + } + + updateConstraints(); +} + +void DictApplet::autoDefine(const QString &word) +{ + Q_UNUSED(word) + m_timer->start(); +} + + +class CheckableStringListModel: public QStringListModel +{ +public: + CheckableStringListModel(QObject* parent, const QStringList& dicts, const QHash& activeDicts_) + : QStringListModel(parent) + , activeDicts(activeDicts_) + { + setStringList(dicts); + } + QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const + { + Q_UNUSED(section) + Q_UNUSED(orientation) + + if (role!=Qt::DisplayRole) + return QVariant(); + return i18n("Dictionary"); + } + Qt::DropActions supportedDropActions() const {return Qt::MoveAction;} + Qt::ItemFlags flags(const QModelIndex& index) const + { + if (!index.isValid()) + return Qt::ItemIsEnabled | Qt::ItemIsDropEnabled; + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsDragEnabled; + } + bool setData (const QModelIndex& index, const QVariant& value, int role=Qt::EditRole) + { + if (role==Qt::CheckStateRole) + { + activeDicts[stringList().at(index.row())]=value.toInt()==Qt::Checked; + return true; + } + else + return QStringListModel::setData(index,value,role); + } + QVariant data(const QModelIndex& index, int role=Qt::EditRole) const + { + if (!index.isValid()) + return QVariant(); + + if (role==Qt::CheckStateRole) + return ( activeDicts.contains(stringList().at(index.row()))&&activeDicts.value(stringList().at(index.row())) )?Qt::Checked:Qt::Unchecked; + return QStringListModel::data(index,role); + } + +public: + QHash activeDicts; +}; + + +void DictApplet::createConfigurationInterface(KConfigDialog *parent) +{ + if (dataEngine(QLatin1String( "qstardict" ))->isValid()) { + QTreeView* widget=new QTreeView(parent); + widget->setDragEnabled(true); + widget->setAcceptDrops(true); + widget->setDragDropMode(QAbstractItemView::InternalMove); + widget->setDropIndicatorShown(true); + widget->setItemsExpandable(false); + widget->setAllColumnsShowFocus(true); + widget->setRootIsDecorated(false); + + delete m_dictsModel.data(); + CheckableStringListModel *model = new CheckableStringListModel(parent,m_dicts,m_activeDicts); + m_dictsModel = model; + widget->setModel(model); + + parent->addPage(widget, parent->windowTitle(), Applet::icon()); + connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted())); + connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted())); + } +} + +void DictApplet::popupEvent(bool shown) +{ + //kDebug() << shown; + if (shown && m_wordEdit) { + focusEditor(); + } +} + +void DictApplet::configAccepted() +{ + if (m_dictsModel) { + CheckableStringListModel *model = m_dictsModel.data(); + m_dicts = model->stringList(); + m_activeDicts = model->activeDicts; + } + KConfigGroup cg = config(); + cg.writeEntry("KnownDictionaries", m_dicts); + + QStringList activeDictNames; + for (QStringList::const_iterator i = m_dicts.constBegin(); i != m_dicts.constEnd(); ++i) + if (m_activeDicts.contains(*i) && m_activeDicts.value(*i)) + activeDictNames<<*i; + + cg.writeEntry("ActiveDictionaries", activeDictNames); + + define(); + emit configNeedsSaving(); +} + +void DictApplet::focusEditor() +{ + m_wordEdit->clearFocus(); + m_wordEdit->setFocus(); + m_wordEdit->nativeWidget()->clearFocus(); + m_wordEdit->nativeWidget()->setFocus(); +} + +#include "dict.moc" diff --git a/kdeplasma-addons/applets/dict/dict.h b/kdeplasma-addons/applets/dict/dict.h new file mode 100644 index 00000000..4910d1ec --- /dev/null +++ b/kdeplasma-addons/applets/dict/dict.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2008 Nick Shaforostoff + * + * based on work by: + * Copyright (C) 2007 Thomas Georgiou and Jeff Cooper + * + * 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, see . + */ + +#ifndef DICT_H +#define DICT_H + +#include +#include + +class QTimer; +class CheckableStringListModel; + +class QGraphicsLinearLayout; + +namespace Plasma +{ + class IconWidget; + class LineEdit; + class TextBrowser; +} + +class DictApplet: public Plasma::PopupApplet +{ + Q_OBJECT + public: + DictApplet(QObject *parent, const QVariantList &args); + ~DictApplet(); + void init(); + + QGraphicsWidget *graphicsWidget(); + void setPath(const QString&); + + public slots: + void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data); + void autoDefine(const QString &word); + void linkDefine(const QString &word); + void configChanged(); + + protected slots: + void define(); + void configAccepted(); + void focusEditor(); + void syncTheme(); + + protected: + void createConfigurationInterface(KConfigDialog *parent); + void popupEvent(bool shown); + + private: + QString m_source; + QTimer* m_timer; + QString m_dataEngine; + //QGraphicsPixmapItem *m_graphicsIcon; + QGraphicsWidget *m_graphicsWidget; + QGraphicsLinearLayout *m_layout; + QGraphicsLinearLayout *m_horLayout; + Plasma::LineEdit *m_wordEdit; + //Plasma::Flash *m_flash; +// QTextBrowser* m_defBrowser; + Plasma::TextBrowser* m_defBrowser; + Plasma::IconWidget *m_icon; + +// QList< QPair > m_dicts; + QWeakPointer m_dictsModel; + QStringList m_dicts; + QHash m_activeDicts; +}; + +K_EXPORT_PLASMA_APPLET(qstardict, DictApplet) + +#endif diff --git a/kdeplasma-addons/applets/dict/hisc-app-accessories-dictionary.svgz b/kdeplasma-addons/applets/dict/hisc-app-accessories-dictionary.svgz new file mode 100644 index 00000000..18df3a62 Binary files /dev/null and b/kdeplasma-addons/applets/dict/hisc-app-accessories-dictionary.svgz differ diff --git a/kdeplasma-addons/applets/dict/plasma-dict-default.desktop b/kdeplasma-addons/applets/dict/plasma-dict-default.desktop new file mode 100644 index 00000000..eb0f3953 --- /dev/null +++ b/kdeplasma-addons/applets/dict/plasma-dict-default.desktop @@ -0,0 +1,132 @@ +[Desktop Entry] +Name=Dictionary +Name[ar]=قاموس +Name[ast]=Diccionariu +Name[bs]=rječnik +Name[ca]=Diccionari +Name[ca@valencia]=Diccionari +Name[cs]=Slovník +Name[csb]=Slowôrz +Name[da]=Ordbog +Name[de]=Wörterbuch +Name[el]=Λεξικό +Name[en_GB]=Dictionary +Name[eo]=Vortaro +Name[es]=Diccionario +Name[et]=Sõnaraamat +Name[eu]=Hiztegia +Name[fi]=Sanakirja +Name[fr]=Dictionnaire +Name[ga]=Foclóir +Name[gl]=Dicionario +Name[he]=מילון +Name[hr]=Rječnik +Name[hu]=Szótár +Name[is]=Orðabók +Name[it]=Dizionario +Name[ja]=辞書 +Name[kk]=Сөздік +Name[km]=វចនានុក្រម +Name[ko]=사전 +Name[ku]=Ferheng +Name[lt]=Žodynas +Name[lv]=Vārdnīca +Name[mr]=शब्दकोश +Name[ms]=Kamus +Name[nb]=Ordbok +Name[nds]=Wöörbook +Name[nl]=Woordenboek +Name[nn]=Ordbok +Name[oc]=Diccionari +Name[pa]=ਡਿਕਸ਼ਨਰੀ +Name[pl]=Słownik +Name[pt]=Dicionário +Name[pt_BR]=Dicionário +Name[ro]=Dicționar +Name[ru]=Словарь +Name[sk]=Slovník +Name[sl]=Slovar +Name[sq]=Fjalori +Name[sr]=речник +Name[sr@ijekavian]=рјечник +Name[sr@ijekavianlatin]=rječnik +Name[sr@latin]=rečnik +Name[sv]=Ordlista +Name[th]=พจนานุกรม +Name[tr]=Sözlük +Name[ug]=لۇغەت +Name[uk]=Словник +Name[wa]=Motî +Name[x-test]=xxDictionaryxx +Name[zh_CN]=词典 +Name[zh_TW]=字典 +Comment=Look up the meaning of words and their translation into different languages +Comment[ar]=انظر معاني الكلمات و ترجمتها بلغات مختلفة +Comment[ast]=Gueta pol significáu de pallabres y la so traducción a delles llingües +Comment[bs]=Potražite značenja riječi i njihove prevode na različite jezike +Comment[ca]=Cerca el significat de paraules i la seva traducció en diferents idiomes +Comment[ca@valencia]=Cerca el significat de paraules i la seua traducció en diferents idiomes +Comment[cs]=Vyhledat význam slov a jejich překlad do různých jazyků +Comment[da]=Slå ords betydning op samt deres oversættelse til forskellige sprog. +Comment[de]=Die Bedeutung von Wörtern und ihre Übersetzung in verschiedene Sprachen nachschlagen +Comment[el]=Αναζήτηση σημασίας λέξεων και της μετάφρασης τους σε διάφορες γλώσσες +Comment[en_GB]=Look up the meaning of words and their translation into different languages +Comment[es]=Busca el significado de palabras y su traducción a varios idiomas +Comment[et]=Sõnade tähenduse ja nende tõlgete otsimine +Comment[eu]=Bilatu hitzen esanahia eta beraien itzulpena hizkuntza ezberdinetan +Comment[fi]=Etsi sanojen merkityksiä ja vastineita eri kielillä +Comment[fr]=Cherche la définition de mots et leur traduction dans différentes langues +Comment[ga]=Aimsigh sainmhíniú ar fhocail nó a n-aistriúcháin go teangacha eile +Comment[gl]=Procura o significado das palabras e a tradución a diferentes linguas +Comment[he]=מאפשר לחפש פירוש של מילים ואת התרגום שלהם בשפות שונות +Comment[hr]=Potraži značenje riječi i njihov prijevod na razne jezike +Comment[hu]=Szavak és jelentésük keresése különböző nyelveken +Comment[is]=Fletta upp skilgreiningum orða og þýðingum þeirra á ýmsar tungur +Comment[it]=Cerca il significato delle parole e la loro traduzione in diverse lingue +Comment[ja]=単語の意味や他の言語の訳語を調べます +Comment[kk]=Түрлі тілдердегі сөздерінің мәнін я аудармасын қарау +Comment[km]=រកមើល​អត្ថន័យ​របស់​ពាក្យ និង​ការ​បកប្រែ​របស់​ពួកគេ​ក្នុង​ភាសា​ផ្សេង +Comment[ko]=단어의 뜻을 찾고 다른 언어로 표시하기 +Comment[ku]=Wateya peyvan û wergerandina wan jê zimanên din re binihêre +Comment[lv]=Uzmeklē vārdu nozīmes un to tulkojumus dažādās valodās +Comment[mr]=शब्दांचे अर्थ व त्याचे वेगवेगळ्या भाषांमध्ये भाषांतर बघा +Comment[nb]=Slå opp betydningen av ord og deres oversettelse til forskjellige språk +Comment[nds]=De Verkloren vun Wöör un ehr Översetten na verscheden Spraken naslaan +Comment[nl]=Zoek de betekenis van woorden en hun vertaling in verschillende talen op +Comment[nn]=Slå opp ordtydingar og omsetjingar +Comment[pl]=Wyszukiwarka znaczeń wyrazów i ich tłumaczeń na inne języki +Comment[pt]=Procurar o significado das palavras e das suas traduções em várias línguas +Comment[pt_BR]=Procura o significado de palavras e a tradução para vários idiomas +Comment[ro]=Caută semnificația cuvintelor și traducerea acestora în diferite limbi +Comment[ru]=Поиск значений слов и их перевод на другие языки +Comment[sk]=Vyhľadanie významu slov a ich preklad do rôznych jazykov +Comment[sl]=Poiščite pomen besed in njihov prevod v druge jezike +Comment[sr]=Потражите значења речи и њихове преводе на различите језике +Comment[sr@ijekavian]=Потражите значења ријечи и њихове преводе на различите језике +Comment[sr@ijekavianlatin]=Potražite značenja riječi i njihove prevode na različite jezike +Comment[sr@latin]=Potražite značenja reči i njihove prevode na različite jezike +Comment[sv]=Slå upp betydelsen hos ord och deras översättning till olika språk +Comment[th]=ค้นหาความหมายของคำและการแปลความหมายในภาษาต่าง ๆ +Comment[tr]=Sözcüklerin farklı dillerdeki anlamına bakın +Comment[uk]=Погляньте на значення слів та на їхній переклад іншими мовами +Comment[wa]=Cachîz après çou k' volexhe dire les mots eyet leu ratournaedje dins sacwants lingaedjes +Comment[x-test]=xxLook up the meaning of words and their translation into different languagesxx +Comment[zh_CN]=查阅单词词义以及其不同语言的翻译 +Comment[zh_TW]=查看單字的意義與不同語言的翻譯 +Type=Service +Icon=accessories-dictionary + +X-KDE-ServiceTypes=Plasma/Applet +X-KDE-Library=plasma_applet_dict +X-KDE-PluginInfo-Author=The Plasma Team +X-KDE-PluginInfo-Email=plasma-devel@kde.org +X-KDE-PluginInfo-Name=dict +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-Category=Language +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true + +X-Plasma-Requires-FileDialog=Unused +X-Plasma-Requires-LaunchApp=Unused diff --git a/kdeplasma-addons/applets/eyes/CMakeLists.txt b/kdeplasma-addons/applets/eyes/CMakeLists.txt new file mode 100644 index 00000000..f4c90570 --- /dev/null +++ b/kdeplasma-addons/applets/eyes/CMakeLists.txt @@ -0,0 +1,19 @@ +project(eyes) + + +set(eyes_SRCS eyes.cpp) + +kde4_add_plugin(plasma_applet_eyes ${eyes_SRCS}) +target_link_libraries(plasma_applet_eyes + ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS}) + +install(TARGETS plasma_applet_eyes + DESTINATION ${PLUGIN_INSTALL_DIR}) + +install(FILES plasma-applet-eyes.desktop + DESTINATION ${SERVICES_INSTALL_DIR}) + +install(FILES eyes.svg + DESTINATION ${DATA_INSTALL_DIR}/desktoptheme/default/widgets/) + +kde4_install_icons(${ICON_INSTALL_DIR}) diff --git a/kdeplasma-addons/applets/eyes/eyes.cpp b/kdeplasma-addons/applets/eyes/eyes.cpp new file mode 100644 index 00000000..5a7229f7 --- /dev/null +++ b/kdeplasma-addons/applets/eyes/eyes.cpp @@ -0,0 +1,188 @@ +/*************************************************************************** + * Copyright 2008-2009 by Olivier Goffart * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "eyes.h" + +#include +#include + +#include +#include + +#include + +Eyes::Eyes(QObject *parent, const QVariantList &args) + : Plasma::Applet(parent, args) , timerInterval(50), previousMousePos(-1,-1) +{ + resize(192, 128); + + m_svg = new Plasma::Svg(this); + m_svg->setImagePath(QLatin1String( "widgets/eyes" )); + m_svg->setContainsMultipleImages(true); + + rightPupil = new Plasma::SvgWidget(this); + rightPupil->setSvg(m_svg); + rightPupil->setElementID(QLatin1String( "rightPupil" )); + + leftPupil = new Plasma::SvgWidget(this); + leftPupil->setSvg(m_svg); + leftPupil->setElementID(QLatin1String( "leftPupil" )); + + timerId = startTimer(50); + setAspectRatioMode(Plasma::IgnoreAspectRatio); + setHasConfigurationInterface(false); +} + +Eyes::~Eyes() +{ + +} + +void Eyes::constraintsEvent(Plasma::Constraints constraints) +{ + Q_UNUSED(constraints) + + if (constraints & Plasma::FormFactorConstraint) { + setBackgroundHints(NoBackground); + } + + if (constraints & Plasma::SizeConstraint) { + if(formFactor() == Plasma::Vertical) { + setMinimumSize(QSizeF(0, boundingRect().width()/1.5)); + setMaximumSize(QSizeF(-1, boundingRect().width()/1.5)); + } else if(formFactor() == Plasma::Horizontal) { + setMinimumSize(QSizeF(boundingRect().height()*1.5,0)); + setMaximumSize(QSizeF(boundingRect().height()*1.5,-1)); + } else { + setMinimumSize(QSizeF()); + setMaximumSize(QSizeF()); + } + + double pupilSize = qMin( qMin(boundingRect().width()/2, boundingRect().height()) / 5, + (boundingRect().width()/2 + boundingRect().height()) / 12); + + leftPupil->resize(pupilSize, pupilSize); + rightPupil->resize(pupilSize, pupilSize); + } + previousMousePos = QPoint(-1,-1); +} + +void Eyes::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, + const QRect &contentsRect) +{ + Q_UNUSED(option) + QRect rect = contentsRect; + rect.setWidth(rect.width()/2 - 2); + m_svg->paint(p, rect, QLatin1String( "leftEye" )); + rect.translate(rect.width() + 2*2 , 0); + m_svg->paint(p, rect, QLatin1String( "rightEye" )); +} + + + +static QPointF pupilPos( const QRectF &eyesRect, const QPointF &mousePos) +{ + const QPointF vect = mousePos - eyesRect.center(); //cursor position relative to the center of the eyes + const qreal abs_vect = vect.x() * vect.x() + vect.y() * vect.y(); + + if (qFuzzyCompare(vect.x() + 1 , qreal(1.0))) { + if (vect.y() > eyesRect.height()/2) { + return eyesRect.center() + QPoint( 0, eyesRect.height()/2); + } else if (vect.y() < -eyesRect.height()/2) { + return eyesRect.center() + QPoint( 0, -eyesRect.height()/2); + } else { + return mousePos; + } + } + + const qreal a = eyesRect.width() / 2; + const qreal b = eyesRect.height() / 2; + const qreal tan_alpha = vect.y() / vect.x(); + + /* + the pupil need to be on the intersection between the line + y = x * tan_alpha + and the ellipse + x^2/a^2 + y^2/b^2 + */ + + qreal x = a*b / sqrt(b*b + a*a * tan_alpha*tan_alpha); + if (vect.x() < 0) { + x = -x; + } + const qreal y = x*tan_alpha; + + if (abs_vect < (x * x) + (y * y)) { + return mousePos; + } + + return eyesRect.center() + QPointF(x, y); +} + +void Eyes::timerEvent(QTimerEvent *e) +{ + if (e->timerId() != timerId) { + Plasma::Applet::timerEvent(e); + return; + } + + QPoint absMousePos = QCursor::pos(); + + if (absMousePos == previousMousePos) { + if (timerInterval > 300) + return; + timerInterval += 50; + killTimer(timerId); + timerId = startTimer(timerInterval); + return; + } + + if (timerInterval != 50) { + timerInterval = 50; + killTimer(timerId); + timerId = startTimer(timerInterval); + } + + QGraphicsView *myview = view(); + if (!myview) { + return; + } + + previousMousePos = absMousePos; + //cursor position relative to the item coordonate + QPointF mousePos = mapFromScene( myview->mapToScene( myview->mapFromGlobal( absMousePos ) ) ); + + const QRectF bounding = boundingRect(); + const qreal paddingX = bounding.width() / 9; + const qreal paddingY = bounding.height() / 5; + + QRectF eyesRect = boundingRect(); + // left pupil + eyesRect.setWidth(eyesRect.width()/2 - 2); + leftPupil->setPos(pupilPos(eyesRect.adjusted(paddingX,paddingY,-paddingX,-paddingY), mousePos) + - leftPupil->boundingRect().center()); + + //right pupil + eyesRect.translate(eyesRect.width() + 2*2 , 0); + rightPupil->setPos(pupilPos(eyesRect.adjusted(paddingX,paddingY,-paddingX,-paddingY), mousePos) + - rightPupil->boundingRect().center()); +} + + +#include "eyes.moc" diff --git a/kdeplasma-addons/applets/eyes/eyes.h b/kdeplasma-addons/applets/eyes/eyes.h new file mode 100644 index 00000000..892cdda1 --- /dev/null +++ b/kdeplasma-addons/applets/eyes/eyes.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright 2008 by Olivier Goffart * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef EYES_H +#define EYES_H + +#include +#include +#include + +class Eyes : public Plasma::Applet +{ + Q_OBJECT + public: + Eyes(QObject *parent, const QVariantList &args); + ~Eyes(); + + void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect& contentsRect); + void constraintsEvent(Plasma::Constraints constraints); + + protected: + void timerEvent(QTimerEvent *); + Plasma::SvgWidget *leftPupil, *rightPupil; + int timerId; + int timerInterval; + QPoint previousMousePos; + Plasma::Svg *m_svg; +}; + +K_EXPORT_PLASMA_APPLET(eyes, Eyes) + +#endif diff --git a/kdeplasma-addons/applets/eyes/eyes.svg b/kdeplasma-addons/applets/eyes/eyes.svg new file mode 100644 index 00000000..fde42efb --- /dev/null +++ b/kdeplasma-addons/applets/eyes/eyes.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + diff --git a/kdeplasma-addons/applets/eyes/hi128-app-eyes.png b/kdeplasma-addons/applets/eyes/hi128-app-eyes.png new file mode 100644 index 00000000..9880ce64 Binary files /dev/null and b/kdeplasma-addons/applets/eyes/hi128-app-eyes.png differ diff --git a/kdeplasma-addons/applets/eyes/hi16-app-eyes.png b/kdeplasma-addons/applets/eyes/hi16-app-eyes.png new file mode 100644 index 00000000..b4594d84 Binary files /dev/null and b/kdeplasma-addons/applets/eyes/hi16-app-eyes.png differ diff --git a/kdeplasma-addons/applets/eyes/hi22-app-eyes.png b/kdeplasma-addons/applets/eyes/hi22-app-eyes.png new file mode 100644 index 00000000..0d865d94 Binary files /dev/null and b/kdeplasma-addons/applets/eyes/hi22-app-eyes.png differ diff --git a/kdeplasma-addons/applets/eyes/hi256-app-eyes.png b/kdeplasma-addons/applets/eyes/hi256-app-eyes.png new file mode 100644 index 00000000..e5330e8d Binary files /dev/null and b/kdeplasma-addons/applets/eyes/hi256-app-eyes.png differ diff --git a/kdeplasma-addons/applets/eyes/hi64-app-eyes.png b/kdeplasma-addons/applets/eyes/hi64-app-eyes.png new file mode 100644 index 00000000..79250b81 Binary files /dev/null and b/kdeplasma-addons/applets/eyes/hi64-app-eyes.png differ diff --git a/kdeplasma-addons/applets/eyes/hisc-app-eyes.svgz b/kdeplasma-addons/applets/eyes/hisc-app-eyes.svgz new file mode 100644 index 00000000..161bebde Binary files /dev/null and b/kdeplasma-addons/applets/eyes/hisc-app-eyes.svgz differ diff --git a/kdeplasma-addons/applets/eyes/plasma-applet-eyes.desktop b/kdeplasma-addons/applets/eyes/plasma-applet-eyes.desktop new file mode 100644 index 00000000..1bf0ed2a --- /dev/null +++ b/kdeplasma-addons/applets/eyes/plasma-applet-eyes.desktop @@ -0,0 +1,128 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Eyes +Name[ar]=أعين +Name[ast]=Güeyos +Name[bs]=oči +Name[ca]=Ulls +Name[ca@valencia]=Ulls +Name[cs]=Oči +Name[da]=Øjne +Name[de]=Augen +Name[el]=Μάτια +Name[en_GB]=Eyes +Name[eo]=Okuloj +Name[es]=Ojos +Name[et]=Silmad +Name[eu]=Begiak +Name[fi]=Silmät +Name[fr]=Yeux +Name[ga]=Eyes +Name[gl]=Ollos +Name[he]=עיניים +Name[hr]=Oči +Name[hu]=Szemek +Name[is]=Augu +Name[it]=Occhi +Name[ja]=Eyes +Name[kk]=Көздер +Name[km]=ភ្នែក +Name[ko]=눈 +Name[ku]=Çav +Name[lt]=Akys +Name[lv]=Acis +Name[mr]=डोळे +Name[nb]=Øyne +Name[nds]=Ogen +Name[nl]=Ogen +Name[nn]=Auge +Name[pa]=ਅੱਖਾਂ +Name[pl]=Oczy +Name[pt]=Olhos +Name[pt_BR]=Olhos +Name[ro]=Ochi +Name[ru]=Глазки +Name[sk]=Oči +Name[sl]=Oči +Name[sq]=Sytë +Name[sr]=очи +Name[sr@ijekavian]=очи +Name[sr@ijekavianlatin]=oči +Name[sr@latin]=oči +Name[sv]=Ögon +Name[th]=ดวงตา +Name[tr]=Gözler +Name[ug]=كۆز +Name[uk]=Очі +Name[wa]=Ouys +Name[x-test]=xxEyesxx +Name[zh_CN]=眼睛 +Name[zh_TW]=Eyes +Comment=XEyes clone +Comment[ar]=مستنسخ XEyes +Comment[ast]=Clon de XEyes +Comment[bs]=XEyes klon +Comment[ca]=Clon de l'XEyes +Comment[ca@valencia]=Clon de l'XEyes +Comment[cs]=Klon XEyes +Comment[da]=Klon af XEyes. +Comment[de]=XEyes-Klon +Comment[el]=Κλώνος του XEyes +Comment[en_GB]=XEyes clone +Comment[es]=Clon de XEyes +Comment[et]=XEyesi klooon +Comment[eu]=XEyes-en klona +Comment[fi]=XEyes-klooni +Comment[fr]=Clone de XEyes +Comment[ga]=Clón XEyes +Comment[gl]=Clon do XEyes +Comment[he]=עותק של XEyes +Comment[hr]=Klon XEyesa +Comment[hu]=XEyes-klón +Comment[is]=Klón af XAugu +Comment[it]=Clone di XEyes +Comment[ja]=XEyes のクローン +Comment[kk]=XEyes бағдаламаның клоны +Comment[km]=ក្លូន XEyes +Comment[ko]=마우스 커서를 따라다니는 눈 +Comment[ku]=Jibergirtî XEyes +Comment[lt]=XEyes klonas +Comment[lv]=XEyes klons +Comment[mr]=X-डोळे प्रतिकृती +Comment[nb]=Klone av XEyes +Comment[nds]=XEyes-Kloon +Comment[nl]=Kloon van XEyes +Comment[nn]=Klon av XEyes-programmet +Comment[pa]=XEyes ਕਲੋਨ +Comment[pl]=Klon XEyes +Comment[pt]=Clone do XEyes +Comment[pt_BR]=Clone do XEyes +Comment[ro]=Clonă XEyes +Comment[ru]=Аналог программы XEyes +Comment[sk]=Klon XEyes +Comment[sl]=Dvojnik XEyes +Comment[sr]=Клон Икс‑очију +Comment[sr@ijekavian]=Клон Икс‑очију +Comment[sr@ijekavianlatin]=Klon X‑očiju +Comment[sr@latin]=Klon X‑očiju +Comment[sv]=Klon av Xeyes +Comment[th]=เลียนแบบโปรแกรมดวงตา X +Comment[tr]=XEyes kopyası +Comment[uk]=Клон XEyes +Comment[wa]=Clône d' XEyes +Comment[x-test]=xxXEyes clonexx +Comment[zh_CN]=XEyes 克隆 +Comment[zh_TW]=XEyes 的複製品 +Icon=eyes +Type=Service +ServiceTypes=Plasma/Applet +X-KDE-Library=plasma_applet_eyes +X-KDE-PluginInfo-Author=Olivier Goffart +X-KDE-PluginInfo-Email=ogoffart@kde.org +X-KDE-PluginInfo-Name=eyes +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-License=GPL + +X-Plasma-Requires-FileDialog=Unused +X-Plasma-Requires-LaunchApp=Unused diff --git a/kdeplasma-addons/applets/fifteenPuzzle/CMakeLists.txt b/kdeplasma-addons/applets/fifteenPuzzle/CMakeLists.txt new file mode 100644 index 00000000..561992b1 --- /dev/null +++ b/kdeplasma-addons/applets/fifteenPuzzle/CMakeLists.txt @@ -0,0 +1,16 @@ +project(plasma-fifteenPuzzle) + +add_subdirectory(icons) +include_directories( ${KDE4_INCLUDES} ) + +set(fifteenPuzzle_SRCS src/fifteenPuzzle.cpp src/fifteen.cpp src/piece.cpp ) + +kde4_add_ui_files(fifteenPuzzle_SRCS src/fifteenPuzzleConfig.ui ) +kde4_add_plugin(plasma_applet_fifteenPuzzle ${fifteenPuzzle_SRCS}) + +target_link_libraries(plasma_applet_fifteenPuzzle ${KDE4_PLASMA_LIBS} ${KDE4_KIO_LIBS}) + + +install(TARGETS plasma_applet_fifteenPuzzle DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES plasma-applet-fifteenPuzzle.desktop DESTINATION ${SERVICES_INSTALL_DIR}) +install(FILES images/blanksquare.svg DESTINATION ${DATA_INSTALL_DIR}/desktoptheme/default/fifteenPuzzle/) diff --git a/kdeplasma-addons/applets/fifteenPuzzle/icons/CMakeLists.txt b/kdeplasma-addons/applets/fifteenPuzzle/icons/CMakeLists.txt new file mode 100644 index 00000000..106884f4 --- /dev/null +++ b/kdeplasma-addons/applets/fifteenPuzzle/icons/CMakeLists.txt @@ -0,0 +1 @@ +kde4_install_icons( ${ICON_INSTALL_DIR} ) diff --git a/kdeplasma-addons/applets/fifteenPuzzle/icons/hisc-app-fifteenpuzzle.svgz b/kdeplasma-addons/applets/fifteenPuzzle/icons/hisc-app-fifteenpuzzle.svgz new file mode 100644 index 00000000..357d355d Binary files /dev/null and b/kdeplasma-addons/applets/fifteenPuzzle/icons/hisc-app-fifteenpuzzle.svgz differ diff --git a/kdeplasma-addons/applets/fifteenPuzzle/images/blanksquare.svg b/kdeplasma-addons/applets/fifteenPuzzle/images/blanksquare.svg new file mode 100644 index 00000000..d99c68b8 --- /dev/null +++ b/kdeplasma-addons/applets/fifteenPuzzle/images/blanksquare.svg @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/kdeplasma-addons/applets/fifteenPuzzle/plasma-applet-fifteenPuzzle.desktop b/kdeplasma-addons/applets/fifteenPuzzle/plasma-applet-fifteenPuzzle.desktop new file mode 100644 index 00000000..913aa0cd --- /dev/null +++ b/kdeplasma-addons/applets/fifteenPuzzle/plasma-applet-fifteenPuzzle.desktop @@ -0,0 +1,129 @@ +[Desktop Entry] +Name=Fifteen Puzzle +Name[ar]=أحجية الخمسة عشر +Name[ast]=Frañetiestes de quince pieces +Name[bs]=Petnaest kvadrata +Name[ca]=Trencaclosques quinze +Name[ca@valencia]=Trencaclosques quinze +Name[cs]=Hra Patnáct +Name[csb]=Piãtnôsce pùzzlów +Name[da]=Puslespillet 15 +Name[de]=Fünfzehn Steine +Name[el]=Παζλ 15 κομματιών +Name[en_GB]=Fifteen Puzzle +Name[es]=Rompecabezas de quince piezas +Name[et]=Viieteistkümnemäng +Name[eu]=Hamabosteko buruhaustekoa +Name[fi]=Puzzle 15 +Name[fr]=Taquin +Name[ga]=Puzal Cúig Déag +Name[gl]=Quebracabezas de quince pezas +Name[he]=פאזל מספרים +Name[hr]=Fifteen Puzzle +Name[hu]=15-ös kirakó +Name[is]=Fimmtán púsl +Name[it]=Il gioco del quindici +Name[ja]=15 ピースパズル +Name[kk]='Он бес' ойны +Name[km]=ផ្ដុំ​រូបភាព​ ១៥ +Name[ko]=열다섯 조각 퍼즐 +Name[ku]=Peydanok 15 +Name[lt]=Penkiolika dalių +Name[lv]=Piecpadsmit gabali +Name[mr]=पंधरा कोडे +Name[nb]=Femten brikker +Name[nds]=Föffteihn Stücken +Name[nl]=Vijftien-puzzel +Name[nn]=Spelet femten +Name[pa]=ਪੰਦਰਾਂ ਬੁਝਾਰਤ +Name[pl]=Piętnaście kawałków +Name[pt]=Puzzle dos Quinze +Name[pt_BR]=Quebra-cabeça quinze +Name[ro]=Fifteen Puzzle +Name[ru]=Пятнашки +Name[sk]=Hra pätnástka +Name[sl]=Petnajst kosov +Name[sr]=петнаестица +Name[sr@ijekavian]=петнаестица +Name[sr@ijekavianlatin]=petnaestica +Name[sr@latin]=petnaestica +Name[sv]=Femtonspel +Name[th]=เกมเรียงสิบห้าชิ้น +Name[tr]=Onbeşli Yapboz +Name[uk]=Гра у п’ятнашки +Name[wa]=Puzeul des céncwantes +Name[x-test]=xxFifteen Puzzlexx +Name[zh_CN]=十五子拼图 +Name[zh_TW]=Fifteen 解謎遊戲 +Comment=Put the pieces in order +Comment[ar]=ضع القطع في مكانها الصحيح +Comment[ast]=Tente d'axeitar les pieces +Comment[bs]=Poređajte djeliće ispravnim redoslijedom +Comment[ca]=Poseu les peces en ordre +Comment[ca@valencia]=Poseu les peces en orde +Comment[cs]=Zkuste dílky správně poskládat +Comment[da]=Sæt brikkerne i orden. +Comment[de]=Bringen Sie die Teile in die richtige Reihenfolge +Comment[el]=Τοποθετήσετε τα κομμάτια στη θέση τους +Comment[en_GB]=Put the pieces in order +Comment[es]=Intente ordenar las piezas +Comment[et]=Tükikeste seadmine õigesse järjekorda +Comment[eu]=Piezak ordenean ipini +Comment[fi]=Pane palat järjestykseen +Comment[fr]=Remettez les pièces dans l'ordre +Comment[ga]=Cuir na píosaí in ord +Comment[gl]=Poña as pezas en orde +Comment[he]=סדר את החלקים לפי הסדר +Comment[hr]=Složite komadiće u niz +Comment[hu]=Rakja sorba a darabokat +Comment[is]=Raða hlutunum á sinn stað +Comment[it]=Rimetti i pezzi in ordine +Comment[ja]=15 個のピースを正しい順序に並べるパズル +Comment[kk]=Тастарды реттеу ойыны +Comment[km]=ដាក់​ចំណែក​ជា​លំដាប់ +Comment[ko]=조각을 순서대로 맞춰 보세요 +Comment[ku]=Perçe yan rêz bike +Comment[lt]=Sudėti tvarkingai detalės +Comment[lv]=Salieciet gabalus pareizā kārtībā +Comment[mr]=तुकडे क्रमाने लावा +Comment[nb]=Plasser brikkene i rekkefølge +Comment[nds]=Stücken in de Reeg bringen +Comment[nl]=Zet de stukken in de juiste volgorde +Comment[nn]=Flytt brikkene i rett rekkjefølgje +Comment[pa]=ਟੁਕੜਿਆਂ ਨੂੰ ਲੜੀਬੱਧ ਕਰੋ +Comment[pl]=Układanie kawałków w porządku +Comment[pt]=Colocar as peças por ordem +Comment[pt_BR]=Coloque as peças em ordem +Comment[ro]=Potriviți piesele +Comment[ru]=Головоломка: расположите клеточки по порядку +Comment[sk]=Skúste správne poskladať kúsky +Comment[sl]=Postavite kose v pravilni vrstni red +Comment[sr]=Поређајте делиће исправним редоследом +Comment[sr@ijekavian]=Поређајте дјелиће исправним редослиједом +Comment[sr@ijekavianlatin]=Poređajte djeliće ispravnim redoslijedom +Comment[sr@latin]=Poređajte deliće ispravnim redosledom +Comment[sv]=Placera brickorna i ordning +Comment[th]=เกมจัดเรียงชิ้นส่วนสิบห้าชิ้นให้ถูกลำดับ +Comment[tr]=Parçaları sıraya koyun +Comment[uk]=Спробуйте впорядкувати плитки +Comment[wa]=Metoz les pices en ôre +Comment[x-test]=xxPut the pieces in orderxx +Comment[zh_CN]=按顺序摆放拼图块 +Comment[zh_TW]=將數字依順序排好 +Icon=fifteenpuzzle +Type=Service +ServiceTypes=Plasma/Applet + +X-KDE-Library=plasma_applet_fifteenPuzzle +X-KDE-PluginInfo-Author=Jesper Thomschutz +X-KDE-PluginInfo-Email=jesperht@yahoo.com +X-KDE-PluginInfo-Name=fifteenPuzzle +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-Category=Fun and Games +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true + +X-Plasma-Requires-FileDialog=Unused +X-Plasma-Requires-LaunchApp=Unused diff --git a/kdeplasma-addons/applets/fifteenPuzzle/src/Messages.sh b/kdeplasma-addons/applets/fifteenPuzzle/src/Messages.sh new file mode 100755 index 00000000..bab24ae7 --- /dev/null +++ b/kdeplasma-addons/applets/fifteenPuzzle/src/Messages.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash +$EXTRACTRC *.ui >> rc.cpp +$XGETTEXT *.cpp -o $podir/plasma_applet_fifteenPuzzle.pot diff --git a/kdeplasma-addons/applets/fifteenPuzzle/src/fifteen.cpp b/kdeplasma-addons/applets/fifteenPuzzle/src/fifteen.cpp new file mode 100644 index 00000000..ebdcf2c0 --- /dev/null +++ b/kdeplasma-addons/applets/fifteenPuzzle/src/fifteen.cpp @@ -0,0 +1,405 @@ +/*************************************************************************** + * Copyright (C) 2007 by Jesper Thomschutz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "fifteen.h" +#include "piece.h" + +#include +#include +#include +#include + +#include +#include + +#include +#include + +Fifteen::Fifteen(QGraphicsItem* parent, int size) + : QGraphicsWidget(parent), + m_size(0), // this will immediately get overwritten by setSize(size) below, but needs an initial value + m_pixmap(0) +{ + m_pieces.resize(size*size); + m_splitPixmap = false; + m_numerals = true; + m_solved = true; + m_svg = new Plasma::Svg(); + setSize(size); + setCacheMode(DeviceCoordinateCache); +} + +Fifteen::~Fifteen() +{ + qDeleteAll(m_pieces); + delete m_svg; +} + + +void Fifteen::setSize(int size) +{ + if (m_size == size) { + return; + } + m_size = qMax(size, 1); + startBoard(); + setPreferredSize(48 * size, 48 * size); + setMinimumSize(24 * size, 24 * size); +} + +void Fifteen::setColor(const QColor& c) +{ + m_color = c; + updatePieces(); +} + +int Fifteen::size() const +{ + return m_size; +} + +const QColor& Fifteen:: color() const +{ + return m_color; +} + +void Fifteen::setPixmap(QPixmap *pixmap) +{ + m_pixmap = pixmap; + if (m_pixmap) { + updatePieces(); + updatePixmaps(); + } +} + +void Fifteen::updatePixmaps() +{ + if (!m_pixmap) { + return; + } + QSize size = m_pieces[0]->size().toSize() * m_size; + QPixmap copyPixmap = m_pixmap->scaled(size); + + for (int i = 0; i < m_size * m_size; i++) { + if (!m_pieces[i]) continue; + QRect rect = m_pieces[i]->boundingRect().toRect(); + // use the index of this piece in the solved puzzle to decide which pixmap + // tile to use; the index in the array (i) is just its current position + int index = m_pieces[i]->id() - 1; + int posX = (index % m_size) * rect.width(); + int posY = (index / m_size) * rect.height(); + + m_pieces[i]->setPartialPixmap(copyPixmap.copy(posX, posY, rect.width(), rect.height())); + } +} + +void Fifteen::startBoard() +{ + // abort the old puzzle if necessary (this resets the puzzle's timer) + if (!m_solved) { + emit aborted(); + } + qDeleteAll(m_pieces); + m_pieces.fill(NULL); + int d = m_size * m_size; + m_pieces.resize(d); + for (int i = 0; i < d; ++i) { + m_pieces[i] = new Piece(i+1, this, m_svg); + if (i == d - 1) { + m_blank = m_pieces[i]; + } else { + connect(m_pieces[i], SIGNAL(pressed(Piece*)), this, SLOT(piecePressed(Piece*))); + } + } + m_solved = true; + updatePieces(); + updatePixmaps(); +} + +void Fifteen::shuffle() +{ + // shuffle the array of pieces + qsrand(QTime::currentTime().msec()); + for (int i = m_size * m_size - 1; i > 0; i--) { + // choose a random number such that 0 <= rand <= i + int rand = qrand() % (i + 1); + qSwap(m_pieces[i], m_pieces[rand]); + } + + // make sure the new board is solveable + + // count the number of inversions + // an inversion is a pair of tiles at positions a, b where + // a < b but value(a) > value(b) + + // also count the number of lines the blank tile is from the bottom + int inversions = 0; + int blankRow = -1; + for (int i = 0; i < m_size * m_size; i++) { + if (m_pieces[i] == m_blank) { + blankRow = i / m_size; + continue; + } + for (int j = 0; j < i; j++) { + if (m_pieces[j] == m_blank) { + continue; + } + if (m_pieces[i]->id() < m_pieces[j]->id()) { + inversions++; + } + } + } + + if (blankRow == -1) { + kDebug() << "Unable to find row of blank tile"; + } + + // we have a solveable board if: + // size is odd: there are an even number of inversions + // size is even: the number of inversions is odd if and only if + // the blank tile is on an odd row from the bottom + bool solveable = (m_size % 2 == 1 && inversions % 2 == 0) || + (m_size % 2 == 0 && (inversions % 2 == 0) == ((m_size - blankRow) % 2 == 1)); + if (!solveable) { + // make the grid solveable by swapping two adjacent pieces around + int pieceA = 0; + int pieceB = 1; + if (m_pieces[pieceA] == m_blank) { + pieceA = m_size + 1; + } else if (m_pieces[pieceB] == m_blank) { + pieceB = m_size; + } + qSwap(m_pieces[pieceA], m_pieces[pieceB]); + } + + // move the pieces to their new locations + for (int i = 0; i < m_size * m_size; i++) { + if (m_pieces[i] == m_blank) { + // don't animate the blank piece + int width = contentsRect().width() / m_size; + int height = contentsRect().height() / m_size; + m_pieces[i]->setPos((i % m_size) * width, (i / m_size) * height); + } else { + movePiece(m_pieces[i], i % m_size, i / m_size); + } + } + + // assume the shuffle didn't result in a sorted board + // in the unlikely event that it did, the user just has to move a tile + // and put it back again to solve it + m_solved = false; + toggleBlank(false); + emit started(); +} + +void Fifteen::resizeEvent(QGraphicsSceneResizeEvent *event) +{ + Q_UNUSED(event); + + updatePieces(); + updatePixmaps(); +} + +void Fifteen::updateFont() +{ + int width = contentsRect().width() / m_size; + int height = contentsRect().height() / m_size; + + QString test = "99"; + int smallest = KGlobalSettings::smallestReadableFont().pixelSize(); + int fontSize = height / 3; + QFont f = font(); + f.setBold(true); + f.setPixelSize(fontSize); + + QFontMetrics fm(f); + QRect rect = fm.boundingRect(test); + while (rect.width() > width - 2 || rect.height() > height - 2) { + --fontSize; + f.setPixelSize(fontSize); + + if (fontSize <= smallest) { + f = KGlobalSettings::smallestReadableFont(); + break; + } + + fm = QFontMetrics(f); + rect = fm.boundingRect(test); + } + + m_font = f; +} + +void Fifteen::setShowNumerals(bool show) +{ + m_numerals = show; + updatePieces(); +} + +void Fifteen::setSvg(const QString &path, bool identicalPieces) +{ + m_svg->setImagePath(path); + m_numerals = m_numerals || identicalPieces; + updatePieces(); +} + +void Fifteen::updatePieces() +{ + updateFont(); + + QSizeF size = contentsRect().size(); + int width = size.width() / m_size; + int height = size.height() / m_size; + + for (int i = 0; i < m_size * m_size; ++i) { + m_pieces[i]->showNumeral(m_numerals); + m_pieces[i]->setSplitImage(m_pixmap != NULL); + m_pieces[i]->resize(QSizeF(width, height)); + m_pieces[i]->setPos((i % m_size) * width, (i / m_size) * height); + m_pieces[i]->setFont(m_font); + m_pieces[i]->update(); + } + + if (!m_pixmap) { + m_svg->resize(width, height); + } +} + +void Fifteen::checkSolved() +{ + bool sorted = true; + for (int i = 0; i < m_size * m_size; i++) { + if (m_pieces[i]->id() != i + 1) { + sorted = false; + break; + } + } + + if (m_solved && !sorted) { + // the board has already been solved, so the user is playing with tiles on a solved board + toggleBlank(false); + } else if (m_solved && sorted) { + // the user has finished playing with tiles on a solved board, and it is solved again + toggleBlank(true); + } else if (!m_solved && sorted) { + emit solved(); + m_solved = true; + toggleBlank(true); + } +} + +void Fifteen::piecePressed(Piece *item) +{ + int itemX = -1, itemY = -1, blankX = -1, blankY = -1; + for (int i = 0; i < m_size * m_size; i++) { + if (item == m_pieces[i]) { + itemX = i % m_size; + itemY = i / m_size; + } + if (m_blank == m_pieces[i]) { + blankX = i % m_size; + blankY = i / m_size; + } + } + + if (itemX == -1 || itemY == -1 || blankX == -1 || blankY == -1) { + kDebug() << "Missing piece!"; + return; + } + + if (blankX == itemX && blankY != itemY) { + while (blankY < itemY) { + swapPieceWithBlank(itemX, blankY + 1, blankX, blankY); + blankY++; + } + while (blankY > itemY) { + swapPieceWithBlank(itemX, blankY - 1, blankX, blankY); + blankY--; + } + } else if (blankY == itemY && blankX != itemX) { + while (blankX < itemX) { + swapPieceWithBlank(blankX + 1, itemY, blankX, blankY); + blankX++; + } + while (blankX > itemX) { + swapPieceWithBlank(blankX - 1, itemY, blankX, blankY); + blankX--; + } + } + + checkSolved(); +} + +void Fifteen::swapPieceWithBlank(int pieceX, int pieceY, int blankX, int blankY) +{ + Piece *piece = m_pieces[(pieceY * m_size) + pieceX]; + + int width = contentsRect().width() / m_size; + int height = contentsRect().height() / m_size; + QPointF pos = QPointF(pieceX * width, pieceY * height); + + // swap widget positions + movePiece(piece, blankX, blankY); + m_blank->setPos(pos); + + // swap game positions + qSwap(m_pieces[(pieceY * m_size) + pieceX], + m_pieces[(blankY * m_size) + blankX]); +} + +void Fifteen::movePiece(Piece *piece, int newX, int newY) +{ + int width = contentsRect().width() / m_size; + int height = contentsRect().height() / m_size; + QPointF pos = QPointF(newX * width, newY * height); + + // stop and delete any existing animation + Plasma::Animation *animation = m_animations.value(piece).data(); + if (animation) { + if (animation->state() == QAbstractAnimation::Running) { + animation->stop(); + } + delete animation; + animation = NULL; + } + animation = Plasma::Animator::create(Plasma::Animator::SlideAnimation, this); + animation->setTargetWidget(piece); + animation->setProperty("easingCurve", QEasingCurve::InOutQuad); + animation->setProperty("movementDirection", Plasma::Animation::MoveAny); + animation->setProperty("distancePointF", pos - piece->pos()); + m_animations[piece] = animation; + animation->start(QAbstractAnimation::DeleteWhenStopped); +} + +void Fifteen::toggleBlank(bool show) +{ + if (show) { + if (!m_blank->isVisible()) { + Plasma::Animation *animation = Plasma::Animator::create(Plasma::Animator::FadeAnimation, this); + animation->setProperty("startOpacity", 0.0); + animation->setProperty("targetOpacity", 1.0); + animation->setTargetWidget(m_blank); + animation->start(QAbstractAnimation::DeleteWhenStopped); + m_blank->show(); + } + } else { + m_blank->hide(); + } +} + diff --git a/kdeplasma-addons/applets/fifteenPuzzle/src/fifteen.h b/kdeplasma-addons/applets/fifteenPuzzle/src/fifteen.h new file mode 100644 index 00000000..2a27f5b1 --- /dev/null +++ b/kdeplasma-addons/applets/fifteenPuzzle/src/fifteen.h @@ -0,0 +1,85 @@ +/*************************************************************************** + * Copyright (C) 2007 by Jesper Thomschutz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef FIFTEEN_H +#define FIFTEEN_H + +#include +#include +#include + +#include + +class Piece; + +namespace Plasma +{ + class Animation; +} + +class Fifteen : public QGraphicsWidget +{ + Q_OBJECT + public: + Fifteen(QGraphicsItem *parent = 0, int size = 4); + ~Fifteen(); + void updatePieces(); + int size() const; + const QColor& color() const; + + signals: + void started(); + void solved(); + void aborted(); + + public slots: + void piecePressed(Piece *item); + void setSvg(const QString &path, bool identicalPieces); + void setPixmap(QPixmap *pixmap); + void updatePixmaps(); + void setShowNumerals(bool show); + void startBoard(); + void shuffle(); + void setSize(int i); + void setColor(const QColor& c); + + protected: + void resizeEvent(QGraphicsSceneResizeEvent * event); + + private: + void checkSolved(); + void updateFont(); + void drawPieces(); + void swapPieceWithBlank(int pieceX, int pieceY, int blankX, int blankY); + void movePiece(Piece *piece, int newX, int newY); + void toggleBlank(bool show); + int m_size; + QColor m_color; + QPixmap *m_pixmap; + bool m_solved; + QVector m_pieces; + Piece *m_blank; + Plasma::Svg *m_svg; + QFont m_font; + bool m_splitPixmap; + bool m_numerals; + QHash > m_animations; +}; + +#endif diff --git a/kdeplasma-addons/applets/fifteenPuzzle/src/fifteenPuzzle.cpp b/kdeplasma-addons/applets/fifteenPuzzle/src/fifteenPuzzle.cpp new file mode 100644 index 00000000..8a152898 --- /dev/null +++ b/kdeplasma-addons/applets/fifteenPuzzle/src/fifteenPuzzle.cpp @@ -0,0 +1,208 @@ +/*************************************************************************** + * Copyright (C) 2007 by Jesper Thomschutz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "fifteenPuzzle.h" + +//Qt +#include +#include + +//KDE +#include +#include + +//Plasma +#include + +static const char defaultImage[] = "fifteenPuzzle/blanksquare"; + +FifteenPuzzle::FifteenPuzzle(QObject *parent, const QVariantList &args) + : Plasma::PopupApplet(parent, args), + m_pixmap(0), + m_seconds(0) +{ + setHasConfigurationInterface(true); + setPopupIcon("fifteenpuzzle"); + + m_timer.setInterval(1000); + m_timer.setSingleShot(false); + connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateTimer())); + + m_graphicsWidget = new QGraphicsWidget(this); + QGraphicsAnchorLayout *layout = new QGraphicsAnchorLayout(); + m_graphicsWidget->setLayout(layout); + + m_board = new Fifteen(m_graphicsWidget); + connect(m_board, SIGNAL(started()), this, SLOT(startTimer())); + connect(m_board, SIGNAL(solved()), &m_timer, SLOT(stop())); + connect(m_board, SIGNAL(aborted()), this, SLOT(cancelTimer())); + layout->addAnchors(m_board, layout, Qt::Horizontal); + layout->addAnchor(m_board, Qt::AnchorTop, layout, Qt::AnchorTop); + + m_shuffleButton = new Plasma::PushButton(m_graphicsWidget); + m_shuffleButton->setText(i18n("Shuffle")); + m_shuffleButton->setIcon(KIcon("roll")); + m_shuffleButton->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed, + QSizePolicy::PushButton)); + connect(m_shuffleButton, SIGNAL(clicked()), m_board, SLOT(shuffle())); + layout->addAnchor(m_shuffleButton, Qt::AnchorTop, m_board, Qt::AnchorBottom); + layout->addCornerAnchors(m_shuffleButton, Qt::BottomLeftCorner, layout, Qt::BottomLeftCorner); + + m_timeLabel = new Plasma::Label(m_graphicsWidget); + m_timeLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed, + QSizePolicy::Label)); + updateTimerLabel(); + layout->addAnchor(m_timeLabel, Qt::AnchorTop, m_board, Qt::AnchorBottom); + layout->addCornerAnchors(m_timeLabel, Qt::BottomRightCorner, layout, Qt::BottomRightCorner); + + layout->addAnchor(m_shuffleButton, Qt::AnchorRight, m_timeLabel, Qt::AnchorLeft)->setSizePolicy(QSizePolicy::MinimumExpanding); +} + +void FifteenPuzzle::init() +{ + createMenu(); + + configChanged(); +} + +QGraphicsWidget* FifteenPuzzle::graphicsWidget() +{ + return m_graphicsWidget; +} + +void FifteenPuzzle::configChanged() +{ + KConfigGroup cg = config(); + + m_imagePath = cg.readEntry("ImagePath", QString()); + m_usePlainPieces = m_imagePath.isEmpty() || cg.readEntry("UsePlainPieces", true); + m_showNumerals = cg.readEntry("ShowNumerals", true); + + m_board->setColor(cg.readEntry("boardColor", QColor())); + m_board->setSize(qMax(4, cg.readEntry("boardSize", 4))); + + if (!m_usePlainPieces) { + if (!QFile::exists(m_imagePath)) { + // check if it exists in the theme + m_imagePath = Plasma::Theme::defaultTheme()->imagePath(m_imagePath); + } + if (m_imagePath.isEmpty()) { + m_usePlainPieces = true; + } else { + if (!m_pixmap) { + m_pixmap = new QPixmap(); + } + m_pixmap->load(m_imagePath); + m_board->setPixmap(m_pixmap); + } + } + if (m_usePlainPieces) { + m_board->setPixmap(0); + m_board->setSvg(QLatin1String(defaultImage), m_usePlainPieces); + m_showNumerals = true; + + delete m_pixmap; + m_pixmap = 0; + } + + m_board->setShowNumerals(m_showNumerals); +} + +void FifteenPuzzle::createConfigurationInterface(KConfigDialog *parent) +{ + QWidget *page = new QWidget(parent); + ui.setupUi(page); + parent->addPage(page, i18n("General"), icon()); + + connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted())); + connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted())); + + if (m_usePlainPieces) { + ui.rb_identical->setChecked(true); + } else { + ui.rb_split->setChecked(true); + } + ui.urlRequester->setUrl(m_imagePath); + ui.cb_showNumerals->setChecked(m_showNumerals); + ui.color->setColor(m_board->color()); + ui.size->setValue(m_board->size()); + + connect(ui.size, SIGNAL(valueChanged(int)), parent, SLOT(settingsModified())); + connect(ui.color, SIGNAL(activated(QColor)), parent, SLOT(settingsModified())); + connect(ui.rb_identical, SIGNAL(toggled(bool)), parent, SLOT(settingsModified())); + connect(ui.rb_split, SIGNAL(toggled(bool)), parent, SLOT(settingsModified())); + connect(ui.cb_showNumerals, SIGNAL(toggled(bool)), parent, SLOT(settingsModified())); +} + +void FifteenPuzzle::configAccepted() +{ + KConfigGroup cg = config(); + + cg.writeEntry("ShowNumerals", ui.cb_showNumerals->isChecked()); + cg.writeEntry("UsePlainPieces", ui.rb_identical->isChecked()); + cg.writeEntry("ImagePath", ui.urlRequester->url().path()); + cg.writeEntry("boardSize", ui.size->value()); + cg.writeEntry("boardColor", ui.color->color()); + + emit configNeedsSaving(); +} + +void FifteenPuzzle::startTimer() +{ + m_seconds = 0; + updateTimerLabel(); + m_timer.start(); +} + +void FifteenPuzzle::updateTimer() +{ + m_seconds++; + updateTimerLabel(); +} + +void FifteenPuzzle::cancelTimer() +{ + m_timer.stop(); + m_seconds = 0; + updateTimerLabel(); +} + +void FifteenPuzzle::updateTimerLabel() +{ + QString min = QString::number(m_seconds / 60).rightJustified(2, QLatin1Char('0'), false); + QString sec = QString::number(m_seconds % 60).rightJustified(2, QLatin1Char('0'), false); + m_timeLabel->setText(i18nc("The time since the puzzle started, in minutes and seconds", + "Time: %1:%2", min, sec)); +} + +void FifteenPuzzle::createMenu() +{ + QAction *shuffle = new QAction(i18n("Shuffle Pieces"), this); + m_actions.append(shuffle); + connect(shuffle, SIGNAL(triggered(bool)), m_board, SLOT(shuffle())); +} + +QList FifteenPuzzle::contextualActions() +{ + return m_actions; +} + + +#include "fifteenPuzzle.moc" + diff --git a/kdeplasma-addons/applets/fifteenPuzzle/src/fifteenPuzzle.h b/kdeplasma-addons/applets/fifteenPuzzle/src/fifteenPuzzle.h new file mode 100644 index 00000000..cf788538 --- /dev/null +++ b/kdeplasma-addons/applets/fifteenPuzzle/src/fifteenPuzzle.h @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (C) 2007 by Jesper Thomschutz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef FIFTEENPUZZLE_H +#define FIFTEENPUZZLE_H + +#include +#include +#include + +#include +#include + +#include "fifteen.h" +#include "ui_fifteenPuzzleConfig.h" + +class FifteenPuzzle : public Plasma::PopupApplet +{ + Q_OBJECT + public: + FifteenPuzzle(QObject *parent, const QVariantList &args); + + void init(); + virtual QList contextualActions(); + virtual QGraphicsWidget* graphicsWidget(); + protected slots: + void configAccepted(); + + public slots: + void configChanged(); + + private: + void updateTimerLabel(); + void createMenu(); + QGraphicsWidget *m_graphicsWidget; + QPixmap *m_pixmap; + Fifteen *m_board; + QList m_actions; + QTimer m_timer; + int m_seconds; + Plasma::Label *m_timeLabel; + Plasma::PushButton *m_shuffleButton; + bool m_usePlainPieces; + QString m_imagePath; + bool m_showNumerals; + Ui::fifteenPuzzleConfig ui; + + private slots: + void createConfigurationInterface(KConfigDialog *parent); + void startTimer(); + void updateTimer(); + void cancelTimer(); +}; + +K_EXPORT_PLASMA_APPLET(fifteenPuzzle, FifteenPuzzle) + +#endif diff --git a/kdeplasma-addons/applets/fifteenPuzzle/src/fifteenPuzzleConfig.ui b/kdeplasma-addons/applets/fifteenPuzzle/src/fifteenPuzzleConfig.ui new file mode 100644 index 00000000..ff82f331 --- /dev/null +++ b/kdeplasma-addons/applets/fifteenPuzzle/src/fifteenPuzzleConfig.ui @@ -0,0 +1,210 @@ + + + fifteenPuzzleConfig + + + + 0 + 0 + 306 + 112 + + + + Configure Fifteen Puzzle + + + + + + Size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + size + + + + + + + pieces wide + + + 4 + + + + + + + Use plain pieces: + + + true + + + + + + + + + + Use custom image: + + + + + + + false + + + Qt::NonModal + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 13 + 20 + + + + + + + + false + + + Show numerals: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + cb_showNumerals + + + + + + + + + false + + + + + + + + + + Qt::Vertical + + + + 70 + 0 + + + + + + + + + KUrlRequester + QFrame +
kurlrequester.h
+
+ + KColorCombo + QComboBox +
kcolorcombo.h
+
+
+ + + + rb_split + toggled(bool) + urlRequester + setEnabled(bool) + + + 152 + 106 + + + 284 + 109 + + + + + rb_split + toggled(bool) + color + setDisabled(bool) + + + 66 + 106 + + + 284 + 79 + + + + + rb_split + toggled(bool) + cb_showNumerals + setEnabled(bool) + + + 152 + 106 + + + 284 + 136 + + + + + rb_split + toggled(bool) + lb_showNumbers + setEnabled(bool) + + + 67 + 102 + + + 85 + 124 + + + + +
diff --git a/kdeplasma-addons/applets/fifteenPuzzle/src/piece.cpp b/kdeplasma-addons/applets/fifteenPuzzle/src/piece.cpp new file mode 100644 index 00000000..2efb72ec --- /dev/null +++ b/kdeplasma-addons/applets/fifteenPuzzle/src/piece.cpp @@ -0,0 +1,122 @@ +/*************************************************************************** + * Copyright (C) 2007 by Jesper Thomschutz * + * * + * 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 . * + ***************************************************************************/ + +// Thanks to ThomasZ and Jens B-W for making this prettier than just some +// off-centered text and gradients ;) + +#include "piece.h" + +#include +#include +#include +#include + +#include +#include "fifteen.h" + +Piece::Piece(int id, Fifteen* parent, Plasma::Svg* svg) + : QGraphicsWidget(parent) +{ + m_id = id; + m_numeral = true; + m_splitPixmap = false; + m_svg = svg; + m_fifteen = parent; + m_bg = new QGraphicsRectItem(this); + setCacheMode(DeviceCoordinateCache); +} + +int Piece::id() const +{ + return m_id; +} + +void Piece::setSplitImage(bool splitPixmap) +{ + m_splitPixmap = splitPixmap; +} + +void Piece::setPartialPixmap(QPixmap pixmap) +{ + m_partialPixmap.setPixmap(pixmap); + m_splitPixmap = true; +} + +void Piece::setFont(const QFont &font) +{ + m_font = font; +} + +void Piece::showNumeral(bool show) +{ + m_numeral = show; +} + +void Piece::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget) +{ + if (m_splitPixmap) { + m_partialPixmap.paint(painter, option, widget); + } else { + // here we assume that the svg has already been resized correctly by Fifteen::updatePixmaps() + QColor c(m_fifteen->color()); + c.setAlphaF(0.5); + painter->setBrush(c); + painter->drawRect(boundingRect()); + m_svg->paint(painter, QPointF(0, 0)); + } + + if (!m_numeral) { + return; + } + + painter->setFont(m_font); + + QFontMetrics m(m_font); + QString text = QString::number(m_id); + + QPen pen = painter->pen(); + + pen.setColor(QColor(0, 0, 0, 90)); + painter->setPen(pen); + painter->drawText((( size().width() / 2) - m.width(text) / 2) + 2, + (( size().height() / 2) + m.ascent() / 2) + 2, text); + + + pen.setColor(QColor(Qt::white)); + painter->setPen(pen); + painter->drawText(( size().width() / 2) - m.width(text) / 2, + ( size().height() / 2) + m.ascent() / 2, text); + +} + +void Piece::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_UNUSED(event); + if (event->button() != Qt::LeftButton) { + event->ignore(); + return; + } + + event->accept(); + emit pressed(this); +} + + + diff --git a/kdeplasma-addons/applets/fifteenPuzzle/src/piece.h b/kdeplasma-addons/applets/fifteenPuzzle/src/piece.h new file mode 100644 index 00000000..d0e58d0f --- /dev/null +++ b/kdeplasma-addons/applets/fifteenPuzzle/src/piece.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2007 by Jesper Thomschutz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef PIECE_H +#define PIECE_H + +#include +#include +#include + +#include + +class Fifteen; + +class Piece : public QGraphicsWidget +{ + Q_OBJECT + public: + Piece(int id, Fifteen * parent, Plasma::Svg *svg); + int id() const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + void showNumeral(bool show); + void setPartialPixmap(QPixmap pixmap); + void setSplitImage(bool splitPixmap); + void setFont(const QFont &font); + + private: + int m_id; + bool m_numeral; + bool m_splitPixmap; + QGraphicsPixmapItem m_partialPixmap; + QFont m_font; + Plasma::Svg *m_svg; + QGraphicsRectItem *m_bg; + Fifteen *m_fifteen; + + protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event); + + signals: + void pressed(Piece *item); +}; + +#endif diff --git a/kdeplasma-addons/applets/fileWatcher/CMakeLists.txt b/kdeplasma-addons/applets/fileWatcher/CMakeLists.txt new file mode 100644 index 00000000..dc680ecd --- /dev/null +++ b/kdeplasma-addons/applets/fileWatcher/CMakeLists.txt @@ -0,0 +1,12 @@ +project(plasma-fileWatcher) +include_directories( ${KDE4_INCLUDES} ) + +set(fileWatcher_SRCS fileWatcher.cpp fileWatcherTextItem.cpp) + +kde4_add_ui_files(fileWatcher_SRCS fileWatcherConfig.ui filtersConfig.ui) +kde4_add_plugin(plasma_applet_fileWatcher ${fileWatcher_SRCS}) + +target_link_libraries(plasma_applet_fileWatcher ${KDE4_PLASMA_LIBS} ${KDE4_KIO_LIBS}) + +install(TARGETS plasma_applet_fileWatcher DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES plasma-fileWatcher-default.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/kdeplasma-addons/applets/fileWatcher/Messages.sh b/kdeplasma-addons/applets/fileWatcher/Messages.sh new file mode 100755 index 00000000..720d6a5a --- /dev/null +++ b/kdeplasma-addons/applets/fileWatcher/Messages.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash +$EXTRACTRC *.ui >> rc.cpp +$XGETTEXT *.cpp -o $podir/plasma_applet_fileWatcher.pot diff --git a/kdeplasma-addons/applets/fileWatcher/fileWatcher.cpp b/kdeplasma-addons/applets/fileWatcher/fileWatcher.cpp new file mode 100644 index 00000000..3ac9fb90 --- /dev/null +++ b/kdeplasma-addons/applets/fileWatcher/fileWatcher.cpp @@ -0,0 +1,295 @@ +/*************************************************************************** + * Copyright (C) 2007 by Jesper Thomschutz * + * Simon Hausmann * + * Copyright (C) 2008 by Davide Bettio * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "fileWatcher.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include "fileWatcherTextItem.h" + +FileWatcher::FileWatcher(QObject *parent, const QVariantList &args) + : Plasma::Applet(parent, args), + file(new QFile(this)), + watcher(new KDirWatch(this)), + textItem(new FileWatcherTextItem(this)), + textStream(0) +{ + setAspectRatioMode(Plasma::IgnoreAspectRatio); + setHasConfigurationInterface(true); + resize(400, 200); +} + +FileWatcher::~FileWatcher() +{ + delete textStream; +} + +void FileWatcher::init() +{ + Plasma::ToolTipManager::self()->registerWidget(this); + textItem->moveBy(contentsRect().x(), contentsRect().y()); + textItem->setSize((int) contentsRect().width(), (int) contentsRect().height()); + textDocument = textItem->document(); + + QObject::connect(watcher, SIGNAL(dirty(QString)), this, SLOT(loadFile(QString))); + QObject::connect(watcher, SIGNAL(created(QString)), this, SLOT(loadFile(QString))); + QObject::connect(watcher, SIGNAL(deleted(QString)), this, SLOT(fileDeleted(QString))); + + configChanged(); + + updateRows(); + + textItem->update(); +} + +void FileWatcher::configChanged() +{ + KConfigGroup cg = config(); + + QString path = cg.readEntry("path", QString()); + setAssociatedApplicationUrls(KUrl(path)); + textItem->setDefaultTextColor(cg.readEntry("textColor", Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor))); + textItem->setFont(cg.readEntry("font", Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont))); + + m_filters = cg.readEntry("filters", QStringList()); + m_showOnlyMatches = cg.readEntry("showOnlyMatches", false); + m_useRegularExpressions = cg.readEntry("useRegularExpressions", false); + + if (path.isEmpty()) { + setConfigurationRequired(true, i18n("Select a file to watch.")); + } else { + loadFile(path); + } +} + +void FileWatcher::updateRows() +{ + QFontMetrics metrics(textItem->font()); + textDocument->setMaximumBlockCount((int) (contentsRect().height()) / metrics.height()); + + if (textStream){ + textDocument->clear(); + textItem->update(); + textStream->seek(0); + newData(); + } +} + +void FileWatcher::constraintsEvent(Plasma::Constraints constraints) +{ + if (constraints & Plasma::SizeConstraint){ + textItem->setSize((int) contentsRect().width(), (int) contentsRect().height()); + textItem->setPos(contentsRect().topLeft()); + updateRows(); + } + if (constraints & Plasma::FormFactorConstraint) { + const Plasma::FormFactor f = formFactor(); + if (f == Plasma::Planar || f == Plasma::MediaCenter) { + setMinimumSize(200, 100); + } else { + setMinimumSize(-1, -1); + } + } +} + +void FileWatcher::fileDeleted(const QString &path) +{ + delete textStream; + textStream = 0; + file->close(); + setConfigurationRequired(true, i18n("Could not open file: %1", path)); + textDocument->clear(); +} + +void FileWatcher::loadFile(const QString& path) +{ + if (path.isEmpty()) return; + + bool newFile = !textStream || m_currentPath != path; + + if (newFile) { + delete textStream; + textStream = 0; + watcher->removeFile(m_currentPath); + watcher->addFile(path); + file->close(); + + KMimeType::Ptr mimeType = KMimeType::findByFileContent(path); + if (!(mimeType->is("text/plain") || mimeType->name() == QLatin1String("application/x-zerosize"))) { + setConfigurationRequired(true, i18n("Cannot watch non-text file: %1", path)); + return; + } + + file->setFileName(path); + if (!file->open(QIODevice::ReadOnly | QIODevice::Text)){ + setConfigurationRequired(true, i18n("Could not open file: %1", path)); + return; + } + + textStream = new QTextStream(file); + + setConfigurationRequired(false); + Plasma::ToolTipContent toolTipData; + toolTipData.setMainText(path); + Plasma::ToolTipManager::self()->setContent(this, toolTipData); + m_currentPath = path; + textDocument->clear(); + } + + newData(); +} + +void FileWatcher::newData() +{ + QTextCursor cursor(textDocument); + cursor.movePosition(QTextCursor::End); + cursor.beginEditBlock(); + + QStringList list; + + { + //Slight speed optimization hack for bigger files. + //Doing this is faster than doing unnecessary insertText() + QString data = textStream->readAll(); + + if (data.isEmpty()) { + textStream->seek(0); + data = textStream->readAll(); + textDocument->clear(); + } + + QStringList tmpList = data.split('\n', QString::SkipEmptyParts); + //Add lines from the back into the file + for (int i = tmpList.size() - 1; i >= 0; --i){ + if (m_showOnlyMatches){ + for (int j = 0; j < m_filters.size(); ++j) + if (tmpList.at(i).contains(QRegExp(m_filters.at(j), Qt::CaseSensitive, m_useRegularExpressions ? QRegExp::RegExp : QRegExp::FixedString))){ + list.insert(0, tmpList.at(i)); + break; + } + } + else + list.insert(0, tmpList.at(i)); + + if (list.size() == textDocument->maximumBlockCount()) break; + } + } + + // go through the lines of readed block + for (int i = 0; i < list.size(); ++i){ + // insert new block before line, but skip insertion on beginning of document + // because we don't want empty space on first line + if (cursor.position() != 0){ + cursor.insertBlock(); + } + + cursor.insertText(list.at(i)); + } + + cursor.endEditBlock(); + emit sizeHintChanged(Qt::PreferredSize); +} + +void FileWatcher::createConfigurationInterface(KConfigDialog *parent) +{ + QWidget *widget = new QWidget(); + ui.setupUi(widget); + parent->addPage(widget, i18n("General"), icon()); + connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted())); + connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted())); + + ui.pathUrlRequester->setUrl(file->fileName()); + ui.fontRequester->setFont(textItem->font()); + ui.fontColorButton->setColor(textItem->defaultTextColor()); + + widget = new QWidget(); + filtersUi.setupUi(widget); + parent->addPage(widget, i18n("Filters"), icon()); + + filtersUi.filtersListWidget->setItems(m_filters); + filtersUi.showOnlyMatchesCheckBox->setChecked(m_showOnlyMatches); + filtersUi.useRegularExpressionsRadioButton->setChecked(m_useRegularExpressions); + + connect(ui.fontColorButton,SIGNAL(changed(QColor)),parent, SLOT(settingsModified())); + connect(ui.fontRequester,SIGNAL(fontSelected(QFont)),parent, SLOT(settingsModified())); + connect(ui.pathUrlRequester,SIGNAL(textChanged(QString)),parent, SLOT(settingsModified())); + connect(filtersUi.filtersListWidget,SIGNAL(changed()),parent, SLOT(settingsModified())); + connect(filtersUi.showOnlyMatchesCheckBox,SIGNAL(toggled(bool)),parent, SLOT(settingsModified())); + connect(filtersUi.useExactMatchRadioButton,SIGNAL(toggled(bool)),parent, SLOT(settingsModified())); + connect(filtersUi.useRegularExpressionsRadioButton,SIGNAL(toggled(bool)),parent, SLOT(settingsModified())); +} + +void FileWatcher::configAccepted() +{ + KConfigGroup cg = config(); + + QFileInfo file(ui.pathUrlRequester->url().toLocalFile()); + QString tmpPath; + + if (file.isFile()){ + tmpPath = file.absoluteFilePath(); + cg.writePathEntry("path", file.absoluteFilePath()); + } + + textItem->setFont(ui.fontRequester->font()); + cg.writeEntry("font", ui.fontRequester->font()); + + textItem->setDefaultTextColor(ui.fontColorButton->color()); + cg.writeEntry("textColor", ui.fontColorButton->color()); + + m_filters = filtersUi.filtersListWidget->items(); + cg.writeEntry("filters", m_filters); + + m_showOnlyMatches = filtersUi.showOnlyMatchesCheckBox->isChecked(); + cg.writeEntry("showOnlyMatches", m_showOnlyMatches); + + m_useRegularExpressions = filtersUi.useRegularExpressionsRadioButton->isChecked(); + cg.writeEntry("useRegularExpressions", m_useRegularExpressions); + + textItem->update(); + loadFile(tmpPath); + setAssociatedApplicationUrls(KUrl(tmpPath)); + + emit configNeedsSaving(); +} + +QSizeF FileWatcher::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const +{ + QSizeF hint = QGraphicsWidget::sizeHint(which, constraint); + if (which == Qt::PreferredSize) { + hint.setHeight(qMax((qreal)200.0, textItem->document()->size().height())); + } + + return hint; +} + +#include "fileWatcher.moc" diff --git a/kdeplasma-addons/applets/fileWatcher/fileWatcher.h b/kdeplasma-addons/applets/fileWatcher/fileWatcher.h new file mode 100644 index 00000000..c8ad34d3 --- /dev/null +++ b/kdeplasma-addons/applets/fileWatcher/fileWatcher.h @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright (C) 2007 by Jesper Thomschutz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef FILEWATCHER_H +#define FILEWATCHER_H + +#include +#include + +#include "ui_fileWatcherConfig.h" +#include "ui_filtersConfig.h" + +class QFile; +class QTextDocument; +class KDirWatch; +class FileWatcherTextItem; + + +class FileWatcher : public Plasma::Applet +{ + Q_OBJECT + + public: + FileWatcher(QObject *parent, const QVariantList &args); + ~FileWatcher(); + + void init(); + + protected: + void constraintsEvent(Plasma::Constraints constraints); + QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; + + + public slots: + void configChanged(); + + protected slots: + void configAccepted(); + + private slots: + void newData(); + void loadFile(const QString& path); + void fileDeleted(const QString& path); + + void createConfigurationInterface(KConfigDialog *parent); + + private: + void updateRows(); + + QFile *file; + KDirWatch *watcher; + FileWatcherTextItem *textItem; + QTextStream *textStream; + QTextDocument *textDocument; + + QString m_currentPath; + + QStringList m_filters; + bool m_showOnlyMatches; + bool m_useRegularExpressions; + + Ui::fileWatcherConfig ui; + Ui::filtersConfig filtersUi; +}; + +K_EXPORT_PLASMA_APPLET(fileWatcher, FileWatcher) + +#endif diff --git a/kdeplasma-addons/applets/fileWatcher/fileWatcherConfig.ui b/kdeplasma-addons/applets/fileWatcher/fileWatcherConfig.ui new file mode 100644 index 00000000..b3022136 --- /dev/null +++ b/kdeplasma-addons/applets/fileWatcher/fileWatcherConfig.ui @@ -0,0 +1,221 @@ + + + fileWatcherConfig + + + + 0 + 0 + 584 + 321 + + + + Configure File Watcher + + + + + + + 75 + true + + + + File + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 13 + 20 + + + + + + + + File: + + + pathUrlRequester + + + + + + + + 75 + true + + + + Font + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 13 + 22 + + + + + + + + Font: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Color: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + fontColorButton + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 389 + 71 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 13 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 13 + + + + + + + + Qt::NonModal + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 4 + + + + + + + + + KUrlRequester + QFrame +
kurlrequester.h
+ 1 +
+ + KFontRequester + QWidget +
kfontrequester.h
+
+ + KColorButton + QPushButton +
kcolorbutton.h
+
+
+ + +
diff --git a/kdeplasma-addons/applets/fileWatcher/fileWatcherTextItem.cpp b/kdeplasma-addons/applets/fileWatcher/fileWatcherTextItem.cpp new file mode 100644 index 00000000..7103e7ad --- /dev/null +++ b/kdeplasma-addons/applets/fileWatcher/fileWatcherTextItem.cpp @@ -0,0 +1,39 @@ +/*************************************************************************** + * Copyright (C) 2008 by Davide Bettio * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "fileWatcherTextItem.h" + +#include + +FileWatcherTextItem::FileWatcherTextItem(QGraphicsItem * parent) + : QGraphicsTextItem(parent) +{ } + +QRectF FileWatcherTextItem::boundingRect() const +{ + return QRectF(0, 0, m_w, m_h); +} + +void FileWatcherTextItem::setSize(int w, int h) +{ + m_w = w; + m_h = h; + + prepareGeometryChange(); +} diff --git a/kdeplasma-addons/applets/fileWatcher/fileWatcherTextItem.h b/kdeplasma-addons/applets/fileWatcher/fileWatcherTextItem.h new file mode 100644 index 00000000..8221c66b --- /dev/null +++ b/kdeplasma-addons/applets/fileWatcher/fileWatcherTextItem.h @@ -0,0 +1,42 @@ +/*************************************************************************** + * Copyright (C) 2008 by Davide Bettio * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + + +#ifndef FILEWATCHERTEXTITEM_H +#define FILEWATCHERTEXTITEM_H + +#include + +class FileWatcherTextItem : public QGraphicsTextItem +{ + Q_OBJECT + + public: + FileWatcherTextItem(QGraphicsItem * parent = 0); + void setSize(int w, int h); + + protected: + virtual QRectF boundingRect() const; + + private: + int m_w; + int m_h; +}; + +#endif diff --git a/kdeplasma-addons/applets/fileWatcher/filtersConfig.ui b/kdeplasma-addons/applets/fileWatcher/filtersConfig.ui new file mode 100644 index 00000000..8185d7ad --- /dev/null +++ b/kdeplasma-addons/applets/fileWatcher/filtersConfig.ui @@ -0,0 +1,219 @@ + + filtersConfig + + + + 0 + 0 + 641 + 431 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + false + + + + + + + false + + + + 75 + true + + + + Filters settings: + + + + + + + false + + + Use regular expressions + + + + + + + false + + + Use exact match + + + true + + + + + + + Qt::Vertical + + + + 20 + 25 + + + + + + + + false + + + + 75 + true + + + + Filters: + + + + + + + Show only lines that match filters + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 10 + + + + + + + + + KEditListWidget + QWidget +
keditlistwidget.h
+
+
+ + + + showOnlyMatchesCheckBox + toggled(bool) + label + setEnabled(bool) + + + 61 + 14 + + + 10 + 56 + + + + + showOnlyMatchesCheckBox + toggled(bool) + filtersListWidget + setEnabled(bool) + + + 170 + 15 + + + 161 + 105 + + + + + showOnlyMatchesCheckBox + toggled(bool) + label_2 + setEnabled(bool) + + + 69 + 17 + + + 12 + 345 + + + + + showOnlyMatchesCheckBox + toggled(bool) + useRegularExpressionsRadioButton + setEnabled(bool) + + + 76 + 17 + + + 177 + 368 + + + + + showOnlyMatchesCheckBox + toggled(bool) + useExactMatchRadioButton + setEnabled(bool) + + + 76 + 13 + + + 117 + 380 + + + + +
diff --git a/kdeplasma-addons/applets/fileWatcher/plasma-fileWatcher-default.desktop b/kdeplasma-addons/applets/fileWatcher/plasma-fileWatcher-default.desktop new file mode 100644 index 00000000..bfb7eead --- /dev/null +++ b/kdeplasma-addons/applets/fileWatcher/plasma-fileWatcher-default.desktop @@ -0,0 +1,129 @@ +[Desktop Entry] +Name=File Watcher +Name[ar]=مراقب الملفات +Name[ast]=Monitor de ficheros +Name[bs]=nadzirač datoteka +Name[ca]=Vigilant de fitxers +Name[ca@valencia]=Vigilant de fitxers +Name[cs]=Sledování souborů +Name[csb]=Òbzérôcz lopka +Name[da]=Filovervåger +Name[de]=Dateiüberwachung +Name[el]=Επόπτης αρχείου +Name[en_GB]=File Watcher +Name[es]=Monitor de archivos +Name[et]=Failijälgija +Name[eu]=Fitxategi begiralea +Name[fi]=Tiedostonkatselin +Name[fr]=Observateur de fichiers +Name[ga]=Fairtheoir Comhad +Name[gl]=Vixilante de ficheiros +Name[he]=צופה הקבצים +Name[hr]=Motritelj datoteka +Name[hu]=Fájlfigyelő +Name[is]=Skráavörður +Name[it]=Osservatore di file +Name[ja]=ファイルウォッチャー +Name[kk]=Файлды бақылау +Name[km]=កម្មវិធី​មើល​ឯកសារ +Name[ko]=파일 감시기 +Name[ku]=Şopandina Pelê +Name[lt]=Failų stebėtojas +Name[lv]=Failu novērotājs +Name[mr]=फाईल नोंदकर्ता +Name[nb]=Filovervåker +Name[nds]=Dateibeluern +Name[nl]=Bestandenvolger +Name[nn]=Filovervaking +Name[pa]=ਫਾਇਲ ਨਿਗਰਾਨ +Name[pl]=Monitorowanie plików +Name[pt]=Vigilante de Ficheiros +Name[pt_BR]=Monitor de arquivos +Name[ro]=Supraveghetor de fișiere +Name[ru]=Наблюдение за файлом +Name[sk]=Sledovač súborov +Name[sl]=Opazovalnik datotek +Name[sr]=надзирач фајлова +Name[sr@ijekavian]=надзирач фајлова +Name[sr@ijekavianlatin]=nadzirač fajlova +Name[sr@latin]=nadzirač fajlova +Name[sv]=Filövervakning +Name[th]=เฝ้าดูแฟ้ม +Name[tr]=Dosya Takipçisi +Name[uk]=Переглядач файлів +Name[wa]=Riwaiteu des fitchî +Name[x-test]=xxFile Watcherxx +Name[zh_CN]=文件观察器 +Name[zh_TW]=檔案監看器 +Comment=Watch for changes in specified files +Comment[ar]=راقب التغييرات في ملفات محددة +Comment[ast]=Avisa si hai cambeos nos ficheros indicaos +Comment[bs]=Pratite promjene u određenim datotekama +Comment[ca]=Vigila de canvis en els fitxers especificats +Comment[ca@valencia]=Vigila de canvis en els fitxers especificats +Comment[cs]=Sledování změn v zadaných souborech +Comment[da]=Overvåg ændringer i specificerede filer. +Comment[de]=Dateien auf Änderungen überwachen +Comment[el]=Παρακολούθηση τροποποιήσεων σε καθορισμένα αρχεία +Comment[en_GB]=Watch for changes in specified files +Comment[es]=Avisa si hay cambios en los archivos indicados +Comment[et]=Määratud failide muutuste jälgimine +Comment[eu]=Begiratu adierazitako fitxategietan egiten diren aldaketak +Comment[fi]=Seuraa tiedostojen muutoksia +Comment[fr]=Observe les modifications des fichiers spécifiés +Comment[ga]=Bí ag fairís ar athruithe i gcomhad áirithe +Comment[gl]=Vixía as modificacións en ficheiros específicos +Comment[he]=צפה בשינויים של קבצים +Comment[hr]=Motri promjene u navedenim datotekama +Comment[hu]=Kijelölt fájlok változásainak figyelése +Comment[is]=Fylgjast með breytingum á tilteknum skrám +Comment[it]=Osserva i cambiamenti nel file specificato +Comment[ja]=指定したファイルの変更を監視します +Comment[kk]=Таңдалған файлдардағы өзгерістерді бақылау +Comment[km]=មើល​ការ​ផ្លាស់ប្ដូរ​នៅ​ក្នុង​ឯកសារ​ដែល​បាន​បញ្ជាក់ +Comment[ko]=지정한 파일의 변화 감시하기 +Comment[ku]=Di pelên taybet de guherandinan bişopîne +Comment[lt]=Stebėti pakitimus nurodytuose failuose +Comment[lv]=Novēro izmaiņas norādītajos failos +Comment[mr]=निर्देशीत फाईल्समधील बदलांवर लक्ष ठेवा +Comment[nb]=Overvåk endringer i valgte filer +Comment[nds]=Angeven Dateien op Ännern beluern +Comment[nl]=Volg bepaalde bestanden en hun wijzigingen +Comment[nn]=Overvak filer etter endringar +Comment[pa]=ਖਾਸ ਫਾਇਲਾਂ ਲਈ ਬਦਲਾਅ ਉੱਤੇ ਰੱਖੋ ਨਿਗ੍ਹਾ +Comment[pl]=Monitorowanie zmian w danych plikach +Comment[pt]=Vigiar as modificações nos ficheiros indicados +Comment[pt_BR]=Monitora as alterações nos arquivos especificados +Comment[ro]=Urmărește fișierele specificate după modificări +Comment[ru]=Наблюдение за изменениями в выбранном файле +Comment[sk]=Sledovanie zmien v zadaných súboroch +Comment[sl]=Opazujte, če pride do sprememb v navedenih datotekah +Comment[sr]=Пратите промене у одређеним фајловима +Comment[sr@ijekavian]=Пратите промјене у одређеним фајловима +Comment[sr@ijekavianlatin]=Pratite promjene u određenim fajlovima +Comment[sr@latin]=Pratite promene u određenim fajlovima +Comment[sv]=Övervaka ändringar i angivna filer +Comment[th]=เฝ้าดูการเปลี่ยนแปลงของแฟ้มต่าง ๆ ตามที่ระบุ +Comment[tr]=Belirli bir dosyada yapılan değişiklikleri izleyin +Comment[uk]=Спостерігайте за змінами у вказаних файлах +Comment[wa]=Riwaitîz les candjmints dins des fitchîs specifyîs +Comment[x-test]=xxWatch for changes in specified filesxx +Comment[zh_CN]=观察指定文件的更改情况 +Comment[zh_TW]=監看指定檔案的變化 +Type=Service +X-KDE-ServiceTypes=Plasma/Applet +Icon=application-octet-stream + +X-KDE-Library=plasma_applet_fileWatcher +X-KDE-PluginInfo-Author=Jesper Thomschutz +X-KDE-PluginInfo-Email=jesperht@yahoo.com +X-KDE-PluginInfo-Name=fileWatcher +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-Category=File System +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true + +X-Plasma-Requires-FileDialog=Unused +X-Plasma-Requires-LaunchApp=Unused diff --git a/kdeplasma-addons/applets/frame/ARTWORK.TXT b/kdeplasma-addons/applets/frame/ARTWORK.TXT new file mode 100644 index 00000000..25dc892a --- /dev/null +++ b/kdeplasma-addons/applets/frame/ARTWORK.TXT @@ -0,0 +1,4 @@ +Default SVG artwork must have one object with ID "boundingRect" and another with ID "textArea". +"boundingRect" delimits image borders, while "textArea" is the area where the applet will draw text. + +The current (temporany) picture is a modified version of a Pedro Carbajal's artwork, used with permission by the author. It's licensed under GPL. \ No newline at end of file diff --git a/kdeplasma-addons/applets/frame/CMakeLists.txt b/kdeplasma-addons/applets/frame/CMakeLists.txt new file mode 100644 index 00000000..a1012dc2 --- /dev/null +++ b/kdeplasma-addons/applets/frame/CMakeLists.txt @@ -0,0 +1,34 @@ +project(plasma-frame) + +macro_optional_find_package(Kexiv2) +macro_log_feature(KEXIV2_FOUND "libkexiv2" "Library to access EXIF information" "http://www.kde.org" FALSE "0.2.0" "RECOMMENDED: Enables automatic rotation for frame applet" ) + +set(frame_SRCS + frame.cpp + slideshow.cpp + picture.cpp + imagescaler.cpp + imageloader.cpp + configdialog.cpp) + +kde4_add_ui_files(frame_SRCS imageSettings.ui appearanceSettings.ui) + +macro_bool_to_01(KEXIV2_FOUND HAVE_KEXIV2) + +kde4_add_plugin(plasma_applet_frame ${frame_SRCS}) + + +if(HAVE_KEXIV2) + include_directories( ${KEXIV2_INCLUDE_DIR} ) + set_source_files_properties(picture.cpp imageloader.cpp PROPERTIES + COMPILE_FLAGS -DHAVE_KEXIV2) + target_link_libraries(plasma_applet_frame ${KDE4_PLASMA_LIBS} ${KDE4_KIO_LIBS} ${KDE4_KFILE_LIBS} ${KEXIV2_LIBRARIES} ) +else (HAVE_KEXIV2) + target_link_libraries(plasma_applet_frame ${KDE4_PLASMA_LIBS} ${KDE4_KIO_LIBS} ${KDE4_KFILE_LIBS} ) +endif(HAVE_KEXIV2) + +install(TARGETS plasma_applet_frame DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES plasma-frame-default.desktop DESTINATION ${SERVICES_INSTALL_DIR}) +#install(FILES picture-frame-default.jpg DESTINATION ${DATA_INSTALL_DIR}/desktoptheme/default/widgets/) + +install(FILES picture-frame-default.jpg DESTINATION ${DATA_INSTALL_DIR}/plasma-applet-frame/) diff --git a/kdeplasma-addons/applets/frame/Messages.sh b/kdeplasma-addons/applets/frame/Messages.sh new file mode 100755 index 00000000..b2964ff8 --- /dev/null +++ b/kdeplasma-addons/applets/frame/Messages.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash +$EXTRACTRC *.ui >> rc.cpp +$XGETTEXT *.cpp -o $podir/plasma_applet_frame.pot diff --git a/kdeplasma-addons/applets/frame/TODO b/kdeplasma-addons/applets/frame/TODO new file mode 100644 index 00000000..4a5b1b13 --- /dev/null +++ b/kdeplasma-addons/applets/frame/TODO @@ -0,0 +1,27 @@ +TODO FOR 4.1: + +- clean the code: class Picture is added (28th January 2008), still to do is add slideshow code there +- comic-like engine to support many Pictures of The Day => in playground/base/plasma/engines/potd (started 1st February 2008) + +- clean the config dialog and take ideas from Desktop config (share some config settings?) - add recursive dirs as an option for slideshow (although beware of too many options) + +- right-click action: set as wallpaper for the current picture + +------------------ +Ideas about Wikimedia Commons Featured Pictures +http://commons.wikimedia.org/wiki/Commons:Featured_pictures +- get them as wallpapers +- make a package of them and set them as slideshow for screensaver or desktop slideshow +-> credits? +Any questions can be asked to Duesentrieb in #wikimedia-tools on IRC freenode and #wikimedia-tech for anything related to website access. Mailing lists: http://meta.wikimedia.org/wiki/Mailing_lists/overview +---------------- + + +IDEAS FOR THE FRAME APPLET + +- export the pic to Flickr +- display the album cover if the user is playing some music +- from leinir: http://farm1.static.flickr.com/135/328898823_ae9eb3dfd6_m.jpg +The images sort of scale down and fade in when the appear... then after thirty or so pictures are shown, the lower ones fade out again :) +- meta data: flip the pic and read metadata (date, size,...) and add your own comment + diff --git a/kdeplasma-addons/applets/frame/TODO-Tokamak2 b/kdeplasma-addons/applets/frame/TODO-Tokamak2 new file mode 100644 index 00000000..623bb822 --- /dev/null +++ b/kdeplasma-addons/applets/frame/TODO-Tokamak2 @@ -0,0 +1,145 @@ +TODO for KDE 4.3 +---------------- + +****** Tokamak 2 - Porto - February 2009 ******* +******* annma@kde.org ******** + +Reference: http://drop.io/annmakde/asset/frame-pdf + +*************************************************** +1) Junior Job (very easy) +---------------------- +Display picture name as a configuration option for static pictures +- in Settings dialog: add an option then 2 options: picture name or full path + +see frametest-url.tar.gz for starter +see http://bugs.kde.org/show_bug.cgi?id=173831 + + +2) Junior Job (very easy) +---------------------- +Match Settings dialog with Desktop Configuration dialog as +indicated in the pdf of Picture Frame for 4.3 + + +3) Junior Job (medium) (Nepomuk, Strigi and EXIF) +----------------------- +Based on frametest-back.tar.gz code, improve the displayed metadata for +the picture properties, based on what is displayed by GWenView. + +see frametest-back.tar.gz at +http://drop.io/annmakde/asset/frametest-back-tar-gz + +Make a dataengine to get the metadata from the file (so that could be +reused by other apps) + +Get all data from Nepomuk & Strigi. If Exif data is not in Nepomuk, then get it from EXIF +and save it in Nepomuk so next time it is there. +Resources: +http://xesam.org/specs/xesam-ontology-0.95.book.pdf - page 29 +http://api.kde.org/kdesupport-api/kdesupport-apidocs/soprano/html/namespaceSoprano_1_1Vocabulary_1_1Xesam.html +http://www.semanticdesktop.org/ontologies/nexif/ +http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/#Image + +For 4.4: user interaction with Nepomuk metadata, add, remove and change +tags,comment and rating. + + +4) Junior Job (easy) +-------------------- +Add Previous, Play/Pause, Next buttons in Slideshow mode to allow to skip +or play/pause the slideshow + +see frametest-buttons.tar.gz for starter +http://drop.io/annmakde/asset/frametest-buttons-tar-gz + +Annma: get a proper SVG pic from Nuno to do so + + +5) Junior Job (easy) (using Solid) +----------------------- +Implement for Comic - put a patch on kdereviewboard http://reviewboard.kde.org/ +Problem: when you are not connected, the comic displays nothing and never +checks further the state of connection. +- check about networking (see +http://api.kde.org/4.x-api/kdelibs-apidocs/solid/html/tutorial4.html) +to check status (if connected or not) then if not: use +http://api.kde.org/4.x-api/kdelibs-apidocs/solid/html/classSolid_1_1Networking_1_1Notifier.html +Solid::Networking::Notifier and signal void statusChanged (Solid::Networking::Status status) +to get the picture. + + +6) Junior Job (not assessed) +------------------------ +Set a fixed point for the Picture to always been drawn from there. +See bug http://bugs.kde.org/show_bug.cgi?id=183315 + + +7) Junior Job (not assessed) +------------------------- +Add transitions effects to the Slideshow mode +Use Qt 4.5 (current qt-copy and trunk) and Kinetic +use: git clone git://labs.trolltech.com/qt/kinetic +http://labs.trolltech.com/blogs/2008/11/06/welcome-to-kinetic/ + +see http://bugs.kde.org/show_bug.cgi?id=161645 + + +8) Speed up code (advanced) and clean code +------------------------------------------ +When reading pictures, use ThreadWaever +http://api.kde.org/4.x-api/kdelibs-apidocs/threadweaver/html/index.html +and cache the next picture (the QImage) or a batch of next pictures. + +Note: have a look at Desktop Wallpapers in Slideshow mode which already caches the +pictures. See in kdebase/workspace/plasma/wallpapers/ the classes Image and RenderThread + +Profiling tools: valgrind, callgrind, KCacheGrind (in kdesdk module) +You need valgrind from your distribution and KCacheGrind from your KDE source +(trunk or your distro). +Profile it using "plasmoidviewer frame" +Doc: http://blog.bepointbe.be/index.php/2008/10/19/30-a-bit-of-plasma-profiling + +Clean: separate the "get picture" part from the "paint picture" +Add doc comment in .h files. +Give better names and optimize code. + +Scaling: get the ratio of the frame and compare with the picture size. If close: use +smoothTransform, if too much to scale use a less demanding transform + +Get the 2 pictures into 2 children applets. + + +9) PoTD engine (Matías Szeftel) (arlekin on IRC) +------------------------------- +- see what providers are still active and what to add +- credits: what to display to fullfill the proper credits requierements +- GHNS access: how to make packages + where to put the KNS xml file (ftp.kde.org?) + write a HowTo add a new provider + +- cache picture until midnight then get the new picture + +- General Image Engine for comic and frame +==> arlekin and mat69 + +http://www.starobserver.org/ => Another APOD + + +10) Integrate Crystal +--------------------- +crystal is in playground/base/plasma/applets +and needs /playground/base/neopmuk-kde +Use Wikimedia classes to get data from Wikimedia websites for example +a batch of pictures from wikimedia-commons. + + +------------------------------------- + +Potential problems from using Kinetics + +- click to flip picture is also triggered by drop -> make a smal area as the click-to-flip? +- do not call update() + +- Another wish (not researched yet) +http://bugs.kde.org/show_bug.cgi?id=179960 \ No newline at end of file diff --git a/kdeplasma-addons/applets/frame/appearanceSettings.ui b/kdeplasma-addons/applets/frame/appearanceSettings.ui new file mode 100644 index 00000000..8022afd1 --- /dev/null +++ b/kdeplasma-addons/applets/frame/appearanceSettings.ui @@ -0,0 +1,202 @@ + + + AppearanceSettings + + + + 0 + 0 + 302 + 163 + + + + + + + Rounded corners: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + roundCheckBox + + + + + + + Shadow: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + shadowCheckBox + + + + + + + + 0 + 0 + + + + + + + true + + + + + + + Frame: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + frameCheckBox + + + + + + + + + + + + + + false + + + + 0 + 0 + + + + Frame color: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + changeFrameColor + + + + + + + false + + + + 0 + 0 + + + + + 70 + 90 + 130 + + + + + 70 + 90 + 130 + + + + + + + + Qt::Horizontal + + + + 109 + 21 + + + + + + + + + + + + + + + Qt::Vertical + + + + 99 + 153 + + + + + + + + + KColorButton + QPushButton +
kcolorbutton.h
+
+
+ + + + frameCheckBox + toggled(bool) + changeFrameColorLabel + setEnabled(bool) + + + 208 + 96 + + + 59 + 123 + + + + + frameCheckBox + toggled(bool) + changeFrameColor + setEnabled(bool) + + + 208 + 96 + + + 154 + 123 + + + + +
diff --git a/kdeplasma-addons/applets/frame/configdialog.cpp b/kdeplasma-addons/applets/frame/configdialog.cpp new file mode 100644 index 00000000..ef522246 --- /dev/null +++ b/kdeplasma-addons/applets/frame/configdialog.cpp @@ -0,0 +1,151 @@ +/*************************************************************************** + * Copyright (C) 2007 by Tobias Koenig * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "configdialog.h" + +#include + +#include +#include + +#include "picture.h" +#include "imagescaler.h" + +ConfigDialog::ConfigDialog(QWidget *parent) + : QObject(parent) +{ + m_picture = new Picture(this); + connect(m_picture, SIGNAL(pictureLoaded(QImage)), this, SLOT(pictureLoaded(QImage))); + + appearanceSettings = new QWidget(); + appearanceUi.setupUi(appearanceSettings); + + imageSettings = new QWidget(); + imageUi.setupUi(imageSettings); + + imageUi.addDirButton->setIcon(KIcon("list-add")); + imageUi.removeDirButton->setIcon(KIcon("list-remove")); + imageUi.slideShowDelay->setMinimumTime(QTime(0, 0, 1)); // minimum to 1 second + + QString monitorPath = KStandardDirs::locate("data", "kcontrol/pics/monitor.png"); + // Size of monitor image: 200x186 + // Geometry of "display" part of monitor image: (23,14)-[151x115] + imageUi.monitorLabel->setPixmap(QPixmap(monitorPath)); + imageUi.monitorLabel->setWhatsThis(i18n( + "This picture of a monitor contains a preview of " + "the picture you currently have in your frame.")); + m_preview = new QLabel(imageUi.monitorLabel); + m_preview->setScaledContents(true); + m_preview->setGeometry(23, 14, 151, 115); + m_preview->show(); + + connect(imageUi.picRequester, SIGNAL(urlSelected(KUrl)), this, SLOT(changePreview(KUrl))); + connect(imageUi.picRequester->comboBox(), SIGNAL(activated(QString)), this, SLOT(changePreview(QString))); +} + +ConfigDialog::~ConfigDialog() +{ +} + +void ConfigDialog::setRoundCorners(bool round) +{ + appearanceUi.roundCheckBox->setChecked(round); +} + +bool ConfigDialog::roundCorners() const +{ + return appearanceUi.roundCheckBox->isChecked(); +} + +void ConfigDialog::setRandom(bool random) +{ + imageUi.randomCheckBox->setChecked(random); +} + +bool ConfigDialog::random() const +{ + return imageUi.randomCheckBox->isChecked(); +} + +void ConfigDialog::setShadow(bool shadow) +{ + appearanceUi.shadowCheckBox->setChecked(shadow); +} + +bool ConfigDialog::shadow() const +{ + return appearanceUi.shadowCheckBox->isChecked(); +} + +void ConfigDialog::setShowFrame(bool show) +{ + appearanceUi.frameCheckBox->setChecked(show); +} + +bool ConfigDialog::showFrame() const +{ + return appearanceUi.frameCheckBox->isChecked(); +} + +void ConfigDialog::setFrameColor(const QColor& frameColor) +{ + appearanceUi.changeFrameColor->setColor(frameColor); +} + +QColor ConfigDialog::frameColor() const +{ + return appearanceUi.changeFrameColor->color(); +} + +void ConfigDialog::setCurrentUrl(const KUrl& currentUrl) +{ + imageUi.picRequester->setUrl(currentUrl); +} + +KUrl ConfigDialog::currentUrl() const +{ + return imageUi.picRequester->url(); +} + +void ConfigDialog::previewPicture(const QImage &image) +{ + ImageScaler *scaler = new ImageScaler(image, QRect(23, 14, 151, 115).size()); + connect(scaler, SIGNAL(scaled(QImage)), this, SLOT(previewScaled(QImage))); + QThreadPool::globalInstance()->start(scaler); +} + +void ConfigDialog::previewScaled(const QImage &image) +{ + m_preview->setPixmap(QPixmap::fromImage(image)); +} + +void ConfigDialog::changePreview(const KUrl &path) +{ + m_picture->setPicture(path); +} + +void ConfigDialog::pictureLoaded(QImage image) +{ + previewPicture(image); +} + +void ConfigDialog::changePreview(const QString &path) +{ + m_picture->setPicture(KUrl(path)); +} diff --git a/kdeplasma-addons/applets/frame/configdialog.h b/kdeplasma-addons/applets/frame/configdialog.h new file mode 100644 index 00000000..cb5d098d --- /dev/null +++ b/kdeplasma-addons/applets/frame/configdialog.h @@ -0,0 +1,77 @@ +/*************************************************************************** + * Copyright (C) 2007 by Tobias Koenig * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef CONFIGDIALOG_H +#define CONFIGDIALOG_H + +#include "ui_imageSettings.h" +#include "ui_appearanceSettings.h" + +#include "picture.h" + +class ConfigDialog : public QObject +{ + Q_OBJECT +public: + ConfigDialog(QWidget *parent); + ~ConfigDialog(); + // Appearance + /// Round corners for the frame + void setRoundCorners(bool round); + bool roundCorners() const; + /// Randomness for the slideshow + void setRandom(bool random); + bool random() const; + /// Set a shadow for the frame + void setShadow(bool round); + bool shadow() const; + /// Show the frame or not + void setShowFrame(bool show); + bool showFrame() const; + /// Frame Color + void setFrameColor(const QColor& frameColor); + QColor frameColor() const; + // Static Picture + void setCurrentUrl(const KUrl& currentUrl); + KUrl currentUrl() const; + /// Designer Config file + Ui::ImageSettings imageUi; + Ui::AppearanceSettings appearanceUi; + QWidget *imageSettings; + QWidget *appearanceSettings; + /// Image Preview + /// Allow to preview each new chosen picture + void previewPicture(const QImage &img); + +private slots: + /// Update preview when URL changes via the file dialog + void changePreview(const KUrl &); + /// Update preview when URL changes via the combobox + void changePreview(const QString &); + /// The image is loaded, update the preview + void pictureLoaded(QImage image); + /// The preview is scaled + void previewScaled(const QImage &); + +private: + Picture *m_picture; + QLabel *m_preview; +}; + +#endif diff --git a/kdeplasma-addons/applets/frame/frame.cpp b/kdeplasma-addons/applets/frame/frame.cpp new file mode 100644 index 00000000..3f1b8a2b --- /dev/null +++ b/kdeplasma-addons/applets/frame/frame.cpp @@ -0,0 +1,854 @@ +/*************************************************************************** + * Copyright 2007 by Anne-Marie Mahfouf * + * Copyright 2007 by Antonio Vinci * + * Copyright 2008 by Thomas Coopman * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "frame.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "configdialog.h" +#include "picture.h" +#include "slideshow.h" +#include "imagescaler.h" + +Frame::Frame(QObject *parent, const QVariantList &args) + : Plasma::Applet(parent, args), + m_configDialog(0), + m_slideFrame(0) +{ + setHasConfigurationInterface(true); + setAcceptDrops(true); + setAcceptsHoverEvents(true); + setCacheMode(QGraphicsItem::DeviceCoordinateCache); + resize(400, 300); + //make size()==contentssize(), resolves auto-shrinking once for all + setContentsMargins(0, 0, 0, 0); + m_mySlideShow = new SlideShow(this); + if (args.count()) { + m_currentUrl = args.value(0).toString(); + } else { + m_currentUrl = KUrl(); + } + setAssociatedApplicationUrls(m_currentUrl); + + m_updateTimer = new QTimer(this); + m_updateTimer->setSingleShot(true); + connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(delayedUpdateSize())); + + m_autoUpdateTimer = new QTimer(this); + m_autoUpdateTimer->setSingleShot(true); + connect(m_autoUpdateTimer, SIGNAL(timeout()), this, SLOT(reloadImage())); +} + +Frame::~Frame() +{ + m_autoUpdateTimer->stop(); +} + +void Frame::init() +{ + bool frameReceivedUrlArgs = false; + if (!m_currentUrl.isEmpty()) { + frameReceivedUrlArgs = true; + } + + m_currentDay = QDate::currentDate(); + + m_slideNumber = 0; + + // Frame & Shadow dimensions + m_frameOutline = 8; + m_swOutline = 8; + + // Initialize the slideshow timer + connect(m_mySlideShow, SIGNAL(pictureUpdated()), this, SLOT(scalePictureAndUpdate())); + + connect(&m_waitForResize, SIGNAL(timeout()), this, SLOT(scalePictureAndUpdate())); + m_waitForResize.setSingleShot(true); + m_waitForResize.setInterval(200); + + configChanged(); + + KConfigGroup cg = config(); + if (frameReceivedUrlArgs) { + cg.writeEntry("url", m_currentUrl); + emit configNeedsSaving(); + } + + m_menuPresent = false; + + QAction *openAction = action("run associated application"); + openAction->setIcon(SmallIcon("image-x-generic")); + openAction->setText(i18n("&Open Picture...")); + QAction *wallpaperAction = new QAction(KIcon("user-desktop"),i18n("Set as Wallpaper Image"), this); + actions.append(wallpaperAction); + connect(wallpaperAction, SIGNAL(triggered(bool)), this, SLOT(setImageAsWallpaper())); +} + +QList Frame::contextualActions() +{ + return actions; +} + +void Frame::setImageAsWallpaper() +{ + //setting current image of Picture frame as wallaper image + KUrl url; + + if (m_slideShow) { + url = m_mySlideShow->currentUrl(); + } else { + url = m_currentUrl; + } + + kDebug() << KMimeType::findByUrl(url).data()->name(); + + if (containment()->wallpaper() && containment()->wallpaper()->supportsMimetype(KMimeType::findByUrl(url).data()->name())) { + containment()->wallpaper()->setUrls(url); + } else { + KPluginInfo::List wallpaperList = containment()->wallpaper()->listWallpaperInfoForMimetype(KMimeType::findByUrl(url).data()->name()); + bool image = false; + foreach (const KPluginInfo &wallpaper, wallpaperList) { + if (wallpaper.pluginName() == "image") { + image = true; + break; + } + } + + if (image) { + containment()->setWallpaper("image"); + } else if (!wallpaperList.isEmpty()) { + containment()->setWallpaper(wallpaperList.at(0).name()); + } + + if (containment()->wallpaper()) { + containment()->wallpaper()->setUrls(url); + } + } +} + +void Frame::configChanged() +{ + // Get config values + KConfigGroup cg = config(); + m_frameColor = cg.readEntry("frameColor", QColor(70, 90, 130)); //theme? + m_frame = cg.readEntry("frame", false); + m_shadow = cg.readEntry("shadow", true); + m_roundCorners = cg.readEntry("roundCorners", false); + m_slideShow = cg.readEntry("slideshow", false); + m_random = cg.readEntry("random", false); + m_recursiveSlideShow = cg.readEntry("recursive slideshow", false); + m_slideShowPaths = cg.readEntry("slideshow paths", QStringList()); + m_slideshowTime = cg.readEntry("slideshow time", 60); // default to 1 minute + m_currentUrl = cg.readEntry("url", m_currentUrl); + setAssociatedApplicationUrls(m_currentUrl); + m_potdProvider = cg.readEntry("potdProvider", QString()); + m_potd = cg.readEntry("potd", false); + m_autoUpdateIntervall = cg.readEntry("autoupdate time", 0); + + initSlideShow(); +} + +void Frame::slotOpenPicture() +{ + if (!hasAuthorization("LaunchApp")) { + return; + } + KUrl url; + + if (m_slideShow) { + url = m_mySlideShow->currentUrl(); + } else { + url = m_currentUrl; + } + + if (!url.path().isEmpty()) { + new KRun(url, 0); + } +} + +void Frame::constraintsEvent(Plasma::Constraints constraints) +{ + if (constraints & Plasma::FormFactorConstraint) { + setBackgroundHints(Plasma::Applet::NoBackground); + if (formFactor() == Plasma::Horizontal) { + m_frameOutline = 0; + m_swOutline = 4; + } else if (formFactor() == Plasma::Vertical) { + m_frameOutline = 0; + m_swOutline = 4; + } else { + m_frameOutline = 8; + m_swOutline = 8; + //Restore widget geometry to image proportions + QSizeF sizeHint = contentSizeHint(); + if (sizeHint != geometry().size()) { + resize(sizeHint); + emit appletTransformedItself(); + } + } + m_updateTimer->start(400); + } + + if (constraints & Plasma::SizeConstraint) { + //If on panel, keep geometry to 4:3 ratio + if (formFactor() == Plasma::Vertical) { + setMinimumSize(QSizeF(0, contentsRect().width()/1.33)); + setMaximumSize(QSizeF(-1, contentsRect().width()/1.33)); + } else if (formFactor() == Plasma::Horizontal) { + setMinimumSize(QSizeF(contentsRect().height()*1.33,0)); + setMaximumSize(QSizeF(contentsRect().height()*1.33,-1)); + } else { + int min = 48; + if (m_shadow) { + min += m_swOutline; + } + if (m_frame) { + min += m_frameOutline; + } + setMinimumSize(QSizeF(min, min)); + setMaximumSize(QSizeF()); + } + + if (m_slideShow) { + checkSlideFrame(); + + int x = contentsRect().center().x() - (m_slideFrame->size().width() / 2); + int y = contentsRect().bottom() - m_slideFrame->size().height() - 5; + m_slideFrame->setPos(x, y); + } + + m_waitForResize.start(); + m_updateTimer->start(400); + } +} + +QSizeF Frame::contentSizeHint() const +{ + if (!m_pictureSize.isEmpty() && (formFactor() == Plasma::Planar || formFactor() == Plasma::MediaCenter)) { + const qreal maxSize = qMax(contentsRect().width(), contentsRect().height()); + QSize size = m_pictureSize; + size.scale(maxSize, maxSize, Qt::KeepAspectRatio); + return size; + } else { + return contentsRect().size(); + } +} + +QSizeF Frame::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const +{ + if (which != Qt::PreferredSize) { + return Applet::sizeHint(which, constraint); + } else { + return m_pictureSize; + } +} + +void Frame::scalePictureAndUpdate() +{ + QImage img = m_mySlideShow->image(); + ImageScaler *scaler = new ImageScaler(img, contentSizeHint().toSize()); + connect(scaler, SIGNAL(scaled(QImage)), this, SLOT(imageScaled(QImage))); + QThreadPool::globalInstance()->start(scaler); +} + +void Frame::imageScaled(const QImage &img) +{ + m_scaledImage = img; + updatePicture(); +} + +void Frame::updatePicture() +{ + m_pictureSize = m_mySlideShow->image().size(); + QSizeF sizeHint = contentSizeHint(); + int frameLines = qMin(m_frameOutline, (int)(sizeHint.height()/10)); + const QSize contentsSize = sizeHint.toSize(); + + if (m_currentUrl.url().isEmpty() && m_mySlideShow->currentUrl().isEmpty()) { + setAssociatedApplicationUrls(KUrl::List()); + } else { + setAssociatedApplicationUrls(m_mySlideShow->currentUrl()); + } + + if (sizeHint != geometry().size()) { + emit sizeHintChanged(Qt::PreferredSize); + resize(sizeHint); + } + + kDebug() << "Rendering picture"; + Plasma::ToolTipContent toolTipData; + toolTipData.setSubText(m_mySlideShow->currentUrl().fileName()); + Plasma::ToolTipManager::self()->setContent(this, toolTipData); + + // create a QPixmap which can be drawn in paintInterface() + QPixmap picture = QPixmap::fromImage(m_scaledImage); + + if (picture.isNull()) { + return; + } + + m_pixmap = QPixmap(contentsSize); + m_pixmap.fill(Qt::transparent); + QPainter *p = new QPainter(); + p->begin(&m_pixmap); + + int roundingFactor = qMin(qreal(sizeHint.height() / 10), qreal(12.0)) * m_roundCorners; + int swRoundness = roundingFactor + frameLines / 2 * m_frame * m_roundCorners; + + QRectF frameRect(QPoint(0, 0), contentsSize); + frameRect.adjust(m_swOutline, m_swOutline, -m_swOutline, -m_swOutline); //Pretty useless. + + QSizeF scaledSize = frameRect.size(); + scaledSize.scale(frameRect.size(), Qt::KeepAspectRatio); + frameRect = QRectF(QPoint(frameRect.x() + (frameRect.width() - scaledSize.width()) / 2, + frameRect.y() + (frameRect.height() - scaledSize.height()) / 2), scaledSize); + + QRectF shadowRect; + if (m_frame) { + shadowRect = frameRect.adjusted(-frameLines, -frameLines, + frameLines, frameLines); + } else { + shadowRect = frameRect; + } + + // The frame path. It will be used to draw the frame and clip the image. + QPainterPath framePath = Plasma::PaintUtils::roundedRectangle(frameRect, roundingFactor); + + p->setRenderHint(QPainter::SmoothPixmapTransform, true); + p->setRenderHint(QPainter::Antialiasing, true); + + // Shadow + if (m_shadow) { + // The shadow is a couple of lines with decreasing opacity painted around the path + p->setBrush(Qt::NoBrush); + QPen pen = QPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin); + int shadowLines = qMin((int)(sizeHint.height() / 6), m_swOutline); + + // The shadow is drawn from inside to the outside + shadowRect.adjust(+shadowLines, +shadowLines, -shadowLines, -shadowLines); + + // Make the path to paint the frame in a bit smaller so it's inside the shadow + frameRect.adjust(+shadowLines, +shadowLines, -shadowLines, -shadowLines); + framePath = Plasma::PaintUtils::roundedRectangle(frameRect, roundingFactor); + + // Paint the shadow's lines around the picture + for (int i = m_swOutline - shadowLines; i <= m_swOutline; i += 1) { + // It's important to change the opacity using the QColor, as + // QPainter->setOpacity() kills performance + qreal opacity = 0.7 * exp(-(i / (double)(m_swOutline / 3))); + pen.setColor(QColor(0, 0, 0, opacity * 254)); + p->setPen(pen); + QPainterPath tr = Plasma::PaintUtils::roundedRectangle(shadowRect, swRoundness + i); + p->drawPath(tr); + shadowRect.adjust(-1, -1, + 1, + 1); + } + } + + p->setBrush(Qt::NoBrush); + + // Frame + if (m_frame) { + m_frameColor.setAlphaF(0.5); + // The frame is painted twice as thick, the inner half lies behind the picture + // This is important to not make the corners look "cut out" when rounded + p->setPen(QPen(m_frameColor, frameLines * 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); + p->drawPath(framePath); + } + + // Picture + // We save the painter here so the clipping only happens on the pixmap, + // not on pixmap, frame, shadow, etc + p->save(); + if (m_roundCorners) { + p->setClipPath(framePath); + } + + // Respect the smoothScaling setting + p->setRenderHint(QPainter::SmoothPixmapTransform, true); + // draw our pixmap into the computed rectangle + p->drawPixmap(frameRect.toRect(), picture); + p->restore(); + + // black frame + if (m_frame) { + p->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + p->drawPath(framePath); + } else if (m_roundCorners) { + p->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + p->drawPath(framePath); + } + + // Paint status text on top of it all + if (!m_mySlideShow->message().isEmpty()) { + int dist = frameRect.width() / 10; + QRect bgRect = frameRect.adjusted(dist-1, dist-1, -dist, -dist).toRect(); + + // The text's background rounded rectangle + QPainterPath bgPath = Plasma::PaintUtils::roundedRectangle(bgRect, bgRect.height()/15); + + QColor c = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor); + c.setAlphaF(.3); + QColor outline = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor); + outline.setAlphaF(.5); + p->setBrush(c); + p->setPen(outline); + p->setPen(QPen(outline, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + p->drawPath(bgPath); + QString message = m_mySlideShow->message(); + + // Set the font and draw text + p->setRenderHint(QPainter::Antialiasing); + QFont textFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont); + textFont.setPointSize(qMax(KGlobalSettings::smallestReadableFont().pointSize(), bgRect.height() / 6)); + p->setFont(textFont); + + QTextOption option; + option.setAlignment(Qt::AlignCenter); + option.setWrapMode(QTextOption::WordWrap); + + preparePainter(p, bgRect, textFont, message); + + p->setPen(QPen(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + p->drawText(bgRect, message, option); + } + + p->end(); + delete p; + update(); + + if (m_doAutoUpdate && !m_autoUpdateTimer->isActive()) { + kDebug() << "Autoupdate timer restarted:" << m_autoUpdateIntervall << "s"; + m_autoUpdateTimer->start(m_autoUpdateIntervall * 1000); + } +} + +QRect Frame::preparePainter(QPainter *p, const QRect &rect, const QFont &font, const QString &text) +{ + QRect tmpRect; + QFont tmpFont = font; + bool first = true; + + // Starting with the given font, decrease its size until it'll fit in the + // given rect allowing wrapping where possible + do { + if (first) { + first = false; + } else { + tmpFont.setPointSize(qMax(KGlobalSettings::smallestReadableFont().pointSize(), tmpFont.pointSize() - 1)); + } + + const QFontMetrics fm(tmpFont); + int flags = Qt::TextWordWrap; + + tmpRect = fm.boundingRect(rect, flags, text); + } while (tmpFont.pointSize() > KGlobalSettings::smallestReadableFont().pointSize() && + (tmpRect.width() > rect.width() || tmpRect.height() > rect.height())); + + p->setFont(tmpFont); + return tmpRect; +} + + +void Frame::nextPicture() +{ + m_mySlideShow->setUpdateInterval(0); + m_mySlideShow->nextPicture(); + m_mySlideShow->setUpdateInterval(m_slideshowTime * 1000); +} + +void Frame::previousPicture() +{ + m_mySlideShow->setUpdateInterval(0); + m_mySlideShow->previousPicture(); + m_mySlideShow->setUpdateInterval(m_slideshowTime * 1000); +} + +void Frame::addDir() +{ + QPointer dialog = new KDirSelectDialog(KUrl(), true); + if (dialog->exec()) { + QString path = dialog->url().url(); + if (!m_slideShowPaths.contains(path)) { + m_configDialog->imageUi.slideShowDirList->addItem(path); + } + updateButtons(); + } + delete dialog; +} + +void Frame::removeDir() +{ + int row = m_configDialog->imageUi.slideShowDirList->currentRow(); + if (row != -1) { + m_configDialog->imageUi.slideShowDirList->takeItem(row); + updateButtons(); + } +} + +void Frame::updateButtons() +{ + int row = m_configDialog->imageUi.slideShowDirList->currentRow(); + m_configDialog->imageUi.removeDirButton->setEnabled(row != -1); +} + +void Frame::createConfigurationInterface(KConfigDialog *parent) +{ + m_configDialog = new ConfigDialog(parent); + + KService::List services = KServiceTypeTrader::self()->query("PlasmaPoTD/Plugin"); + foreach(const KService::Ptr &service, services) { + const QString service_name(service->name()); + const QVariant service_identifier(service->property("X-KDE-PlasmaPoTDProvider-Identifier", QVariant::String).toString()); + m_configDialog->imageUi.potdComboBox->insertItem(m_configDialog->imageUi.potdComboBox->count(), service_name, service_identifier); + } + + QStandardItemModel* model = static_cast(m_configDialog->imageUi.pictureComboBox->model()); + QStandardItem* item = model->item(2); + + if (item) { + if (services.isEmpty()) + item->setFlags(item->flags() & ~Qt::ItemIsEnabled); + else + item->setFlags(item->flags() | Qt::ItemIsEnabled); + } + + parent->addPage(m_configDialog->imageSettings, i18n("Image"), icon()); + parent->addPage(m_configDialog->appearanceSettings, i18n("Appearance"), "preferences-desktop-theme"); + parent->setDefaultButton(KDialog::Ok); + parent->showButtonSeparator(true); + connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted())); + connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted())); + + connect(m_configDialog->imageUi.removeDirButton, SIGNAL(clicked()), this, SLOT(removeDir())); + connect(m_configDialog->imageUi.addDirButton, SIGNAL(clicked()), this, SLOT(addDir())); + connect(m_configDialog->imageUi.slideShowDirList, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtons())); + + m_configDialog->setRoundCorners(m_roundCorners); + m_configDialog->setShadow(m_shadow); + m_configDialog->setShowFrame(m_frame); + m_configDialog->setFrameColor(m_frameColor); + + if (m_slideShow) { + m_configDialog->imageUi.pictureComboBox->setCurrentIndex(1); + } else if (m_potd) { + m_configDialog->imageUi.pictureComboBox->setCurrentIndex(2); + } else { + m_configDialog->imageUi.pictureComboBox->setCurrentIndex(0); + } + + m_configDialog->imageUi.randomCheckBox->setCheckState(m_random ? Qt::Checked : Qt::Unchecked); + m_configDialog->imageUi.recursiveCheckBox->setCheckState(m_recursiveSlideShow ? Qt::Checked : Qt::Unchecked); + + if (!m_potdProvider.isEmpty()) + m_configDialog->imageUi.potdComboBox->setCurrentIndex(m_configDialog->imageUi.potdComboBox->findData(m_potdProvider)); + else + m_configDialog->imageUi.potdComboBox->setCurrentIndex(0); + + m_configDialog->setCurrentUrl(m_currentUrl); + m_configDialog->imageUi.slideShowDirList->clear(); + m_configDialog->imageUi.slideShowDirList->addItems(m_slideShowPaths); + m_configDialog->imageUi.removeDirButton->setEnabled(!m_slideShowPaths.isEmpty()); + m_configDialog->imageUi.slideShowDelay->setTime(QTime(m_slideshowTime / 3600, (m_slideshowTime / 60) % 60, m_slideshowTime % 60)); + m_configDialog->previewPicture(m_mySlideShow->image()); + m_configDialog->imageUi.autoUpdateTime->setTime(QTime(m_autoUpdateIntervall / 3600, (m_autoUpdateIntervall / 60) % 60)); + + connect(m_configDialog->imageUi.slideShowDelay, SIGNAL(timeChanged(QTime)), + parent, SLOT(settingsModified())); + connect(m_configDialog->imageUi.pictureComboBox, SIGNAL(currentIndexChanged(int)), + parent, SLOT(settingsModified())); + connect(m_configDialog->imageUi.picRequester, SIGNAL(textChanged(QString)), + parent, SLOT(settingsModified())); + connect(m_configDialog->imageUi.autoUpdateTime, SIGNAL(timeChanged(QTime)), + parent, SLOT(settingsModified())); + connect(m_configDialog->imageUi.addDirButton, SIGNAL(clicked(bool)), + parent, SLOT(settingsModified())); + connect(m_configDialog->imageUi.removeDirButton, SIGNAL(clicked(bool)), + parent, SLOT(settingsModified())); + connect(m_configDialog->imageUi.randomCheckBox, SIGNAL(toggled(bool)), + parent, SLOT(settingsModified())); + connect(m_configDialog->imageUi.recursiveCheckBox, SIGNAL(toggled(bool)), + parent, SLOT(settingsModified())); + connect(m_configDialog->imageUi.potdComboBox, SIGNAL(currentIndexChanged(int)), + parent, SLOT(settingsModified())); + connect(m_configDialog->appearanceUi.roundCheckBox, SIGNAL(toggled(bool)), + parent, SLOT(settingsModified())); + connect(m_configDialog->appearanceUi.shadowCheckBox, SIGNAL(toggled(bool)), + parent, SLOT(settingsModified())); + connect(m_configDialog->appearanceUi.frameCheckBox, SIGNAL(toggled(bool)), + parent, SLOT(settingsModified())); + connect(m_configDialog->appearanceUi.changeFrameColor,SIGNAL(changed(QColor)), + parent, SLOT(settingsModified())); +} + +void Frame::configAccepted() +{ + KConfigGroup cg = config(); + // Appearance + m_roundCorners = m_configDialog->roundCorners(); + cg.writeEntry("roundCorners", m_roundCorners); + m_shadow = m_configDialog->shadow(); + cg.writeEntry("shadow", m_shadow); + m_frame = m_configDialog->showFrame(); + cg.writeEntry("frame", m_frame); + m_frameColor = m_configDialog->frameColor(); + cg.writeEntry("frameColor", m_frameColor); + + bool wasPotd = m_potd; + + if (m_configDialog->imageUi.pictureComboBox->currentIndex() == 1) { + m_slideShow = true; + m_potd = false; + } else if (m_configDialog->imageUi.pictureComboBox->currentIndex() == 2) { + m_slideShow = false; + m_potd = true; + } else { + m_slideShow = false; + m_potd = false; + } + + m_random = m_configDialog->random(); + cg.writeEntry("random", m_random); + m_currentUrl = m_configDialog->currentUrl(); + setAssociatedApplicationUrls(m_currentUrl); + cg.writeEntry("url", m_currentUrl); + cg.writeEntry("slideshow", m_slideShow); + m_recursiveSlideShow = m_configDialog->imageUi.recursiveCheckBox->checkState() == Qt::Checked ? true : false; + cg.writeEntry("recursive slideshow", m_recursiveSlideShow); + m_slideShowPaths.clear(); + QStringList dirs; + for (int i = 0; i < m_configDialog->imageUi.slideShowDirList->count(); i++) { + m_slideShowPaths << m_configDialog->imageUi.slideShowDirList->item(i)->text(); + } + cg.writeEntry("slideshow paths", m_slideShowPaths); + + QTime timerTime = m_configDialog->imageUi.slideShowDelay->time(); + m_slideshowTime = timerTime.second() + timerTime.minute() * 60 + timerTime.hour() * 3600; + cg.writeEntry("slideshow time", m_slideshowTime); + + m_autoUpdateTimer->stop(); + + QTime AutoUpdateTimer = m_configDialog->imageUi.autoUpdateTime->time(); + m_autoUpdateIntervall = AutoUpdateTimer.minute() * 60 + AutoUpdateTimer.hour() * 3600; + cg.writeEntry("autoupdate time", m_autoUpdateIntervall); + + QString potdProvider = m_configDialog->imageUi.potdComboBox->itemData(m_configDialog->imageUi.potdComboBox->currentIndex()).toString(); + + if ((wasPotd && !m_potd) || (m_potd && potdProvider != m_potdProvider)) { + // if we go from potd to no potd, or if the provider changes, then we first want to + // stop the potd engine + stopPotd(); + } + + m_potdProvider = potdProvider; + cg.writeEntry("potdProvider", m_potdProvider); + cg.writeEntry("potd", m_potd); + + initSlideShow(); + + emit configNeedsSaving(); +} + +void Frame::stopPotd() +{ + Plasma::DataEngine *engine = dataEngine("potd"); + engine->disconnectSource(m_potdProvider, m_mySlideShow); + m_autoUpdateTimer->stop(); +} + +void Frame::initSlideShow() +{ + m_mySlideShow->setUpdateInterval(0); + m_doAutoUpdate = false; + + if (m_slideShow) { + m_mySlideShow->setRandom(m_random); + m_mySlideShow->setDirs(m_slideShowPaths, m_recursiveSlideShow); + m_mySlideShow->setUpdateInterval(m_slideshowTime * 1000); + } else if (m_potd) { + Plasma::DataEngine *engine = dataEngine("potd"); + engine->connectSource(m_potdProvider, m_mySlideShow); + } else { //no slideshow so no random stuff + m_mySlideShow->setRandom(false); + m_mySlideShow->setImage(m_currentUrl.url()); + + if (m_autoUpdateIntervall > 0) { + m_doAutoUpdate = true; + } + } + + scalePictureAndUpdate(); +} + +void Frame::dragEnterEvent(QGraphicsSceneDragDropEvent *event) +{ + // kDebug() << event->mimeData()->formats(); + if (event->mimeData()->hasUrls()) { + event->acceptProposedAction(); + } else { + event->ignore(); + } +} + +void Frame::dropEvent(QGraphicsSceneDragDropEvent *event) +{ + if (m_slideFrame) { + m_slideFrame->hide(); + } + KUrl droppedUrl = (KUrl::List::fromMimeData(event->mimeData())).at(0); + kDebug() << "dropped URL" << droppedUrl.url(); + if (droppedUrl.protocol() == "desktop") { + KUrl tmpUrl = QString(KGlobalSettings::desktopPath() + droppedUrl.path()); + droppedUrl = tmpUrl; + } + // If the url is a local directory start slideshowmode + if (droppedUrl.isLocalFile() && QFileInfo(droppedUrl.path()).isDir()) { + m_slideShowPaths.clear(); + m_slideShowPaths.append(droppedUrl.path()); + m_slideShow = true; + } else { + kDebug() << "Remote URL" << droppedUrl.url(); + m_currentUrl = droppedUrl; + setAssociatedApplicationUrls(m_currentUrl); + m_slideShow = false; + } + + stopPotd(); + m_potd = false; + initSlideShow(); + + KConfigGroup cg = config(); + cg.writeEntry("url", m_currentUrl); + cg.writeEntry("slideshow", m_slideShow); + cg.writeEntry("slideshow paths", m_slideShowPaths); + emit configNeedsSaving(); +} + +void Frame::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + checkSlideFrame(); + if (m_slideShow) { + m_slideFrame->show(); + } + Applet::hoverEnterEvent(event); +} + +void Frame::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + if (m_slideShow) { + checkSlideFrame(); + m_slideFrame->hide(); + } + Applet::hoverLeaveEvent( event ); +} + +void Frame::checkSlideFrame() +{ + if (m_slideFrame) { + m_slideFrame->hide(); + return; + } + m_slideFrame = new Plasma::Frame( this ); + m_slideFrame->setZValue( 10 ); + + m_backButton = new Plasma::ToolButton(m_slideFrame); + m_backButton->setImage("widgets/arrows", "left-arrow"); + m_backButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + m_backButton->setMaximumSize(IconSize(KIconLoader::MainToolbar), IconSize(KIconLoader::MainToolbar)); + connect(m_backButton, SIGNAL(clicked()), this , SLOT(previousPicture())); + + m_nextButton = new Plasma::ToolButton(m_slideFrame); + m_nextButton->setImage("widgets/arrows", "right-arrow"); + m_nextButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + m_nextButton->setMaximumSize(IconSize(KIconLoader::MainToolbar), IconSize(KIconLoader::MainToolbar)); + connect(m_nextButton, SIGNAL(clicked()), this , SLOT(nextPicture())); + + QGraphicsLinearLayout *buttonsLayout = new QGraphicsLinearLayout(); + buttonsLayout->addItem(m_backButton); + buttonsLayout->addItem(m_nextButton); + m_slideFrame->setLayout(buttonsLayout); + buttonsLayout->activate(); + + m_slideFrame->setFrameShadow( Plasma::Frame::Raised ); + m_slideFrame->hide(); + + constraintsEvent(Plasma::SizeConstraint); +} + +void Frame::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &rect) +{ + Q_UNUSED(option) + if (m_slideShow) { + // temporarily suspend the slideshow to allow time for loading the image + m_mySlideShow->setUpdateInterval(0); + } + + p->drawPixmap(rect, m_pixmap); + + if (m_slideShow) { + // unsuspend the slideshow to allow time for loading the image + m_mySlideShow->setUpdateInterval(m_slideshowTime * 1000); + } +} + +void Frame::delayedUpdateSize() +{ + QSizeF sizeHint = contentSizeHint(); + if (sizeHint != geometry().size()) { + resize(sizeHint); + emit appletTransformedItself(); + } +} + +void Frame::reloadImage() +{ + m_mySlideShow->updateImage(m_currentUrl.url()); +} + +#include "frame.moc" diff --git a/kdeplasma-addons/applets/frame/frame.h b/kdeplasma-addons/applets/frame/frame.h new file mode 100644 index 00000000..688eedef --- /dev/null +++ b/kdeplasma-addons/applets/frame/frame.h @@ -0,0 +1,145 @@ +/*************************************************************************** + * Copyright 2007 by Anne-Marie Mahfouf * + * Copyright 2007 by Antonio Vinci * + * Copyright 2008 by Thomas Coopman * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef FRAME_H +#define FRAME_H + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +class ConfigDialog; +class QGraphicsSceneDragDropEvent; +class SlideShow; + +namespace Plasma +{ + class ToolButton; + class Frame; +} + +class Frame : public Plasma::Applet +{ + Q_OBJECT +public: + Frame(QObject *parent, const QVariantList &args); + ~Frame(); + + void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, + const QRect &contentsRect); + void init(); + QSizeF contentSizeHint() const; + virtual QList contextualActions(); + +public slots: + void createConfigurationInterface(KConfigDialog *parent); + void configChanged(); + void setImageAsWallpaper(); + +protected Q_SLOTS: + void dropEvent(QGraphicsSceneDragDropEvent *event); + void dragEnterEvent(QGraphicsSceneDragDropEvent *event); + void configAccepted(); + void updatePicture(); + void nextPicture(); + void previousPicture(); + void slotOpenPicture(); + +private Q_SLOTS: + void addDir(); + void removeDir(); + void updateButtons(); + void delayedUpdateSize(); + void scalePictureAndUpdate(); + void imageScaled(const QImage &img); + void reloadImage(); + +protected: + void constraintsEvent(Plasma::Constraints constraints); + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; + +private: + void stopPotd(); + void initSlideShow(); + void checkSlideFrame(); + + QRect preparePainter(QPainter *p, const QRect &rect, const QFont &font, const QString &text); + + /// The current color of the frame + QColor m_frameColor; + /// Configuration dialog + ConfigDialog *m_configDialog; + /// true if the user wants a frame. If false, there's only the black border around the picture + bool m_frame; + /// If true, the frame will have rounded corners + bool m_roundCorners; + /// If true, the picture will have a drop shadow. + bool m_shadow; + /// PoTD + QString m_potdProvider; + bool m_potd; + /// Stores the current picture URL when slideShow is false. Wikipedia Picture of the Day is default. + KUrl m_currentUrl; + /// The current slideshow folder + QStringList m_slideShowPaths; + unsigned int m_slideNumber; + int m_slideshowTime; + /// The size of the current picture + QSize m_pictureSize; + /// Frame & shadow outline thickness + int m_frameOutline; + int m_swOutline; + /// Slideshow + bool m_slideShow; + bool m_menuPresent; + bool m_random; + bool m_recursiveSlideShow; + SlideShow* m_mySlideShow; + /// Auto update + int m_autoUpdateIntervall; + bool m_doAutoUpdate; + QTimer* m_autoUpdateTimer; + /// Day Change for PoTD + QTimer *m_dateChangedTimer; + QDate m_currentDay; + QList actions; + + QPixmap m_pixmap; + QImage m_scaledImage; + QTimer* m_updateTimer; + Plasma::ToolButton* m_backButton; + Plasma::ToolButton* m_nextButton; + Plasma::Frame* m_slideFrame; + QTimer m_waitForResize; +}; + +K_EXPORT_PLASMA_APPLET(frame, Frame) + +#endif diff --git a/kdeplasma-addons/applets/frame/imageSettings.ui b/kdeplasma-addons/applets/frame/imageSettings.ui new file mode 100644 index 00000000..7230527f --- /dev/null +++ b/kdeplasma-addons/applets/frame/imageSettings.ui @@ -0,0 +1,424 @@ + + + ImageSettings + + + + 0 + 0 + 462 + 265 + + + + + + + + + + + Image + + + + + Slideshow + + + + + Picture of the day + + + + + + + + + 0 + 0 + + + + 0 + + + + + + + + + Picture: + + + + + + + true + + + *.png *.jpeg *.jpg *.svg *.svgz *.bmp *.tif + + + KFile::ExistingOnly|KFile::File + + + Qt::NonModal + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::MinimumExpanding + + + + 40 + 91 + + + + + + + + TextLabel + + + + + + + Qt::Horizontal + + + QSizePolicy::MinimumExpanding + + + + 40 + 101 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Auto-update: + + + + + + + Updates the picture from the source in the given time. +Useful if you want a live cam or weather data to be up to date. + + + never + + + hh'h' mm'min' + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + 0 + 0 + + + + + + + + + + &Add Folder... + + + + + + + false + + + &Remove Folder + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 40 + + + + + + + + + + + + + + Qt::Horizontal + + + + + + + + + Include subfolders: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + recursiveCheckBox + + + + + + + + + + + + + + Randomize: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + randomCheckBox + + + + + + + + + + + + + + Change images every: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + slideShowDelay + + + + + + + + 0 + 0 + 0 + 2000 + 1 + 1 + + + + QDateTimeEdit::HourSection + + + hh 'Hours' mm 'Mins' ss 'Secs' + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + Select Picture of the day source: + + + potdComboBox + + + + + + + + + + Qt::Vertical + + + + 20 + 68 + + + + + + + + + + + + + KUrlRequester + QFrame +
kurlrequester.h
+ 1 +
+ + KListWidget + QListWidget +
klistwidget.h
+
+ + KPushButton + QPushButton +
kpushbutton.h
+
+ + KComboBox + QComboBox +
kcombobox.h
+
+
+ + + + pictureComboBox + currentIndexChanged(int) + stackedWidget + setCurrentIndex(int) + + + 184 + 220 + + + 184 + 264 + + + + +
diff --git a/kdeplasma-addons/applets/frame/imageloader.cpp b/kdeplasma-addons/applets/frame/imageloader.cpp new file mode 100644 index 00000000..f99cb6e2 --- /dev/null +++ b/kdeplasma-addons/applets/frame/imageloader.cpp @@ -0,0 +1,97 @@ +/*************************************************************************** + * Copyright 2010 by Davide Bettio * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "imageloader.h" + +#include +#include + +#ifdef HAVE_KEXIV2 +#include +#endif + +ImageLoader::ImageLoader(const QString &path) +{ + m_path = path; +#ifdef HAVE_KEXIV2 + // prevets crashes due the xmp library not having a thread safe init + // may get fixed in future version of exiv2 according to devs + // FIXME: due to not knowing when it is safe to *uninitialize* exiv2 since others + // may be using it, this may ultimately result in a small one-time memory leak; + // either we need to know all users of KExiv2, or the thread safety issue needs + // to get fixed. + KExiv2Iface::KExiv2::initializeExiv2(); +#endif +} + +QImage ImageLoader::correctRotation(const QImage& tempImage, const QString &path) +{ + QImage image = QImage(); + if (!tempImage.isNull()) { +#ifdef HAVE_KEXIV2 + KExiv2Iface::KExiv2 exif(path); + QMatrix m; + switch (exif.getImageOrientation()) { + case KExiv2Iface::KExiv2::ORIENTATION_HFLIP: + m.scale(-1.0,1.0); + image = tempImage.transformed(m); + break; + case KExiv2Iface::KExiv2::ORIENTATION_ROT_180: + m.rotate(180); + image = tempImage.transformed(m); + break; + case KExiv2Iface::KExiv2::ORIENTATION_VFLIP: + m.scale(1.0,-1.0); + image = tempImage.transformed(m); + break; + case KExiv2Iface::KExiv2::ORIENTATION_ROT_90: + m.rotate(90); + image = tempImage.transformed(m); + break; + case KExiv2Iface::KExiv2::ORIENTATION_ROT_90_HFLIP: + m.rotate(90); + m.scale(-1.0,1.0); + image = tempImage.transformed(m); + break; + case KExiv2Iface::KExiv2::ORIENTATION_ROT_90_VFLIP: + m.rotate(90); + m.scale(1.0,-1.0); + image = tempImage.transformed(m); + break; + case KExiv2Iface::KExiv2::ORIENTATION_ROT_270: + m.rotate(270); + image = tempImage.transformed(m); + break; + default: + image = tempImage; + } +#else + image = tempImage; +#endif + } + return image; +} + +void ImageLoader::run() +{ + QImage img = correctRotation(QImage(m_path), m_path); + emit loaded(img); +} + +#include "imageloader.moc" diff --git a/kdeplasma-addons/applets/frame/imageloader.h b/kdeplasma-addons/applets/frame/imageloader.h new file mode 100644 index 00000000..89f24cc1 --- /dev/null +++ b/kdeplasma-addons/applets/frame/imageloader.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright 2010 by Davide Bettio * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef IMAGELOADER_H +#define IMAGELOADER_H + +#include +#include +#include + +class QImage; + +class ImageLoader : public QObject, public QRunnable +{ + Q_OBJECT + +public: + ImageLoader(const QString &path); + static QImage correctRotation(const QImage& tempImage, const QString &path); + void run(); + +Q_SIGNALS: + void loaded(QImage); + +private: + QString m_path; +}; + +#endif diff --git a/kdeplasma-addons/applets/frame/imagescaler.cpp b/kdeplasma-addons/applets/frame/imagescaler.cpp new file mode 100644 index 00000000..7989091f --- /dev/null +++ b/kdeplasma-addons/applets/frame/imagescaler.cpp @@ -0,0 +1,37 @@ +/*************************************************************************** + * Copyright 2010 by Davide Bettio * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "imagescaler.h" + +#include + +ImageScaler::ImageScaler(const QImage &img, QSize size) +{ + m_image = img; + m_size = size; +} + +void ImageScaler::run() +{ + QImage img = m_image.scaled(m_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + + emit scaled(img); +} + +#include "imagescaler.moc" diff --git a/kdeplasma-addons/applets/frame/imagescaler.h b/kdeplasma-addons/applets/frame/imagescaler.h new file mode 100644 index 00000000..b4a8ab0a --- /dev/null +++ b/kdeplasma-addons/applets/frame/imagescaler.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright 2010 by Davide Bettio * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef IMAGESCALER_H +#define IMAGESCALER_H + +#include +#include +#include +#include + +class ImageScaler : public QObject, public QRunnable +{ + Q_OBJECT + +public: + ImageScaler(const QImage &img, QSize size); + void run(); + +Q_SIGNALS: + void scaled(const QImage &image); + +private: + QImage m_image; + QSize m_size; +}; + +#endif diff --git a/kdeplasma-addons/applets/frame/picture-frame-default.jpg b/kdeplasma-addons/applets/frame/picture-frame-default.jpg new file mode 100644 index 00000000..3df59c2a Binary files /dev/null and b/kdeplasma-addons/applets/frame/picture-frame-default.jpg differ diff --git a/kdeplasma-addons/applets/frame/picture-frame-default.svgz b/kdeplasma-addons/applets/frame/picture-frame-default.svgz new file mode 100644 index 00000000..69e38021 Binary files /dev/null and b/kdeplasma-addons/applets/frame/picture-frame-default.svgz differ diff --git a/kdeplasma-addons/applets/frame/picture.cpp b/kdeplasma-addons/applets/frame/picture.cpp new file mode 100644 index 00000000..635d845d --- /dev/null +++ b/kdeplasma-addons/applets/frame/picture.cpp @@ -0,0 +1,179 @@ +/*************************************************************************** + * Copyright 2008 by Anne-Marie Mahfouf * + * Copyright 2008 by Thomas Coopman * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "picture.h" + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "imageloader.h" + +Picture::Picture(QObject *parent) + : QObject(parent) +{ + m_defaultImage = KGlobal::dirs()->findResource("data", "plasma-applet-frame/picture-frame-default.jpg"); + m_checkDir = false; + + // listen for changes to the file we're displaying + m_fileWatch = new KDirWatch(this); + connect(m_fileWatch,SIGNAL(dirty(QString)),this,SLOT(reload())); + connect(m_fileWatch,SIGNAL(created(QString)),this,SLOT(reload())); + connect(m_fileWatch,SIGNAL(deleted(QString)),this,SLOT(reload())); +} + +Picture::~Picture() +{ +} + +QString Picture::message() +{ + return m_message; +} + +void Picture::setMessage(const QString &message) +{ + m_message = message; +} + +void Picture::setAllowNullImages(bool allowNull) +{ + m_allowNullImages = allowNull; +} + +bool Picture::allowNullImages() const +{ + return m_allowNullImages; +} + +QImage Picture::defaultPicture(const QString &message) +{ + // Create a QImage with same axpect ratio of default svg and current pixelSize + kDebug() << "Default Image:" << m_defaultImage; + QImage image = QImage(m_defaultImage); + m_message = message; + return image; +} + +void Picture::setPicture(const KUrl ¤tUrl) +{ + m_currentUrl = currentUrl; + kDebug() << currentUrl; + + if (!m_currentUrl.isEmpty() && !m_currentUrl.isLocalFile()) { + kDebug() << "Not a local file, downloading" << currentUrl; + KIO::StoredTransferJob * job = KIO::storedGet( currentUrl, KIO::NoReload, KIO::HideProgressInfo); + connect(job, SIGNAL(finished(KJob*)), this, SLOT(slotFinished(KJob*))); + emit pictureLoaded(defaultPicture(i18n("Loading image..."))); + } else { + ImageLoader *loader = 0; + if (m_checkDir) { + m_message = i18nc("Info", "Dropped folder is empty. Please drop a folder with image(s)"); + m_checkDir = false; + } else if (currentUrl.isEmpty()) { + m_message = i18nc("Info", "Put your photo here or drop a folder to start a slideshow"); + kDebug() << "default image ..."; + } else { + loader = new ImageLoader(m_currentUrl.path()); + setPath(m_currentUrl.path()); + m_message.clear(); + } + + if (!loader) { + loader = new ImageLoader(m_defaultImage); + } + + connect(loader, SIGNAL(loaded(QImage)), this, SLOT(checkImageLoaded(QImage))); + QThreadPool::globalInstance()->start(loader); + } +} + +KUrl Picture::url() +{ + return m_currentUrl; +} + +void Picture::setPath(const QString &path) +{ + // Now switch the file watch to the new path + if (m_path != path) { + m_fileWatch->removeFile(m_path); + kDebug() << "-" << m_path; + m_path = path; + m_fileWatch->addFile(m_path); + kDebug() << "+" << m_path; + } +} + +void Picture::reload() +{ + kDebug() << "Picture reload"; + setMessage(QString()); + ImageLoader *loader = new ImageLoader(m_path); + connect(loader, SIGNAL(loaded(QImage)), this, SLOT(checkImageLoaded(QImage))); + QThreadPool::globalInstance()->start(loader); +} + +void Picture::customizeEmptyMessage() +{ + m_checkDir = true; +} + +void Picture::slotFinished( KJob *job ) +{ + QString filename = m_currentUrl.fileName(); + QString path = KStandardDirs::locateLocal("cache", "plasma-frame/" + m_currentUrl.fileName()); + QImage image; + + if (job->error()) { + kDebug() << "Error loading image:" << job->errorString(); + image = defaultPicture(i18n("Error loading image: %1", job->errorString())); + } else if (KIO::StoredTransferJob * transferJob = qobject_cast(job)) { + image.loadFromData(transferJob->data()); + kDebug() << "Successfully downloaded, saving image to" << path; + m_message.clear(); + image.save(path); + kDebug() << "Saved to" << path; + setPath(path); + } + + emit checkImageLoaded(ImageLoader::correctRotation(image, path)); +} + +void Picture::checkImageLoaded(const QImage &newImage) +{ + if (!m_allowNullImages && newImage.isNull()) { + emit pictureLoaded(defaultPicture(i18n("Error loading image. Image was probably deleted."))); + } else { + emit pictureLoaded(newImage); + } +} + +#include "picture.moc" diff --git a/kdeplasma-addons/applets/frame/picture.h b/kdeplasma-addons/applets/frame/picture.h new file mode 100644 index 00000000..cce458a6 --- /dev/null +++ b/kdeplasma-addons/applets/frame/picture.h @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright 2008 by Anne-Marie Mahfouf * + * Copyright 2008 by Thomas Coopman * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef PICTURE_H +#define PICTURE_H + + +#include +#include +#include + +/** + * @brief Picture choice + * @author Anne-Marie Mahfouf + * + * This class handles the choice of the picture and + * makes it ready for the Frame class to paint this picture. + */ + +class Picture : public QObject +{ + Q_OBJECT + +public: + explicit Picture(QObject *parent); + ~Picture(); + /** + * Set Default picture with written message @p message if no picture or folder was chosen + * by the user + **/ + QImage defaultPicture(const QString &message); + /** + * Set picture from location @p currentUrl + **/ + void setPicture(const KUrl ¤tUrl); + KUrl url(); + QString message(); + void setMessage(const QString &message); + void setAllowNullImages(bool allowNull); + bool allowNullImages() const; + +Q_SIGNALS: + void pictureLoaded(QImage image); + +private Q_SLOTS: + void slotFinished(KJob *job); + void reload(); + void checkImageLoaded(const QImage &newImage); + void customizeEmptyMessage(); + +private: + void setPath(const QString &path); + KUrl m_currentUrl; + QString m_path; // The local path of the image on disk + KDirWatch *m_fileWatch; + QString m_message; + QString m_defaultImage; + bool m_checkDir; + bool m_allowNullImages; +}; + + +#endif + diff --git a/kdeplasma-addons/applets/frame/plasma-frame-default.desktop b/kdeplasma-addons/applets/frame/plasma-frame-default.desktop new file mode 100644 index 00000000..0a5e5974 --- /dev/null +++ b/kdeplasma-addons/applets/frame/plasma-frame-default.desktop @@ -0,0 +1,131 @@ +[Desktop Entry] +Name=Picture Frame +Name[ar]=إطار الصورة +Name[ast]=Marcu d'imáxenes +Name[bs]=uramljena slika +Name[ca]=Marc de fotografies +Name[ca@valencia]=Marc de fotografies +Name[cs]=Rámeček obrázku +Name[csb]=Ramka òbrazu +Name[da]=Billedramme +Name[de]=Bilderrahmen +Name[el]=Πλαίσιο εικόνας +Name[en_GB]=Picture Frame +Name[es]=Marco de imágenes +Name[et]=Pildiraam +Name[eu]=Irudi markoa +Name[fi]=Kuvakehys +Name[fr]=Cadre de photos +Name[ga]=Fráma Pictiúir +Name[gl]=Portarretratos +Name[he]=מסגרת תמונה +Name[hr]=Okvir za sliku +Name[hu]=Képkeret +Name[is]=Myndarammi +Name[it]=Cornice immagine +Name[ja]=写真フレーム +Name[kk]=Сурет +Name[km]=ស៊ុម​រូបភាព +Name[ko]=그림 액자 +Name[ku]=Çarçoveya Wêneyê +Name[lt]=Paveikslėlių rėmelis +Name[lv]=Attēla rāmis +Name[mr]=छायाचित्र फ्रेम +Name[nb]=Bilderamme +Name[nds]=Bildrahmen +Name[nl]=Fotolijst +Name[nn]=Biletramme +Name[pa]=ਤਸਵੀਰ ਫਰੇਮ +Name[pl]=Ramka na zdjęcia +Name[pt]=Moldura de Imagens +Name[pt_BR]=Moldura de imagens +Name[ro]=Cadru imagine +Name[ru]=Фоторамка +Name[sk]=Rámček obrázku +Name[sl]=Okvir s sliko +Name[sr]=урамљена слика +Name[sr@ijekavian]=урамљена слика +Name[sr@ijekavianlatin]=uramljena slika +Name[sr@latin]=uramljena slika +Name[sv]=Bildram +Name[th]=กรอบแสดงภาพ +Name[tr]=Fotoğraf Çerçevesi +Name[uk]=Картинна рамка +Name[wa]=Cwåde di foto +Name[x-test]=xxPicture Framexx +Name[zh_CN]=桌面像框 +Name[zh_TW]=圖片框架 +Comment=Display your favorite pictures +Comment[ar]=اعرض صورك المفضلة +Comment[ast]=Amuesa les tos imáxenes favorites +Comment[bs]=Prikazuje vaše omiljene slike +Comment[ca]=Mostra les fotografies preferides +Comment[ca@valencia]=Mostra les fotografies preferides +Comment[cs]=Zobrazit vaše oblíbené obrázky +Comment[csb]=Wëskrzëni swòj lubòtny òbrôzk +Comment[da]=Vis dine yndlingsbilleder. +Comment[de]=Zeigt Ihre Lieblingsbilder an +Comment[el]=Εμφάνιση των αγαπημένων εικόνων σας +Comment[en_GB]=Display your favourite pictures +Comment[es]=Muestra sus imágenes favoritas +Comment[et]=Lemmikpiltide näitamine +Comment[eu]=Zure irudi gogokoak bistaratu +Comment[fi]=Näytä suosikkikuvasi +Comment[fr]=Affiche vos images préférées +Comment[ga]=Taispeáin na pictiúir is ansa leat +Comment[gl]=Mostra as súas imaxes favoritas +Comment[he]=הצג את התמונות המועדפות עליך +Comment[hr]=Prikažite Vaše omiljene slike +Comment[hu]=Megjeleníti kedvenc képeit +Comment[is]=Birtir uppáhaldsmyndirnar þínar +Comment[it]=Mostra le tue immagini preferite +Comment[ja]=お気に入りの写真を表示します +Comment[kk]=Таңдамалы суреттеріңізді көрсету +Comment[km]=បង្ហាញ​រូបភាព​ពេញចិត្ត​របស់​អ្នក +Comment[ko]=좋아하는 그림 보기 +Comment[ku]=Wêneyên xwe yên bijarte nîşan bide +Comment[lt]=Rodyti jūsų mėgstamus paveikslėlius +Comment[lv]=Rāda jūsu iecienītos attēlus +Comment[mr]=तुमच्या पसंतीची छायाचित्रे दर्शवा +Comment[nb]=Vis dine yndlingsbilder +Comment[nds]=Wiest Dien leevst Biller +Comment[nl]=Toon uw favoriete afbeeldingen +Comment[nn]=Vis favorittbileta dine +Comment[pa]=ਆਪਣੀਆਂ ਪਸੰਦੀਆਂ ਤਸਵੀਰਾਂ ਵੇਖੋ +Comment[pl]=Wyświetlacz ulubionych zdjęć +Comment[pt]=Mostra as suas imagens favoritas +Comment[pt_BR]=Mostra as suas imagens favoritas +Comment[ro]=Afișează imaginile dumneavoastră preferate +Comment[ru]=Слайд-шоу из любимых изображений +Comment[sk]=Zobrazenie vašich obľúbených obrázkov +Comment[sl]=Prikazuje vaše najljubše slike +Comment[sr]=Приказује ваше омиљене слике +Comment[sr@ijekavian]=Приказује ваше омиљене слике +Comment[sr@ijekavianlatin]=Prikazuje vaše omiljene slike +Comment[sr@latin]=Prikazuje vaše omiljene slike +Comment[sv]=Visa dina favoritbilder +Comment[th]=แสดงรูปภาพต่าง ๆ ที่คุณชื่นชอบ +Comment[tr]=En sevdiğiniz fotoğraflarınız masaüstünde +Comment[uk]=Відображає ваші улюблені картинки +Comment[wa]=Håynêye les fotos k' vos veyoz voltî +Comment[x-test]=xxDisplay your favorite picturesxx +Comment[zh_CN]=显示您喜欢的图片 +Comment[zh_TW]=顯示您最愛的圖片 +Icon=view-preview +Type=Service +X-Plasma-DropMimeTypes=image/jpeg,image/png + +X-KDE-ServiceTypes=Plasma/Applet +X-KDE-Library=plasma_applet_frame +X-KDE-PluginInfo-Author=Anne-Marie Mahfouf +X-KDE-PluginInfo-Email=plasma-devel@kde.org +X-KDE-PluginInfo-Name=frame +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://userbase.kde.org/Plasma/PictureFrame +X-KDE-PluginInfo-Category=Graphics +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true + +X-Plasma-Requires-FileDialog=Unused +X-Plasma-Requires-LaunchApp=Optional diff --git a/kdeplasma-addons/applets/frame/slideshow.cpp b/kdeplasma-addons/applets/frame/slideshow.cpp new file mode 100644 index 00000000..462e9957 --- /dev/null +++ b/kdeplasma-addons/applets/frame/slideshow.cpp @@ -0,0 +1,246 @@ +/*************************************************************************** + * Copyright 2008 by Thomas Coopman * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "slideshow.h" + +#include +#include +#include + +#include +#include + +#include "picture.h" + +SlideShow::SlideShow(QObject *parent) + : QObject(parent) +{ + m_filters << "*.jpeg" << "*.jpg" << "*.png" << "*.svg" << "*.svgz" << "*.bmp" << "*.tif"; // use mime types? + m_slideNumber = 0; + m_useRandom = false; + + m_picture = new Picture(this); + m_picture->setAllowNullImages(true); + connect(m_picture, SIGNAL(pictureLoaded(QImage)), this, SLOT(pictureLoaded(QImage))); + connect(this, SIGNAL(emptyDirMessage()), m_picture, SLOT(customizeEmptyMessage())); + + m_timer = new QTimer(this); + connect(m_timer, SIGNAL(timeout()), this, SLOT(nextPicture())); +} + +SlideShow::~SlideShow() +{ +} + +void SlideShow::setRandom(bool useRandom) +{ + m_useRandom = useRandom; +} + +void SlideShow::setDirs(const QStringList &slideShowPath, bool recursive) +{ + QDateTime setDirStart = QDateTime::currentDateTime(); + + m_image = QImage(); + m_indexList.clear(); + m_picturePaths.clear(); + + foreach(const QString &path, slideShowPath) { + addDir(KUrl(path).path(), recursive); + } + + // select 1st picture + firstPicture(); + + kDebug() << "Loaded " << m_picturePaths.size() << " pictures in " << setDirStart.secsTo(QDateTime::currentDateTime()) << " seconds"; + if( m_picturePaths.isEmpty()) { + emit emptyDirMessage(); + } +} + +void SlideShow::setupRandomSequence() +{ + KRandomSequence randomSequence; + m_indexList.clear(); + + for (int j = 0; j < m_picturePaths.count(); j++) { + m_indexList.append(j); + } + + randomSequence.randomize(m_indexList); +} + +void SlideShow::setImage(const QString &imagePath) +{ + m_image = QImage(); + m_picturePaths.clear(); + addImage(imagePath); + m_currentUrl = url(); +} + +void SlideShow::addImage(const QString &imagePath) +{ + m_picturePaths.append(imagePath); +} + +void SlideShow::addDir(const QString &path, bool recursive) +{ + QDirIterator dirIterator(path, m_filters, QDir::Files, (recursive ? QDirIterator::Subdirectories | QDirIterator::FollowSymlinks : QDirIterator::NoIteratorFlags)); + QStringList dirPicturePaths; + + while (dirIterator.hasNext()) { + dirIterator.next(); + dirPicturePaths.append(dirIterator.filePath()); + } + + // the pictures have to be sorted before adding them to the list, + // because the QDirIterator sorts them in a different way than QDir::entryList + dirPicturePaths.sort(); + m_picturePaths.append(dirPicturePaths); +} + +QImage SlideShow::image() const +{ + if (m_image.isNull() || m_currentUrl != m_picture->url()) { + kDebug() << "reloading from Picture" << m_currentUrl; + //m_currentUrl = m_picture->url(); + m_picture->setPicture(m_currentUrl); + } + return m_image; +} + +void SlideShow::updateImage(const QString &newUrl) +{ + m_picture->setPicture(newUrl); +} + +KUrl SlideShow::url(int offset) +{ + if (m_picturePaths.isEmpty()) { + return KUrl(); + } + + m_slideNumber += offset; + + const int count = m_picturePaths.count(); + if (m_slideNumber < 0) { + m_slideNumber = (count - ((-m_slideNumber) % count)) % count; + } else if (m_slideNumber >= count) { + m_slideNumber = m_slideNumber % count; + } + + if (m_useRandom) { + if (m_indexList.isEmpty()) { + setupRandomSequence(); + } + + return KUrl(m_picturePaths.at(m_indexList.at(m_slideNumber))); + } + + return KUrl(m_picturePaths.at(m_slideNumber)); +} + +void SlideShow::firstPicture() +{ + m_slideNumber = 0; + m_currentUrl = url(0); + m_image = image(); + emit pictureUpdated(); +} + +void SlideShow::nextPicture() +{ + m_currentUrl = url(1); + m_image = image(); + emit pictureUpdated(); +} + +void SlideShow::previousPicture() +{ + m_currentUrl = url(-1); + m_image = image(); + emit pictureUpdated(); +} + +KUrl SlideShow::currentUrl() const +{ + return m_currentUrl; +} + +void SlideShow::setUpdateInterval(int msec) +{ + m_timer->stop(); + if (msec > 1) { + if (m_currentUrl.isEmpty()) { + m_currentUrl = url(); + } + m_timer->start(msec); + } +} + +QString SlideShow::message() const +{ + return m_picture->message(); +} + +void SlideShow::pictureLoaded(const QImage &image) +{ + if (image.isNull()) { + // something is not right with this image file .. remove it from our lists. + m_picturePaths.removeAt(m_slideNumber); + m_indexList.clear(); + m_currentUrl = url(0); + m_picture->setPicture(m_currentUrl); + return; + } + + m_image = image; + emit pictureUpdated(); +} + +void SlideShow::clearPicture() +{ + m_image = QImage(); +} + +void SlideShow::dataUpdated(const QString &name, const Plasma::DataEngine::Data &data) +{ + Q_UNUSED(name); + if (data.isEmpty()) { + m_image = QImage(); + m_picture->setMessage(i18n("No Picture from this Provider.")); + return; + } + + m_image = data["Image"].value(); + m_currentUrl = data["Url"].toString(); + //kDebug() << name << "got data with keys of" << data.keys() << m_image.isNull() << data["Url"]; + //Compatibility with old dataengines + if (m_image.isNull()) { + QPixmap tmpPixmap = data["Image"].value(); + if (!tmpPixmap.isNull()) { + m_image = tmpPixmap.toImage(); + } + } + + m_picture->setMessage(QString()); + emit pictureUpdated(); +} + +#include "slideshow.moc" diff --git a/kdeplasma-addons/applets/frame/slideshow.h b/kdeplasma-addons/applets/frame/slideshow.h new file mode 100644 index 00000000..13f39f5e --- /dev/null +++ b/kdeplasma-addons/applets/frame/slideshow.h @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright 2008 by Thomas Coopman * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef SLIDESHOW_H +#define SLIDESHOW_H + +#include +#include +#include + +#include + +#include + +#include "picture.h" + +class QTimer; + +class SlideShow : public QObject +{ + Q_OBJECT + +public: + explicit SlideShow(QObject *parent); + ~SlideShow(); + + void setDirs(const QStringList &slideShowPaths, bool recursive = false); + void setImage(const QString &imagePath); + void setRandom(bool); + QImage image() const; + KUrl currentUrl() const; + QString message() const; + void updateImage(const QString &url); + void setUpdateInterval(int msec); + +public Q_SLOTS: + void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data); + void firstPicture(); + void nextPicture(); + void previousPicture(); + +Q_SIGNALS: + void pictureUpdated(); + QString emptyDirMessage(); + +private Q_SLOTS: + void clearPicture(); + void pictureLoaded(const QImage &image); + +private: + void addImage(const QString &imagePath); + void addDir(const QString &path, bool recursive); + KUrl url(int offset = 1); + void setupRandomSequence(); + + QStringList m_picturePaths; + QStringList m_filters; + int m_slideNumber; + bool m_useRandom; + + QList m_indexList; + KUrl m_currentUrl; + QTimer *m_timer; + QImage m_image; + Picture *m_picture; +}; + +#endif /*SLIDESHOW_H*/ diff --git a/kdeplasma-addons/applets/fuzzy-clock/CMakeLists.txt b/kdeplasma-addons/applets/fuzzy-clock/CMakeLists.txt new file mode 100644 index 00000000..1068150a --- /dev/null +++ b/kdeplasma-addons/applets/fuzzy-clock/CMakeLists.txt @@ -0,0 +1,11 @@ +project(fuzzy-clock) + +set(fuzzyclock_SRCS fuzzyClock.cpp) + +kde4_add_ui_files(fuzzyclock_SRCS fuzzyClockConfig.ui ) +kde4_add_plugin(plasma_applet_fuzzy_clock ${fuzzyclock_SRCS}) +target_link_libraries(plasma_applet_fuzzy_clock ${KDE4WORKSPACE_PLASMACLOCK_LIBRARY} ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS}) + +install(TARGETS plasma_applet_fuzzy_clock DESTINATION ${PLUGIN_INSTALL_DIR}) + +install(FILES plasma-clock-fuzzy.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/kdeplasma-addons/applets/fuzzy-clock/Messages.sh b/kdeplasma-addons/applets/fuzzy-clock/Messages.sh new file mode 100755 index 00000000..c8c9f068 --- /dev/null +++ b/kdeplasma-addons/applets/fuzzy-clock/Messages.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash +$EXTRACTRC *.ui >> rc.cpp +$XGETTEXT *.cpp -o $podir/plasma_applet_fuzzy_clock.pot diff --git a/kdeplasma-addons/applets/fuzzy-clock/fuzzyClock.cpp b/kdeplasma-addons/applets/fuzzy-clock/fuzzyClock.cpp new file mode 100644 index 00000000..06afdc37 --- /dev/null +++ b/kdeplasma-addons/applets/fuzzy-clock/fuzzyClock.cpp @@ -0,0 +1,752 @@ +/*************************************************************************** + * Copyright (c) 1996-2002 the kicker authors. (fuzzy logic) * + * Copyright (C) 2007 by Riccardo Iaconelli * + * Copyright (C) 2007 by Sven Burmeister * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "fuzzyClock.h" + +#include +#include +#include + +#include +#include +#include +#include + +#include + +Clock::Clock(QObject *parent, const QVariantList &args) + : ClockApplet(parent, args), + m_oldContentSize(QSizeF (0,0)), + m_adjustToHeight(1), + m_useCustomFontColor(false), + m_configUpdated(false), + m_fontColor(Qt::white), + m_fontTimeBold(false), + m_fontTimeItalic(false), + m_fontTime(KGlobalSettings::smallestReadableFont()), + m_showTimezone(false), + m_showDate(false), + m_showYear(false), + m_showDay(false), + m_layout(0) +{ + KGlobal::locale()->insertCatalog("libplasmaclock"); + KGlobal::locale()->insertCatalog("timezones4"); + setHasConfigurationInterface(true); + setBackgroundHints(Plasma::Applet::DefaultBackground); + //If we do not set this, the user has to press CTRL when shrinking the plasmoid on the desktop beyond a certain size. + setAspectRatioMode(Plasma::IgnoreAspectRatio); +} + +Clock::~Clock() +{ +} + +void Clock::init() +{ + ClockApplet::init(); + + initFuzzyTimeStrings(); + + m_contentSize = geometry().size(); + + kDebug() << "The first content's size [geometry().size()] we get, init() called: " << geometry().size(); + + m_locale = KGlobal::locale(); + + clockConfigChanged(); + + //By default we use the smallest readable font. + m_fontDate = QFont ( KGlobalSettings::smallestReadableFont() ); + + m_margin = 2; + m_verticalSpacing = 2; + + Plasma::DataEngine* timeEngine = dataEngine("time"); + timeEngine->connectSource(currentTimezone(), this, 6000, Plasma::AlignToMinute); + + connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(updateColors())); +} + +void Clock::clockConfigChanged() +{ + KConfigGroup cg = config(); + + m_showTimezone = cg.readEntry("showTimezone", false); + m_showDate = cg.readEntry("showDate", true); + m_showYear = cg.readEntry("showYear",false); + m_showDay = cg.readEntry("showDay",true); + + m_fuzzyness = cg.readEntry("fuzzyness", 1); + + m_fontTime = cg.readEntry("fontTime", KGlobalSettings::smallestReadableFont()); + m_useCustomFontColor = cg.readEntry("useCustomFontColor", false); + if (m_useCustomFontColor){ + m_fontColor = cg.readEntry("fontColor", m_fontColor); + }else{ + m_fontColor = KColorScheme(QPalette::Active, KColorScheme::View, Plasma::Theme::defaultTheme()->colorScheme()).foreground().color(); + } + m_fontTimeBold = cg.readEntry("fontTimeBold", true); + m_fontTimeItalic = cg.readEntry("fontTimeItalic", false); + + m_fontTime.setBold(m_fontTimeBold); + m_fontTime.setItalic(m_fontTimeItalic); + + m_adjustToHeight = cg.readEntry("adjustToHeight", 1); +} + +Qt::Orientations Clock::expandingDirections() const +{ + //This tells the layout whether it's ok to be stretched, even if we do not need that space. Since we would become far too wide on a panel we do not want that. + return 0; +} + +// QSizeF Clock::contentSizeHint() const +// { +// return contentSize(); +// } + +void Clock::constraintsEvent(Plasma::Constraints constraints) +{ + kDebug() << "constraintsEvent() called"; + + if (constraints & Plasma::SizeConstraint || constraints & Plasma::FormFactorConstraint) { + if ( (m_oldContentSize.toSize() != geometry().size() && m_oldContentSize.toSize() != QSize (0,0)) || m_configUpdated == true ) { //The size changed or config was updated + kDebug() << "The content's size [geometry().size()] changed! old: " << m_oldContentSize << "new: " << geometry().size(); + + if ( m_configUpdated ) { + calculateDateString(); + calculateTimeString(); + } + + kDebug() << "Constraints changed: " << constraints; + + if (formFactor() == Plasma::Planar || formFactor() == Plasma::MediaCenter) { + kDebug() << "######## Other FormFactor"; + + calculateSize(); + } else { + kDebug() << "######## Small FormFactor"; + + calculateSize(); + } + + kDebug() << "The new size has been calculated and set.\nneeded m_contenSize (if not in panel): " << m_contentSize << "\nactual content's size [geometry().size()] is: " << geometry().size() << "\nminimumSize() needed (in panel): " << minimumSize(); + + m_oldContentSize = geometry().size(); + m_configUpdated = false; + + update(); + } + } +} + +void Clock::dataUpdated(const QString& source, const Plasma::DataEngine::Data &data) +{ + Q_UNUSED(source); + m_time = data["Time"].toTime(); + m_date = data["Date"].toDate(); + + kDebug() << "dataUpdated() was called."; + + if (m_time.minute() == m_lastTimeSeen.minute()) { + // avoid unnecessary repaints +// kDebug() << "avoided unnecessary update!"; + return; + } + + if (Plasma::ToolTipManager::self()->isVisible(this)) { + updateTipContent(); + } + + updateClockApplet(data); + + m_lastTimeSeen = m_time; + + calculateDateString(); + calculateTimeString(); + + //The timestring changed. + if (m_timeString != m_lastTimeStringSeen || m_dateString != m_lastDateStringSeen) { + + //The size might have changed + calculateSize(); + + m_lastTimeStringSeen = m_timeString; + m_lastDateStringSeen = m_dateString; + + updateGeometry(); + + //request to get painted. + update(); + } +} + +void Clock::createClockConfigurationInterface(KConfigDialog *parent) +{ + QWidget *widget = new QWidget(); + ui.setupUi(widget); + parent->addPage(widget, i18n("General"), icon()); + + ui.fuzzynessSlider->setSliderPosition( m_fuzzyness ); + ui.showTimezone->setChecked( m_showTimezone ); + ui.showDate->setChecked( m_showDate ); + ui.showYear->setChecked( m_showYear ); + ui.showDay->setChecked( m_showDay ); + ui.adjustToHeight->setSliderPosition( m_adjustToHeight ); + + ui.fontTimeBold->setChecked(m_fontTimeBold); + ui.fontTimeItalic->setChecked(m_fontTimeItalic); + ui.fontTime->setCurrentFont(m_fontTime); + ui.fontColor->setColor(m_fontColor); + ui.useCustomFontColor->setChecked(m_useCustomFontColor); + + connect(ui.fontTime, SIGNAL(editTextChanged(QString)), parent, SLOT(settingsModified())); + connect(ui.fontTimeBold, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); + connect(ui.fontTimeItalic, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); + connect(ui.useThemeColor, SIGNAL(toggled(bool)), parent, SLOT(settingsModified())); + connect(ui.adjustToHeight, SIGNAL(valueChanged(int)), parent, SLOT(settingsModified())); + connect(ui.showDate, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); + connect(ui.showDay, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); + connect(ui.showYear, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); + connect(ui.showTimezone, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); + connect(ui.fuzzynessSlider, SIGNAL(valueChanged(int)), parent, SLOT(settingsModified())); +} + +void Clock::clockConfigAccepted() +{ + KConfigGroup cg = config(); + QGraphicsItem::update(); + + m_fontTime = ui.fontTime->currentFont(); + cg.writeEntry("fontTime", m_fontTime); + + //In case adjustToHeight was disabled we have to reset the point-size of fontTime + m_fontTime.setPointSize ( m_fontDate.pointSize() ); + + m_useCustomFontColor = ui.useCustomFontColor->isChecked(); + cg.writeEntry("useCustomFontColor", m_useCustomFontColor); + if (m_useCustomFontColor) { + m_fontColor = ui.fontColor->color(); + } else { + m_fontColor = KColorScheme(QPalette::Active, KColorScheme::View, Plasma::Theme::defaultTheme()->colorScheme()).foreground().color(); + } + cg.writeEntry("fontColor", ui.fontColor->color()); + + m_fontTimeBold = ui.fontTimeBold->isChecked(); + cg.writeEntry("fontTimeBold", m_fontTimeBold); + + m_fontTimeItalic = ui.fontTimeItalic->isChecked(); + cg.writeEntry("fontTimeItalic", m_fontTimeItalic); + + m_fontTime.setBold(m_fontTimeBold); + m_fontTime.setItalic(m_fontTimeItalic); + + m_fuzzyness = ui.fuzzynessSlider->value(); + cg.writeEntry("fuzzyness", m_fuzzyness); + + m_showDate = ui.showDate->isChecked(); + cg.writeEntry("showDate", m_showDate); + m_showYear = ui.showYear->isChecked(); + cg.writeEntry("showYear", m_showYear); + m_showDay = ui.showDay->isChecked(); + cg.writeEntry("showDay", m_showDay); + + m_adjustToHeight = ui.adjustToHeight->value(); + kDebug() << "adjustToHeight" << m_adjustToHeight; + + cg.writeEntry("adjustToHeight", m_adjustToHeight); + + m_showTimezone = ui.showTimezone->isChecked(); + cg.writeEntry("showTimezone", m_showTimezone); + + dataEngine("time")->connectSource(currentTimezone(), this, 6000, Plasma::AlignToMinute); + + m_configUpdated = true; + updateConstraints(); + + emit configNeedsSaving(); +} + +void Clock::changeEngineTimezone(const QString &oldTimezone, const QString &newTimezone) +{ + dataEngine("time")->disconnectSource(oldTimezone, this); + dataEngine("time")->connectSource(newTimezone, this, 6000, Plasma::AlignToMinute); +} + +void Clock::calculateDateString() +{ + if (!m_date.isValid() || ( m_showTimezone == false && m_showDate == false) ) { + return; + } + + QString day = KGlobal::locale()->calendar()->formatDate(m_date, KLocale::Day, KLocale::ShortNumber); + QString month = KGlobal::locale()->calendar()->formatDate(m_date, KLocale::Month, KLocale::ShortName); + QString year = KGlobal::locale()->calendar()->formatDate(m_date, KLocale::Year, KLocale::LongNumber); + + //Copied from the digital-clock + if (m_showDate) { + if (m_showYear) { + m_dateString = i18nc("@label Short date: " + "%1 day in the month, %2 short month name, %3 year", + "%1 %2 %3", day, month, year); + } + else { + m_dateString = i18nc("@label Short date: " + "%1 day in the month, %2 short month name", + "%1 %2", day, month); + } + if (m_showDay) { + QString weekday = KGlobal::locale()->calendar()->formatDate(m_date, KLocale::DayOfWeek, KLocale::ShortName); + m_dateString = i18nc("@label Day of the week with date: " + "%1 short day name, %2 short date", + "%1, %2", weekday, m_dateString); + } + } + +// QString newDateString = m_locale->formatDate ( m_date , m_locale->ShortDate ); + +// if( m_showDate == true ) { +// m_dateString = newDateString; +// } + + if( m_showTimezone == true ) { + QString timezonetranslated = i18n( currentTimezone().toUtf8().data()); + timezonetranslated = timezonetranslated.replace('_', ' '); + m_timezoneString = '(' + timezonetranslated + ')'; + } +} + +void Clock::initFuzzyTimeStrings() +{ + m_hourNames << i18nc("hour in the messages below","one") + << i18nc("hour in the messages below","two") + << i18nc("hour in the messages below","three") + << i18nc("hour in the messages below","four") + << i18nc("hour in the messages below","five") + << i18nc("hour in the messages below","six") + << i18nc("hour in the messages below","seven") + << i18nc("hour in the messages below","eight") + << i18nc("hour in the messages below","nine") + << i18nc("hour in the messages below","ten") + << i18nc("hour in the messages below","eleven") + << i18nc("hour in the messages below","twelve"); + + m_normalFuzzy << ki18nc("%1 the hour translated above","%1 o'clock") + << ki18nc("%1 the hour translated above","five past %1") + << ki18nc("%1 the hour translated above","ten past %1") + << ki18nc("%1 the hour translated above","quarter past %1") + << ki18nc("%1 the hour translated above","twenty past %1") + << ki18nc("%1 the hour translated above","twenty five past %1") + << ki18nc("%1 the hour translated above","half past %1") + << ki18nc("%1 the hour translated above","twenty five to %1") + << ki18nc("%1 the hour translated above","twenty to %1") + << ki18nc("%1 the hour translated above","quarter to %1") + << ki18nc("%1 the hour translated above","ten to %1") + << ki18nc("%1 the hour translated above","five to %1") + << ki18nc("%1 the hour translated above","%1 o'clock"); + + m_dayTime << i18n("Night") + << i18n("Early morning") << i18n("Morning") << i18n("Almost noon") + << i18n("Noon") << i18n("Afternoon") << i18n("Evening") + << i18n("Late evening"); + + m_weekTime << i18n("Start of week") + << i18n("Middle of week") + << i18n("End of week") + << i18n("Weekend!"); +} + +void Clock::calculateTimeString() +{ + if (!m_time.isValid()) { + return; + } + + const int hours = m_time.hour(); +// int hours = 1; + const int minutes = m_time.minute(); +// int minutes = 0; + + bool upcaseFirst = i18nc("Whether to uppercase the first letter of " + "completed fuzzy time strings above: " + "translate as 1 if yes, 0 if no.", + "1") != QString('0'); + + //Create time-string + QString newTimeString; + + if (m_fuzzyness == 1 || m_fuzzyness == 2) { + // NOTE: Time strings are deliberately assembled here with English + // only in mind: translators are able to script the translation to + // their liking, and this code provides the least surprise for that. + // Those inquiring should be directed to kde-i18n-doc mailing list + // for instructions on how to make it right for their language. + + int sector = 0; + int realHour = 0; + + if (m_fuzzyness == 1) { + if (minutes > 2) { + sector = (minutes - 3) / 5 + 1; + } + } else { + if (minutes > 6) { + sector = ((minutes - 7) / 15 + 1) * 3; + } + } + + int deltaHour = (sector <= 6 ? 0 : 1); + if ((hours + deltaHour) % 12 > 0) { //there is a modulo + realHour = (hours + deltaHour) % 12 - 1; + } else { + realHour = 12 - ((hours + deltaHour) % 12 + 1); + } + + newTimeString = m_normalFuzzy[sector].subs(m_hourNames[realHour]).toString(); + if (upcaseFirst) { + newTimeString.replace(0, 1, QString(newTimeString.at(0).toUpper())); + } + } else if (m_fuzzyness == 3) { + newTimeString = m_dayTime[hours / 3]; + } else { + //Timezones not yet implemented: int dow = QDateTime::currentDateTime().addSecs(TZoffset).date().dayOfWeek(); + int dow = QDateTime::currentDateTime().date().dayOfWeek(); + + int weekStrIdx; + if (dow == 1) { + weekStrIdx = 0; + } + else if (dow >= 2 && dow <= 4) { + weekStrIdx = 1; + } + else if (dow == 5) { + weekStrIdx = 2; + } + else { + weekStrIdx = 3; + } + + newTimeString = m_weekTime[weekStrIdx]; + } + + m_timeString = newTimeString; +} + +void Clock::calculateSize() +{ + //Minimal sizes. + // QFont minimalFontTime = m_fontTime; + // minimalFontTime.setPointsize ( m_fontDate.pointsize() ); + // QFontMetrics fmMinimalTime ( minimalFontTime ); + // + // minimalTimeStringSize = QSizeF( minimalFontTime.width( m_timeString ) + m_margin*2,minimalFontTime.height() ); + + //In case adjustToHeight was disabled we have to reset the point-size of fontTime + m_fontTime.setPointSize ( m_fontDate.pointSize() ); + + //Actual size, set in config or init + QFontMetrics m_fmTime ( m_fontTime ); + m_timeStringSize = QSizeF( m_fmTime.width( m_timeString ) + m_margin*2,m_fmTime.height() ); + + QFontMetrics m_fmDate ( m_fontDate ); + + //The date+timezone are currently hardcoded to the smallestReadableFont + m_dateStringSize = QSizeF ( m_fmDate.width( m_dateString ), m_fmDate.height() ); + m_timezoneStringSize = QSizeF( m_fmDate.width( m_timezoneString ), m_fmDate.height() ); + + int minimumWantedSize = KGlobalSettings::smallestReadableFont().pointSize(); + if (formFactor() == Plasma::Horizontal) { + QFont font(m_fontTime); + font.setPixelSize(size().height()/2); + QFontInfo fi(font); + minimumWantedSize = fi.pointSize(); + } + + + if ( contentsRect().size().width() > m_timeStringSize.width() && (formFactor() == Plasma::Planar || formFactor() == Plasma::MediaCenter)) { //plasmoid wider than timestring + kDebug() << "Plasmoid wider than the timestring"; + if( m_showDate == true && m_showTimezone == true ) { //date + timezone enabled + kDebug() << "Date + Timezone enabled"; + if ( contentsRect().size().width() > m_dateStringSize.width() + m_timezoneStringSize.width() ) { //date + timezone fit -> 2 rows within the plasmoid + + kDebug() << "plasmoid wider than date + timezone in 1 row"; + m_subtitleString = m_dateString + ' ' + m_timezoneString; //Set subtitleString + + //set subtitleSize + m_subtitleStringSize = QSizeF ( m_fmDate.width ( m_dateString + ' ' + m_timezoneString ) , m_dateStringSize.height()*1 ); + } else { //date + timezone are split into two lines to fit the plasmoid -> 3 rows within the plasmoid + kDebug() << "Plasmoid not wide enough for date + timezone in 1 row -> 2 rows"; + m_subtitleString = m_dateString + '\n' + m_timezoneString; //Set subtitleString + + //set subtitleSize + m_subtitleStringSize = QSizeF ( qMax( m_dateStringSize.width(),m_timezoneStringSize.width() ) , m_dateStringSize.height()*2 ); + } + } else if ( m_showDate == true ) { + kDebug() << "Only Date enabled"; + m_subtitleString = m_dateString; //Set subtitleString + + //set subtitleSize + m_subtitleStringSize = QSizeF ( m_dateStringSize.width() , m_dateStringSize.height() ); + } else if ( m_showTimezone == true ) { + kDebug() << "Only timezone enabled"; + m_subtitleString = m_timezoneString; //Set subtitleString + + //set subtitleSize + m_subtitleStringSize = QSizeF ( m_timezoneStringSize.width() , m_timezoneStringSize.height() ); + } else { //no subtitle + kDebug() << "Neither date nor timezone enabled"; + m_subtitleStringSize = QSizeF ( 0,0 ); + } + + // //If the date/timezone was re-enabled we might have a wide enough, but not high enough plasmoid whose minimumContentSize only fits the timestring. -> increase minimumContentSize + if ( m_timeStringSize.height() + m_verticalSpacing + m_subtitleStringSize.height() > minimumSize().height() ) { + kDebug() << "Although the plasmoid is wider than necessary the height is too small -> set new minimum height: " << m_timeStringSize.height() + m_verticalSpacing + m_subtitleStringSize.height(); + setMinimumSize ( QSizeF ( minimumSize().width(),m_timeStringSize.height() + m_verticalSpacing + m_subtitleStringSize.height() ) ); + + kDebug() << "New minimumContentSize(): " << minimumSize(); + } + + //Make the timestring fit the plasmoid since it is bigger than minimumWantedSize + m_fontTime.setPointSize(qMax((int)( geometry().size().height()/1.5), minimumWantedSize) ); + + m_fmTime = QFontMetrics( m_fontTime ); + + while ( ( m_fmTime.width( m_timeString ) > contentsRect().size().width() - 2*m_margin || + m_fmTime.height() > contentsRect().size().height() - m_subtitleStringSize.height() - m_verticalSpacing ) && + m_fontTime.pointSize() > minimumWantedSize) { + + //decrease pointSize + m_fontTime.setPointSize(m_fontTime.pointSize() - 1); + + m_fmTime = QFontMetrics( m_fontTime ); + + m_timeStringSize = QSizeF ( m_fmTime.width( m_timeString ), m_fmTime.height() ); + } + + //Adjust the height to the new horizontal size + m_contentSize = QSizeF ( contentsRect().width(),m_timeStringSize.height() + m_verticalSpacing + m_subtitleStringSize.height() ); + + if ( formFactor() == Plasma::Horizontal ) { //if we are on the panel we are forced to accept the given height. + kDebug() << "needed height: " << m_contentSize.height() << "fixed height forced on us: " << geometry().size().height(); + //FIXME: it was resizing to size() itself + //resize ( QSizeF ( m_contentSize.width(),geometry().size().height() ) ); + } else { + //add margins + resize(m_contentSize + QSizeF(size()-contentsRect().size())); + setPreferredSize(m_contentSize + QSizeF(size()-contentsRect().size())); + resize(preferredSize()); + emit sizeHintChanged(Qt::PreferredSize); + emit appletTransformedItself(); + } + + } else { //in a panel or timestring wider than plasmoid -> change size to the minimal needed space, i.e. the timestring will not increase in point-size OR plasmoid in Panel. + + kDebug() << "Plasmoid is in a panel or too small for the timestring, we are using minimumWantedSize as pointSize"; + + if ( m_showDate == true && m_showTimezone == true ) { //Date + timezone enabled + kDebug() << "Date + timezone enabled"; + + //If the user has set adjustToHeight to true the timezone and date are put into one line. This is a design decision and not based on anything else but the opinion that a slightly increased point-size is not what adjustToHeight is meant for. The latter is meant to replace the need to be able to set a font-size in the settings. Bigger fonts than this and only slightly bigger ones don't make sense on the panel. The desktop-plasmoid is not imfluenced by this. + if( m_timeStringSize.width() > m_dateStringSize.width() + m_timezoneStringSize.width() || m_adjustToHeight != 0 ) { //Time wider than date + timezone -> 2 rows in plasmoid + kDebug() << "timestring is wider than date + timezone in one row -> 1 row."; + m_subtitleString = m_dateString + ' ' + m_timezoneString; //Set subtitleString + + //set subtitleSize + m_subtitleStringSize = QSizeF ( m_fmDate.width ( m_dateString + ' ' + m_timezoneString ) , m_dateStringSize.height()*1 ); + + //set new minimal width to fit the strings + m_minimumContentSize = QSizeF ( m_timeStringSize.width(),m_subtitleStringSize.height() + m_verticalSpacing + m_subtitleStringSize.height() ); + } else { //date and timezone have to be split. + kDebug() << "Date + timezone do not fit into one row -> 2 rows."; + m_subtitleString = m_dateString + '\n' + m_timezoneString; //Set subtitleString + + //set subtitleSize + m_subtitleStringSize = QSizeF ( qMax ( m_dateStringSize.width(),m_timezoneStringSize.width() ), m_dateStringSize.height()*2 ); + + kDebug() << "max: " << qMax ( m_timeStringSize.width(),qMax ( m_dateStringSize.width(),m_timezoneStringSize.width() ) ) << " timestring: " << m_timeStringSize.width() << "date: " << m_dateStringSize.width() << "timezone: " << m_timezoneStringSize.width(); + + //set new minimal width to fit widest string and adjust the height + m_minimumContentSize = QSizeF ( qMax ( m_timeStringSize.width(),qMax ( m_dateStringSize.width(),m_timezoneStringSize.width() ) ),m_timeStringSize.height() + m_verticalSpacing + m_subtitleStringSize.height() ); + } + } else if ( m_showDate == true ) { + kDebug() << "Only date is enabled"; + m_subtitleString = m_dateString; //Set subtitleString + + //set subtitleSize + m_subtitleStringSize = QSizeF ( m_dateStringSize.width(), m_dateStringSize.height() ); + + //set new minimal width to fit the widest string + m_minimumContentSize = QSizeF ( qMax ( m_dateStringSize.width(),m_timeStringSize.width() ),m_timeStringSize.height() + m_verticalSpacing + m_subtitleStringSize.height() ); + } else if ( m_showTimezone == true ) { + kDebug() << "Only timezone is enabled"; + m_subtitleString = m_timezoneString; //Set subtitleString + + //set subtitleSize + m_subtitleStringSize = QSizeF ( m_timezoneStringSize.width(), m_timezoneStringSize.height() ); + + //set new size to fit the strings + m_minimumContentSize = QSizeF ( qMax ( m_timezoneStringSize.width(),m_timeStringSize.width() ),m_timeStringSize.height() + m_verticalSpacing + m_subtitleStringSize.height() ); + } else { //no subtitle + kDebug() << "Neither timezone nor date are enabled"; + //set subtitleSize + m_subtitleStringSize = QSizeF ( 0,0 ); + + m_minimumContentSize = QSizeF ( m_timeStringSize.width(),m_timeStringSize.height() );//set new minimal width + } + + float heightToUse = 0; + + //Use x of the available height for the timstring + if ( m_adjustToHeight == 1 ) { + heightToUse = (float)2/3; + kDebug() << "We will use 2/3 of the panel's height for the time: " << heightToUse; + } else if ( m_adjustToHeight == 2 ) { + kDebug() << "We will use all of the panel's height for the time."; + heightToUse = 1; + } + + //If the user enabled adjustToHeight we increase the point-size until the height is fully used. 40 as limit to avoid an endless loop. + if ( m_adjustToHeight != 0 ) { + kDebug() << "We try to find a larger font that fits the size:"; + + //FIXME: if the clock is the only applet on a vertical panel and returns 0 via expandingDirections(), it still gets the full height of the panel as recommended height, i.e. on a vertical panel width a height of 800, geometry().size().height() does not return 48 but some huge value. Unless this is fixed in plasma, the while-loop will take a while. + + //Make the timestring fit the plasmoid since it is bigger than minimumWantedSize + m_fontTime.setPointSize(qMax((int)( geometry().size().height()/1.5), minimumWantedSize) ); + + m_fmTime = QFontMetrics( m_fontTime ); + + kDebug() << "Starting with a point size of: " << m_fontTime.pointSize(); + + kDebug() << "We want to have: \nwidth: < " << geometry().size().width() - 2*m_margin << "\nheight < " << (geometry().size().height() - m_subtitleStringSize.height() - m_verticalSpacing)*heightToUse; + + while ( ( ( m_fmTime.width( m_timeString ) > geometry().size().width() - 2*m_margin && formFactor() != Plasma::Horizontal ) || + m_fmTime.height() > (geometry().size().height() - m_subtitleStringSize.height() - m_verticalSpacing)*heightToUse ) && + m_fontTime.pointSize() > minimumWantedSize) { + + //decrease pointSize + m_fontTime.setPointSize(m_fontTime.pointSize() - 1); + + kDebug() << "new point size: " << m_fontTime.pointSize(); + + m_fmTime = QFontMetrics( m_fontTime ); + + m_timeStringSize = QSizeF ( m_fmTime.width( m_timeString ), m_fmTime.height() ); + } + } + + //Adjust the width to the new size, including margins, will be reverted, if the panel is vertical + m_minimumContentSize = QSizeF ( m_timeStringSize.width() + m_margin*2,m_minimumContentSize.height() ); + + kDebug() << "Set new minimumSize: geometry().size() " << geometry().size() << "\nm_minimumContentSize: " << m_minimumContentSize; + + //if the width given by the panel is too wide, e.g. when switching from panel at the right to panel at the bottom we get some 600 as width + //However: If we are in a vertical panel, we should use the width given. + if( m_timeStringSize.width() + m_margin*2 < geometry().size().width() && formFactor() != Plasma::Vertical ) { + kDebug() << "The width we got was too big, we need less, so lets resize."; + setMinimumSize ( m_minimumContentSize + (size() - contentsRect().size()) ); + } + + if ( formFactor() == Plasma::Horizontal ) { //if we are on the panel we are forced to accept the given height. + kDebug() << "needed height: " << m_minimumContentSize.height() << "[horizontal panel] fixed height forced on us: " << geometry().size().height() << " adding margin-left/-right of: " << m_margin << "width is going to be set resize( " << m_minimumContentSize.width() << "," << geometry().size().height() << ")"; + + setMinimumSize(QSizeF(m_minimumContentSize.width(), 0)); + //Expand the panel as necessary + setPreferredSize(minimumSize()); + emit sizeHintChanged(Qt::PreferredSize); + } else if ( formFactor() == Plasma::Vertical ) { + kDebug() << "needed width: " << m_minimumContentSize.width() << "[vertical panel] fixed width forced on us: " << geometry().size().width() << " adding margin left/right of: " << m_margin; + + setMinimumSize ( QSizeF(0, m_minimumContentSize.height()) ); + //Expand the panel as necessary + setPreferredSize(minimumSize()); + emit sizeHintChanged(Qt::PreferredSize); + }else { //FIXME: In case this height does not fit the content -> disable timezone (and date) + //if the minimal width is larger than the actual size -> force minimal needed width + if( m_fontTime.pointSize() <= m_fontDate.pointSize() ) { + setMinimumSize ( m_minimumContentSize + (size() - contentsRect().size()) ); + } + + //we use the minimal height here, since the user has given us too much height we cannot use for anything useful. minimal width because we are in a panel. + kDebug() << "we set the minimum size needed as the size we want"; + setPreferredSize ( QSizeF ( m_minimumContentSize.width() + m_margin*2,m_minimumContentSize.height() ) + (size() - contentsRect().size()) ); + resize(preferredSize()); + emit sizeHintChanged(Qt::PreferredSize); + emit appletTransformedItself(); + } + } +} + +void Clock::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect) +{ + Q_UNUSED( option ); + + kDebug() << "We get painted!"; + + if( m_showDate == true || m_showTimezone == true ) { + + m_fontDate = QFont( KGlobalSettings::smallestReadableFont() ); + QFontMetrics m_fmDate( m_fontDate ); + p->setPen(QPen(m_fontColor)); + p->setFont( m_fontDate ); + + kDebug() << "date + timezone [" << m_subtitleString << "] gets painted. y: " << -m_subtitleStringSize.height() + contentsRect.size().height() << "width: " << contentsRect.size().width() << "[needed: " << m_fmDate.width( m_subtitleString ) << "] " << "height:" << m_subtitleStringSize.height(); + + if( m_showDate == true || m_showTimezone == true ) { + //Draw the subtitle + p->drawText( QRectF(contentsRect.x(), + contentsRect.y() - m_subtitleStringSize.height() + contentsRect.size().height(), + contentsRect.size().width(), + m_subtitleStringSize.height()) , + m_subtitleString, + QTextOption(Qt::AlignHCenter) + ); + } + } + + QFontMetrics m_fmTime ( m_fontTime ); + + kDebug() << "timestrings [" << m_timeString << "] gets painted. width: " << contentsRect.size().width() << "[needed: " << m_fmTime.width( m_timeString ) << "] " << "height: " << m_timeStringSize.height(); + + p->setFont( m_fontTime ); + p->setPen(QPen(m_fontColor)); + p->setRenderHint(QPainter::SmoothPixmapTransform); + p->setRenderHint(QPainter::Antialiasing); + + p->drawText( QRectF(contentsRect.x(), + contentsRect.y(), + contentsRect.size().width(), + m_timeStringSize.height()) , + m_timeString, + QTextOption(Qt::AlignHCenter) + ); +} + +void Clock::updateColors() +{ + if (!m_useCustomFontColor) { + m_fontColor = KColorScheme(QPalette::Active, KColorScheme::View, Plasma::Theme::defaultTheme()->colorScheme()).foreground().color(); + update(); + } +} + +#include "fuzzyClock.moc" diff --git a/kdeplasma-addons/applets/fuzzy-clock/fuzzyClock.h b/kdeplasma-addons/applets/fuzzy-clock/fuzzyClock.h new file mode 100644 index 00000000..9bf5c4ef --- /dev/null +++ b/kdeplasma-addons/applets/fuzzy-clock/fuzzyClock.h @@ -0,0 +1,129 @@ +/*************************************************************************** + * Copyright (C) 2007 by Sven Burmeister * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef CLOCK_H +#define CLOCK_H + +#include + +#include + +#include "ui_fuzzyClockConfig.h" + +class QTime; +class QDate; + +class KLocalizedString; + +class Clock : public ClockApplet +{ + Q_OBJECT + public: + Clock(QObject *parent, const QVariantList &args); + ~Clock(); + + void init(); + void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect); + void setPath(const QString&); +// QSizeF contentSizeHint() const; + +Qt::Orientations expandingDirections() const; + + public slots: + void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data); + + protected slots: +// void acceptedTimeStringState(bool); + void updateColors(); + + protected: + void constraintsEvent(Plasma::Constraints constraints); + void createClockConfigurationInterface(KConfigDialog *parent); + void clockConfigAccepted(); + void clockConfigChanged(); + void changeEngineTimezone(const QString &oldTimezone, const QString &newTimezone); + + private: + void initFuzzyTimeStrings(); + + void calculateTimeString(); + void calculateDateString(); + void calculateSize(); + + // temporary, sort out a correct way for applets to be notified + // when their content size changes and then rather than tracking + // the content size, re-implement the appropriate method to + // update the graphic sizes and so on + QSizeF m_contentSize; + QSizeF m_oldContentSize; + QSizeF m_minimumContentSize; + + bool m_configUpdated; + + QString m_timeString; + QString m_dateString; + QString m_timezoneString; + QString m_subtitleString; + + QSizeF m_timeStringSize; + QSizeF m_dateStringSize; + QSizeF m_timezoneStringSize; + QSizeF m_subtitleStringSize; + + int m_adjustToHeight; + bool m_useCustomFontColor; + QColor m_fontColor; + bool m_fontTimeBold; + bool m_fontTimeItalic; + + QFont m_fontTime; + QFont m_fontDate; + +// QFontMetrics m_fmTime; +// QFontMetrics m_fmDate; + + int m_fuzzyness; + bool m_showTimezone; + bool m_showDate; + bool m_showYear; + bool m_showDay; + QTime m_time; + QDate m_date; + KLocale *m_locale; + QVBoxLayout *m_layout; + + QTime m_lastTimeSeen; + QString m_lastTimeStringSeen; + QString m_lastDateStringSeen; + + /// Designer Config file + Ui::fuzzyClockConfig ui; + + QStringList m_hourNames; + QList m_normalFuzzy; + QStringList m_dayTime; + QStringList m_weekTime; + + int m_margin; + int m_verticalSpacing; +}; + +K_EXPORT_PLASMA_APPLET(fuzzy_clock, Clock) + +#endif diff --git a/kdeplasma-addons/applets/fuzzy-clock/fuzzyClockConfig.ui b/kdeplasma-addons/applets/fuzzy-clock/fuzzyClockConfig.ui new file mode 100644 index 00000000..15cc6585 --- /dev/null +++ b/kdeplasma-addons/applets/fuzzy-clock/fuzzyClockConfig.ui @@ -0,0 +1,580 @@ + + + fuzzyClockConfig + + + + 0 + 0 + 437 + 417 + + + + + + + + 75 + true + + + + Appearance + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 17 + 25 + + + + + + + + Font style: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + fontTime + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 17 + + + + + + + + + + Check if you want the font in bold + + + When this is checked, the clock font will be bold. + + + &Bold + + + + + + + Check if you want the font in italic + + + When this is checked, the clock font will be in italic. + + + &Italic + + + + + + + Font color: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + useThemeColor + + + + + + + + 0 + 0 + + + + Use current desktop theme color + + + This is default. The clock will get its font color from the current desktop theme. + + + Use theme color + + + true + + + + + + + + + + 0 + 0 + + + + Choose your own font color + + + When checked you can choose a custom color for the clock font by clicking on the color widget on the right. + + + Use custom color: + + + + + + + false + + + Color chooser + + + Click on this button and the KDE standard color dialog will show. You can then choose the new color you want for your clock. + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Adjust text to panel-height: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + adjustToHeight + + + + + + + 0: disable; 2: use full panel-height + + + 2 + + + Qt::Horizontal + + + QSlider::TicksBothSides + + + + + + + + 75 + true + + + + Information + + + + + + + Show date: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + showDate + + + + + + + + + Display the date of the day + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + false + + + Display day of the week + + + Add the day of the week to the date display. + + + Show day of the &week + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + false + + + Display the current year + + + Add the year to the date string. + + + Show &year + + + + + + + + + Show time zone: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + showTimezone + + + + + + + + + Display the time zone name + + + Display the time zone name under the time. + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Degree of fuzzyness: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + fuzzynessSlider + + + + + + + 1: least fuzzy + + + 1 + + + 4 + + + Qt::Horizontal + + + QSlider::TicksBothSides + + + 1 + + + + + + + Qt::Vertical + + + + 40 + 9 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 5 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 10 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 5 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 5 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 5 + + + + + + + + + KFontComboBox + KComboBox +
kfontcombobox.h
+
+ + KColorButton + QPushButton +
kcolorbutton.h
+
+ + KComboBox + QComboBox +
kcombobox.h
+
+
+ + + + useCustomFontColor + toggled(bool) + fontColor + setEnabled(bool) + + + 262 + 158 + + + 325 + 151 + + + + + showDate + toggled(bool) + showDay + setEnabled(bool) + + + 178 + 270 + + + 281 + 293 + + + + + showDate + toggled(bool) + showYear + setEnabled(bool) + + + 167 + 258 + + + 477 + 322 + + + + +
diff --git a/kdeplasma-addons/applets/fuzzy-clock/plasma-clock-fuzzy.desktop b/kdeplasma-addons/applets/fuzzy-clock/plasma-clock-fuzzy.desktop new file mode 100644 index 00000000..56be95e0 --- /dev/null +++ b/kdeplasma-addons/applets/fuzzy-clock/plasma-clock-fuzzy.desktop @@ -0,0 +1,131 @@ +[Desktop Entry] +Name=Fuzzy Clock +Name[ar]=ساعة تقريبية +Name[ast]=Reló imprecisu +Name[bs]=Neprecizni sat +Name[ca]=Rellotge aproximat +Name[ca@valencia]=Rellotge aproximat +Name[cs]=Nejasné hodiny +Name[da]=Unøjagtigt ur +Name[de]=Umgangssprachliche Uhr +Name[el]=Ασαφές ρολόι +Name[en_GB]=Fuzzy Clock +Name[es]=Reloj impreciso +Name[et]=Segane kell +Name[eu]=Ordulari lausoa +Name[fi]=Epätarkka kello +Name[fr]=Horloge floue +Name[ga]=Clog Doiléir +Name[gl]=Reloxo impreciso +Name[he]=שעון מטשטש +Name[hr]=Neizrazit sat +Name[hu]=Fuzzy óra +Name[is]=Ónákvæm klukka +Name[it]=Orologio confuso +Name[ja]=あいまい時計 +Name[kk]=Жазбаша сағат +Name[km]=នាឡិកា​ស្រពិចស្រពិល +Name[ko]=퍼지 시계 +Name[ku]=Demjimêra Şêlû +Name[lt]=Netikslus laikrodis +Name[lv]=Aptuvens pulkstenis +Name[mr]=फझी घड्याळ +Name[nb]=Muntlig klokke +Name[nds]=Bummelig-Klock +Name[nl]=Vage klok +Name[nn]=Uklar klokke +Name[oc]=Relòtge fosc +Name[pa]=ਫਜ਼ੀ ਘੜੀ +Name[pl]=Rozmyty zegar +Name[pt]=Relógio Difuso +Name[pt_BR]=Relógio aproximado +Name[ro]=Ceas evaziv +Name[ru]=Неточное время +Name[sk]=Približné hodiny +Name[sl]=Zgovorna ura +Name[sq]=Orë e Mjegullt +Name[sr]=одокативни сат +Name[sr@ijekavian]=одокативни сат +Name[sr@ijekavianlatin]=odokativni sat +Name[sr@latin]=odokativni sat +Name[sv]=Inexakt klocka +Name[th]=นาฬิกาแบบตรรกะพื้นฐาน +Name[tr]=Bulanık Saat +Name[uk]=Нечіткий годинник +Name[wa]=Ôrlodje a l' avirance +Name[x-test]=xxFuzzy Clockxx +Name[zh_CN]=模糊时钟 +Name[zh_TW]=模糊時鐘 + +Comment=Time displayed in a less precise format +Comment[ar]=الوقت يظهر بتنسيق أقل دقة +Comment[ast]=Amuesa la hora nún formatu menos precisu +Comment[bs]=Vrijeme prikazano na manje precizan način +Comment[ca]=L'hora mostrada en un format aproximat +Comment[ca@valencia]=L'hora mostrada en un format aproximat +Comment[cs]=Zobrazení času v nejasném formátu +Comment[da]=Tiden vist i et mindre præcist format. +Comment[de]=Zeigt die Zeit weniger genau an +Comment[el]=Εμφάνιση ώρας σε μια λιγότερο ακριβή μορφή +Comment[en_GB]=Time displayed in a less precise format +Comment[es]=Muestra la hora en un formato menos preciso +Comment[et]=Aja näitamine mitte nii täpsel kujul +Comment[eu]=Ordua era lausoan bistaratua +Comment[fi]=Aika näytettynä epätarkassa muodossa +Comment[fr]=Heure affichée avec un format peu précis +Comment[ga]=Taispeáin an t-am i bhformáid níos lú beaichte +Comment[gl]=Mostra a hora nun formato impreciso +Comment[he]=השעה מוצגת בפורמט קצת פחות מדוייק +Comment[hr]=Vrijeme prikazano u manje preciznim oblicima +Comment[hu]=Kevésbé precíz formátumban megjelenített idő +Comment[is]=Birtir tímann á minna nákvæmu sniði +Comment[it]=Ora mostrata in modo meno preciso +Comment[ja]=時間をあいまいな形式で表示します +Comment[kk]=Уақытты жазу түрде көрсететін сағат +Comment[km]=បាន​បង្ហាញ​ពេលវេលា​នៅក្នុងទ្រង់ទ្រាយជាក់លាក់ +Comment[ko]=개략적인 형태로 시간 보여주기 +Comment[ku]=Dem di teşeya xuyakirina kêmtir de tê nîşandan +Comment[lt]=Laikas rodomas mažesnio tikslumo formatu +Comment[lv]=Rāda laiku mazāk precīzā formātā +Comment[mr]=कमी अचूकतेने वेळ दर्शविली जाते +Comment[nb]=Viser tiden i et mindre presist format +Comment[nds]=Tiet, wiest in en nich so akraat Formaat +Comment[nl]=De tijd in iets minder nauwkeurig formaat +Comment[nn]=Klokka – meir eller mindre nøyaktig +Comment[pl]=Czas wyświetlany w mniej precyzyjnym formacie +Comment[pt]=Hora mostrada num formato menos exacto +Comment[pt_BR]=Hora exibida em formato menos preciso +Comment[ro]=Ora afișată într-un format mai puțin exact +Comment[ru]=Время в словесной записи +Comment[sk]=Čas zobrazený v menej presnom formáte +Comment[sl]=Čas je prikazan v ne preveč natančni obliki +Comment[sr]=Време приказано на мање прецизан начин +Comment[sr@ijekavian]=Вријеме приказано на мање прецизан начин +Comment[sr@ijekavianlatin]=Vrijeme prikazano na manje precizan način +Comment[sr@latin]=Vreme prikazano na manje precizan način +Comment[sv]=Tidvisning med ett mindre exakt format +Comment[th]=แสดงเวลาในรูปแบบที่มีความแม่นยำน้อย +Comment[tr]=Saati daha az belirli bir şekilde göster +Comment[uk]=Час, показаний у менш точному форматі +Comment[wa]=L' eure håynêye dins ene cogne moens precise +Comment[x-test]=xxTime displayed in a less precise formatxx +Comment[zh_CN]=以不精确格式显示的时间 +Comment[zh_TW]=以較不精確的方式顯示時間 + +Icon=clock +Type=Service +ServiceTypes=Plasma/Applet + +X-KDE-Library=plasma_applet_fuzzy_clock +X-KDE-PluginInfo-Author=Riccardo Iaconelli, Sven Burmeister +X-KDE-PluginInfo-Email=riccardo@kde.org, sven.burmeister@gmx.net +X-KDE-PluginInfo-Name=fuzzy-clock +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://http://userbase.kde.org/Plasma/Clocks +X-KDE-PluginInfo-Category=Date and Time +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true + +X-Plasma-Requires-FileDialog=Unused +X-Plasma-Requires-LaunchApp=Unused diff --git a/kdeplasma-addons/applets/icontasks/CMakeLists.txt b/kdeplasma-addons/applets/icontasks/CMakeLists.txt new file mode 100644 index 00000000..58548e81 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/CMakeLists.txt @@ -0,0 +1,64 @@ +set(tasks_SRCS + windowtaskitem.cpp tasks.cpp taskitemlayout.cpp abstracttaskitem.cpp taskgroupitem.cpp applauncheritem.cpp + jobmanager.cpp dockmanager.cpp dockitem.cpp dockhelper.cpp dockconfig.cpp mediabuttons.cpp unity.cpp unityitem.cpp + dbusstatus.cpp recentdocuments.cpp + tooltips/tooltipcontent.cpp tooltips/tooltip.cpp tooltips/tooltipmanager.cpp tooltips/windowpreview.cpp + tooltips/dialogshadows.cpp tooltips/dialogshadows_p.h + ) + +# Generate DBUS XML files, would like to use +# qt4_generate_dbus_interface(${CMAKE_CURRENT_SOURCE_DIR}/dockmanager.h net.launchpad.DockManager.xml) +# qt4_generate_dbus_interface(${CMAKE_CURRENT_SOURCE_DIR}/dockitem.h net.launchpad.DockItem.xml) +# ...but this does not work, as we also depend on the xml files in qt4_add_dbus_adaptor :-( +# So, need to manually create via: +# +# qdbuscpp2xml -M -P -S dockmanager.h -o net.launchpad.DockManager.xml +# qdbuscpp2xml -M -P -S dockitem.h -o net.launchpad.DockItem.xml + +qt4_add_dbus_adaptor(tasks_SRCS net.launchpad.DockManager.xml dockmanager.h DockManager) +qt4_add_dbus_adaptor(tasks_SRCS net.launchpad.DockItem.xml dockitem.h DockItem) + +qt4_add_dbus_interface(tasks_SRCS org.mpris.MediaPlayer2.Player.xml playerv2interface) + +MACRO(QT4_ADD_DBUS_INTERFACE_EX _sources _interface _basename _extrainclude) +# GET_FILENAME_COMPONENT(_infile ${_interface} ABSOLUTE) + set(_infile ${CMAKE_CURRENT_SOURCE_DIR}/${_interface}) + + SET(_header ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h) + SET(_impl ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp) + SET(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc) + + # handling more arguments (as in FindQt4.cmake from KDE4) will come soon, then + # _params will be used for more than just -m + SET(_params -m) + + ADD_CUSTOM_COMMAND(OUTPUT ${_impl} ${_header} + COMMAND ${QT_DBUSXML2CPP_EXECUTABLE} ${_params} -i ${_extrainclude} -p ${_basename} ${_infile} + DEPENDS ${_infile}) + + SET_SOURCE_FILES_PROPERTIES(${_impl} PROPERTIES SKIP_AUTOMOC TRUE) + + QT4_GENERATE_MOC(${_header} ${_moc}) + + SET(${_sources} ${${_sources}} ${_impl} ${_header} ${_moc}) + MACRO_ADD_FILE_DEPENDENCIES(${_impl} ${_moc}) + +ENDMACRO(QT4_ADD_DBUS_INTERFACE_EX) + +qt4_add_dbus_interface_ex(tasks_SRCS org.freedesktop.MediaPlayer.player.xml playerv1interface dbusstatus.h) + +kde4_add_ui_files(tasks_SRCS appearanceconfig.ui behaviourconfig.ui dockconfig.ui) +kde4_add_plugin(plasma_applet_icontasks ${tasks_SRCS}) + +target_link_libraries(plasma_applet_icontasks ${KDE4_KDEUI_LIBS} ${KDE4_PLASMA_LIBS} ${KDE4_KIO_LIBS} ${DBUSMENUQT_LIBRARIES} ${KDE4WORKSPACE_TASKMANAGER_LIBS}) + +if(Q_WS_X11) + target_link_libraries(plasma_applet_icontasks ${X11_LIBRARIES}) +endif(Q_WS_X11) + +include_directories(${CMAKE_BINARY_DIR} ${DBUSMENUQT_INCLUDE_DIR}) + +install(TARGETS plasma_applet_icontasks DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES plasma-applet-icontasks.desktop DESTINATION ${SERVICES_INSTALL_DIR}) +install(FILES badge.svgz launcherseparator.svgz progress.svgz indicators.svgz dropindicators.svgz DESTINATION ${DATA_INSTALL_DIR}/desktoptheme/default/icontasks/) +install(FILES mediabuttonsrc DESTINATION ${DATA_INSTALL_DIR}/${CMAKE_PROJECT_NAME}) diff --git a/kdeplasma-addons/applets/icontasks/Messages.sh b/kdeplasma-addons/applets/icontasks/Messages.sh new file mode 100755 index 00000000..b4a0b036 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/Messages.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash +$EXTRACTRC *.ui >> rc.cpp +$XGETTEXT */*.cpp *.cpp -o $podir/plasma_applet_icontasks.pot diff --git a/kdeplasma-addons/applets/icontasks/README b/kdeplasma-addons/applets/icontasks/README new file mode 100644 index 00000000..c4711d03 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/README @@ -0,0 +1,106 @@ +KDE Plasma Tasks Applet +======================= + +This is a desktop applet for KDE Plasma which provides a view +of the user's running graphical tasks and allows them to +switch between these tasks. + +It is intended as a replacement for the taskbar found in +KDE 3. + +Goals +===== + +This section describes the main goals of the tasks applet from the user's +perspective: + +- Provide a clear, attractive visual depiction of the user's running graphical tasks +- Allow the user to navigate between tasks quickly +- Allow the user to group related tasks so that they can be operated on + as one* + + +1. Task representation + + The information currently available from which a task representation can be + constructed: + + - Window title + - A (typically small) pixmap + - The 'window class' of a window which can in some cases be used + to look up an appropriate icon for that application. + - Notifications about changes to a window's state (eg. raised, + lowered, wants attention) + + This information is fairly limited. In order to provide more interesting + and useful representations in future, additional information will be + required. + + - A reliable source for a scalable icon for the task + - Information about the documents associated with a task + - Information about the people associated with a task + +2. Navigation between tasks + + The tasks applet should try to make it as easy as possible + for the user to perform a 'context switch' between the different + tasks they are performing. + + On a basic level, this means that: + + - The user must be able to identify the task from a small + representation + - Easily activate a task's representation which causes the + corresponding window to be raised and placed at the top + of the screen. + + Note: One of the flaws of KDE 3's Kicker is that task + representations are placed in a 2-task high grid + at one edge of the screen. This means that only half + of the task representations touch the screen edge and as a result + only half of them benefit from the 'infinite size' of a screen + edge with respect to activating it with the mouse. + + In the KDE 3.5.x series there is a bug in Kicker where the + colour of the text for a minimized task is grey, against what + is usually a grey/silverish panel background. This makes the + text difficult to read. + + Navigation between tasks usually occurs for two reasons: + + A) The user decides to switch to a different task of their own + volition. + + Example: Greg has been writing a business letter to a client, + he decides he wishes to take a break for twenty minutes + during which he intends to listen to music and read + the latest news online. + + He therefore wishes to switch away from the word document + and email related to that letter to his music player and + feed reader. + + B) An external interruption + + Example: Paul is watching the latest episode of a TV drama online when + he is alerted by his messaging client that a friend he wants + to talk to has come online. Paul then wishes to switch + away from the TV episode he is watching and start a conversation + with his friend. + +3. Grouping + + This is intended to be the main area of innovation in the KDE Plasma + 'taskbar' versus that found in KDE 3, Gnome, Windows, and Mac OS X. + + Some of these windows are likely to be related to the same logical + activity from the user's point of view. For example, a paper which + the user is writing and the various research material used to + write that paper. + + The idea is to allow the user to easily group these related tasks + so that he can treat them as one. That is, bringing all of them + to the front, closing all of them or layout out the windows within + a group so that they are all visible on screen at the same time + and can be worked with together. + diff --git a/kdeplasma-addons/applets/icontasks/abstracttaskitem.cpp b/kdeplasma-addons/applets/icontasks/abstracttaskitem.cpp new file mode 100644 index 00000000..df5c07f0 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/abstracttaskitem.cpp @@ -0,0 +1,1939 @@ +/*************************************************************************** + * Copyright (C) 2007 by Robert Knight * + * Copyright (C) 2008 by Alexis Ménard * + * Copyright (C) 2008 by Marco Martin * + * * + * 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 . * + ***************************************************************************/ + +// Own +#include "abstracttaskitem.h" +#include "dockitem.h" +#include "dockmanager.h" +#include "unity.h" +#include "jobmanager.h" +#include "mediabuttons.h" +#include "unityitem.h" +#include "recentdocuments.h" + +// Qt +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef Q_WS_X11 +#include +#endif + +// KDE +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include "tooltips/tooltipmanager.h" +#include + +#include "taskmanager/task.h" +#include "taskmanager/taskmanager.h" +#include "taskmanager/taskgroup.h" + +#include "tasks.h" +#include "taskgroupitem.h" +#include "applauncheritem.h" + +#include +#include + +struct Tile { + QPixmap left; + QPixmap center; + QPixmap right; +}; + +static QCache colorCache; +static QCache tileCache(50); +static QCache scaledCache(50); +static QPixmap shineCache; + +static QAction theSepAction("Separator", 0L); + +void AbstractTaskItem::clearCaches(int cache) +{ + if (cache & Cache_Bgnd) { + colorCache.clear(); + tileCache.clear(); + shineCache = QPixmap(); + } + + if (cache & Cache_Scale) { + scaledCache.clear(); + } +} + +static QPixmap scaleIcon(const QIcon &icon, const QSize &sz, const QPixmap &pix) +{ + static const int constStep = 4; + QSize s((sz.width() / constStep)*constStep, (sz.height() / constStep)*constStep); + QString key; + key.sprintf("%llx-%x-%x", icon.cacheKey(), s.width(), s.height()); + if (scaledCache.contains(key)) { + return *scaledCache[key]; + } + + QPixmap *scaled = new QPixmap(pix.scaled(s, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + scaledCache.insert(key, scaled); + return *scaled; +} + +static bool hsvLess(const QColor &c1, const QColor &c2) +{ + int h1, s1, v1, h2, s2, v2; + c1.getHsv(&h1, &s1, &v1); + c2.getHsv(&h2, &s2, &v2); + + return + (h1 << 16 | s1 << 8 | v1) < + (h2 << 16 | s2 << 8 | v2); +} + +static bool isNear(const QColor &c1, const QColor &c2) +{ + int h1, s1, v1, h2, s2, v2; + c1.getHsv(&h1, &s1, &v1); + c2.getHsv(&h2, &s2, &v2); + + return + qAbs(h1 - h2) <= 8 && + qAbs(s1 - s2) <= 16 && + qAbs(v1 - v2) <= 32; +} + +static QColor dominantColor(const QIcon &icon) +{ + if (colorCache.contains(icon.cacheKey())) { + return *colorCache[icon.cacheKey()]; + } + + static const QColor constBlackSubstitute(64 , 64 , 64); + static const int constMin = 32; // Min value of r, g, and b + + QImage image(icon.pixmap(32, 32).toImage()); + QVector colors(image.width() * image.height()); + + int count = 0; + + // find the mean color + for (int x = 0; x < image.width(); ++ x) { + for (int y = 0; y < image.height(); ++ y) { + QRgb rgb = image.pixel(x, y); + + // only use non-(total-)transparent colors + if (qAlpha(rgb) != 0) { + QColor color(rgb); + + // only use colors that aren't too grey + if (color.saturation() > 24) { + colors[count] = color; + + ++ count; + } + } + } + } + + if (count == 0) { + colorCache.insert(icon.cacheKey(), new QColor(constBlackSubstitute)); + return *colorCache[icon.cacheKey()]; + } + + colors.resize(count); + qSort(colors.begin(), colors.end(), hsvLess); + + int mid = count / 2; + QColor midColor(colors[mid]); + QColor *begin = colors.data() + mid; + + // find similar colors before the mean: + if (mid != 0) { + -- begin; + + while (begin != colors.data()) { + if (isNear(*(begin - 1), midColor)) { + -- begin; + } else { + break; + } + } + } + + QColor* end = colors.data() + mid; + + // find similar colors after the mean: + while (end != colors.data() + colors.size()) { + if (isNear(*end, midColor)) { + ++ end; + } else { + break; + } + } + + // average of similar colors: + unsigned int r = 0, g = 0, b = 0; + for (QColor* it = begin; it != end; ++ it) { + r += it->red(); + g += it->green(); + b += it->blue(); + } + + int similarCount = std::distance(begin, end); + QColor color(r / similarCount, g / similarCount, b / similarCount); + int h, s, v; + color.getHsv(&h, &s, &v); + + if (v < 196) { + v = 196; + } else if (v > 224) { + v = 224; + } + + if (s < 128) { + s = 128; + } else if (s > 196) { + s = 196; + } + + color.setHsv(h, s, v); + + static const int constStep = 8; + QColor *col = new QColor((color.red() / constStep)*constStep, (color.green() / constStep)*constStep, (color.blue() / constStep)*constStep); + + if (col->red() < constMin && col->green() < constMin && col->blue() < constMin) { + *col = constBlackSubstitute; + } + colorCache.insert(icon.cacheKey(), col); + return *col; +} + +const Tile & coloredBackground(const QColor &color, const QSize &size) +{ + qreal radius = qMin(4.0, size.width() / 4.0); + int sectionWidth = qMax(2, (int)(radius + 1)); + + quint64 key = (((quint64)(sectionWidth & 0xFFFF)) << 48) + + (((quint64)(size.height() & 0xFFFF)) << 32) + + (color.red() << 16) + + (color.blue() << 8) + + (color.green()); + if (tileCache.contains(key)) { + return *tileCache[key]; + } + + QPixmap pix(sectionWidth * 3, size.height()); + pix.fill(Qt::transparent); + QPainter painter(&pix); + QPainterPath path(Plasma::PaintUtils::roundedRectangle(QRectF(0.5, 0.5, pix.width() - 1, pix.height() - 1), radius)); + QLinearGradient grad(QPoint(0, 0), QPoint(0, pix.height())); + QColor col(color); + + col.setAlphaF(0.7); + grad.setColorAt(0, KColorUtils::lighten(col, 0.5)); + grad.setColorAt(1.0, KColorUtils::darken(col, 0.35)); + + painter.setRenderHint(QPainter::Antialiasing, true); + painter.fillPath(path, grad); + +// col.setAlphaF(0.5); + painter.setPen(col); // KColorUtils::lighten(color, 0.2)); + painter.drawPath(path); + painter.end(); + + Tile *tile = new Tile; + tile->left = pix.copy(0, 0, sectionWidth, pix.height()); + tile->center = pix.copy(sectionWidth, 0, sectionWidth, pix.height()); + tile->right = pix.copy(sectionWidth * 2, 0, sectionWidth, pix.height()); + tileCache.insert(key, tile); + return *tile; +} + +const QPixmap & shine(const QSize &sz) +{ + QSize size(sz); + size.setHeight(sz.width() / 2); + + if (shineCache.size() == size) { + return shineCache; + } + + shineCache = QPixmap(size); + shineCache.fill(Qt::transparent); + QPainter painter(&shineCache); + QRadialGradient rad(QPointF(shineCache.width() / 2.0, 0), shineCache.width() / 2.0, QPointF(shineCache.width() / 2.0, 0)); + QColor c(Qt::white); + double alpha(0.6); + + c.setAlphaF(alpha); + rad.setColorAt(0, c); + c.setAlphaF(alpha * 0.625); +// rad.setColorAt(0.5, c); +// c.setAlphaF(alpha*0.125); +// rad.setColorAt(0.75, c); + c.setAlphaF(0); + rad.setColorAt(1, c); + painter.fillRect(QRect(0, 1, shineCache.width(), shineCache.height()), rad); + painter.end(); + + return shineCache; +} + +static QSize rotateFrame(const QSize &sz, bool rot) +{ + return rot ? QSize(sz.height(), sz.width()) : sz; +} + +static const int HOVER_EFFECT_TIMEOUT = 900; + +AbstractTaskItem::AbstractTaskItem(QGraphicsWidget *parent, Tasks *applet) + : QGraphicsWidget(parent), + m_abstractItem(0), + m_applet(applet), + m_flags(0), + m_backgroundFadeAnim(0), + m_alpha(1), + m_backgroundPrefix("normal"), + m_dockItem(0), + m_unityItem(0), + m_activateTimerId(0), + m_updateGeometryTimerId(0), + m_updateTimerId(0), + m_hoverEffectTimerId(0), + m_attentionTimerId(0), + m_attentionTicks(0), + m_mediaStateTimerId(0), + m_lastViewId(0), +// m_showText(true), + m_layoutAnimationLock(false), + m_firstGeometryUpdate(false), + m_progressSource(IS_None), + m_lastProgress(-1), + m_currentProgress(-1) +{ + m_layoutAnimation = new QPropertyAnimation(this, "animationPos", this); + m_layoutAnimation->setEasingCurve(QEasingCurve::InOutQuad); + m_layoutAnimation->setDuration(250); + + setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); + setAcceptsHoverEvents(true); + setAcceptDrops(true); + setFocusPolicy(Qt::StrongFocus); + setFlag(QGraphicsItem::ItemIsFocusable); + + checkSettings(); + connect(applet->itemBackground(), SIGNAL(repaintNeeded()), this, SLOT(syncActiveRect())); + connect(applet, SIGNAL(settingsChanged()), this, SLOT(checkSettings())); + IconTasks::ToolTipManager::self()->registerWidget(this); +} + +QSize AbstractTaskItem::basicPreferredSize() const +{ + QFontMetrics fm(KGlobalSettings::taskbarFont()); + QSize mSize = fm.size(0, "M"); + const int iconsize = KIconLoader::SizeSmall; + + int size = (int)qMin((mSize.width() * 12 + m_applet->itemLeftMargin() + m_applet->itemRightMargin() + iconsize), + qMax(mSize.height(), iconsize) + m_applet->itemTopMargin() + m_applet->itemBottomMargin()); + return QSize(size, size); +} + +void AbstractTaskItem::setPreferredOffscreenSize() +{ + QFontMetrics fm(KGlobalSettings::taskbarFont()); + int textWidth = fm.width(text()); + QSize mSize = fm.size(0, "M"); + int iconsize = KIconLoader::SizeSmall; + + QSizeF s(qMax(qMin(textWidth, 512) + 8, mSize.width() * 12) + m_applet->offscreenLeftMargin() + m_applet->offscreenRightMargin() + iconsize, + qMax(mSize.height(), iconsize) + m_applet->offscreenTopMargin() + m_applet->offscreenBottomMargin()); + setPreferredSize(s); +} + +void AbstractTaskItem::setPreferredOnscreenSize() +{ + setPreferredSize(basicPreferredSize()); +} + +AbstractTaskItem::~AbstractTaskItem() +{ + stopWindowHoverEffect(); + emit destroyed(this); + IconTasks::ToolTipManager::self()->unregisterWidget(this); + + QList timers = QList() << m_activateTimerId + << m_updateGeometryTimerId + << m_updateTimerId + << m_hoverEffectTimerId + << m_attentionTimerId + << m_mediaStateTimerId; + foreach (int t, timers) { + if (t) { + killTimer(t); + } + } +} + +void AbstractTaskItem::checkSettings() +{ + TaskGroupItem *group = qobject_cast(this); + + if (m_applet->showToolTip() && (!group || group->collapsed())) { + clearToolTip(); + } else { + IconTasks::ToolTipManager::self()->unregisterWidget(this); + } +} + +void AbstractTaskItem::updateToolTipMediaState() +{ + IconTasks::ToolTipContent data; + QString key = mediaButtonKey(); + + if (!key.isEmpty()) { + data.setPlayState(MediaButtons::self()->playbackStatus(key, pid())); + } + + data.setAutohide(false); + data.setMediaUpdate(true); + IconTasks::ToolTipManager::self()->setContent(this, data); +} + +void AbstractTaskItem::clearToolTip() +{ + if (m_mediaStateTimerId) { + killTimer(m_mediaStateTimerId); + m_mediaStateTimerId = 0; + } + IconTasks::ToolTipContent data; +#if KDE_IS_VERSION(4, 7, 0) + data.setInstantPopup(m_applet->instantToolTip()); +#endif + + IconTasks::ToolTipManager::self()->setContent(this, data); +} + +void AbstractTaskItem::clearAbstractItem() +{ + m_abstractItem = 0; +} + +QString AbstractTaskItem::text() const +{ + if (m_abstractItem) { + return m_abstractItem->name(); + } else { + kDebug() << "no abstract item?"; + } + + return QString(); +} + +QIcon AbstractTaskItem::icon(bool useDockManager) const +{ + if (useDockManager && m_dockItem && !m_dockItem->icon().isNull()) { + return m_dockItem->icon(); + } + + if (m_abstractItem) { + if (m_applet->launcherIcons() && m_icon.isNull()) { + KUrl launcherUrl(m_abstractItem->launcherUrl()); + if (launcherUrl.isLocalFile() && KDesktopFile::isDesktopFile(launcherUrl.toLocalFile())) { + KDesktopFile f(launcherUrl.toLocalFile()); + if (f.tryExec()) { + m_icon = KIcon(f.readIcon()); + } + } + } + + return m_applet->launcherIcons() && !m_icon.isNull() ? m_icon : m_abstractItem->icon(); + } + + return QIcon(); +} + +void AbstractTaskItem::setTaskFlags(TaskFlags flags) +{ + if ((flags & TaskWantsAttention) && (flags & TaskHasFocus)) { + flags &= ~TaskWantsAttention; + } + + if (((m_flags & TaskWantsAttention) != 0) != ((flags & TaskWantsAttention) != 0)) { + //kDebug() << "task attention state changed" << m_attentionTimerId; + m_flags = flags; + if (flags & TaskWantsAttention) { + m_applet->needsVisualFocus(true); + // start attention getting + if (!m_attentionTimerId) { + m_attentionTimerId = startTimer(500); + } + } else { + m_applet->needsVisualFocus(false); + if (m_attentionTimerId) { + killTimer(m_attentionTimerId); + m_attentionTimerId = 0; + } + } + } + + m_flags = flags; + + QString newBackground; + if (m_flags & TaskIsMinimized) { + newBackground = "minimized"; + } else if (m_flags & TaskHasFocus) { + newBackground = "focus"; + } else { + newBackground = "normal"; + } + + if (newBackground != m_backgroundPrefix) { + fadeBackground(newBackground, 250); + } +} + +void AbstractTaskItem::fadeBackground(const QString &newBackground, int duration) +{ + TaskGroupItem *group = qobject_cast(this); + if (group && !group->collapsed()) { + return; + } + + m_oldBackgroundPrefix = m_backgroundPrefix; + m_backgroundPrefix = newBackground; + + if (m_oldBackgroundPrefix.isEmpty()) { + update(); + } else { + if (!m_backgroundFadeAnim) { + m_backgroundFadeAnim = new QPropertyAnimation(this); + m_backgroundFadeAnim->setDuration(duration); + m_backgroundFadeAnim->setEasingCurve(QEasingCurve::InQuad); + m_backgroundFadeAnim->setPropertyName("backgroundFadeAlpha"); + m_backgroundFadeAnim->setTargetObject(this); + m_backgroundFadeAnim->setStartValue(0); + m_backgroundFadeAnim->setEndValue(1); + } + + m_backgroundFadeAnim->start(); + } +} + +AbstractTaskItem::TaskFlags AbstractTaskItem::taskFlags() const +{ + return m_flags; +} + +void AbstractTaskItem::toolTipAboutToShow() +{ + if (m_applet->showToolTip()) { + updateToolTip(); + connect(IconTasks::ToolTipManager::self(), + SIGNAL(windowPreviewActivated(WId, Qt::MouseButtons, Qt::KeyboardModifiers, QPoint)), + this, SLOT(windowPreviewActivated(WId, Qt::MouseButtons, Qt::KeyboardModifiers, QPoint))); + connect(IconTasks::ToolTipManager::self(), + SIGNAL(windowButtonActivated(WId, Qt::MouseButtons, Qt::KeyboardModifiers, QPoint)), + this, SLOT(controlWindow(WId, Qt::MouseButtons))); + connect(IconTasks::ToolTipManager::self(), + SIGNAL(mediaButtonPressed(int)), this, SLOT(mediaButtonPressed(int))); + } else { + clearToolTip(); + } +} + +void AbstractTaskItem::toolTipHidden() +{ + clearToolTip(); + disconnect(IconTasks::ToolTipManager::self(), + SIGNAL(windowPreviewActivated(WId, Qt::MouseButtons, Qt::KeyboardModifiers, QPoint)), + this, SLOT(windowPreviewActivated(WId, Qt::MouseButtons, Qt::KeyboardModifiers, QPoint))); + disconnect(IconTasks::ToolTipManager::self(), + SIGNAL(windowButtonActivated(WId, Qt::MouseButtons, Qt::KeyboardModifiers, QPoint)), + this, SLOT(controlWindow(WId, Qt::MouseButtons))); + disconnect(IconTasks::ToolTipManager::self(), + SIGNAL(mediaButtonPressed(int)), this, SLOT(mediaButtonPressed(int))); +} + +QString AbstractTaskItem::mediaButtonKey() +{ + KUrl lUrl = launcherUrl(); + QString desktopEntry; + if (lUrl.isValid()) { + desktopEntry = lUrl.fileName().remove(".desktop").toLower(); + if (desktopEntry.startsWith("kde4-")) { + desktopEntry = desktopEntry.mid(5); + } + } + + if (MediaButtons::self()->isMediaApp(desktopEntry)) { + QString key = windowClass().toLower(); + + if (key.isEmpty()) { + key = desktopEntry; + } + + return key; + } + + return QString(); +} + +void AbstractTaskItem::mediaButtonPressed(int b) +{ + QString key = mediaButtonKey(); + if (!key.isEmpty()) { + switch (b) { + case IconTasks::ToolTipManager::MB_PREV: + MediaButtons::self()->previous(key, pid()); + break; + case IconTasks::ToolTipManager::MB_PLAY_PAUSE: + MediaButtons::self()->playPause(key, pid()); + break; + case IconTasks::ToolTipManager::MB_NEXT: + MediaButtons::self()->next(key, pid()); + break; + default: + break; + } + + // Update the playstate after a timer, to give player time to react... + if (m_mediaStateTimerId) { + killTimer(m_mediaStateTimerId); + m_mediaStateTimerId = 0; + } + m_mediaStateTimerId = startTimer(250); + } +} + +void AbstractTaskItem::windowPreviewActivated(WId id, Qt::MouseButtons buttons, Qt::KeyboardModifiers, const QPoint &pos) +{ + if (buttons & Qt::LeftButton) { + if (parentGroup()) { + AbstractTaskItem *item = parentGroup()->taskItemForWId(id); + if (item) { + IconTasks::ToolTipManager::self()->hide(this); + item->activate(); + } + } + } else if (buttons & Qt::RightButton) { + if (parentGroup()) { + AbstractTaskItem *item = parentGroup()->taskItemForWId(id); + if (item) { + // Onnly show menu if th e hide timer has not already gone off!!! + if (IconTasks::ToolTipManager::self()->stopHideTimer(this)) { + item->showContextMenu(pos, false); + IconTasks::ToolTipManager::self()->startHideTimer(this); + } + } + } + } else if (buttons & Qt::MidButton) { + switch (m_applet->middleClick()) { + case Tasks::MC_Close: { + if (parentGroup()) { + AbstractTaskItem *item = parentGroup()->taskItemForWId(id); + if (item) { + item->m_abstractItem->close(); + } + } + break; + } + case Tasks::MC_MoveToCurrentDesktop: { + if (parentGroup()) { + AbstractTaskItem *item = parentGroup()->taskItemForWId(id); + if (item) { + item->toCurrentDesktop(); + } + } + break; + } + default: + break; + } + } +} + +void AbstractTaskItem::controlWindow(WId id, Qt::MouseButtons buttons) +{ + // TODO: More window actions... + if (buttons & Qt::LeftButton) { + if (parentGroup()) { + AbstractTaskItem *item = parentGroup()->taskItemForWId(id); + if (item && item->m_abstractItem) { + IconTasks::ToolTipManager::self()->hide(this); + item->m_abstractItem->close(); + } + } + } +} + +void AbstractTaskItem::middleClick() +{ + if (m_abstractItem) { + switch (m_applet->middleClick()) { + case Tasks::MC_NewInstance: { + KUrl url = m_abstractItem->launcherUrl(); + + if (!url.isEmpty()) { + new KRun(url, 0); + } + break; + } + case Tasks::MC_Close: + m_abstractItem->close(); + break; + case Tasks::MC_MoveToCurrentDesktop: + toCurrentDesktop(); + break; + default: + break; + } + } +} + +void AbstractTaskItem::queueUpdate() +{ + if (m_updateTimerId || m_attentionTimerId) { + return; + } + + if (m_lastUpdate.elapsed() < 100) { + m_updateTimerId = startTimer(100); + return; + } + + publishIconGeometry(); + update(); + m_lastUpdate.restart(); +} + +void AbstractTaskItem::focusInEvent(QFocusEvent *event) +{ + Q_UNUSED(event) + + setTaskFlags(m_flags | TaskHasFocus); + update(); +} + +void AbstractTaskItem::focusOutEvent(QFocusEvent *event) +{ + Q_UNUSED(event) + + setTaskFlags(m_flags & ~TaskHasFocus); + update(); +} + +void AbstractTaskItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event) + fadeBackground("hover", 250); + QGraphicsWidget *w = parentWidget(); + if (w && this != m_applet->rootGroupItem()) { + if (m_hoverEffectTimerId) { + killTimer(m_hoverEffectTimerId); + m_hoverEffectTimerId = 0; + } + + m_hoverEffectTimerId = startTimer(HOVER_EFFECT_TIMEOUT); + } +} + +void AbstractTaskItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event) + + stopWindowHoverEffect(); + + QString backgroundPrefix; + if (m_flags & TaskWantsAttention && 0 != m_attentionTimerId) { + backgroundPrefix = "attention"; + } else if (m_flags & TaskIsMinimized) { + backgroundPrefix = "minimized"; + } else if (m_flags & TaskHasFocus) { + backgroundPrefix = "focus"; + } else { + backgroundPrefix = "normal"; + } + + fadeBackground(backgroundPrefix, 150); +} + +void AbstractTaskItem::stopWindowHoverEffect() +{ + if (m_hoverEffectTimerId) { + killTimer(m_hoverEffectTimerId); + m_hoverEffectTimerId = 0; + } + + if (m_lastViewId && m_applet->highlightWindows()) { + Plasma::WindowEffects::highlightWindows(m_lastViewId, QList()); + } +} + +void AbstractTaskItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + switch (event->button()) { + case Qt::LeftButton: + if (boundingRect().contains(event->pos())) { + activate(); + } + break; + case Qt::MidButton: + middleClick(); + break; + default: + break; + } +} + +void AbstractTaskItem::mousePressEvent(QGraphicsSceneMouseEvent *) +{ + update(); +} + +void AbstractTaskItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + //kDebug(); + if (QPoint(event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < QApplication::startDragDistance()) { + return; + } //Wait a bit before starting drag + + QMimeData* mimeData = new QMimeData(); + //#ifndef ICON_TASKS_SHOW_DROP_INDICATOR_FOR_MOVE + mimeData->setProperty("icontasks-item-ptr", (qulonglong)this); + //#else + //mimeData->setProperty("icontasks-item-index", m_applet->rootGroupItem()->indexOf(this, false)); + //#endif + setAdditionalMimeData(mimeData); + + if (mimeData->formats().isEmpty()) { + delete mimeData; + return; + } + + QDrag *drag = new QDrag(event->widget()); + drag->setMimeData(mimeData); + //#ifndef ICON_TASKS_SHOW_DROP_INDICATOR_FOR_MOVE + drag->setPixmap(icon().pixmap(KIconLoader::SizeSmall, KIconLoader::SizeSmall)); + //#else + //drag->setPixmap(icon().pixmap(iconSize(m_applet->autoIconScaling() ? boundingRect().adjusted(4, 4, -5, -5) : boundingRect()).width())); + //#endif + drag->exec(); +} + +void AbstractTaskItem::timerEvent(QTimerEvent *event) +{ + if (event->timerId() == m_activateTimerId) { + killTimer(m_activateTimerId); + m_activateTimerId = 0; + if (!isActive()) { + activate(); + } + } else if (event->timerId() == m_updateGeometryTimerId) { + killTimer(m_updateGeometryTimerId); + m_updateGeometryTimerId = 0; + m_firstGeometryUpdate = true; + publishIconGeometry(); + } else if (event->timerId() == m_updateTimerId) { + killTimer(m_updateTimerId); + m_updateTimerId = 0; + update(); + } else if (event->timerId() == m_attentionTimerId) { + ++m_attentionTicks; + if (m_attentionTicks > (Tasks::Style_Plasma == m_applet->style() ? 6 : 9)) { + killTimer(m_attentionTimerId); + m_attentionTimerId = 0; + m_attentionTicks = 0; + } + + if (m_attentionTicks % 2 == 0) { + fadeBackground("attention", Tasks::Style_Plasma == m_applet->style() ? 200 : 300); + } else { + fadeBackground("normal", Tasks::Style_Plasma == m_applet->style() ? 250 : 375); + } + } else if (event->timerId() == m_hoverEffectTimerId) { + killTimer(m_hoverEffectTimerId); + m_hoverEffectTimerId = 0; + if (!isUnderMouse()) { + return; + } + +#ifdef Q_WS_X11 + QList windows; + + if (m_abstractItem && m_abstractItem->itemType() == TaskManager::GroupItemType) { + TaskManager::TaskGroup *group = qobject_cast(m_abstractItem); + + if (group) { + TaskGroupItem *groupItem = qobject_cast(this); + if (groupItem && groupItem->popupDialog()) { + kDebug() << "adding" << groupItem->popupDialog()->winId(); + windows.append(groupItem->popupDialog()->winId()); + } + + foreach (AbstractGroupableItem * item, group->members()) { + if (item->itemType() == TaskManager::TaskItemType) { + TaskManager::TaskItem *taskItem = qobject_cast(item); + if (taskItem && taskItem->task()) { + windows.append(taskItem->task()->window()); + } + } //TODO: if taskgroup, recurse through sub-groups? + } + } + } else { + WindowTaskItem *windowTaskItem = qobject_cast(this); + if (windowTaskItem && windowTaskItem->parent()) { + TaskGroupItem *groupItem = qobject_cast(windowTaskItem->parent()); + if (groupItem && groupItem->popupDialog()) { + windows.append(groupItem->popupDialog()->winId()); + } + } + + TaskManager::TaskItem *taskItem = qobject_cast(m_abstractItem); + if (taskItem && taskItem->task()) { + windows.append(taskItem->task()->window()); + } + } + + stopWindowHoverEffect(); + QGraphicsView *view = m_applet->view(); + if (view && m_applet->highlightWindows()) { + m_lastViewId = view->winId(); + Plasma::WindowEffects::highlightWindows(m_lastViewId, windows); + } +#endif + } else if (event->timerId() == m_mediaStateTimerId) { + killTimer(m_mediaStateTimerId); + m_mediaStateTimerId = 0; + updateToolTipMediaState(); + } else { + QGraphicsWidget::timerEvent(event); + } +} + +bool AbstractTaskItem::isStartupWithTask() const +{ + return busyWidget() && parentGroup() && parentGroup()->matchingItem(m_abstractItem); +} + +bool AbstractTaskItem::isToolTipVisible() const +{ + return IconTasks::ToolTipManager::self()->isVisible(this); +} + +void AbstractTaskItem::updateProgress(int v, InfoSource source) +{ + if (source == m_progressSource || IS_None == m_progressSource) { + m_progressSource = source; + m_currentProgress = v; + if (m_lastProgress != m_currentProgress && (m_currentProgress < 1 || 100 == m_currentProgress || abs(m_currentProgress - m_lastProgress) > 2)) { + queueUpdate(); + } + + if (m_currentProgress < 0) { + m_progressSource = IS_None; + } + } +} + +void AbstractTaskItem::dockItemUpdated() +{ + if (m_dockItem) { + updateProgress(m_dockItem->progress(), IS_DockManager); + queueUpdate(); + } +} + +void AbstractTaskItem::unityItemUpdated() +{ + if (m_unityItem) { + updateProgress(m_unityItem->progressVisible() ? m_unityItem->progress() : -1, IS_Unity); + queueUpdate(); + } +} + +void AbstractTaskItem::drawProgress(QPainter *painter, const QRectF &rect) +{ + if (rect.width() < 12 || rect.height() < 12) { + return; + } + + m_lastProgress = m_currentProgress; + + double height = qMin(8.0, rect.height() / 4.0); + QRectF border(rect.x(), rect.bottom() - (height + 1), rect.width(), height); + qreal fill = ((border.width() - 1.0) * m_currentProgress) / 100.0; + Plasma::FrameSvg *svg = m_applet->progressBar(); + + svg->setElementPrefix("bar-inactive"); + + if (border.size() != svg->frameSize()) { + m_applet->resizeProgressBar(border.size()); + } + svg->paintFrame(painter, border.topLeft()); + + if (fill > 0.0 && fill < 4.0) { + fill = 4.0; + } + if (fill >= 2.0) { + bool rtl = Qt::RightToLeft == layoutDirection(); + QRectF fillRect(rtl ? border.right() - fill : border.x(), border.y(), fill, border.height()); + svg->setElementPrefix("bar-active"); + + if (fillRect.size() != svg->frameSize()) { + m_applet->resizeProgressBar(fillRect.size()); + } + + svg->paintFrame(painter, fillRect.topLeft()); + } +} + +void AbstractTaskItem::drawBadge(QPainter *painter, const QRectF &bounds, const QString &badge) +{ + static const qreal constMaxPercent = 0.95; + static const int constBlockSize = 4; + + QFont font(KGlobalSettings::taskbarFont()); + font.setItalic(false); + QFontMetrics fm(font); + QRect textRect = fm.boundingRect(badge).adjusted(-4, -2, 4, 2); + int origWidth = textRect.width(); + + // To save lots of re-sizing, adjust width in step of 4 pixels + textRect.setWidth(((textRect.width() / constBlockSize)*constBlockSize) + (textRect.width() % constBlockSize ? constBlockSize : 0)); + + if (textRect.width() > (bounds.width()*constMaxPercent)) { + // Perhaps rounding has made it too big? + textRect.setWidth(origWidth); + if (textRect.width() > (bounds.width()*constMaxPercent)) { + // Try decreasing font size... + font = KGlobalSettings::smallestReadableFont(); + font.setItalic(false); + fm = QFontMetrics(font); + textRect = fm.boundingRect(badge).adjusted(-2, -1, 2, 1); + } + } + + if (textRect.width() <= (bounds.width()*constMaxPercent)) { + QColor txtCol(textColor()); + bool rtl = Qt::RightToLeft == layoutDirection(); + QRectF textRectF(rtl ? bounds.x() : bounds.right() - textRect.width(), + bounds.y() + 1, textRect.width(), textRect.height()); + Plasma::FrameSvg *svg = m_applet->badgeBackground(); + + if (Tasks::Style_Plasma != m_applet->style()) { + textRectF.adjust(rtl ? -1 : 1, -1, rtl ? -1 : 1, -1); + } + + svg->setElementPrefix(txtCol.value() > 160 ? "dark" : "light"); + if (textRectF.size() != svg->frameSize()) { + m_applet->resizeBadgeBackground(textRectF.size()); + } + svg->paintFrame(painter, textRectF.topLeft()); + painter->setFont(font); + painter->setPen(QPen(txtCol, 1.0)); + painter->drawText(textRectF, Qt::AlignCenter, badge); + } +} + +void AbstractTaskItem::drawIndicators(QPainter *painter, const QRectF &bounds) +{ + QString suffix = m_flags & TaskWantsAttention ? "-attention" : m_flags & TaskIsMinimized ? "-minimized" : ""; + QString position; + bool vertical = Plasma::Vertical == m_applet->formFactor(); + qreal dimension = vertical ? bounds.height() : bounds.width(); + qreal size = dimension > 48 ? qMin(24.0, dimension / 4.0) : qMin(12.0, dimension / 2.0); + QSizeF iSize(vertical ? size * 0.75 : size, vertical ? size : size * 0.75); + bool group = qobject_cast(this); + Plasma::Svg *svg = m_applet->indicators(); + + if (iSize != svg->size()) { + svg->resize(iSize); + } + + switch (m_applet->location()) { + case Plasma::TopEdge: + if (group) { + svg->paint(painter, QPointF(bounds.x() + ((bounds.width() - (iSize.width() * 1.5)) / 2.0) + (iSize.width() * 0.5), + bounds.y()), + "down" + suffix); + svg->paint(painter, QPointF(bounds.x() + ((bounds.width() - (iSize.width() * 1.5)) / 2.0), + bounds.y()), + "down" + suffix); + } else { + svg->paint(painter, QPointF(bounds.x() + ((bounds.width() - iSize.width()) / 2.0), + bounds.y()), + "down" + suffix); + } + if (m_flags & TaskHasFocus) { + svg->paint(painter, QPointF(bounds.x() + ((bounds.width() - iSize.width()) / 2.0), + bounds.y() + (bounds.height() - iSize.height())), + "up" + suffix); + } + break; + case Plasma::RightEdge: + if (group) { + svg->paint(painter, QPointF(bounds.x() + (bounds.width() - iSize.width()), + bounds.y() + ((bounds.height() - (iSize.height() * 1.5)) / 2.0) + (iSize.height() * 0.5)), + "left" + suffix); + svg->paint(painter, QPointF(bounds.x() + (bounds.width() - iSize.width()), + bounds.y() + ((bounds.height() - (iSize.height() * 1.5)) / 2.0)), + "left" + suffix); + } else { + svg->paint(painter, QPointF(bounds.x() + (bounds.width() - iSize.width()), + bounds.y() + ((bounds.height() - iSize.height()) / 2.0)), + "left" + suffix); + } + if (m_flags & TaskHasFocus) { + svg->paint(painter, QPointF(bounds.x(), + bounds.y() + ((bounds.height() - iSize.height()) / 2.0)), + "right" + suffix); + } + break; + case Plasma::LeftEdge: + if (group) { + svg->paint(painter, QPointF(bounds.x(), + bounds.y() + ((bounds.height() - (iSize.height() * 1.5)) / 2.0) + (iSize.height() * 0.5)), + "right" + suffix); + svg->paint(painter, QPointF(bounds.x(), + bounds.y() + ((bounds.height() - (iSize.height() * 1.5)) / 2.0)), + "right" + suffix); + } else { + svg->paint(painter, QPointF(bounds.x(), + bounds.y() + ((bounds.height() - iSize.height()) / 2.0)), + "right" + suffix); + } + if (m_flags & TaskHasFocus) { + svg->paint(painter, QPointF(bounds.x() + (bounds.width() - iSize.width()), + bounds.y() + ((bounds.height() - iSize.height()) / 2.0)), + "left" + suffix); + } + break; + default: + case Plasma::BottomEdge: + if (group) { + svg->paint(painter, QPointF(bounds.x() + ((bounds.width() - (iSize.width() * 1.5)) / 2.0) + (iSize.width() * 0.5), + bounds.y() + (bounds.height() - iSize.height())), + "up" + suffix); + svg->paint(painter, QPointF(bounds.x() + ((bounds.width() - (iSize.width() * 1.5)) / 2.0), + bounds.y() + (bounds.height() - iSize.height())), + "up" + suffix); + } else { + svg->paint(painter, QPointF(bounds.x() + ((bounds.width() - iSize.width()) / 2.0), + bounds.y() + (bounds.height() - iSize.height())), + "up" + suffix); + } + if (m_flags & TaskHasFocus) { + svg->paint(painter, QPointF(bounds.x() + ((bounds.width() - iSize.width()) / 2.0), + bounds.y()), + "down" + suffix); + } + } +} + +void AbstractTaskItem::drawColoredBackground(QPainter *painter, const QStyleOptionGraphicsItem *option) +{ + // Do not paint with invalid sizes, the happens when the layout is being initialized + if (!option->rect.isValid()) { + return; + } + + QSize sz = size().toSize() - QSize(4, 4); + const Tile &tile = coloredBackground(dominantColor(icon()), sz); + QPointF pos = size().toSize() == m_activeRect.size().toSize() ? m_activeRect.topLeft() + QPoint(2, 2) : QPointF(2, 2); + + if (!tile.left.isNull()) { + painter->drawPixmap(pos, tile.left); + painter->drawTiledPixmap(pos.x() + tile.left.width(), pos.y(), sz.width() - (tile.left.width() + tile.right.width()), tile.center.height(), tile.center); + painter->drawPixmap((pos.x() + sz.width()) - tile.right.width(), pos.y(), tile.right); + } +} + +void AbstractTaskItem::drawShine(QPainter *painter, const QStyleOptionGraphicsItem *option) +{ + // Do not paint with invalid sizes, the happens when the layout is being initialized + if (!option->rect.isValid()) { + return; + } + + QPixmap pixmap = shine(size().toSize() - QSize(4, 4)); + if (pixmap.size() == (m_activeRect.size().toSize() - QSize(4, 4))) { + painter->drawPixmap(m_activeRect.topLeft() + QPoint(2, 2), pixmap); + } else { + painter->drawPixmap(QPoint(2, 2), pixmap); + } +} + +void AbstractTaskItem::addOverlay(QPixmap &pix) +{ + if (m_dockItem && !m_dockItem->overlayIcon().isNull()) { + int overlaySize=(int)(qMin(16.0, qMin(pix.width(), pix.height())/3.0)+0.5); + overlaySize=((overlaySize/4)*4)+(overlaySize%4 ? 4 : 0); + if(overlaySize>4) { + QPixmap overlay = m_dockItem->overlayIcon().pixmap(QSize(overlaySize, overlaySize)); + if(!overlay.isNull()) { + QPainter overlayPainter(&pix); + QPoint pos = Qt::RightToLeft == layoutDirection() ? QPoint(pix.width()-overlay.width()+1, 0) : QPoint(0, 0); + overlayPainter.drawPixmap(pos, overlay); + } + } + } +} + +void AbstractTaskItem::paint(QPainter *painter, + const QStyleOptionGraphicsItem *option, + QWidget *) +{ + if (!m_abstractItem) { + return; + } + + qreal origOpacity = 1.0; + bool fadeBackground = false; + + if (busyWidget()) { + AbstractTaskItem *item = parentGroup()->matchingItem(m_abstractItem); + if (item) { + QRectF iconR = item->iconRect(/*m_applet->autoIconScaling() ? item->boundingRect().adjusted(4,4,-5,-5) : */item->boundingRect(), false); + QPointF pos = item->mapToParent(QPointF(iconR.x(), iconR.y())); + + busyWidget()->setGeometry(QRectF(pos.x(), pos.y(), iconR.width(), iconR.height())); + busyWidget()->show(); + setGeometry(QRectF(-1, -1, 1, 1)); // Hide this item... + return; + } else { + origOpacity = painter->opacity(); + fadeBackground = true; + } + } + + //kDebug() << "painting" << (QObject*)this << text(); + painter->setRenderHint(QPainter::Antialiasing); + QRectF bounds(boundingRect()); + bool showText = bounds.width() > (bounds.height() * 4); // Want text for popup! + + if ((Tasks::Style_Plasma == m_applet->style() || showText) && (m_abstractItem->itemType() != TaskManager::LauncherItemType)) { //Launchers have no frame + // draw background + drawBackground(painter, option); + if (fadeBackground) { + painter->setOpacity(origOpacity * 0.50); + } + } else if (Tasks::Style_IconTasksColored == m_applet->style()) { + if (fadeBackground) { + painter->setOpacity(origOpacity * 0.50); + } + drawColoredBackground(painter, option); + } + + // draw icon and text + drawTask(painter, option, showText); + + if (fadeBackground) { + painter->setOpacity(origOpacity); + } +} + +void AbstractTaskItem::syncActiveRect() +{ + Plasma::FrameSvg *itemBackground = m_applet->itemBackground(); + itemBackground->setElementPrefix("normal"); + + qreal left, top, right, bottom; + itemBackground->getMargins(left, top, right, bottom); + + itemBackground->setElementPrefix("focus"); + qreal activeLeft, activeTop, activeRight, activeBottom; + itemBackground->getMargins(activeLeft, activeTop, activeRight, activeBottom); + + m_activeRect = QRectF(QPointF(0, 0), size()); + m_activeRect.adjust(left - activeLeft, top - activeTop, + -(right - activeRight), -(bottom - activeBottom)); + + itemBackground->setElementPrefix(m_backgroundPrefix); + + queueUpdate(); +} + +void AbstractTaskItem::resizeEvent(QGraphicsSceneResizeEvent *event) +{ + syncActiveRect(); + resizeBackground(event->newSize().toSize()); +} + +void AbstractTaskItem::resizeBackground(const QSize &size) +{ + Plasma::FrameSvg *itemBackground = m_applet->itemBackground(); + bool vertical = Plasma::Vertical == m_applet->formFactor(), + rot = vertical && m_applet->rotate(); + QSize sz = rotateFrame(size, rot) + (vertical ? QSize(2, 2) : QSize(0, 0)); + + itemBackground->setElementPrefix("focus"); + m_applet->resizeItemBackground(sz); + itemBackground->setElementPrefix("normal"); + m_applet->resizeItemBackground(sz); + itemBackground->setElementPrefix("minimized"); + m_applet->resizeItemBackground(sz); + itemBackground->setElementPrefix("attention"); + m_applet->resizeItemBackground(sz); + itemBackground->setElementPrefix("hover"); + m_applet->resizeItemBackground(sz); + + //restore the prefix + itemBackground->setElementPrefix(m_backgroundPrefix); +} + +void AbstractTaskItem::drawBackground(QPainter *painter, const QStyleOptionGraphicsItem *option) +{ + // Do not paint with invalid sizes, the happens when the layout is being initialized + if (!option->rect.isValid()) { + return; + } + + bool rot = Plasma::Vertical == m_applet->formFactor() && m_applet->rotate(); + + /*FIXME -could be done more elegant with caching in tasks in a qhash . + -do not use size() directly because this introduces the blackline syndrome. + -This line is only needed when we have different items in the taskbar because of an expanded group for example. otherwise the resizing in the resizeEvent is sufficient + */ + Plasma::FrameSvg *itemBackground = m_applet->itemBackground(); + QPointF adj = Plasma::LeftEdge == m_applet->location() || Plasma::RightEdge == m_applet->location() + ? QPointF(-1, -1) : QPointF(0, 0); + + if (rot) { + painter->save(); + painter->rotate(-90); + painter->translate(-boundingRect().height(), 0); + } + + if (~option->state & QStyle::State_Sunken && + (!m_backgroundFadeAnim || m_backgroundFadeAnim->state() != QAbstractAnimation::Running)) { + itemBackground->setElementPrefix(m_backgroundPrefix); + //since a single framesvg is shared between all tasks, we could have to resize it even if there wasn't a resizeevent + if (rotateFrame(size().toSize(), rot) != itemBackground->frameSize()) { + resizeBackground(size().toSize()); + } + + if (itemBackground->frameSize() == m_activeRect.size().toSize()) { + itemBackground->paintFrame(painter, m_activeRect.topLeft() + adj); + } else { + itemBackground->paintFrame(painter, adj); + } + //itemBackground->paintFrame(painter, backgroundPosition); + if (rot) painter->restore(); + return; + } + + itemBackground->setElementPrefix(m_oldBackgroundPrefix); + //since a single framesvg is shared between all tasks, we could have to resize it even if there wasn't a resizeevent + if (rotateFrame(size().toSize(), rot) != itemBackground->frameSize()) { + resizeBackground(size().toSize()); + } + + QPixmap oldBackground; + + if (option->state & QStyle::State_Sunken) { + oldBackground = QPixmap(m_activeRect.size().toSize()); + oldBackground.fill(Qt::transparent); + m_alpha = 0.4; + } else { + oldBackground = itemBackground->framePixmap(); + } + + itemBackground->setElementPrefix(m_backgroundPrefix); + //since a single framesvg is shared between all tasks, we could have to resize it even if there wasn't a resizeevent + if (rotateFrame(size().toSize(), rot) != itemBackground->frameSize()) { + resizeBackground(size().toSize()); + } + + QPixmap result = Plasma::PaintUtils::transition(oldBackground, itemBackground->framePixmap(), m_alpha); + + if (result.size() == m_activeRect.size().toSize()) { + painter->drawPixmap(m_activeRect.topLeft() + adj, result); + } else { + painter->drawPixmap(QPoint(0, 0) + adj, result); + } + if (rot) painter->restore(); +} + +void AbstractTaskItem::drawTask(QPainter *painter, const QStyleOptionGraphicsItem *option, bool showText) +{ + Q_UNUSED(option) + + QRectF boundOrig = boundingRect(); + QRectF bounds = boundOrig; + + if (/*(m_abstractItem->itemType() != TaskManager::LauncherItemType) &&*/ showText) { + bounds = bounds.adjusted(m_applet->itemLeftMargin(), m_applet->itemTopMargin(), -m_applet->itemRightMargin(), -m_applet->itemBottomMargin()); + } else { + bounds = bounds.adjusted(4, 4, -5, -5); + } + + WindowTaskItem *window = qobject_cast(this); + QGraphicsWidget *busyWidget; + busyWidget = window ? window->busyWidget() : 0; + + QRectF iconR = iconRect(m_applet->autoIconScaling() ? bounds : boundOrig, showText); + + if (busyWidget) { + QRectF bwR = iconRect(boundOrig, false); + QPointF pos = mapToParent(QPointF(bwR.x(), bwR.y())); + busyWidget->setGeometry(QRectF(pos.x(), pos.y(), bwR.width(), bwR.height())); + busyWidget->show(); + } + + /* + kDebug() << bool(option->state & QStyle::State_MouseOver) << m_backgroundFadeAnim << + (m_backgroundFadeAnim ? m_backgroundFadeAnim->state() : QAbstractAnimation::Stopped);*/ + const bool fadingBg = m_backgroundFadeAnim && m_backgroundFadeAnim->state() == QAbstractAnimation::Running; + QIcon icn(icon(true)); + QSize iSize = iconR.toRect().size(); + QPixmap result = icn.pixmap(iSize); + + if (!m_applet->autoIconScaling() && result.size() != iSize) { + result = scaleIcon(icn, iconR.toRect().size(), result); + if (result.size() != iSize) { + int xmod = (iSize.width() - result.width()) / 2, + ymod = (iSize.height() - result.height()) / 2; + iconR.adjust(xmod, ymod, -xmod, -ymod); + } + } + + addOverlay(result); + + if ((!fadingBg && !(option->state & QStyle::State_MouseOver)) || + (m_oldBackgroundPrefix != "hover" && m_backgroundPrefix != "hover")) { + // QIcon::paint does some alignment work and can lead to funny + // things when icon().size() != iconR.toRect().size() + qreal opacity = painter->opacity(); + if (Tasks::Style_Plasma != m_applet->style()) { + if (m_attentionTimerId) { + painter->setOpacity(0.25 + ((((m_alpha > 0.5 ? m_alpha : 1.0 - m_alpha) - 0.5) / 0.5) * 0.75)); + } +// else if (m_flags & TaskIsMinimized) { +// painter->setOpacity(0.6*painter->opacity()); +// } + } + painter->drawPixmap(iconR.topLeft(), result); + if (Tasks::Style_Plasma != m_applet->style() && (/* (m_flags & TaskIsMinimized) || */m_attentionTimerId)) { + painter->setOpacity(opacity); + } + } else { + KIconEffect *effect = KIconLoader::global()->iconEffect(); + + if (effect->hasEffect(KIconLoader::Desktop, KIconLoader::ActiveState)) { + if (qFuzzyCompare(qreal(1.0), m_alpha)) { + result = effect->apply(result, KIconLoader::Desktop, KIconLoader::ActiveState); + } else { + result = Plasma::PaintUtils::transition(result, + effect->apply(result, KIconLoader::Desktop, + KIconLoader::ActiveState), m_backgroundPrefix != "hover" ? 1 - m_alpha : m_alpha); + } + } + painter->drawPixmap(iconR.topLeft(), result); + } + + painter->setPen(QPen(textColor(), 1.0)); + + if (m_abstractItem->itemType() != TaskManager::LauncherItemType) { + if (showText) { + QRect rect = textRect(bounds).toRect(); + if (rect.height() > 20) { + rect.adjust(2, 2, -2, -2); // Create a text margin + } + + QFont f(KGlobalSettings::taskbarFont()); + QFontMetrics fm(f); + QString txt = fm.elidedText(text(), Qt::ElideRight, rect.width(), QPalette::WindowText); + QColor txtCol(textColor()); + + painter->setPen(txtCol); + painter->setFont(font()); + if (txtCol.value() < 128 && rect.height() > 4) { + int haloWidth = qMin(rect.width(), fm.width(txt)); + if (haloWidth > 4) { + Plasma::PaintUtils::drawHalo(painter, QRectF(rect.x() + 0.5, rect.y() + 0.5, haloWidth - 1, rect.height() - 1)); + } + } + painter->drawText(rect, txt, QTextOption(Qt::AlignVCenter)); + if (m_flags & TaskWantsAttention && 0 != m_attentionTimerId) { + painter->drawText(rect.adjusted(1, 0, 1, 0), txt, QTextOption(Qt::AlignVCenter)); + } + } + + TaskGroupItem *groupItem = qobject_cast(this); + if (groupItem && Tasks::Style_Plasma == m_applet->style()) { + int iSize = iconR.height() > 28 ? 16 : 8; + QPixmap pix(KIcon("list-add").pixmap(iSize, iSize)); + bool rtl = Qt::RightToLeft == layoutDirection(); + int glow = 1, + x = (rtl ? iconR.left() : (iconR.right() - (pix.width()))) + 2, + y = (iconR.bottom() - (pix.height() + 2)) + 2; + double glowX = (x - glow) + ((pix.width() + (2 * glow)) / 2.0), + glowY = (y - glow) + ((pix.height() + (2 * glow)) / 2.0); + + QRadialGradient gradient(QPointF(glowX, glowY), (pix.width() + (2 * glow)) / 2.0, QPointF(glowX, glowY)); + QColor c(Qt::white); + c.setAlphaF(0.5); + gradient.setColorAt(0, c); + gradient.setColorAt(0.6, c); + c.setAlphaF(0.0); + gradient.setColorAt(1.0, c); + painter->fillRect(QRect(x - glow, y - glow, pix.width() + (2 * glow), pix.height() + (2 * glow)), gradient); + painter->drawPixmap(x, y, pix); + } + } + + if (showText) { + return; + } + + if (Tasks::Style_IconTasksColored == m_applet->style()) { + drawShine(painter, option); + } + + if (busyWidget) { + return; + } + + if (m_unityItem && m_unityItem->countVisible()) { + drawBadge(painter, iconR, QString().setNum(m_unityItem->count())); + } else if (m_dockItem && !m_dockItem->badge().isEmpty()) { + drawBadge(painter, iconR, m_dockItem->badge()); + } + + if (!showText && JobManager::self()->isEnabled() && m_currentProgress >= 0) { + drawProgress(painter, iconR); + } + + if (Tasks::Style_Plasma != m_applet->style() && (m_abstractItem->itemType() != TaskManager::LauncherItemType)) { + drawIndicators(painter, rect()); + } +} + +qreal AbstractTaskItem::backgroundFadeAlpha() const +{ + return m_alpha; +} + +void AbstractTaskItem::setBackgroundFadeAlpha(qreal progress) +{ + m_alpha = progress; + update(); +} + +bool AbstractTaskItem::shouldIgnoreDragEvent(QGraphicsSceneDragDropEvent *event) +{ + bool locked = m_applet->groupManager().launchersLocked(); + + if (event->mimeData()->hasFormat(TaskManager::Task::mimetype()) || + event->mimeData()->hasFormat(TaskManager::Task::groupMimetype()) || + (!locked && event->mimeData()->hasFormat(AppLauncherItem::mimetype()))) { + return true; + } + + if (!locked && event->mimeData()->hasFormat("text/uri-list")) { + // we want to check if we have .desktop files; if so, then we treat it as a possible + // drop for a launcher + const KUrl::List uris = KUrl::List::fromMimeData(event->mimeData()); + if (!uris.isEmpty()) { + foreach (const QUrl & uri, uris) { + KUrl url(uri); + if (!url.isLocalFile()) { + return false; + } + + const QString path = url.toLocalFile(); + + if (QFileInfo(path).isDir()) { + return false; + } + + if (KDesktopFile::isDesktopFile(path)) { + KDesktopFile f(path); + if (f.tryExec()) { + return true; + } + } + } + } + } + + return false; +} + +QList AbstractTaskItem::getAppMenu() +{ + QList appMenu; + bool addedDocs = false; + bool addedUnityItems = false; + KUrl lUrl = launcherUrl(); + + if (lUrl.isValid()) { + appMenu = RecentDocuments::self()->get(lUrl.fileName().remove(".desktop")); + addedDocs = true; + } + + if (m_unityItem) { + QList unityActions = m_unityItem->menu(); + addedUnityItems = !unityActions.isEmpty(); + if (addedDocs && addedUnityItems) { + theSepAction.setSeparator(true); + appMenu.append(&theSepAction); + } + appMenu.append(unityActions); + } + + if (m_dockItem && !addedUnityItems) { + QList dockActions = m_dockItem->menu(); + if (addedDocs && !dockActions.isEmpty()) { + theSepAction.setSeparator(true); + appMenu.append(&theSepAction); + } + appMenu.append(dockActions); + } + + return appMenu; +} + +void AbstractTaskItem::registerWithHelpers() +{ + JobManager::self()->registerTask(this); + DockManager::self()->registerTask(this); + Unity::self()->registerTask(this); +} + +void AbstractTaskItem::unregisterFromHelpers() +{ + JobManager::self()->unregisterTask(this); + DockManager::self()->unregisterTask(this); + Unity::self()->unregisterTask(this); + m_dockItem = 0; + m_unityItem = 0; +} + +void AbstractTaskItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) +{ + if (shouldIgnoreDragEvent(event)) { + event->ignore(); + return; + } + + event->accept(); + + if (!m_activateTimerId) { + m_activateTimerId = startTimer(250); + m_oldDragPos = event->pos(); + } +} + +void AbstractTaskItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event) +{ + // restart the timer so that activate() is only called after the mouse + // stops moving + if (m_activateTimerId && event->pos() != m_oldDragPos) { + m_oldDragPos = event->pos(); + killTimer(m_activateTimerId); + m_activateTimerId = startTimer(250); + } +} + +void AbstractTaskItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) +{ + Q_UNUSED(event); + + if (m_activateTimerId) { + killTimer(m_activateTimerId); + m_activateTimerId = 0; + } +} + +QRect AbstractTaskItem::iconGeometry() const +{ + if (!scene() || !boundingRect().isValid()) { + return QRect(); + } + + QGraphicsView *parentView = 0; + QGraphicsView *possibleParentView = 0; + // The following was taken from Plasma::Applet, it doesn't make sense to make the item an applet, and this was the easiest way around it. + foreach (QGraphicsView * view, scene()->views()) { + if (view->sceneRect().intersects(sceneBoundingRect()) || + view->sceneRect().contains(scenePos())) { + if (view->isActiveWindow()) { + parentView = view; + break; + } else { + possibleParentView = view; + } + } + } + + if (!parentView) { + parentView = possibleParentView; + + if (!parentView) { + return QRect(); + } + } + + QRect rect = parentView->mapFromScene(mapToScene(boundingRect())).boundingRect().adjusted(0, 0, 1, 1); + rect.moveTopLeft(parentView->mapToGlobal(rect.topLeft())); + return rect; +} + +void AbstractTaskItem::publishIconGeometry() const +{ +} + +void AbstractTaskItem::publishIconGeometry(const QRect &rect) const +{ + Q_UNUSED(rect) +} + +void AbstractTaskItem::setAnimationPos(const QPointF &pos) +{ + m_layoutAnimationLock = true; + setPos(pos); + m_layoutAnimationLock = false; +} + +QPointF AbstractTaskItem::animationPos() const +{ + return pos(); +} + +void AbstractTaskItem::setGeometry(const QRectF& geometry) +{ + if (geometry == QGraphicsWidget::geometry()) { + // Stop layout animiation! Without this a gap in the taskbar can appear when + // a whole task group is closed (e.g. start 2 KCalcs (with a launcher), and + // close via right-click menu). + // Looks like we have a first animation to move item below KCalc group + // down/right by 1 space he we immediately get a setGeometry moving back to + // the start. But because geometry==QGraphicsWidget::geometry, nothing happend. + m_layoutAnimation->stop(); + if (m_updateGeometryTimerId) { + killTimer(m_updateGeometryTimerId); + m_updateGeometryTimerId = 0; + } + return; + } + + QPointF oldPos = pos(); + + if (m_lastGeometryUpdate.elapsed() < 500) { + if (m_updateGeometryTimerId) { + killTimer(m_updateGeometryTimerId); + m_updateGeometryTimerId = 0; + } + + m_updateGeometryTimerId = startTimer(500 - m_lastGeometryUpdate.elapsed()); + } else { + publishIconGeometry(); + m_lastGeometryUpdate.restart(); + } + + //TODO:remove when we will have proper animated layouts + if (m_firstGeometryUpdate && !m_layoutAnimationLock) { + QRectF animStartGeom(oldPos, geometry.size()); + QGraphicsWidget::setGeometry(animStartGeom); + + if (m_layoutAnimation->state() == QAbstractAnimation::Running) { + m_layoutAnimation->stop(); + } + + m_layoutAnimation->setEndValue(geometry.topLeft()); + m_layoutAnimation->start(); + } else { + QGraphicsWidget::setGeometry(geometry); + } +} + +QRectF AbstractTaskItem::iconRect(const QRectF &b, bool showText) +{ + QRectF bounds(b); + const int right = bounds.right(); + + if (showText) { + //leave enough space for the text. useful in vertical panel + bounds.setWidth(qMax(bounds.width() / 3, qMin(minimumSize().height(), bounds.width()))); + + //restore right position if the layout is RTL + if (QApplication::layoutDirection() == Qt::RightToLeft) { + bounds.moveRight(right); + } + } + + m_lastIconSize = iconSize(bounds); + + if (showText) { + return QStyle::alignedRect(QApplication::layoutDirection(), + (showText ? Qt::AlignLeft : Qt::AlignCenter) | Qt::AlignVCenter, + m_lastIconSize, bounds.toRect()); + } else { + return QRectF(bounds.x() + ((bounds.width() - m_lastIconSize.width()) / 2.0), + bounds.y() + ((bounds.height() - m_lastIconSize.height()) / 2.0), + m_lastIconSize.width(), m_lastIconSize.height()); + } +} + +QSize AbstractTaskItem::iconSize(const QRectF &bounds) const +{ + QSize size; + if (m_applet->autoIconScaling()) { + size = icon().actualSize(bounds.size().toSize()); + + static const int constMargin = 2; + + if (size.width() == size.height()) { + if (size.width() > KIconLoader::SizeSmall - constMargin && size.width() < KIconLoader::SizeSmall + constMargin) { + size = QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall); + } else if (size.width() > KIconLoader::SizeSmallMedium - constMargin && size.width() < KIconLoader::SizeSmallMedium + constMargin) { + size = QSize(KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium); + } else if (size.width() > KIconLoader::SizeMedium - constMargin && size.width() < KIconLoader::SizeMedium + constMargin) { + size = QSize(KIconLoader::SizeMedium, KIconLoader::SizeMedium); + } else if (size.width() > KIconLoader::SizeLarge - constMargin && size.width() < KIconLoader::SizeLarge + constMargin) { + size = QSize(KIconLoader::SizeLarge, KIconLoader::SizeLarge); + } else if (size.width() > KIconLoader::SizeHuge - constMargin && size.width() < KIconLoader::SizeHuge + constMargin) { + size = QSize(KIconLoader::SizeHuge, KIconLoader::SizeHuge); + } + } + } else { + size = bounds.size().toSize(); // + int sz = (qMin(size.width(), size.height()) * m_applet->iconScale()) / 100; + size = QSize(sz, sz); + } + + return size; +} + +QRectF AbstractTaskItem::textRect(const QRectF &bounds) +{ + QSize size(bounds.size().toSize()); + QRectF effectiveBounds(bounds); + + size.rwidth() -= int(iconRect(bounds, true).width()) + qMax(0, IconTextSpacing - 2); + return QStyle::alignedRect(QApplication::layoutDirection(), Qt::AlignRight | Qt::AlignVCenter, size, effectiveBounds.toRect()); +} + +QColor AbstractTaskItem::textColor() const +{ + QColor color; + qreal bias; + Plasma::Theme *theme = Plasma::Theme::defaultTheme(); + + if ((m_oldBackgroundPrefix == "attention" || m_backgroundPrefix == "attention") && + m_applet->itemBackground()->hasElement("hint-attention-button-color")) { + bool animatingBg = m_backgroundFadeAnim && m_backgroundFadeAnim->state() == QAbstractAnimation::Running; + if (animatingBg) { + if (m_oldBackgroundPrefix == "attention") { + bias = 1 - m_alpha; + } else { + bias = m_alpha; + } + + color = KColorUtils::mix(theme->color(Plasma::Theme::TextColor), + theme->color(Plasma::Theme::ButtonTextColor), bias); + } else if (m_backgroundPrefix != "attention") { + color = theme->color(Plasma::Theme::TextColor); + } else { + color = theme->color(Plasma::Theme::ButtonTextColor); + } + } else { + color = theme->color(Plasma::Theme::TextColor); + } + + if (m_flags & TaskIsMinimized) { + color.setAlphaF(0.85); + } + + return color; +} + +bool AbstractTaskItem::isGroupMember(const TaskGroupItem *group) const +{ + if (!m_abstractItem || !group) { + kDebug() << "no task"; + return false; + } + + return m_abstractItem->isGroupMember(group->group()); + +} + +bool AbstractTaskItem::isGrouped() const +{ + if (!m_abstractItem) { + kDebug() << "no item"; + return false; + } + + return m_abstractItem->isGrouped(); +} + +TaskGroupItem * AbstractTaskItem::parentGroup() const +{ + TaskGroupItem *group = qobject_cast(parentWidget()); + + //lucky case: directly in a group + if (group) { + return group; + } + + //in a popup or a popup's popup? + QObject *candidate = parentWidget(); + + while (candidate) { + group = qobject_cast(candidate); + candidate = candidate->parent(); + if (group) { + return group; + } + } + + return 0; +} + +TaskManager::AbstractGroupableItem * AbstractTaskItem::abstractItem() +{ + return m_abstractItem; +} + +#include "abstracttaskitem.moc" diff --git a/kdeplasma-addons/applets/icontasks/abstracttaskitem.h b/kdeplasma-addons/applets/icontasks/abstracttaskitem.h new file mode 100644 index 00000000..33fe7db1 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/abstracttaskitem.h @@ -0,0 +1,306 @@ +/*************************************************************************** + * Copyright (C) 2007 by Robert Knight * + * Copyright (C) 2008 by Alexis Ménard * + * Copyright (C) 2008 by Marco Martin * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + + +#ifndef ABSTRACTTASKITEM_H +#define ABSTRACTTASKITEM_H + +// KDE +#include +#include + +// Own +#include "taskmanager/taskgroup.h" + +// Qt +#include +#include +#include +#include +#include + +class QTextOption; +class QTextLayout; +class QString; +class QAction; + +// Plasma +#include + +class Tasks; +class TaskGroupItem; +class LayoutWidget; +class DockItem; +class UnityItem; + +/** + * A baseclass for a task + */ +class AbstractTaskItem : public QGraphicsWidget +{ + Q_OBJECT + Q_PROPERTY(QPointF animationPos READ animationPos WRITE setAnimationPos) + Q_PROPERTY(qreal backgroundFadeAlpha READ backgroundFadeAlpha WRITE setBackgroundFadeAlpha) + +public: + enum InfoSource { + IS_None, + IS_Job, + IS_DockManager, + IS_Unity + }; + + enum Cache { + Cache_Bgnd = 0x01, + Cache_Scale = 0x02, + Cache_All = Cache_Bgnd | Cache_Scale + }; + + static void clearCaches(int cache = Cache_All); + + /** Constructs a new representation for an abstract task. */ + AbstractTaskItem(QGraphicsWidget *parent, Tasks *applet); + + /** Destruct the representation for an abstract task. */ + virtual ~AbstractTaskItem(); + + /** The text changed for this task item. */ + void textChanged(); + + /** Sets the icon for this task item. */ + void setIcon(const QIcon &icon); + + /** + * This enum describes the generic flags which are currently + * set by the task. + */ + enum TaskFlag { + /** + * This flag is set by the task to indicate that it wants + * the user's attention. + */ + TaskWantsAttention = 1, + /** + * Indicates that the task's window has the focus + */ + TaskHasFocus = 2, + /** + * Indicates that the task is iconified + */ + TaskIsMinimized = 4 + }; + Q_DECLARE_FLAGS(TaskFlags, TaskFlag) + + /** Sets the task flags for this item. */ + void setTaskFlags(TaskFlags flags); + + /** Returns the task's current flags. */ + TaskFlags taskFlags() const; + + /** Returns current text for this task. */ + virtual QString text() const; + + /** Returns the current icon for this task. */ + QIcon icon(bool useDockManager = false) const; + + virtual void close() = 0; + + /** Tells the window manager the minimized task's geometry. */ + virtual void publishIconGeometry() const; + virtual void publishIconGeometry(const QRect &rect) const; + QRect iconGeometry() const; // helper for above + + /** Overridden from LayoutItem */ + void setGeometry(const QRectF& geometry); + + /** Convenience Functions to get information about Grouping */ + /** Only true if the task is not only member of rootGroup */ + bool isGrouped() const; + bool isGroupMember(const TaskGroupItem *group) const; + TaskGroupItem *parentGroup() const; + + virtual bool isWindowItem() const = 0; + virtual bool isActive() const = 0; + + virtual void setAdditionalMimeData(QMimeData* mimeData) = 0; + + void setLayoutWidget(LayoutWidget* widget); + TaskManager::AbstractGroupableItem * abstractItem(); + + /** Returns the preferred size calculated on base of the fontsize and the iconsize*/ + QSize basicPreferredSize() const; + void setPreferredOffscreenSize(); + void setPreferredOnscreenSize(); + + //TODO: to be removed when we have proper animated layouts + QPointF animationPos() const; + void setAnimationPos(const QPointF &pos); + + virtual QGraphicsWidget *busyWidget() const { + return 0L; + } + bool isStartupWithTask() const; + bool isToolTipVisible() const; + + virtual void showContextMenu(const QPoint &, bool) { } + virtual QString appName() const = 0; + virtual KUrl launcherUrl() const = 0; + virtual QString windowClass() const = 0; + void updateProgress(int v, InfoSource source = IS_Job); + void dockItemUpdated(); + void unityItemUpdated(); + void setDockItem(DockItem *i) { + m_dockItem = i; + } + void setUnityItem(UnityItem *i) { + m_unityItem = i; + } + virtual int pid() const { + return 0; + } + virtual void toCurrentDesktop() { } + QString mediaButtonKey(); + +Q_SIGNALS: + void activated(AbstractTaskItem *); + void destroyed(AbstractTaskItem *); + +public Q_SLOTS: + virtual void activate() = 0; + void toolTipAboutToShow(); + void toolTipHidden(); + void mediaButtonPressed(int b); + void windowPreviewActivated(WId id, Qt::MouseButtons buttons, Qt::KeyboardModifiers, const QPoint &pos); + void controlWindow(WId id, Qt::MouseButtons buttons); + +protected: + void middleClick(); + void dragEnterEvent(QGraphicsSceneDragDropEvent *event); + void dragMoveEvent(QGraphicsSceneDragDropEvent *event); + void dragLeaveEvent(QGraphicsSceneDragDropEvent *event); + + // reimplemented + void focusInEvent(QFocusEvent *event); + void focusOutEvent(QFocusEvent *event); + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void timerEvent(QTimerEvent *event); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + + void drawProgress(QPainter *painter, const QRectF &rect); + void drawBadge(QPainter *painter, const QRectF &rect, const QString &badge); + void drawIndicators(QPainter *painter, const QRectF &rect); + void drawColoredBackground(QPainter *painter, const QStyleOptionGraphicsItem *option); + void drawShine(QPainter *painter, const QStyleOptionGraphicsItem *option); + void addOverlay(QPixmap &pix); + + /** Draws the background for the task item. */ + virtual void drawBackground(QPainter *painter, const QStyleOptionGraphicsItem *option); + /** Draws the icon and text which represent the task item. */ + virtual void drawTask(QPainter *painter, const QStyleOptionGraphicsItem *option, bool showText); + + virtual void updateTask(::TaskManager::TaskChanges changes) = 0; // pure virtual function + virtual void updateToolTip() = 0; // pure virtual function + void updateToolTipMediaState(); + void clearToolTip(); + void stopWindowHoverEffect(); + bool shouldIgnoreDragEvent(QGraphicsSceneDragDropEvent *event); + QList getAppMenu(); + void registerWithHelpers(); + void unregisterFromHelpers(); + +protected Q_SLOTS: + /** Event compression **/ + void queueUpdate(); + + qreal backgroundFadeAlpha() const; + void setBackgroundFadeAlpha(qreal progress); + + void syncActiveRect(); + void checkSettings(); + void clearAbstractItem(); + +protected: + // area of item occupied by task's icon + QRectF iconRect(const QRectF &bounds, bool showText = false); + QSize iconSize(const QRectF &bounds) const; + // area of item occupied by task's text + QRectF textRect(const QRectF &bounds); + // start an animation to chnge the task background + void fadeBackground(const QString &newBackground, int duration); + // text color, use this because it could be animated + QColor textColor() const; + void resizeBackground(const QSize &size); + + void resizeEvent(QGraphicsSceneResizeEvent *event); + + TaskManager::AbstractGroupableItem * m_abstractItem; + LayoutWidget *m_layoutWidget; + + Tasks *m_applet; + TaskFlags m_flags; + + // distance (in pixels) between a task's icon and its text + static const int IconTextSpacing = 4; + static const int TaskItemHorizontalMargin = 4; + static const int TaskItemVerticalMargin = 4; + + //TODO: remove when we have animated layouts + QPropertyAnimation *m_layoutAnimation; + QPropertyAnimation *m_backgroundFadeAnim; + + qreal m_alpha; + QString m_oldBackgroundPrefix; + QString m_backgroundPrefix; + DockItem *m_dockItem; + UnityItem *m_unityItem; + +private: + QRectF m_activeRect; + + QTime m_lastGeometryUpdate; + QTime m_lastUpdate; + QSize m_lastIconSize; + int m_activateTimerId; + int m_updateGeometryTimerId; + int m_updateTimerId; + int m_hoverEffectTimerId; + int m_attentionTimerId; + int m_attentionTicks; + int m_mediaStateTimerId; + + WId m_lastViewId; + + bool m_layoutAnimationLock : 1; + bool m_firstGeometryUpdate : 1; + + mutable QIcon m_icon; + + InfoSource m_progressSource; + int m_lastProgress; + int m_currentProgress; + QPointF m_oldDragPos; +}; + +#endif diff --git a/kdeplasma-addons/applets/icontasks/appearanceconfig.ui b/kdeplasma-addons/applets/icontasks/appearanceconfig.ui new file mode 100644 index 00000000..1bb8792b --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/appearanceconfig.ui @@ -0,0 +1,261 @@ + + + appearanceconfig + + + + 0 + 0 + 480 + 283 + + + + + 0 + + + + + Style: + + + + + + + + + + Rotate vertical frames: + + + rotate + + + + + + + <p>Controls whether the frames drawn around taskbar entries should be rotated 90-degrees counter-clockwise when the taskbar is in a vertical panel.</p> + + + + + + + + + + Tooltips: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + toolTips + + + + + + + + + + Window preview size: + + + previewSize + + + + + + + <p>Controls the width of window previews with tooltips.</p> + + + px + + + + + + + + + + Always use launcher icons: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + launcherIcons + + + + + + + <p>Enabling this item forces the icon for a running application to be the same as that used for the launcher. This resolves some oddities where the launcher icon is different from the application icon - as happens with LibreOffice.</p> + + + + + + + + + + Scale icons to: + + + iconScale + + + + + + + <p>Controls the scaling of the taskbar icon. When set to &quot;Automatic&quot;, the taskbar will attempt to determine the optimal size.</p> + + + % + + + 10 + + + + + + + Spacing: + + + spacing + + + + + + + <p>Set the amount of extra spacing between items.</p> + + + px + + + + + + 0 + + + + + + + Maximum rows: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + maxRows + + + + + + + <p>Controls the maximum number of rows (for a horizontal taskbar), or columns (for a vertical taskbar), that will be used.</p> + + + 1 + + + 2 + + + + + + + Sorting: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + sortingStrategy + + + + + + + + 200 + 0 + + + + + + + + Separator: + + + showSeparator + + + + + + + <p>When enabled, and there is only 1 row/column, then a separator will be drawn between the launchers/tasks-with-launchers and non-launcher tasks.</p> + + + + + + + Highlight windows: + + + + + + + + + + + + + + + KIntSpinBox + QSpinBox +
knuminput.h
+
+
+ + style + rotate + toolTips + previewSize + launcherIcons + iconScale + spacing + maxRows + sortingStrategy + showSeparator + + + +
diff --git a/kdeplasma-addons/applets/icontasks/applauncheritem.cpp b/kdeplasma-addons/applets/icontasks/applauncheritem.cpp new file mode 100644 index 00000000..f721b5a9 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/applauncheritem.cpp @@ -0,0 +1,155 @@ +/*************************************************************************** + * Copyright (C) 2010 by Anton Kreuzkamp * + * * + * 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 . * + ***************************************************************************/ + +// Own +#include "applauncheritem.h" +#include "taskgroupitem.h" +#include "jobmanager.h" +#include "dockmanager.h" +#include "dockitem.h" +#include "mediabuttons.h" +#include "unity.h" + +#include "taskmanager/taskactions.h" +#include "taskmanager/groupmanager.h" + +// Qt +#include +#include + +// KDE +#include +#include + +#include "tooltips/tooltipmanager.h" +#include +#include +#include + +QString AppLauncherItem::mimetype() +{ + return "taskmanager:/launcher"; +} + +AppLauncherItem::AppLauncherItem(QGraphicsWidget* parent, Tasks* applet, TaskManager::LauncherItem* launcher) + : AbstractTaskItem(parent, applet) +{ + m_launcher = launcher; + m_abstractItem = launcher; + registerWithHelpers(); +} + +AppLauncherItem::~AppLauncherItem() +{ + close(false); +} + +void AppLauncherItem::close() +{ + close(true); +} + +void AppLauncherItem::close(bool hide) +{ + unregisterFromHelpers(); + if (hide) { + setVisible(false); + } +} + +QString AppLauncherItem::windowClass() const +{ + return m_applet->groupManager().launcherWmClass(launcherUrl()); +} + +void AppLauncherItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if ((event->button() == Qt::LeftButton || (event->button() == Qt::MidButton && Tasks::MC_NewInstance == m_applet->middleClick())) && + boundingRect().contains(event->pos())) { + m_launcher->launch(); + } +} + +void AppLauncherItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *e) +{ + if (!KAuthorized::authorizeKAction("kwin_rmb") || !m_launcher) { + QGraphicsWidget::contextMenuEvent(e); + return; + } + + QList actionList; + + QAction *configAction = m_applet->action("configure"); + if (configAction && configAction->isEnabled()) { + actionList.append(configAction); + } + + TaskManager::BasicMenu *menu = new TaskManager::BasicMenu(0, m_launcher, &m_applet->groupManager(), actionList, getAppMenu()); + menu->adjustSize(); + + if (m_applet->formFactor() != Plasma::Vertical) { + menu->setMinimumWidth(size().width()); + } + + Q_ASSERT(m_applet->containment()); + Q_ASSERT(m_applet->containment()->corona()); + stopWindowHoverEffect(); + menu->exec(m_applet->containment()->corona()->popupPosition(this, menu->size())); + menu->deleteLater(); +} + + +void AppLauncherItem::updateToolTip() +{ + IconTasks::ToolTipContent data(m_launcher->name(), m_launcher->genericName(), m_launcher->icon()); +#if KDE_IS_VERSION(4, 7, 0) + data.setInstantPopup(m_applet->instantToolTip()); +#endif + QString key = mediaButtonKey(); + if (!key.isEmpty()) { + data.setPlayState(MediaButtons::self()->playbackStatus(key)); + data.setClickable(true); + } + + IconTasks::ToolTipManager::self()->setContent(this, data); +} + +void AppLauncherItem::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) { + m_launcher->launch(); + } else { + QGraphicsWidget::keyPressEvent(event); + } +} + +void AppLauncherItem::setAdditionalMimeData(QMimeData* mimeData) +{ + if (m_launcher) { + m_launcher->addMimeData(mimeData); + + // Add our own mimetype, so that AbstractTaskItem knows to ignore drag envets of this type, + // then taskgroup will receive the event, and launchers can be re-ordered!!! + QByteArray data; + mimeData->setData(mimetype(), data); + } +} + +#include "applauncheritem.moc" + diff --git a/kdeplasma-addons/applets/icontasks/applauncheritem.h b/kdeplasma-addons/applets/icontasks/applauncheritem.h new file mode 100644 index 00000000..35f521f6 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/applauncheritem.h @@ -0,0 +1,83 @@ +/*************************************************************************** + * Copyright (C) 2010 by Anton Kreuzkamp * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + + +#ifndef APPLAUNCHERITEM_H +#define APPLAUNCHERITEM_H + +#include "abstracttaskitem.h" +// Own +#include "taskmanager/taskmanager.h" +#include "taskmanager/launcheritem.h" + +/** + * A launcheritem to quickly launch applications. + */ +class AppLauncherItem : public AbstractTaskItem +{ + Q_OBJECT + +public: + /** Constructs a new representation for a launcher. */ + AppLauncherItem(QGraphicsWidget *parent, Tasks *applet, TaskManager::LauncherItem *launcher); + ~AppLauncherItem(); + + TaskManager::LauncherItem* launcher() { + return m_launcher; + } + + virtual bool isWindowItem() const { + return false; + } + virtual bool isActive() const { + return false; + } + virtual void setAdditionalMimeData(QMimeData* mimeData); + virtual void close(); + virtual void updateTask(TaskManager::TaskChanges) {} + + static QString mimetype(); + + QString appName() const { + return m_launcher->name(); + } + KUrl launcherUrl() const { + return m_launcher->launcherUrl(); + } + QString windowClass() const; + +private: + void close(bool hide); + +public slots: + virtual void activate() {} + +protected: + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void keyPressEvent(QKeyEvent *event); + void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); + void updateToolTip(); + + +private: + TaskManager::LauncherItem *m_launcher; + +}; + +#endif diff --git a/kdeplasma-addons/applets/icontasks/badge.svgz b/kdeplasma-addons/applets/icontasks/badge.svgz new file mode 100644 index 00000000..8e9edce4 Binary files /dev/null and b/kdeplasma-addons/applets/icontasks/badge.svgz differ diff --git a/kdeplasma-addons/applets/icontasks/behaviourconfig.ui b/kdeplasma-addons/applets/icontasks/behaviourconfig.ui new file mode 100644 index 00000000..ec0a9ba6 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/behaviourconfig.ui @@ -0,0 +1,228 @@ + + + behaviourconfig + + + + 0 + 0 + 341 + 274 + + + + + 0 + + + + + General + + + + + + Show job progress on task icon: + + + showProgress + + + + + + + <p>When enabled, a progressbar will be drawn over the applications icons to represent its overall job progress.</p> + + + + + + + + + + Show control buttons on media player tooltips: + + + mediaButtons + + + + + + + <p>When enabled - previous, play/pause, and next buttons will be shown in the tooltips for media players.</p> + + + + + + + + + + Enable support for Unity features: + + + unity + + + + + + + <p>Toggles support for the Unity D-Bus API.</p> + + + + + + + + + + Show recent documents: + + + recentDocuments + + + + + + + <p>Toggles support for listing an application's recent documents in its popup menu.</p> + + + + + + + + + + Group click action: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + groupClick + + + + + + + <p>Configures what should occur when a task group is clicked.</p> + + + + + + + Middle-click action: + + + middleClick + + + + + + + + + + + + + Filters + + + + QFormLayout::ExpandingFieldsGrow + + + + + Only show tasks from the current screen: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + showOnlyCurrentScreen + + + + + + + + + + + + + + Only show tasks from the current desktop: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + showOnlyCurrentDesktop + + + + + + + + + + + + + + Only show tasks from the current activity: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + showOnlyCurrentActivity + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 2 + + + + + + + + + diff --git a/kdeplasma-addons/applets/icontasks/dbusstatus.cpp b/kdeplasma-addons/applets/icontasks/dbusstatus.cpp new file mode 100644 index 00000000..3dd29bd8 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/dbusstatus.cpp @@ -0,0 +1,46 @@ +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "dbusstatus.h" + +QDBusArgument& operator<< (QDBusArgument& arg, const DBusStatus& status) +{ + arg.beginStructure(); + arg << status.play; + arg << status.random; + arg << status.repeat; + arg << status.repeat_playlist; + arg.endStructure(); + return arg; +} + +const QDBusArgument& operator>> (const QDBusArgument& arg, DBusStatus& status) +{ + arg.beginStructure(); + arg >> status.play; + arg >> status.random; + arg >> status.repeat; + arg >> status.repeat_playlist; + arg.endStructure(); + return arg; +} diff --git a/kdeplasma-addons/applets/icontasks/dbusstatus.h b/kdeplasma-addons/applets/icontasks/dbusstatus.h new file mode 100644 index 00000000..4195851b --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/dbusstatus.h @@ -0,0 +1,47 @@ +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __DBUS_STATUS_H__ +#define __DBUS_STATUS_H__ + +#include +#include + +struct DBusStatus { // From Amarok. + int play; // Playing = 0, Paused = 1, Stopped = 2 + int random; // Linearly = 0, Randomly = 1 + int repeat; // Go_To_Next = 0, Repeat_Current = 1 + int repeat_playlist; // Stop_When_Finished = 0, Never_Give_Up_Playing = 1, Never_Let_You_Down = 42 + + enum MprisPlayState { + Mpris_Playing = 0, + Mpris_Paused = 1, + Mpris_Stopped = 2, + }; +}; + +Q_DECLARE_METATYPE(DBusStatus) +QDBusArgument& operator <<(QDBusArgument& arg, const DBusStatus& status); +const QDBusArgument& operator >>(const QDBusArgument& arg, DBusStatus& status); + +#endif diff --git a/kdeplasma-addons/applets/icontasks/dockconfig.cpp b/kdeplasma-addons/applets/icontasks/dockconfig.cpp new file mode 100644 index 00000000..6fc1c367 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/dockconfig.cpp @@ -0,0 +1,598 @@ +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "dockconfig.h" +#include "dockmanager.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum ESelection { + SelUsable, + SelEnabled, + SelDisabled, + SelAll +}; + +enum Role { + RoleUser = Qt::UserRole, + RoleAvailable, + RoleDir, + RoleScript, + RoleComment, + RoleApp, + RoleDBus +}; + +DockConfig::DockConfig(KConfigDialog *p) +{ + p->addPage(this, i18n("Dock Manager"), "preferences-system-windows"); + + ui.setupUi(this); + DockConfigItemDelegate *delegate = new DockConfigItemDelegate(ui.view, this); + ui.view->setItemDelegate(delegate); + ui.view->sortItems(Qt::AscendingOrder); + + QStringList dirs = DockManager::self()->dirs(); + QString home = QDir::homePath(); + + foreach (QString dir, dirs) { + QStringList metas = QDir(QString(dir + "/metadata")).entryList(QStringList() << "*.info"); + + foreach (QString m, metas) { + Entry e; + e.user = dir.startsWith(home); + e.script = m.left(m.length() - 5); + e.dir = dir; + + QString script = dir + "/scripts/" + e.script; + if (QFile::exists(script)) { + KConfig cfg(dir + "/metadata/" + m, KConfig::NoGlobals); + + if (cfg.hasGroup("DockmanagerHelper")) { + KConfigGroup grp(&cfg, "DockmanagerHelper"); + e.appName = grp.readEntry("AppName", QString()); + e.dbusName = grp.readEntry("DBusName", QString()); + e.description = grp.readEntry("Description", QString()); + e.name = grp.readEntry("Name", QString()); + if (!e.name.isEmpty() && !e.description.isEmpty()) { + e.icon = grp.readEntry("Icon", QString()); + e.available = e.appName.isEmpty() || !KStandardDirs::findExe(e.appName).isEmpty(); + e.enabled = DockManager::self()->enabledHelpers().contains(script); + createItem(e); + } + } + } + } + } + + ui.addButton->setIcon(KIcon("list-add")); + ui.removeButton->setIcon(KIcon("list-remove")); + ui.enable->setChecked(DockManager::self()->isEnabled()); + ui.view->setEnabled(ui.enable->isChecked()); + ui.removeButton->setEnabled(false); + ui.addButton->setEnabled(DockManager::self()->isEnabled()); + + connect(ui.view, SIGNAL(itemSelectionChanged()), SLOT(selectionChanged())); + connect(ui.addButton, SIGNAL(clicked(bool)), SLOT(add())); + connect(ui.removeButton, SIGNAL(clicked(bool)), SLOT(del())); + connect(ui.enable, SIGNAL(toggled(bool)), SLOT(enableWidgets(bool))); + connect(ui.enable, SIGNAL(toggled(bool)), p, SLOT(settingsModified())); + connect(delegate, SIGNAL(changed()), this, SIGNAL(settingsModified())); + connect(this, SIGNAL(settingsModified()), p, SLOT(settingsModified())); +} + +DockConfig::~DockConfig() +{ + // Delete the item delegate, otherwise we get lots of the following printed to the screen: + // KWidgetItemDelegateEventListener::eventFilter: User of KWidgetItemDelegate should not delete widgets created by createItemWidgets! + QAbstractItemDelegate *delegate = ui.view->itemDelegate(); + if (delegate) { + delete delegate; + } +} + +bool DockConfig::isEnabled() +{ + return ui.enable->isChecked(); +} + +QSet DockConfig::enabledHelpers() +{ + QSet h; + QAbstractItemModel *model = ui.view->model(); + + for (int row = 0; row < model->rowCount(); ++row) { + QModelIndex idx = model->index(row, 0); + + if (model->data(idx, Qt::CheckStateRole).toBool()) { + h.insert(model->data(idx, RoleDir).toString() + "/scripts/" + model->data(idx, RoleScript).toString()); + } + } + return h; +} + +void DockConfig::selectionChanged() +{ + QList items = ui.view->selectedItems(); + QListWidgetItem *item = items.count() ? items.first() : 0L; + + ui.removeButton->setEnabled(ui.enable->isChecked() && item && item->data(RoleUser).toBool()); +} + +void DockConfig::add() +{ + KFileDialog *dlg = new KFileDialog(KUrl(), QLatin1String("application/x-bzip-compressed-tar application/x-compressed-tar application/x-tar"), this); + dlg->setOperationMode(KFileDialog::Opening); + dlg->setMode(KFile::File | KFile::LocalOnly | KFile::ExistingOnly); + dlg->setCaption(i18n("Open")); + dlg->setAttribute(Qt::WA_DeleteOnClose); + dlg->setWindowModality(Qt::WindowModal); + connect(dlg, SIGNAL(accepted()), SLOT(fileSelected())); + dlg->show(); +} + +void DockConfig::fileSelected() +{ + KFileDialog *dlg = qobject_cast(sender()); + KUrl url = dlg ? dlg->selectedUrl() : KUrl(); + + if (url.isValid()) { + QString fileName; + + if (url.isLocalFile()) { + fileName = url.toLocalFile(); + } else { + if (!KIO::NetAccess::download(url, fileName, this)) { + KMessageBox::error(this, i18n("Sorry, failed to download\n%1", url.prettyUrl())); + return; + } + } + + // Uncompress... + KTar tar(fileName); + + if (tar.open(QIODevice::ReadOnly)) { + const KArchiveDirectory *dir = tar.directory(); + + if (dir) { + const KArchiveEntry *meta = 0, + *script = 0; + foreach (QString entry, dir->entries()) { + if ("scripts" == entry) { + const KArchiveEntry *d = dir->entry(entry); + if (d && d->isDirectory()) { + foreach (QString f, ((KArchiveDirectory *)d)->entries()) { + if (f.endsWith(".py")) { + script = ((KArchiveDirectory *)d)->entry(f); + break; + } else { + script = ((KArchiveDirectory *)d)->entry(f); + } + } + } else { + break; + } + } else if ("metadata" == entry) { + const KArchiveEntry *d = dir->entry(entry); + if (d && d->isDirectory()) { + foreach (QString f, ((KArchiveDirectory *)d)->entries()) { + if (f.endsWith(".info")) { + meta = ((KArchiveDirectory *)d)->entry(f); + break; + } + } + } else { + break; + } + } + + if (script && meta) { + break; + } + } + + if (script && meta && meta->name() == (script->name() + ".info")) { + Entry e; + QString destDir = QString(KGlobal::dirs()->localxdgdatadir() + "/dockmanager").replace("//", "/"); + QString error; + KTempDir tempDir; + + tempDir.setAutoRemove(true); + e.user = true; + e.script = script->name(); + e.dir = destDir; + + // Check contents of meta data *before* attempting to install... + ((KArchiveFile *)meta)->copyTo(tempDir.name()); + KConfig cfg(tempDir.name() + meta->name(), KConfig::NoGlobals); + + if (cfg.hasGroup("DockmanagerHelper")) { + KConfigGroup grp(&cfg, "DockmanagerHelper"); + e.appName = grp.readEntry("AppName", QString()); + e.dbusName = grp.readEntry("DBusName", QString()); + e.description = grp.readEntry("Description", QString()); + e.name = grp.readEntry("Name", QString()); + if (!e.name.isEmpty() && !e.description.isEmpty()) { + e.icon = grp.readEntry("Icon", QString()); + e.available = e.appName.isEmpty() || !KStandardDirs::findExe(e.appName).isEmpty(); + e.enabled = DockManager::self()->enabledHelpers().contains(destDir + "/scripts/" + script->name()); + } else { + error = i18n("

Contents of metadata file are invalid.

    "); + if (e.name.isEmpty()) { + error += i18n("
  • Name field is missing.
  • "); + } + if (e.description.isEmpty()) { + error += i18n("
  • Description field is missing.
  • "); + } + error += QLatin1String("

"); + } + } else { + error = i18n("

Metadata file does not contain DockmanagerHelper group.

"); + } + + if (!error.isEmpty()) { + KMessageBox::detailedError(this, i18n("Invalid DockManager plugin."), error); + } else if ((!QFile::exists(destDir + "/metadata/" + meta->name()) && + !QFile::exists(destDir + "/scripts/" + script->name())) || + KMessageBox::Yes == KMessageBox::warningYesNo(this, i18n("

A Plugin named %1 already exists.

" + "

Overwrite?

", + script->name()), + i18n("Overwrite?"))) { + bool abortInstall = false; + + if (QFile::exists(destDir + "/metadata/" + meta->name()) && !QFile::remove(destDir + "/metadata/" + meta->name())) { + KMessageBox::error(this, i18n("

Sorry, failed to remove previous plugin metadata file.

" + "

%1

", destDir + "/metadata/" + meta->name())); + abortInstall = true; + } + if (!abortInstall && QFile::exists(destDir + "/scripts/" + script->name()) && !QFile::remove(destDir + "/scripts/" + script->name())) { + KMessageBox::error(this, i18n("

Sorry, failed to remove previous plugin metadata file.

" + "

%1

", destDir + "/scripts/" + script->name())); + abortInstall = true; + } + if (!abortInstall && (!(QDir(destDir + "/scripts/").exists() || KStandardDirs::makeDir(destDir + "/scripts/")))) { + KMessageBox::error(this, i18n("

Sorry, failed to create scripts folder.

" + "

%1

", destDir + "/scripts/")); + abortInstall = true; + } + if (!abortInstall && (!(QDir(destDir + "/metadata/").exists() || KStandardDirs::makeDir(destDir + "/metadata/")))) { + KMessageBox::error(this, i18n("

Sorry, failed to create metadata folder.

" + "

%1

", destDir + "/metadata/")); + abortInstall = true; + } + if (!abortInstall) { + ((KArchiveFile *)script)->copyTo(destDir + "/scripts/"); + if (!QFile::exists(destDir + "/scripts/" + script->name())) { + KMessageBox::error(this, i18n("Sorry, failed to install script file.")); + abortInstall = true; + } + } + if (!abortInstall) { + ((KArchiveFile *)meta)->copyTo(destDir + "/metadata/"); + if (!QFile::exists(destDir + "/metadata/" + meta->name())) { + KMessageBox::error(this, i18n("Sorry, failed to install metadata file.")); + abortInstall = true; + } + } + + if (!abortInstall) { + // Make sure script is executable... + // Clear any umask before setting file perms + mode_t oldMask(umask(0000)); + ::chmod(QFile::encodeName(destDir + "/scripts/" + script->name()).constData(), 0755); + // Reset umask + ::umask(oldMask); + + QListWidgetItem *item = createItem(e); + foreach (QListWidgetItem * i, ui.view->selectedItems()) { + i->setSelected(false); + } + item->setSelected(true); + ui.view->scrollToItem(item); + } + } + } else { + QString error = QLatin1String("

    "); + if (!script) { + error += i18n("
  • Script file is missing.
  • "); + } + if (!meta) { + error += i18n("
  • Metadata file is missing.
  • "); + } + error += QLatin1String("

"); + KMessageBox::detailedError(this, i18n("Invalid DockManager plugin."), error); + } + } + } + + if (!url.isLocalFile()) { + KIO::NetAccess::removeTempFile(fileName); + } + } +} + +void DockConfig::del() +{ + QList items = ui.view->selectedItems(); + QListWidgetItem *item = items.count() ? items.first() : 0L; + + if (item && item->data(RoleUser).toBool() && + KMessageBox::Yes == KMessageBox::warningYesNo(this, i18n("

Are you sure you wish to delete %1

(%2)

", + item->text(), item->data(RoleScript).toString()), + i18n("Remove Script"))) { + QString dir = item->data(RoleDir).toString(), + script = item->data(RoleScript).toString(); + if (QFile::remove(dir + "/scripts/" + script) && QFile::remove(dir + "/metadata/" + script + ".info")) { + int row = ui.view->row(item); + QListWidgetItem *other = ui.view->item(row + 1); + + if (!other && row > 0) { + other = ui.view->item(row - 1); + } + delete item; + if (other) { + other->setSelected(true); + } + emit settingsModified(); + } else { + KMessageBox::error(this, i18n("

Failed to delete the script file.

%1

", dir + "/scripts/" + script)); + } + } +} + +void DockConfig::enableWidgets(bool e) +{ + if (e) { + QList items = ui.view->selectedItems(); + QListWidgetItem *item = items.count() ? items.first() : 0L; + + ui.removeButton->setEnabled(item && item->data(RoleUser).toBool()); + } else { + ui.removeButton->setEnabled(false); + } + ui.addButton->setEnabled(e); + ui.view->setEnabled(e); +} + +QListWidgetItem * DockConfig::createItem(const Entry &e) +{ + QListWidgetItem *item = new QListWidgetItem(ui.view); + item->setText(e.name); + item->setData(RoleComment, e.description); + item->setData(Qt::DecorationRole, e.icon); + item->setCheckState(e.available && e.enabled ? Qt::Checked : Qt::Unchecked); + item->setData(RoleUser, e.user); + item->setData(RoleAvailable, e.available); + item->setData(RoleDir, e.dir); + item->setData(RoleScript, e.script); + item->setData(RoleApp, e.appName); + item->setData(RoleDBus, e.dbusName); + return item; +} + +static const int constMargin = 5; + +DockConfigItemDelegate::DockConfigItemDelegate(QAbstractItemView *itemView, QObject *parent) + : KWidgetItemDelegate(itemView, parent) + , checkBox(new QCheckBox) + , pushButton(new KPushButton) +{ + pushButton->setIcon(KIcon("configure")); // only for getting size matters +} + +DockConfigItemDelegate::~DockConfigItemDelegate() +{ + delete checkBox; + delete pushButton; +} + +int DockConfigItemDelegate::dependantLayoutValue(int value, int width, int totalWidth) const +{ + if (itemView()->layoutDirection() == Qt::LeftToRight) { + return value; + } + + return totalWidth - width - value; +} + +void DockConfigItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + if (!index.isValid()) { + return; + } + + int xOffset = checkBox->sizeHint().width(); + bool disabled = !itemView()->isEnabled() || !index.model()->data(index, RoleAvailable).toBool(); + + painter->save(); + + QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, 0); + + int iconSize = option.rect.height() - constMargin * 2; + QPixmap pixmap = KIconLoader::global()->loadIcon(index.model()->data(index, Qt::DecorationRole).toString(), + KIconLoader::Desktop, iconSize, disabled ? KIconLoader::DisabledState : KIconLoader::DefaultState); + painter->drawPixmap(QRect(dependantLayoutValue(constMargin + option.rect.left() + xOffset, iconSize, option.rect.width()), constMargin + option.rect.top(), iconSize, iconSize), + pixmap, QRect(0, 0, iconSize, iconSize)); + + + QRect contentsRect(dependantLayoutValue(constMargin * 2 + iconSize + option.rect.left() + xOffset, option.rect.width() - constMargin * 3 - iconSize - xOffset, option.rect.width()), + constMargin + option.rect.top(), option.rect.width() - constMargin * 3 - iconSize - xOffset, option.rect.height() - constMargin * 2); + int lessHorizontalSpace = constMargin * 2 + pushButton->sizeHint().width(); + + contentsRect.setWidth(contentsRect.width() - lessHorizontalSpace); + + if (option.state & QStyle::State_Selected) { + painter->setPen(option.palette.highlightedText().color()); + } + + if (itemView()->layoutDirection() == Qt::RightToLeft) { + contentsRect.translate(lessHorizontalSpace, 0); + } + + painter->save(); + if (disabled) { + QPalette pal(option.palette); + pal.setCurrentColorGroup(QPalette::Disabled); + painter->setPen(pal.text().color()); + } + + painter->save(); + QFont font = titleFont(option.font); + bool system = !index.model()->data(index, RoleUser).toBool(); + + font.setItalic(system); + + QFontMetrics fmTitle(font); + painter->setFont(font); + painter->drawText(contentsRect, Qt::AlignLeft | Qt::AlignTop, fmTitle.elidedText(index.model()->data(index, Qt::DisplayRole).toString(), Qt::ElideRight, contentsRect.width())); + painter->restore(); + + font = painter->font(); + font.setItalic(system); + painter->setFont(font); + painter->drawText(contentsRect, Qt::AlignLeft | Qt::AlignBottom, option.fontMetrics.elidedText(index.model()->data(index, RoleComment).toString(), Qt::ElideRight, contentsRect.width())); + + painter->restore(); + painter->restore(); +} + +QSize DockConfigItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QFont font = titleFont(option.font); + QFontMetrics fmTitle(font); + + return QSize(fmTitle.width(index.model()->data(index, Qt::DisplayRole).toString()) + KIconLoader::SizeMedium + constMargin * 5 + pushButton->sizeHint().width(), + qMax(KIconLoader::SizeMedium + constMargin * 2, fmTitle.height() + option.fontMetrics.height() + constMargin * 2)); +} + +QList DockConfigItemDelegate::createItemWidgets() const +{ + QList widgetList; + + QCheckBox *enabledCheckBox = new QCheckBox; + connect(enabledCheckBox, SIGNAL(clicked(bool)), this, SLOT(itemToggled(bool))); + + KPushButton *aboutPushButton = new KPushButton; + aboutPushButton->setIcon(KIcon("dialog-information")); + connect(aboutPushButton, SIGNAL(clicked(bool)), this, SLOT(aboutClicked())); + + setBlockedEventTypes(enabledCheckBox, QList() << QEvent::MouseButtonPress + << QEvent::MouseButtonRelease << QEvent::MouseButtonDblClick + << QEvent::KeyPress << QEvent::KeyRelease); + + setBlockedEventTypes(aboutPushButton, QList() << QEvent::MouseButtonPress + << QEvent::MouseButtonRelease << QEvent::MouseButtonDblClick + << QEvent::KeyPress << QEvent::KeyRelease); + + widgetList << enabledCheckBox << aboutPushButton; + + return widgetList; +} + +void DockConfigItemDelegate::updateItemWidgets(const QList widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const +{ + QCheckBox *checkBox = static_cast(widgets[0]); + checkBox->resize(checkBox->sizeHint()); + checkBox->move(dependantLayoutValue(constMargin, checkBox->sizeHint().width(), option.rect.width()), option.rect.height() / 2 - checkBox->sizeHint().height() / 2); + + KPushButton *aboutPushButton = static_cast(widgets[1]); + QSize aboutPushButtonSizeHint = aboutPushButton->sizeHint(); + aboutPushButton->resize(aboutPushButtonSizeHint); + aboutPushButton->move(dependantLayoutValue(option.rect.width() - constMargin - aboutPushButtonSizeHint.width(), aboutPushButtonSizeHint.width(), option.rect.width()), + option.rect.height() / 2 - aboutPushButtonSizeHint.height() / 2); + + if (!index.isValid() || !index.internalPointer()) { + checkBox->setVisible(false); + aboutPushButton->setVisible(false); + } else { + checkBox->setChecked(index.model()->data(index, Qt::CheckStateRole).toBool()); + checkBox->setEnabled(index.model()->data(index, RoleAvailable).toBool()); + } +} + +QFont DockConfigItemDelegate::titleFont(const QFont &baseFont) const +{ + QFont retFont(baseFont); + retFont.setBold(true); + + return retFont; +} + +void DockConfigItemDelegate::itemToggled(bool e) +{ + const QModelIndex index = focusedIndex(); + + if (!index.isValid()) { + return; + } + + const_cast(focusedIndex().model())->setData(index, e, Qt::CheckStateRole); + emit changed(); +} + +void DockConfigItemDelegate::aboutClicked() +{ + const QModelIndex index = focusedIndex(); + + if (!index.isValid()) { + return; + } + + const QAbstractItemModel *model = index.model(); + QString appName(model->data(index, RoleApp).toString()); + QString dbusName(model->data(index, RoleDBus).toString()); + + KMessageBox::information(itemView(), + QString("%1
").arg(model->data(index, RoleComment).toString()) + + QString("") + + i18n("", model->data(index, RoleScript).toString()) + + i18n("", model->data(index, RoleDir).toString()) + + (appName.isEmpty() ? QString() : i18n("", appName)) + + (dbusName.isEmpty() ? QString() : i18n("", dbusName)) + + QString("
Script File:%1
Location:%1
Application:%1
D-Bus:%1
"), + model->data(index, Qt::DisplayRole).toString() +#if KDE_IS_VERSION(4, 7, 0) + ,QString(), KMessageBox::WindowModal +#endif + ); +} + +#include "dockconfig.moc" diff --git a/kdeplasma-addons/applets/icontasks/dockconfig.h b/kdeplasma-addons/applets/icontasks/dockconfig.h new file mode 100644 index 00000000..afb5346c --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/dockconfig.h @@ -0,0 +1,107 @@ +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __DOCKCONFIG_H__ +#define __DOCKCONFIG_H__ + +#include "ui_dockconfig.h" +#include +#include +#include +#include + +class KConfigDialog; +class KPushButton; +class QCheckBox; +class QListWidgetItem; + +class DockConfigItemDelegate : public KWidgetItemDelegate +{ + Q_OBJECT + +public: + + DockConfigItemDelegate(QAbstractItemView *itemView, QObject *parent = 0); + virtual ~DockConfigItemDelegate(); + + int dependantLayoutValue(int value, int width, int totalWidth) const; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; + QList createItemWidgets() const; + void updateItemWidgets(const QList widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const; + QFont titleFont(const QFont &baseFont) const; + +Q_SIGNALS: + void changed(); + +private Q_SLOTS: + void itemToggled(bool e); + void aboutClicked(); + +private: + QCheckBox *checkBox; + KPushButton *pushButton; +}; + +class DockConfig : public QWidget +{ + Q_OBJECT + + struct Entry { + QString dir; + QString script; + QString name; + QString description; + QString icon; + bool available; + bool enabled; + bool user; + QString appName; + QString dbusName; + }; + +public: + DockConfig(KConfigDialog *p); + virtual ~DockConfig(); + + bool isEnabled(); + QSet enabledHelpers(); + +Q_SIGNALS: + void settingsModified(); + +public Q_SLOTS: + void selectionChanged(); + void add(); + void fileSelected(); + void del(); + void enableWidgets(bool e); + +private: + QListWidgetItem * createItem(const Entry &e); + +private: + Ui::DockConfig ui; +}; + +#endif diff --git a/kdeplasma-addons/applets/icontasks/dockconfig.ui b/kdeplasma-addons/applets/icontasks/dockconfig.ui new file mode 100644 index 00000000..bc27d34f --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/dockconfig.ui @@ -0,0 +1,62 @@ + + + DockConfig + + + + 0 + 0 + 399 + 209 + + + + + 0 + + + + + Enable DockManager Plugins + + + + + + + true + + + + + + + Add + + + + + + + Remove + + + + + + + Qt::Vertical + + + + 20 + 179 + + + + + + + + + diff --git a/kdeplasma-addons/applets/icontasks/dockhelper.cpp b/kdeplasma-addons/applets/icontasks/dockhelper.cpp new file mode 100644 index 00000000..0e9770fb --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/dockhelper.cpp @@ -0,0 +1,103 @@ +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "dockhelper.h" +#include "dockmanager.h" +#include +#include +#include +#include +#include +#include +#include +#include + +DockHelper::DockHelper(const QString &dir, const QString &fn) + : m_fileName(fn) + , m_dir(dir) + , m_valid(false) + , m_proc(0) +{ + + if (QFile::exists(m_dir + "/metadata/" + m_fileName + ".info") && QFile::exists(m_dir + "/scripts/" + m_fileName)) { + KConfig cfg(m_dir + "/metadata/" + m_fileName + ".info", KConfig::NoGlobals); + + if (cfg.hasGroup("DockmanagerHelper")) { + KConfigGroup grp(&cfg, "DockmanagerHelper"); + QString appName = grp.readEntry("AppName", QString()); + m_dBusName = grp.readEntry("DBusName", QString()); + m_valid = appName.isEmpty() || !KStandardDirs::findExe(appName).isEmpty(); + + if (m_valid) { + if (m_dBusName.isEmpty()) { + start(); + } else { + QDBusServiceWatcher *watcher = new QDBusServiceWatcher(m_dBusName, + QDBusConnection::sessionBus(), + QDBusServiceWatcher::WatchForOwnerChange, this); + connect(watcher, SIGNAL(serviceOwnerChanged(QString, QString, QString)), SLOT(serviceOwnerChanged(QString, QString, QString))); + QDBusReply reply = QDBusConnection::sessionBus().interface()->isServiceRegistered(m_dBusName); + if (reply.isValid() && reply.value()) { + start(); + } + } + } + } + } +} + +DockHelper::~DockHelper() +{ + stop(); +} + +void DockHelper::serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner) +{ + Q_UNUSED(name) + Q_UNUSED(oldOwner) + + if (newOwner.isEmpty()) { + stop(); + } else { + start(); + } +} + +void DockHelper::start() +{ + if (m_valid && !m_proc) { + m_proc = new QProcess(this); + m_proc->start(m_dir + "/scripts/" + m_fileName); + } +} + +void DockHelper::stop() +{ + if (m_proc) { + m_proc->close(); + m_proc->deleteLater(); + m_proc = 0; + } +} + +#include "dockhelper.moc" diff --git a/kdeplasma-addons/applets/icontasks/dockhelper.h b/kdeplasma-addons/applets/icontasks/dockhelper.h new file mode 100644 index 00000000..0be4f87f --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/dockhelper.h @@ -0,0 +1,67 @@ +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __DOCKHELPER_H__ +#define __DOCKHELPER_H__ + +#include +#include +#include + +class DockHelper : public QObject +{ + Q_OBJECT + +public: + DockHelper(const QString &dir, const QString &fn); + virtual ~DockHelper(); + + operator bool() const { + return m_valid; + } + + const QString & fileName() const { + return m_fileName; + } + const QString & dirName() const { + return m_dir; + } + Q_PID pid() const { + return m_proc ? m_proc->pid() : 0; + } + +public Q_SLOTS: + void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); + void start(); + void stop(); + +private: + QString m_fileName; + QString m_dir; + QString m_app; + QString m_dBusName; + bool m_valid; + QProcess *m_proc; +}; + +#endif diff --git a/kdeplasma-addons/applets/icontasks/dockitem.cpp b/kdeplasma-addons/applets/icontasks/dockitem.cpp new file mode 100644 index 00000000..21728fad --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/dockitem.cpp @@ -0,0 +1,269 @@ +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "dockitem.h" +#include "dockitemadaptor.h" +#include "dockmanager.h" +#include "abstracttaskitem.h" +#include +#include +#include +#include +#include + +static qulonglong itemCount = 0; + +static QIcon getIcon(const QString &file, const QString &name=QString()) +{ + if (!file.isEmpty()) { + if (QFile::exists(file)) { + return QIcon(file); + } else if (QIcon::hasThemeIcon(file)) { + return QIcon::fromTheme(file); + } + } + + if (!name.isEmpty() && QIcon::hasThemeIcon(name)) { + return QIcon::fromTheme(name); + } + + return QIcon(); +} + +DockItem::DockItem(const KUrl &desktopFile) + : m_url(desktopFile) + , m_timer(0) + , m_progress(-1) + , m_menuIdCount(0) +{ + new DockItemAdaptor(this); + m_path = QLatin1String("/net/launchpad/DockManager/Item") + QString().setNum(itemCount++); + QDBusConnection::sessionBus().registerObject(m_path, this); +} + +DockItem::~DockItem() +{ + foreach (AbstractTaskItem * i, m_tasks) { + i->setDockItem(0); + } + + QDBusConnection::sessionBus().unregisterObject(m_path, QDBusConnection::UnregisterTree); +} + +QString DockItem::DesktopFile() const +{ + return m_url.toLocalFile(); +} + +QString DockItem::Uri() const +{ + return m_url.url(); +} + +QString DockItem::name() const +{ + if (m_name.isEmpty() && m_url.isLocalFile() && KDesktopFile::isDesktopFile(m_url.toLocalFile())) { + m_name = KDesktopFile(m_url.toLocalFile()).readName(); + } + + return m_name; +} + +QList DockItem::menu() const +{ + QList acts; + QSet insertedMenus; + + foreach (QAction * act, m_menu.values()) { + QString title = act->property("container-title").toString(); + if (!title.isEmpty() && m_actionMenus.contains(title)) { + if (!insertedMenus.contains(title)) { + insertedMenus.insert(title); + acts.append(m_actionMenus[title]->menuAction()); + } + } else { + acts.append(act); + } + } + return acts; +} + +unsigned int DockItem::AddMenuItem(QMap hints) +{ + if (calledFromDBus()) { + DockManager::self()->itemService(this, message().service()); + } + + QString label, + iconName, + iconFile, + container; + + /*if (hints.contains("uri")) { + } else*/ { + label = hints["label"].toString(); + iconName = hints["icon-name"].toString(); + iconFile = hints["icon-file"].toString(); + container = hints["container-title"].toString(); + } + + unsigned int id = m_menuIdCount++; + QIcon icon = getIcon(iconFile, iconName); + QAction *action = icon.isNull() + ? new QAction(label, this) + : new QAction(icon, label, this); + connect(action, SIGNAL(triggered()), this, SLOT(menuActivated())); + action->setData(id); + action->setProperty("container-title", container); + if (!m_actionMenus.contains(container)) { + m_actionMenus.insert(container, new QMenu(container, 0)); + } + m_actionMenus[container]->addAction(action); + m_menu.insert(id, action); + return id; +} + +void DockItem::RemoveMenuItem(unsigned int id) +{ + if (calledFromDBus()) { + DockManager::self()->itemService(this, message().service()); + } + + if (m_menu.contains(id)) { + QAction *act = m_menu[id]; + QString title = act->property("container-title").toString(); + if (!title.isEmpty() && m_actionMenus.contains(title)) { + m_actionMenus[title]->removeAction(act); + if (m_actionMenus[title]->actions().isEmpty()) { + m_actionMenus[title]->deleteLater(); + m_actionMenus.remove(title); + } + } + disconnect(act, SIGNAL(triggered()), this, SLOT(menuActivated())); + m_menu.remove(id); + } +} + +void DockItem::menuActivated() +{ + QObject *s = sender(); + if (s && qobject_cast(s)) { + QAction *item = static_cast(s); + emit MenuItemActivated(item->data().toUInt()); + } +} + +void DockItem::UpdateDockItem(QMap hints) +{ + if (calledFromDBus()) { + DockManager::self()->itemService(this, message().service()); + } + + QMap::ConstIterator it(hints.constBegin()), + end(hints.constEnd()); + int updated = 0; + + for (; it != end; ++it) { + if (it.key() == "badge") { + QString badge = it.value().toString(); + if (badge != m_badge) { + m_badge = badge; + updated++; + } + } else if (it.key() == "progress") { + int prog = it.value().toInt(); + if (prog != m_progress) { + m_progress = prog; + updated++; + } + } else if (it.key() == "icon-file") { + m_icon = getIcon(it.value().toString()); + updated++; + } else if (it.key() == "x-kde-overlay") { + m_overlayIcon = getIcon(it.value().toString()); + updated++; + } + } + + if (updated) { + foreach (AbstractTaskItem * i, m_tasks) { + i->dockItemUpdated(); + } + } +} + +void DockItem::registerTask(AbstractTaskItem *item) +{ + m_tasks.insert(item); + item->setDockItem(this); + if (!m_badge.isEmpty() || !m_icon.isNull() || !m_overlayIcon.isNull() || (m_progress >= 0 && m_progress <= 100)) { + item->dockItemUpdated(); + } + if (m_timer) { + m_timer->stop(); + } +} + +void DockItem::unregisterTask(AbstractTaskItem *item) +{ + m_tasks.remove(item); + + if (0 == m_tasks.count()) { + // No current tasks, so set off timer. If nothing registers then we are no longer used... + if (!m_timer) { + m_timer = new QTimer(this); + connect(m_timer, SIGNAL(timeout()), this, SLOT(check())); + } + m_timer->start(500); + } +} + +void DockItem::reset() +{ + bool updated = !m_badge.isEmpty() || !m_icon.isNull() || !m_overlayIcon.isNull() || (m_progress >= 0 && m_progress <= 100); + + m_badge = QString(); + m_icon = QIcon(); + m_progress = -1; + + foreach (QAction * mnu, m_menu.values()) { + mnu->deleteLater(); + } + + m_menu.clear(); + + if (updated) { + foreach (AbstractTaskItem * i, m_tasks) { + i->dockItemUpdated(); + } + } +} + +void DockItem::check() +{ + if (0 == m_tasks.count()) { + DockManager::self()->remove(this); + } +} + +#include "dockitem.moc" diff --git a/kdeplasma-addons/applets/icontasks/dockitem.h b/kdeplasma-addons/applets/icontasks/dockitem.h new file mode 100644 index 00000000..1a6b268c --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/dockitem.h @@ -0,0 +1,107 @@ +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __DOCKITEM_H__ +#define __DOCKITEM_H__ + +#include +#include +#include +#include +#include +#include + +class AbstractTaskItem; +class QAction; +class QTimer; +class QMenu; + +class DockItem : public QObject, protected QDBusContext +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "net.launchpad.DockItem") + Q_PROPERTY(QString DesktopFile READ DesktopFile) + Q_PROPERTY(QString Uri READ Uri) + +public: + + DockItem(const KUrl &desktopFile); + ~DockItem(); + + QString DesktopFile() const; + QString Uri() const; + const QString & path() const { + return m_path; + } + QString name() const; + const KUrl & url() const { + return m_url; + } + const QIcon & icon() const { + return m_icon; + } + const QIcon & overlayIcon() const { + return m_overlayIcon; + } + const QString & badge() const { + return m_badge; + } + int progress() const { + return m_progress; + } + QList menu() const; + + void registerTask(AbstractTaskItem *item); + void unregisterTask(AbstractTaskItem *item); + void reset(); + +public Q_SLOTS: + Q_SCRIPTABLE unsigned int AddMenuItem(QMap hints); + Q_NOREPLY void RemoveMenuItem(unsigned int id); + Q_NOREPLY void UpdateDockItem(QMap hints); + +private Q_SLOTS: + void menuActivated(); + void check(); + +Q_SIGNALS: + void MenuItemActivated(unsigned int id); + +private: + KUrl m_url; + QString m_path; + mutable QString m_name; + QSet m_tasks; + QMap m_menu; + QTimer *m_timer; + QString m_remoteService; + QMap m_actionMenus; + + QString m_badge; + QIcon m_icon; + QIcon m_overlayIcon; + int m_progress; + unsigned int m_menuIdCount; +}; + +#endif diff --git a/kdeplasma-addons/applets/icontasks/dockmanager.cpp b/kdeplasma-addons/applets/icontasks/dockmanager.cpp new file mode 100644 index 00000000..d40b1686 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/dockmanager.cpp @@ -0,0 +1,536 @@ +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "dockmanager.h" +#include "dockmanageradaptor.h" +#include "dockitem.h" +#include "dockhelper.h" +#include "dockconfig.h" +#include "tasks.h" +#include "abstracttaskitem.h" +#include "windowtaskitem.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const QString constDbusService = "net.launchpad.DockManager"; +static const QString constDbusObject = "/net/launchpad/DockManager"; + +static QString appFromPid(uint pid) +{ + QFile f(QString("/proc/%1/cmdline").arg(pid)); + + if (f.open(QIODevice::ReadOnly)) { + QByteArray bytes = f.read(1024); + + if (bytes.length() > 2) { + return QString(bytes); + } + } + + return QString(); +} + +K_GLOBAL_STATIC(DockManager, dockMgr) + +DockManager * DockManager::self() +{ + return dockMgr; +} + +DockManager::DockManager() + : m_enabled(false) + , m_connected(false) + , m_timer(0) + , m_config(0) + , m_watcher(0) +{ + new DockManagerAdaptor(this); +} + +void DockManager::setEnabled(bool en) +{ + if (en != m_enabled) { + m_enabled = en; + if (m_enabled) { + if (QDBusConnection::sessionBus().registerService(constDbusService)) { + if (QDBusConnection::sessionBus().registerObject(constDbusObject, this)) { + if (stopDaemon()) { + m_connected = true; + reloadItems(); + QTimer::singleShot(500, this, SLOT(updateHelpers())); + QStringList dirList = dirs(); + foreach (QString dir, dirList) { + KDirWatch::self()->addDir(dir + "/scripts"); + KDirWatch::self()->addDir(dir + "/metadata"); + } + connect(KDirWatch::self(), SIGNAL(dirty(const QString&)), this, SLOT(updateHelpersDelayed())); + } else { + kDebug() << "Cannot start dock mamanger interface, failed to terminate dockamanger-daemon"; + } + } else { + kDebug() << "Failed to register dock mamanger object"; + } + } else { + kDebug() << "Failed to register dock mamanger service"; + } + } else { + if (m_connected) { + QDBusConnection::sessionBus().unregisterService(constDbusService); + QDBusConnection::sessionBus().unregisterObject(constDbusObject, QDBusConnection::UnregisterTree); + // Allow dockmanager-daemon to run... + QDBusConnection::sessionBus().unregisterService(constDbusService + ".Daemon"); + + QStringList dirList = dirs(); + foreach (QString dir, dirList) { + KDirWatch::self()->removeDir(dir + "/scripts"); + KDirWatch::self()->removeDir(dir + "/metadata"); + } + disconnect(KDirWatch::self(), SIGNAL(dirty(const QString&)), this, SLOT(updateHelpersDelayed())); + if (m_timer) { + m_timer->stop(); + } + } + foreach (DockHelper * helper, m_helpers) { + delete helper; + } + m_helpers.clear(); + QMap::ConstIterator it(m_items.constBegin()), + end(m_items.constEnd()); + + for (; it != end; ++it) { + delete(*it); + } + m_items.clear(); + m_itemService.clear(); + if (m_watcher) { + disconnect(m_watcher, SIGNAL(serviceOwnerChanged(QString, QString, QString)), this, SLOT(serviceOwnerChanged(QString, QString, QString))); + m_watcher->deleteLater(); + m_watcher = 0; + } + // **Don't clear tasks** these will be neeaded if re-enable... + } + } +} + +struct Thread : public QThread { +public: + static void msleep(unsigned long ms) { + QThread::msleep(ms); + } +}; + +bool DockManager::stopDaemon() +{ + QDBusReply reply = QDBusConnection::sessionBus().interface()->servicePid(constDbusService + ".Daemon"); + + if (reply.isValid()) { + uint pid = reply.value(); + + if (pid > 0) { + if (appFromPid(pid).endsWith("dockmanager-daemon")) { + kDebug() << "Stopping dockmanager-daemon, pid" << pid; + if (::kill(pid, SIGTERM)) { + return false; + } else { + Thread::msleep(250); + } + } else { + return false; + } + } + } + // Now register the service for ourselces, to prevent it starting... + QDBusConnection::sessionBus().registerService("net.launchpad.DockManager.Daemon"); + return true; +} + +void DockManager::reloadItems() +{ + if (!m_connected || !m_enabled) { + return; + } + + QMap existing = m_items; + QMap::ConstIterator taskIt(m_tasks.constBegin()), + taskEnd(m_tasks.constEnd()); + + for (; taskIt != taskEnd; ++taskIt) { + if (m_items.contains(taskIt.value())) { + existing.remove(taskIt.value()); + } else { + DockItem *item = new DockItem(taskIt.value()); + m_items.insert(taskIt.value(), item); + emit ItemAdded(QDBusObjectPath(item->path())); + item->registerTask(taskIt.key()); + } + } + + QMap::ConstIterator it(existing.constBegin()), + end(existing.constEnd()); + + for (; it != end; ++it) { + QStringList services = m_itemService.keys(it.value()); + foreach (QString srv, services) { + if (m_watcher) { + m_watcher->removeWatchedService(srv); + } + m_itemService.remove(srv); + } + emit ItemRemoved(QDBusObjectPath(it.value()->path())); + delete it.value(); + m_items.remove(it.key()); + } +} + +void DockManager::registerTask(AbstractTaskItem *item) +{ + if (!m_tasks.contains(item)) { + KUrl url = item->launcherUrl(); + + if (url.isValid()) { + m_tasks.insert(item, url); + + if (m_connected) { + if (!m_items.contains(url)) { + DockItem *item = new DockItem(url); + m_items.insert(url, item); + emit ItemAdded(QDBusObjectPath(item->path())); + } + + m_items[url]->registerTask(item); + } + } + } +} + +void DockManager::unregisterTask(AbstractTaskItem *item) +{ + if (m_tasks.contains(item)) { + KUrl url = m_tasks[item]; + + if (m_connected) { + // Remove the DockItem if this task was not associated with a launcher... + if (url.isValid() && m_items.contains(url)) { + m_items[url]->unregisterTask(item); + } + } + m_tasks.remove(item); + } +} + +void DockManager::remove(DockItem *item) +{ + if (item) { + emit ItemRemoved(QDBusObjectPath(item->path())); + if (m_items.contains(item->url())) { + m_items.remove(item->url()); + } + item->deleteLater(); + if (m_watcher) { + foreach (QString srv, m_itemService.keys(item)) { + m_watcher->removeWatchedService(srv); + } + } + } +} + +void DockManager::itemService(DockItem *item, const QString &serviceName) +{ + if (m_watcher && m_watcher->watchedServices().contains(serviceName)) { + return; + } + + QDBusReply reply = QDBusConnection::sessionBus().interface()->servicePid(serviceName); + uint servicePid = reply.isValid() ? reply.value() : 0; + bool watchService = false; + + if (0 != servicePid) { + foreach (DockHelper * helper, m_helpers) { + if (helper->pid() == servicePid) { + watchService = true; + break; + } + } + } + + if (!watchService) { // .desktop + return; + } + if (m_watcher) { + QStringList old = m_itemService.keys(item); + if (old.count()) { + foreach (QString srv, old) { + m_watcher->removeWatchedService(srv); + } + } + } + + if (!m_watcher) { + m_watcher = new QDBusServiceWatcher(this); + m_watcher->setConnection(QDBusConnection::sessionBus()); + m_watcher->setWatchMode(QDBusServiceWatcher::WatchForOwnerChange); + connect(m_watcher, SIGNAL(serviceOwnerChanged(QString, QString, QString)), this, SLOT(serviceOwnerChanged(QString, QString, QString))); + } + + m_watcher->addWatchedService(serviceName); + m_itemService[serviceName] = item; +} + +QStringList DockManager::GetCapabilities() +{ + return QStringList() +// << "dock-item-message" +// << "dock-item-tooltip" + << "dock-item-badge" + << "dock-item-progress" +// << "dock-item-visible" + << "dock-item-icon-file" +// << "dock-item-attention" +// << "dock-item-waiting" + << "x-kde-dock-item-overlay" + << "menu-item-with-label" +// << "menu-item-with-uri" + << "menu-item-icon-name" + << "menu-item-icon-file" + << "menu-item-container-title"; +} + +QDBusObjectPath DockManager::GetItemByXid(qlonglong xid) +{ + QMap::ConstIterator it(m_tasks.constBegin()), + end(m_tasks.constEnd()); + + for (; it != end; ++it) { + if (TaskManager::TaskItemType == it.key()->abstractItem()->itemType()) { + WindowTaskItem *item = static_cast(it.key()); + if (item->windowTask() && item->windowTask()->window() == xid) { + if (m_items.contains(it.value())) { + return QDBusObjectPath(m_items[it.value()]->path()); + } + } + } + } + return QDBusObjectPath(); +} + +QList DockManager::GetItems() +{ + QList items; + + QMap::ConstIterator it(m_items.constBegin()), + end(m_items.constEnd()); + + for (; it != end; ++it) { + items.append(QDBusObjectPath((*it)->path())); + } + return items; +} + +QList DockManager::GetItemsByDesktopFile(const QString &desktopFile) +{ + QList items; + + QMap::ConstIterator it(m_items.constBegin()), + end(m_items.constEnd()); + + for (; it != end; ++it) { + if ((*it)->DesktopFile() == desktopFile) { + items.append(QDBusObjectPath((*it)->path())); + } + } + return items; +} + +QList DockManager::GetItemsByName(QString name) +{ + QList items; + + QMap::ConstIterator it(m_items.constBegin()), + end(m_items.constEnd()); + + for (; it != end; ++it) { + if ((*it)->name() == name) { + items.append(QDBusObjectPath((*it)->path())); + } + } + return items; +} + +QList DockManager::GetItemsByPid(int pid) +{ + QList items; + + QMap::ConstIterator it(m_tasks.constBegin()), + end(m_tasks.constEnd()); + + for (; it != end; ++it) { + if (TaskManager::TaskItemType == it.key()->abstractItem()->itemType()) { + WindowTaskItem *item = static_cast(it.key()); + + if (item->windowTask() && item->windowTask()->pid() == pid) { + if (m_items.contains(it.value())) { + items.append(QDBusObjectPath(m_items[it.value()]->path())); + } + } + } + } + return items; +} + +QStringList DockManager::dirs() const +{ + return QStringList() << QString(KGlobal::dirs()->localxdgdatadir() + "/dockmanager").replace("//", "/") + << "/usr/local/share/dockmanager" + << "/usr/share/dockmanager"; +} + +void DockManager::addConfigWidget(KConfigDialog *parent) +{ + if (!m_config) { + m_config = new DockConfig(parent); + connect(parent, SIGNAL(cancelClicked()), this, SLOT(removeConfigWidget())); + } +} + +void DockManager::readConfig(KConfigGroup &cg) +{ + KConfigGroup dm(&cg, "DockManager"); + + QSet prevHelpers = m_enabledHelpers; + m_enabledHelpers = dm.readEntry("EnabledHelpers", QStringList()).toSet(); + setEnabled(dm.readEntry("Enabled", true)); + + if (m_enabled && prevHelpers != m_enabledHelpers) { + updateHelpers(); + } +} + +void DockManager::writeConfig(KConfigGroup &cg) +{ + if (m_config) { + KConfigGroup dm(&cg, "DockManager"); + QSet prevHelpers = m_enabledHelpers; + + m_enabledHelpers = m_config->enabledHelpers(); + setEnabled(m_config->isEnabled()); + dm.writeEntry("Enabled", m_enabled); + dm.writeEntry("EnabledHelpers", m_enabledHelpers.toList()); + + if (m_enabled && prevHelpers != m_enabledHelpers) { + updateHelpers(); + } + removeConfigWidget(); + } +} + +void DockManager::removeConfigWidget() +{ + // Don't delete m_config, as its now owned ny the config dialog... + m_config = 0; +} + +void DockManager::updateHelpersDelayed() +{ + if (!m_timer) { + m_timer = new QTimer(this); + connect(m_timer, SIGNAL(timeout()), this, SLOT(updateHelpers())); + } + m_timer->start(500); +} + +void DockManager::updateHelpers() +{ + if (m_timer) { + m_timer->stop(); + } + + if (!m_enabled || !m_connected) { + return; + } + QStringList dirList = dirs(); + QMap previousHelpers; + QList newHelpers; + + foreach (DockHelper * helper, m_helpers) { + previousHelpers[helper->dirName() + "/scripts/" + helper->fileName()] = helper; + } + + foreach (QString dir, dirList) { + QDir d(dir + "/metadata"); + QStringList metas = QDir(QString(dir + "/metadata")).entryList(QStringList() << "*.info"); + + foreach (QString m, metas) { + QString name = m.left(m.length() - 5); + QString script = dir + "/scripts/" + name; + if (previousHelpers.contains(script)) { + if (m_enabledHelpers.contains(script)) { + previousHelpers.remove(script); + } + } else if (m_enabledHelpers.contains(script)) { + DockHelper *helper = new DockHelper(dir, name); + + if (*helper) { + newHelpers.append(helper); + } else { + delete helper; + } + } + } + } + + QMap::ConstIterator it(previousHelpers.constBegin()), + end(previousHelpers.constEnd()); + + for (; it != end; ++it) { + it.value()->stop(); + it.value()->deleteLater(); + m_helpers.removeAll(it.value()); + } + + foreach (DockHelper * helper, newHelpers) { + m_helpers.append(helper); + } +} + +void DockManager::serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner) +{ + Q_UNUSED(oldOwner) + + if (newOwner.isEmpty() && m_itemService.contains(name)) { + DockItem *item = m_itemService[name]; + if (item) { + item->reset(); + } + m_itemService.remove(name); + } +} + +#include "dockmanager.moc" diff --git a/kdeplasma-addons/applets/icontasks/dockmanager.h b/kdeplasma-addons/applets/icontasks/dockmanager.h new file mode 100644 index 00000000..7412f668 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/dockmanager.h @@ -0,0 +1,105 @@ +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __DOCKMANAGER_H__ +#define __DOCKMANAGER_H__ + +#include +#include +#include +#include + +class DockItem; +class DockHelper; +class DockConfig; +class AbstractTaskItem; +class KConfigDialog; +class KConfigGroup; +class QTimer; +class QDBusServiceWatcher; + +class DockManager : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "net.launchpad.DockManager") + +public: + static DockManager * self(); + + DockManager(); + + void setEnabled(bool en); + bool isEnabled() const { + return m_enabled; + } + void reloadItems(); + void registerTask(AbstractTaskItem *item); + void unregisterTask(AbstractTaskItem *item); + void remove(DockItem *item); + void itemService(DockItem *item, const QString &serviceName); + QStringList dirs() const; + const QSet enabledHelpers() const { + return m_enabledHelpers; + } + + void addConfigWidget(KConfigDialog *parent); + void readConfig(KConfigGroup &cg); + void writeConfig(KConfigGroup &cg); + +private: + bool stopDaemon(); + +public Q_SLOTS: + void removeConfigWidget(); + + Q_SCRIPTABLE QStringList GetCapabilities(); + Q_SCRIPTABLE QDBusObjectPath GetItemByXid(qlonglong xid); + Q_SCRIPTABLE QList GetItems(); + Q_SCRIPTABLE QList GetItemsByDesktopFile(const QString &desktopFile); + Q_SCRIPTABLE QList GetItemsByName(QString name); + Q_SCRIPTABLE QList GetItemsByPid(int pid); + +Q_SIGNALS: + void ItemAdded(const QDBusObjectPath &path); + void ItemRemoved(const QDBusObjectPath &path); + +private Q_SLOTS: + void updateHelpers(); + void updateHelpersDelayed(); + void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); + +private: + bool m_enabled; + bool m_connected; + QMap m_items; + QMap m_itemService; + QMap m_tasks; + QList m_helpers; + QSet m_enabledHelpers; + QTimer *m_timer; + DockConfig *m_config; + QDBusServiceWatcher *m_watcher; +}; + +#endif + diff --git a/kdeplasma-addons/applets/icontasks/dropindicators.svgz b/kdeplasma-addons/applets/icontasks/dropindicators.svgz new file mode 100644 index 00000000..b6ecac45 Binary files /dev/null and b/kdeplasma-addons/applets/icontasks/dropindicators.svgz differ diff --git a/kdeplasma-addons/applets/icontasks/indicators.svgz b/kdeplasma-addons/applets/icontasks/indicators.svgz new file mode 100644 index 00000000..d4794778 Binary files /dev/null and b/kdeplasma-addons/applets/icontasks/indicators.svgz differ diff --git a/kdeplasma-addons/applets/icontasks/jobmanager.cpp b/kdeplasma-addons/applets/icontasks/jobmanager.cpp new file mode 100644 index 00000000..c6c6bf2b --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/jobmanager.cpp @@ -0,0 +1,197 @@ +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "jobmanager.h" +#include "abstracttaskitem.h" +#include "tasks.h" +#include +#include + +K_GLOBAL_STATIC(JobManager, jobMgr) + +static const char *constEngineName = "applicationjobs"; + +JobManager * JobManager::self() +{ + return jobMgr; +} + +JobManager::JobManager() + : m_engine(0) +{ +} + +JobManager::~JobManager() +{ +} + +void JobManager::setEnabled(bool enabled) +{ + if ((m_engine && !enabled) || (enabled && !m_engine)) { + if (enabled) { + m_engine = Plasma::DataEngineManager::self()->loadEngine(constEngineName); + + if (!m_engine->isValid()) { + Plasma::DataEngineManager::self()->unloadEngine(constEngineName); + m_engine = 0; + return; + } + + connect(m_engine, SIGNAL(sourceAdded(const QString)), this, SLOT(addJob(const QString))); + connect(m_engine, SIGNAL(sourceRemoved(const QString)), this, SLOT(removeJob(const QString))); + m_engine->connectAllSources(this); + } else if (m_engine) { + disconnect(m_engine, SIGNAL(sourceAdded(const QString)), this, SLOT(addJob(const QString))); + disconnect(m_engine, SIGNAL(sourceRemoved(const QString)), this, SLOT(removeJob(const QString))); + + QMap >::Iterator it(m_appJobs.begin()), + end(m_appJobs.end()); + + for (; it != end; ++it) { + foreach (const QString & job, *it) { + m_engine->disconnectSource(job, this); + } + } + + Plasma::DataEngineManager::self()->unloadEngine(constEngineName); + m_appJobs.clear(); + m_jobs.clear(); + m_engine = 0; + } + } +} + +void JobManager::registerTask(AbstractTaskItem *task) +{ + QString appName(task->appName()); + + if (!appName.isEmpty()) { + m_tasks[appName].append(task); + + if (m_appJobs.contains(appName)) { + task->updateProgress(appProgress(appName)); + } + } +} + +void JobManager::unregisterTask(AbstractTaskItem *task) +{ + // Remove each reference to task... + QMap >::Iterator it(m_tasks.begin()), + end(m_tasks.end()); + QStringList emptied; + + for (; it != end; ++it) { + if ((*it).contains(task)) { + (*it).removeAll(task); + if (0 == (*it).count()) { + emptied.append(it.key()); + } + } + } + + foreach (const QString & app, emptied) { + m_tasks.remove(app); + } +} + +void JobManager::addJob(const QString &job) +{ + m_engine->connectSource(job, this); +} + +void JobManager::dataUpdated(const QString &job, const Plasma::DataEngine::Data &data) +{ + QString appName = data["appName"].toString(); + + if (appName.isEmpty()) { + return; + } + + int percentage = data.contains("percentage") ? data["percentage"].toInt() : -1; + + if (m_appJobs.contains(appName)) { + m_appJobs[appName].insert(job); + } + + m_jobs[job] = percentage; + update(appName); +} + +void JobManager::removeJob(const QString &job) +{ + m_jobs.remove(job); + QMap >::Iterator it(m_appJobs.begin()), + end(m_appJobs.end()); + QStringList updated, + emptied; + + for (; it != end; ++it) { + if ((*it).contains(job)) { + (*it).remove(job); + if (0 == (*it).count()) { + emptied.append(it.key()); + } else { + updated.append(it.key()); + } + } + } + + foreach (const QString & app, emptied) { + m_appJobs.remove(app); + update(app); + } + + foreach (const QString & app, updated) { + update(app); + } +} + +int JobManager::appProgress(const QString &app) +{ + int numJobs = 0, + total = 0; + + foreach (const QString & job, m_appJobs[app]) { + int p = m_jobs[job]; + if (-1 != p) { + numJobs++; + total += p; + } + } + + return 0 == numJobs ? -1 : total / numJobs; +} + +void JobManager::update(const QString &app) +{ + if (m_tasks.contains(app)) { + int p = appProgress(app); + + foreach (AbstractTaskItem * item, m_tasks[app]) { + item->updateProgress(p); + } + } +} + +#include "jobmanager.moc" diff --git a/kdeplasma-addons/applets/icontasks/jobmanager.h b/kdeplasma-addons/applets/icontasks/jobmanager.h new file mode 100644 index 00000000..700f6d9b --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/jobmanager.h @@ -0,0 +1,72 @@ +#ifndef _JOB_MANAGER_H__ +#define _JOB_MANAGER_H__ + +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include + +class AbstractTaskItem; + +class JobManager : public QObject +{ + Q_OBJECT + +public: + + static JobManager * self(); + + JobManager(); + ~JobManager(); + + void setEnabled(bool enabled); + bool isEnabled() const { + return 0 != m_engine; + } + void registerTask(AbstractTaskItem *task); + void unregisterTask(AbstractTaskItem *task); + +private Q_SLOTS: + + void addJob(const QString &job); + void dataUpdated(const QString &job, const Plasma::DataEngine::Data &data); + void removeJob(const QString &job); + +private: + + int appProgress(const QString &app); + void update(const QString &app); + +private: + + Plasma::DataEngine *m_engine; + QMap > m_appJobs; // Map from appName to list of job names + QMap m_jobs; // Map from job name to job percentage + QMap > m_tasks; +}; + +#endif diff --git a/kdeplasma-addons/applets/icontasks/launcherseparator.svgz b/kdeplasma-addons/applets/icontasks/launcherseparator.svgz new file mode 100644 index 00000000..0babb520 Binary files /dev/null and b/kdeplasma-addons/applets/icontasks/launcherseparator.svgz differ diff --git a/kdeplasma-addons/applets/icontasks/mediabuttons.cpp b/kdeplasma-addons/applets/icontasks/mediabuttons.cpp new file mode 100644 index 00000000..db84eef1 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/mediabuttons.cpp @@ -0,0 +1,359 @@ +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "mediabuttons.h" +#include "dbusstatus.h" +#include "playerv1interface.h" +#include "playerv2interface.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +K_GLOBAL_STATIC(MediaButtons, mediaBtns) + +static const QString constV2Prefix = QLatin1String("org.mpris.MediaPlayer2."); +static const QString constV1Prefix = QLatin1String("org.mpris."); + +static QString playbackStatus(OrgFreedesktopMediaPlayerInterface *iface) +{ + DBusStatus status = iface->GetStatus(); + + switch (status.play) { + case DBusStatus::Mpris_Playing: return "Playing"; + case DBusStatus::Mpris_Paused: return "Paused"; + case DBusStatus::Mpris_Stopped: return "Stopped"; + } + return QString(); +} + +MediaButtons::Interface::~Interface() +{ + if (v1) { + delete v1; + } + if (v2) { + delete v2; + } +} + +void MediaButtons::Interface::next() +{ + if (v2) { + v2->Next(); + } else if (v1) { + v1->Next(); + } +} + +void MediaButtons::Interface::previous() +{ + if (v2) { + v2->Previous(); + } else if (v1) { + v1->Prev(); + } +} + +void MediaButtons::Interface::playPause() +{ + if (v2) { + v2->PlayPause(); + } else if (v1) { + if ("Playing" ==::playbackStatus(v1)) { + v1->Pause(); + } else { + v1->Play(); + } + } +} + +QString MediaButtons::Interface::playbackStatus() +{ + if (v2) { + return v2->playbackStatus(); + } else if (v1) { + return ::playbackStatus(v1); + } + + return QString(); +} + +QString MediaButtons::Interface::service() +{ + if (v2) { + return v2->service(); + } else if (v1) { + return v1->service(); + } + + return QString(); +} + +MediaButtons * MediaButtons::self() +{ + return mediaBtns; +} + +MediaButtons::MediaButtons() + : m_watcher(0) + , m_enabled(false) +{ + qDBusRegisterMetaType(); +} + +void MediaButtons::setEnabled(bool en) +{ + if (en != m_enabled) { + m_enabled = en; + if (m_enabled) { + m_watcher = new QDBusServiceWatcher(this); + m_watcher->setConnection(QDBusConnection::sessionBus()); + m_watcher->setWatchMode(QDBusServiceWatcher::WatchForOwnerChange); + connect(m_watcher, SIGNAL(serviceOwnerChanged(QString, QString, QString)), this, SLOT(serviceOwnerChanged(QString, QString, QString))); + connect(KSycoca::self(), SIGNAL(databaseChanged(QStringList)), SLOT(sycocaChanged(QStringList))); + readConfig(); + updateApps(); + } else if (m_watcher) { + disconnect(m_watcher, SIGNAL(serviceOwnerChanged(QString, QString, QString)), this, SLOT(serviceOwnerChanged(QString, QString, QString))); + disconnect(KSycoca::self(), SIGNAL(databaseChanged(QStringList)), this, SLOT(sycocaChanged(QStringList))); + + foreach (Interface * iface, m_interfaces.values()) { + delete iface; + } + m_interfaces.clear(); + + delete m_watcher; + } + } +} + +void MediaButtons::sycocaChanged(const QStringList &types) +{ + if (types.contains("apps")) { + updateApps(); + } +} + +void MediaButtons::serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner) +{ + bool isV2 = name.startsWith(constV2Prefix); + QString n = QString(name).remove(isV2 ? constV2Prefix : constV1Prefix).toLower(); + QMap::iterator it(m_interfaces.find(n)), + end(m_interfaces.end()); + + if (newOwner.isEmpty()) { + if (it != end) { + if ((*it)->isV2() == isV2) { + delete(*it); + m_interfaces.erase(it); + } + } + } else if (oldOwner.isEmpty()) { + if (isV2) { + OrgMprisMediaPlayer2PlayerInterface *iface = new OrgMprisMediaPlayer2PlayerInterface(name, "/org/mpris/MediaPlayer2", QDBusConnection::sessionBus(), this); + if (iface->canControl()) { + if (it != end) { + delete(*it); + m_interfaces.erase(it); + } + m_interfaces.insert(n, new Interface(iface)); + } else { + delete iface; + } + } else if (it == end || !(*it)->isV2()) { + OrgFreedesktopMediaPlayerInterface *iface = new OrgFreedesktopMediaPlayerInterface(name, "/Player", QDBusConnection::sessionBus(), this); + if (it != end) { + delete(*it); + m_interfaces.erase(it); + } + m_interfaces.insert(n, new Interface(iface)); + } + } +} + +void MediaButtons::next(const QString &name, int pid) +{ + if (m_enabled) { + Interface *iface = getInterface(name, pid); + if (iface) { + iface->next(); + } + } +} + +void MediaButtons::previous(const QString &name, int pid) +{ + if (m_enabled) { + Interface *iface = getInterface(name, pid); + if (iface) { + iface->previous(); + } + } +} + +void MediaButtons::playPause(const QString &name, int pid) +{ + if (m_enabled) { + Interface *iface = getInterface(name, pid); + if (iface) { + iface->playPause(); + } + } +} + +QString MediaButtons::playbackStatus(const QString &name, int pid) +{ + if (m_enabled) { + Interface *iface = getInterface(name, pid); + if (iface) { + return iface->playbackStatus(); + } + } + + return QString(); +} + +void MediaButtons::readConfig() +{ + m_aliases.clear(); + m_ignore.clear(); + + QStringList files(KGlobal::dirs()->findAllResources("data", "kdeplasma-addons/mediabuttonsrc")); + + foreach (QString file, files) { + KConfig cfg(file); + KConfigGroup ag(&cfg, "Aliases"); + KConfigGroup gen(&cfg, "General"); + + m_ignore += gen.readEntry("Ignore", QStringList()).toSet(); + m_customMediaApps = gen.readEntry("CustomMediaApps", QStringList()).toSet(); + foreach (const QString & key, ag.keyList()) { + foreach (const QString & alias, ag.readEntry(key, QStringList())) { + m_aliases[alias.toLower()] = key.toLower(); + } + } + } +} + +void MediaButtons::updateApps() +{ + if (!m_enabled) { + return; + } + + KService::List services = KServiceTypeTrader::self()->query("Application", QString("exist Exec and (exist Categories and ( ('AudioVideo' ~subin Categories) or ('Music' ~subin Categories) ) )")); + QStringList prefixes = QStringList() << constV2Prefix << constV1Prefix; + + m_mediaApps.clear(); + m_mediaApps = m_aliases.keys().toSet(); + foreach (const KSharedPtr srv, services) { + QString name = srv->desktopEntryName(); + + if (name.startsWith("kde4-")) { + name = name.mid(5); + } + + if (m_aliases.contains(name)) { + name = m_aliases[name]; + } + + if (m_ignore.contains(name)) { + continue; + } + + m_mediaApps.insert(name.toLower()); + } + m_mediaApps += m_customMediaApps; +} + +MediaButtons::Interface * MediaButtons::getInterface(const QString &name, int pid) +{ + QStringList names; + + if (m_aliases.contains(name)) { + QString alias = m_aliases[name]; + names << alias << alias + "." + QString().setNum(pid) << alias + "-" + QString().setNum(pid); + } + names << name << name + "." + QString().setNum(pid) << name + "-" + QString().setNum(pid); + + foreach (QString n, names) { + if (m_interfaces.contains(n)) { + return m_interfaces[n]; + } + } + + foreach (QString n, names) { + MediaButtons::Interface *i = getV2Interface(n); + if (i) { + return i; + } + } + + foreach (QString n, names) { + MediaButtons::Interface *i = getV1Interface(n); + if (i) { + return i; + } + } + + return 0; +} + +MediaButtons::Interface * MediaButtons::getV2Interface(const QString &name) +{ + QDBusReply reply = QDBusConnection::sessionBus().interface()->isServiceRegistered(constV2Prefix + name); + + if (reply.isValid() && reply.value()) { + serviceOwnerChanged(constV2Prefix + name, QString(), QLatin1String("X")); + if (m_interfaces.contains(name)) { + m_watcher->addWatchedService(constV2Prefix + name); + return m_interfaces[name]; + } + } + + return 0; +} + +MediaButtons::Interface * MediaButtons::getV1Interface(const QString &name) +{ + QDBusReply reply = QDBusConnection::sessionBus().interface()->isServiceRegistered(constV1Prefix + name); + + if (reply.isValid() && reply.value()) { + serviceOwnerChanged(constV1Prefix + name, QString(), QLatin1String("X")); + if (m_interfaces.contains(name)) { + m_watcher->addWatchedService(constV1Prefix + name); + return m_interfaces[name]; + } + } + + return 0; +} + +#include "mediabuttons.moc" diff --git a/kdeplasma-addons/applets/icontasks/mediabuttons.h b/kdeplasma-addons/applets/icontasks/mediabuttons.h new file mode 100644 index 00000000..57ad781b --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/mediabuttons.h @@ -0,0 +1,101 @@ +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __MEDIABUTTONS_H__ +#define __MEDIABUTTONS_H__ + +#include +#include +#include + +class QDBusServiceWatcher; +class OrgMprisMediaPlayer2PlayerInterface; +class OrgFreedesktopMediaPlayerInterface; + +class MediaButtons : public QObject +{ + Q_OBJECT + +public: + class Interface + { + public: + Interface(OrgFreedesktopMediaPlayerInterface *o) : v1(o), v2(0) { } + Interface(OrgMprisMediaPlayer2PlayerInterface *t) : v1(0), v2(t) { } + ~Interface(); + + bool isV1() const { + return 0 != v1; + } + bool isV2() const { + return 0 != v2; + } + + void next(); + void previous(); + void playPause(); + QString playbackStatus(); + QString service(); + private: + OrgFreedesktopMediaPlayerInterface *v1; + OrgMprisMediaPlayer2PlayerInterface *v2; + }; + + static MediaButtons * self(); + + MediaButtons(); + + void setEnabled(bool en); + bool isEnabled() const { + return m_enabled; + } + bool isMediaApp(const QString &desktopEntry) const { + return m_mediaApps.contains(desktopEntry); + } + void next(const QString &name, int pid = 0); + void previous(const QString &name, int pid = 0); + void playPause(const QString &name, int pid = 0); + QString playbackStatus(const QString &name, int pid = 0); + +private Q_SLOTS: + void sycocaChanged(const QStringList &types); + void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); + +private: + void readConfig(); + void updateApps(); + Interface * getInterface(const QString &name, int pid); + Interface * getV2Interface(const QString &name); + Interface * getV1Interface(const QString &name); + +private: + QDBusServiceWatcher *m_watcher; + QMap m_interfaces; + QMap m_aliases; + QSet m_ignore; + QSet m_mediaApps; + QSet m_customMediaApps; + bool m_enabled; +}; + +#endif diff --git a/kdeplasma-addons/applets/icontasks/mediabuttonsrc b/kdeplasma-addons/applets/icontasks/mediabuttonsrc new file mode 100644 index 00000000..37e7d916 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/mediabuttonsrc @@ -0,0 +1,6 @@ +[General] +Ignore=kmix,k3b,ghb,xbmc,flashplayer,audex,kmediafactory,kdenlive,avidemux-qt4,mkvinfo,mkvmergegui,guvcview,pavucontrol,avidemux-qt,devede,kid3 +[Aliases] +amarok=amarok_containers +mpd=qmpdclient,sonata,quimup,qtmpc +dragonplayer=Dragon diff --git a/kdeplasma-addons/applets/icontasks/net.launchpad.DockItem.xml b/kdeplasma-addons/applets/icontasks/net.launchpad.DockItem.xml new file mode 100644 index 00000000..221188cc --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/net.launchpad.DockItem.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kdeplasma-addons/applets/icontasks/net.launchpad.DockManager.xml b/kdeplasma-addons/applets/icontasks/net.launchpad.DockManager.xml new file mode 100644 index 00000000..9070a680 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/net.launchpad.DockManager.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kdeplasma-addons/applets/icontasks/org.freedesktop.MediaPlayer.player.xml b/kdeplasma-addons/applets/icontasks/org.freedesktop.MediaPlayer.player.xml new file mode 100644 index 00000000..4431c9c4 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/org.freedesktop.MediaPlayer.player.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kdeplasma-addons/applets/icontasks/org.mpris.MediaPlayer2.Player.xml b/kdeplasma-addons/applets/icontasks/org.mpris.MediaPlayer2.Player.xml new file mode 100644 index 00000000..3c11567f --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/org.mpris.MediaPlayer2.Player.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kdeplasma-addons/applets/icontasks/plasma-applet-icontasks.desktop b/kdeplasma-addons/applets/icontasks/plasma-applet-icontasks.desktop new file mode 100644 index 00000000..931fe4ec --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/plasma-applet-icontasks.desktop @@ -0,0 +1,107 @@ +[Desktop Entry] +Name=Icon-Only Task Manager +Name[bs]=Icon-Only upravljač zadacima +Name[ca]=Gestor de tasques de només icones +Name[ca@valencia]=Gestor de tasques de només icones +Name[cs]=Ikonový správce úloh +Name[da]=Opgavelinje kun med ikoner +Name[de]=Symbol-Fensterleiste +Name[el]=Διαχειριστής εργασιών με εικονίδια μόνο +Name[en_GB]=Icon-Only Task Manager +Name[es]=Gestor de tareas de solo iconos +Name[et]=Ainult ikoonidega tegumihaldur +Name[fi]=Kuvaketehtävienhallinta +Name[fr]=Gestionnaire de tâches à icônes +Name[gl]=Xestor de tarefas baseado en iconas +Name[hu]=Ikonos feladatkezelő +Name[it]=Gestore attività con sole icone +Name[kk]=Тек таңбашалы тапсырмалар менеджері +Name[km]=តែ​រូបតំណាង​កម្មវិធី​គ្រប់គ្រង​ភារកិច្ច +Name[ko]=아이콘만 있는 작업 관리자 +Name[lt]=Tik ženkliukų užduočių tvarkytuvė +Name[lv]=Tikai ikonu uzdevumu pārvaldnieks +Name[mr]=फक्त-चिन्ह कार्य व्यवस्थापक +Name[nb]=Oppgavebehandler med bare ikoner +Name[nds]="Bloots-Lüttbild"-Opgavenpleger +Name[nl]=Takenbeheer met alleen pictogrammen +Name[pa]=ਕੇਵਲ ਆਈਕਾਨ ਟਾਸਕ ਮੈਨੇਜਰ +Name[pl]=Menadżer zadań tylko z ikonami +Name[pt]=Gestor de Tarefas com Ícones +Name[pt_BR]=Gerenciador de tarefas com ícones +Name[ro]=Gestionar de sarcini bazat pe pictograme +Name[ru]=Панель задач (только значки) +Name[sk]=Správca úloh len s ikonami +Name[sl]=Upravljalnik opravil s samimi ikonami +Name[sr]=менаџер задатака само са иконама +Name[sr@ijekavian]=менаџер задатака само са иконама +Name[sr@ijekavianlatin]=menadžer zadataka samo sa ikonama +Name[sr@latin]=menadžer zadataka samo sa ikonama +Name[sv]=Aktivitetshanterare med bara ikoner +Name[tr]=Sadece-Simge Görev Yöneticisi +Name[uk]=Керування задачами за допомогою піктограм +Name[x-test]=xxIcon-Only Task Managerxx +Name[zh_CN]=图标任务管理器 +Name[zh_TW]=只有圖示的工作管理員 +Comment=Switch between running applications +Comment[ar]=بدِّل بين التطبيقات المفتوحة +Comment[bs]=Prebacujte između programa u radu +Comment[ca]=Commuta entre aplicacions en execució +Comment[ca@valencia]=Commuta entre aplicacions en execució +Comment[cs]=Přepnout mezi běžícími aplikacemi +Comment[da]=Skift mellem kørende programmer +Comment[de]=Zwischen laufenden Programmen wechseln +Comment[el]=Εναλλαγή μεταξύ των εκτελούμενων εφαρμογών +Comment[en_GB]=Switch between running applications +Comment[es]=Cambiar entre las aplicaciones en ejecución +Comment[et]=Lülitumine töötavate rakenduste vahel +Comment[fi]=Vaihda avoinna olevien ohjelmien välillä +Comment[fr]=Basculer entre les applications démarrées +Comment[ga]=Athraigh idir feidhmchláir atá ag rith +Comment[gl]=Manexe os aplicativos que teña abertos. +Comment[hu]=Váltás a futó alkalmazások között +Comment[it]=Passa da un'applicazione in esecuzione all'altra +Comment[kk]=Жегілген қолданбаларды ақтару +Comment[km]=ប្ដូរ​រវាង​កម្មវិធី​ដែល​កំពុង​រត់ +Comment[ko]=실행 중인 프로그램 전환 +Comment[lt]=Persijungti tarp veikiančių programų +Comment[lv]=Pārslēgties starp darbojošām programmām +Comment[mr]=चालू असलेले अनुप्रयोग बदला +Comment[nb]=Bytt mellom kjørende programmer +Comment[nds]=Twischen lopen Programmen wesseln +Comment[nl]=Schakel tussen draaiende programma's +Comment[nn]=Byt mellom program som køyrer +Comment[pa]=ਚੱਲਦੀਆਂ ਐਪਲੀਕੇਸ਼ਨਾਂ ਬਦਲੋ +Comment[pl]=Przełącz pomiędzy działającymi programami +Comment[pt]=Mudar de aplicações em execução +Comment[pt_BR]=Alterna entre os aplicativos em execução +Comment[ro]=Comută printre aplicațiile ce rulează +Comment[ru]=Переключение между запущенными приложениями +Comment[sk]=Prepínať medzi bežiacimi aplikáciami +Comment[sl]=Preklapljajte med zagnanimi programi +Comment[sr]=Пребацивање између покренутих програма +Comment[sr@ijekavian]=Пребацивање између покренутих програма +Comment[sr@ijekavianlatin]=Prebacivanje između pokrenutih programa +Comment[sr@latin]=Prebacivanje između pokrenutih programa +Comment[sv]=Byt mellan program som kör +Comment[tr]=Çalışan uygulamalar arasında geçiş yap +Comment[ug]=ئىجرا بولۇۋاتقان پروگراممىلارنى ئالماشتۇر +Comment[uk]=Перемкніть запущені програми +Comment[x-test]=xxSwitch between running applicationsxx +Comment[zh_CN]=在运行中的应用程序间切换 +Comment[zh_TW]=在執行中的應用程式間切換 +Icon=preferences-desktop-icons +Type=Service +X-KDE-ServiceTypes=Plasma/Applet + +X-KDE-Library=plasma_applet_icontasks +X-KDE-PluginInfo-Author=Craig Drummond +X-KDE-PluginInfo-Email=craig@kde.org +X-KDE-PluginInfo-Name=icontasks +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Category=Windows and Tasks +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL v2+ +X-KDE-PluginInfo-EnabledByDefault=false +X-Plasma-Requires-FileDialog=Unused +X-Plasma-Requires-LaunchApp=Unused + diff --git a/kdeplasma-addons/applets/icontasks/progress.svgz b/kdeplasma-addons/applets/icontasks/progress.svgz new file mode 100644 index 00000000..099c671a Binary files /dev/null and b/kdeplasma-addons/applets/icontasks/progress.svgz differ diff --git a/kdeplasma-addons/applets/icontasks/recentdocuments.cpp b/kdeplasma-addons/applets/icontasks/recentdocuments.cpp new file mode 100644 index 00000000..2e095ebf --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/recentdocuments.cpp @@ -0,0 +1,558 @@ +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "recentdocuments.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +K_GLOBAL_STATIC(RecentDocuments, recentDocs) + +static QLatin1String constXbel("recently-used.xbel"); + +static QList::ConstIterator findUrl(const QList &list, const QString &url) +{ + QList::ConstIterator it(list.constBegin()), + end(list.constEnd()); + for (; it != end; ++it) { + if ((*it)->property("url") == url) { + break; + } + } + return it; +} + +static bool hasUrl(const QList &list, const QString &url) +{ + return list.end() != findUrl(list, url); +} + +static QString dirSyntax(const QString &d) +{ + if (!d.isEmpty()) { + QString ds(d); + + ds.replace("//", "/"); + + int slashPos(ds.lastIndexOf('/')); + + if (slashPos != (((int)ds.length()) - 1)) + ds.append('/'); + + return ds; + } + + return d; +} + +RecentDocuments * RecentDocuments::self() +{ + return recentDocs; +} + +RecentDocuments::RecentDocuments() + : m_enabled(false) + , m_watcher(0) + , m_menu(0) +{ +} + +RecentDocuments::~RecentDocuments() +{ + if (m_menu) { + m_menu->deleteLater(); + } +} + +void RecentDocuments::setEnabled(bool enabled) +{ + if (m_enabled != enabled) { + if (enabled) { + if (m_files.isEmpty()) { + m_files << File(File::Xbel, dirSyntax(KGlobal::dirs()->localxdgdatadir()) + constXbel) + << File(File::Xbel, dirSyntax(QDir::homePath()) + "." + constXbel) + << File(File::Office, dirSyntax(QDir::homePath()) + ".recently-used"); + } + + m_watcher = new KDirWatch(this); + m_watcher->addDir(KRecentDocument::recentDocumentDirectory(), KDirWatch::WatchFiles); + foreach (File f, m_files) { + m_watcher->addFile(f.path); + } + connect(m_watcher, SIGNAL(created(QString)), this, SLOT(added(QString))); + connect(m_watcher, SIGNAL(deleted(QString)), this, SLOT(removed(QString))); + connect(m_watcher, SIGNAL(dirty(QString)), this, SLOT(modified(QString))); + connect(KSycoca::self(), SIGNAL(databaseChanged(QStringList)), this, SLOT(sycocaChanged(const QStringList &))); + readCurrentDocs(); + } else if (m_enabled) { + disconnect(m_watcher, SIGNAL(created(QString)), this, SLOT(added(QString))); + disconnect(m_watcher, SIGNAL(deleted(QString)), this, SLOT(removed(QString))); + disconnect(m_watcher, SIGNAL(dirty(QString)), this, SLOT(modified(QString))); + disconnect(KSycoca::self(), SIGNAL(databaseChanged(QStringList)), this, SLOT(sycocaChanged(const QStringList &))); + delete m_watcher; + m_watcher = 0; + + QMap >::Iterator it(m_docs.begin()), + end(m_docs.end()); + + for (; it != end; ++it) { + foreach (const QAction * act, *it) { + delete act; + } + } + m_docs.clear(); + m_apps.clear(); + } + m_enabled = enabled; + } +} + +QList RecentDocuments::get(const QString &app) +{ + if (m_enabled) { + load(); + if (m_docs.contains(app)) { + if (m_docs[app].count() > 1) { + if (!m_menu) { + m_menu = new TaskManager::ToolTipMenu(0, i18n("Recent Documents")); + } + + QList old=m_menu->actions(); + foreach (QAction * act, old) { + m_menu->removeAction(act); + } + + foreach (QAction * act, m_docs[app]) { + m_menu->addAction(act); + } + + QList acts; + acts.append(m_menu->menuAction()); + return acts; + } + return m_docs[app]; + } + } + return QList(); +} + +void RecentDocuments::added(const QString &path) +{ + if (KDesktopFile::isDesktopFile(path)) { + removed(path); // Remove first! + KDesktopFile df(path); + KConfigGroup de(&df, "Desktop Entry"); + QString url = de.readEntry("URL", QString()); + QString name = KUrl(url).fileName(); + QString app = de.readEntry("X-KDE-LastOpenedWith", QString()); + + if (!name.isEmpty() && !app.isEmpty() && !url.isEmpty() && !hasUrl(m_docs[app], url)) { + QString icon = de.readEntry("Icon", QString()); + QAction *act = icon.isEmpty() ? new QAction(name, this) : new QAction(KIcon(icon), name, this); + act->setToolTip(KUrl(url).prettyUrl()); + act->setProperty("timestamp", (qulonglong)0); + act->setProperty("path", path); + act->setProperty("url", url); + connect(act, SIGNAL(triggered()), SLOT(loadDoc())); + m_docs[app].append(act); + } + } else { + QList::Iterator it(m_files.begin()), + end(m_files.end()); + for (; it != end; ++it) { + if ((*it).path == path) { + (*it).dirty = true; + break; + } + } + } +} + +void RecentDocuments::removed(const QString &path) +{ + if (path.endsWith(".desktop")) { + QMap >::Iterator it(m_docs.begin()), + end(m_docs.end()); + + for (; it != end; ++it) { + foreach (QAction * act, *it) { + if (act->property("path").toString() == path) { + disconnect(act, SIGNAL(triggered()), this, SLOT(loadDoc())); + delete act; + (*it).removeAll(act); + if ((*it).isEmpty()) { + m_docs.erase(it); + } + return; + } + } + } + } else { + QList::Iterator it(m_files.begin()), + end(m_files.end()); + for (; it != end; ++it) { + if ((*it).path == path) { + (*it).dirty = true; + break; + } + } + } +} + +void RecentDocuments::modified(const QString &path) +{ + QList::Iterator it(m_files.begin()), + end(m_files.end()); + for (; it != end; ++it) { + if ((*it).path == path) { + (*it).dirty = true; + break; + } + } +} + +void RecentDocuments::sycocaChanged(const QStringList &types) +{ + if (types.contains("apps")) { + m_apps.clear(); + QList::Iterator it(m_files.begin()), + end(m_files.end()); + for (; it != end; ++it) { + if (File::Xbel == (*it).type) { + (*it).dirty = true; + } + } + } +} + +void RecentDocuments::loadDoc() +{ + QObject *s = sender(); + if (s && qobject_cast(s)) { + QAction *item = static_cast(s); + QString path = item->property("path").toString(); + + if (path.isEmpty()) { + QString exec = item->property("exec").toString(); + KUrl url = KUrl(item->property("url").toString()); + + if (url.isValid() && !exec.isEmpty()) { + KRun::run(exec, KUrl::List() << url, 0, QString(), QString(), "0"); + } + } else { + new KRun(KUrl(path), 0); + } + } +} + +void RecentDocuments::readCurrentDocs() +{ + const QStringList documents = KRecentDocument::recentDocuments(); + foreach (const QString & document, documents) { + added(document); + } +} + +void RecentDocuments::load() +{ + qulonglong now = (qulonglong)QDateTime::currentMSecsSinceEpoch(); + QList::Iterator it(m_files.begin()), + end(m_files.end()); + for (; it != end; ++it) { + if ((*it).dirty) { + if (File::Xbel == (*it).type) { + loadXbel((*it).path, now); + } else if (File::Office == (*it).type) { + loadOffice((*it).path, now); + } + (*it).dirty = false; + } + } +} + +static QString convertMimeType(const QString &mimeType, const KUrl &url) +{ + return mimeType == "text/plain" && url.fileName().endsWith(".csv") + ? QLatin1String("text/csv") : mimeType; +} + +RecentDocuments::App RecentDocuments::officeAppForMimeType(const QString &mimeType) +{ + if (m_apps.contains(mimeType)) { + return m_apps[mimeType]; + } else { + KService::List services = KServiceTypeTrader::self()->query("Application", + QString("exist Exec and (exist ServiceTypes) and ('libreoffice' ~ Exec) and ('%1' in ServiceTypes)").arg(mimeType)); + + if (!services.empty()) { + QString desktopFile = services[0]->entryPath(); + KDesktopFile df(desktopFile); + KConfigGroup grp(&df, "Desktop Entry"); + QString exec = grp.readEntry("Exec", QString()); + + if (!exec.isEmpty()) { + App app(KUrl::fromPath(desktopFile).fileName().remove(".desktop"), exec); + m_apps.insert(mimeType, app); + return app; + } + } + } + + return App(); +} + +RecentDocuments::App RecentDocuments::appForExec(const QString &execString) +{ + if (m_apps.contains(execString)) { + return m_apps[execString]; + } else { + KService::List services = KServiceTypeTrader::self()->query("Application", + QString("exist Exec and ('%1' =~ Exec)").arg(execString)); + if (services.empty()) { + QString execApp = execString; + int space = execApp.indexOf(' '); + if (-1 != space) { + execApp = execApp.left(space); + } + services = KServiceTypeTrader::self()->query("Application", + QString("exist TryExec and ('%1' =~ TryExec)").arg(execApp)); + } + if (!services.empty()) { + QString desktopFile = services[0]->entryPath(); + KDesktopFile df(desktopFile); + KConfigGroup grp(&df, "Desktop Entry"); + QString exec = grp.readEntry("Exec", QString()); + + if (!exec.isEmpty()) { + App app(KUrl::fromPath(desktopFile).fileName().remove(".desktop"), exec); + m_apps.insert(execString, app); + return app; + } + } + } + + return App(); +} + +void RecentDocuments::loadXbel(const QString &path, qulonglong now) +{ + QDomDocument doc("xbel"); + QFile f(path); + + if (f.open(QIODevice::ReadOnly) && doc.setContent(&f)) { + QDomElement root = doc.documentElement(); + if ("xbel" == root.tagName() && root.hasAttribute("version") && "1.0" == root.attribute("version")) { + QDomElement bookmark = root.firstChildElement("bookmark"); + while (!bookmark.isNull()) { + if (bookmark.hasAttribute("href")) { + QDomElement info = bookmark.firstChildElement("info"); + if (!info.isNull()) { + QDomElement metadata = info.firstChildElement("metadata"); + if (!metadata.isNull() && metadata.hasAttribute("owner") && "http://freedesktop.org" == metadata.attribute("owner")) { + QDomElement applications = metadata.firstChildElement("bookmark:applications"); + if (!applications.isNull()) { + QDomElement application = applications.firstChildElement("bookmark:application"); + if (!application.isNull() && application.hasAttribute("exec")) { + KUrl url = bookmark.attribute("href"); + if (url.isValid() && (!url.isLocalFile() || QFile::exists(url.toLocalFile()))) { + QString exec = application.attribute("exec"); + QDomElement mimeType = metadata.firstChildElement("mime:mime-type"); + QString mType; + KMimeType::Ptr mime; + if (!mimeType.isNull() && mimeType.hasAttribute("type")) { + mType = convertMimeType(mimeType.attribute("type"), url); + mime = KMimeType::mimeType(mType); + } + + exec.remove('\''); + + App app = mime && QLatin1String("soffice %u")==exec + ? officeAppForMimeType(mType) + : appForExec(exec); + + if (!app.name.isEmpty()) { + QString name = KUrl(url).fileName(); + + if (!name.isEmpty()) { + bool found = false; + if (!m_docs[app.name].isEmpty()) { + QList::ConstIterator it = findUrl(m_docs[app.name], url.url()); + if (it != m_docs[app.name].constEnd()) { + found = true; + if ((*it)->property("timestamp").toULongLong() > 0) { + (*it)->setProperty("timestamp", now); + } + } + } + if (!found) { + QAction *act = mime + ? new QAction(KIcon(mime->iconName()), name, this) + : new QAction(name, this); + + act->setToolTip(KUrl(url).prettyUrl()); + act->setProperty("timestamp", now); + act->setProperty("url", url.url()); + act->setProperty("exec", app.exec); + act->setProperty("type", (int)File::Xbel); + connect(act, SIGNAL(triggered()), SLOT(loadDoc())); + m_docs[app.name].append(act); + } + } + } + } + } + } + } + } + } + bookmark = bookmark.nextSiblingElement("bookmark"); + } + } + } + + removeOld(now, File::Xbel); +} + +void RecentDocuments::loadOffice(const QString &path, qulonglong now) +{ + QDomDocument doc("RecentFiles"); + QFile f(path); + + if (f.open(QIODevice::ReadOnly) && doc.setContent(&f)) { + QDomElement root = doc.documentElement(); + if ("RecentFiles" == root.tagName()) { + QDomElement recentItem = root.firstChildElement("RecentItem"); + while (!recentItem.isNull()) { + QDomElement groups = recentItem.firstChildElement("Groups"); + if (!groups.isNull()) { + QDomElement group = groups.firstChildElement("Group"); + bool ok = false; + while (!group.isNull()) { + if (group.text() == "openoffice.org") { + ok = true; + break; + } + group = group.nextSiblingElement("Group"); + } + + if (ok) { + QDomElement uri = recentItem.firstChildElement("URI"); + QDomElement mimeType = recentItem.firstChildElement("Mime-Type"); + + if (!uri.isNull() && !mimeType.isNull()) { + KUrl url(uri.text()); + + if (url.isValid() && (!url.isLocalFile() || QFile::exists(url.toLocalFile()))) { + QString mType = convertMimeType(mimeType.text(), url); + App app = officeAppForMimeType(mType); + + if (!app.name.isEmpty() && !app.exec.isEmpty()) { + QString name = KUrl(url).fileName(); + + if (!name.isEmpty()) { + bool found = false; + if (!m_docs[app.name].isEmpty()) { + QList::ConstIterator it = findUrl(m_docs[app.name], url.url()); + if (it != m_docs[app.name].constEnd()) { + found = true; + if ((*it)->property("timestamp").toULongLong() > 0) { + (*it)->setProperty("timestamp", now); + } + } + } + if (!found) { + KMimeType::Ptr mime = KMimeType::mimeType(mType); + QAction *act = mime + ? new QAction(KIcon(mime->iconName()), name, this) + : new QAction(name, this); + + act->setToolTip(KUrl(url).prettyUrl()); + act->setProperty("local", false); + act->setProperty("timestamp", now); + act->setProperty("url", url.url()); + act->setProperty("exec", app.exec); + act->setProperty("type", (int)File::Office); + connect(act, SIGNAL(triggered()), SLOT(loadDoc())); + m_docs[app.name].append(act); + } + } + } + } + } + } + } + recentItem = recentItem.nextSiblingElement("RecentItem"); + } + } + } + + removeOld(now, File::Office); +} + +void RecentDocuments::removeOld(qulonglong now, File::Type type) +{ + QMap >::Iterator it(m_docs.begin()), + end(m_docs.end()); + while (it != end) { + QList old; + + foreach (QAction * act, (*it)) { + qulonglong t = act->property("timestamp").toULongLong(); + if (type==act->property("type").toInt() && t > 0 && t < now) { + old.append(act); + } + } + + foreach (QAction * act, old) { + act->deleteLater(); + (*it).removeAll(act); + } + + if ((*it).isEmpty()) { + QMap >::Iterator cur = it; + it++; + m_docs.erase(cur); + } else { + it++; + } + } +} + +#include "recentdocuments.moc" diff --git a/kdeplasma-addons/applets/icontasks/recentdocuments.h b/kdeplasma-addons/applets/icontasks/recentdocuments.h new file mode 100644 index 00000000..e001c888 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/recentdocuments.h @@ -0,0 +1,96 @@ +#ifndef __RECENT_DOCUMENTS__ +#define __RECENT_DOCUMENTS__ + +/* + * Icon Task Manager + * + * Copyright 2011 Craig Drummond + * + * ---- + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include "taskmanager/taskactions.h" + +class KDirWatch; + +class RecentDocuments : public QObject +{ + Q_OBJECT + + struct File { + enum Type { + Xbel, + Office + }; + + File(Type t, const QString &p) : type(t), path(p), dirty(true) { } + Type type; + QString path; + bool dirty; + }; + + struct App { + App(const QString &n = QString(), const QString &e = QString()) : name(n), exec(e) { } + QString name; + QString exec; + }; + +public: + static RecentDocuments * self(); + + RecentDocuments(); + ~RecentDocuments(); + + void setEnabled(bool enabled); + bool isEnabled() const { + return m_enabled; + } + + QList get(const QString &app); + +private Q_SLOTS: + void added(const QString& path); + void removed(const QString& path); + void modified(const QString& path); + void sycocaChanged(const QStringList &types); + void loadDoc(); + +private: + void readCurrentDocs(); + void load(); + App officeAppForMimeType(const QString &mimeType); + App appForExec(const QString &execString); + void loadXbel(const QString &path, qulonglong now); + void loadOffice(const QString &path, qulonglong now); + void removeOld(qulonglong now, File::Type type); + +private: + + bool m_enabled; + QMap > m_docs; + QMap m_apps; + KDirWatch *m_watcher; + QList m_files; + TaskManager::ToolTipMenu *m_menu; +}; + +#endif diff --git a/kdeplasma-addons/applets/icontasks/taskgroupitem.cpp b/kdeplasma-addons/applets/icontasks/taskgroupitem.cpp new file mode 100644 index 00000000..6f21cdf4 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/taskgroupitem.cpp @@ -0,0 +1,1614 @@ +/*************************************************************************** +* Copyright (C) 2007 by Robert Knight * +* Copyright (C) 2008 by Alexis Ménard * +* * +* 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 . * +***************************************************************************/ + +// Own +#include "taskgroupitem.h" +#include "jobmanager.h" +#include "dockmanager.h" +#include "dockitem.h" +#include "mediabuttons.h" +#include "unity.h" + +// Qt +#include +#include +#include +#include +#include +#include + +// KDE +#include +#include +#include + +#include "taskmanager/taskactions.h" +#include "taskmanager/taskmanager.h" +#include "taskmanager/taskgroup.h" +#include "taskmanager/abstractgroupingstrategy.h" +#include "taskmanager/taskitem.h" + +#include +#include +#include "tooltips/tooltipmanager.h" +#include +#include +#include +#include + +#include "tasks.h" +#include "taskitemlayout.h" +#include "windowtaskitem.h" +#include "applauncheritem.h" + +class DropIndicator : public QGraphicsWidget +{ +public: + + DropIndicator(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0) + : QGraphicsWidget(parent, wFlags) + , m_size(16) + , m_orientation(Qt::Horizontal) { + m_svg = new Plasma::Svg(); + m_svg->setImagePath("icontasks/dropindicators"); + m_svg->setContainsMultipleImages(true); + m_svg->resize(m_size, m_size); + setOrientation(Qt::Horizontal); + + m_animation = new QPropertyAnimation(this, "pos", this); + m_animation->setEasingCurve(QEasingCurve::InOutQuad); + m_animation->setDuration(50); + } + + ~DropIndicator() { + } + + void setOrientation(Qt::Orientation orientation) { + m_orientation = orientation; + } + + Qt::Orientation orientation() { + return m_orientation; + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + Q_UNUSED(option); + Q_UNUSED(widget); + + m_svg->paint(painter, rect().topLeft(), Qt::Horizontal == m_orientation ? "horizontal-dropindicator" : "vertical-dropindicator"); + } + + void setSize(int size) { + int sz = size; + if (sz < 16) { + sz = 16; + } else if (sz > 32) { + sz = 32; + } else { + sz = (sz / 4) * 4; + } + + if (m_size != sz) { + m_size = sz; + m_svg->resize(m_size, m_size); + } + } + + void setPosition(const QRectF &r) { + QPointF newPos = Qt::Horizontal == m_orientation + ? QPointF(r.x() - (m_size / 2.0), r.y() + (r.height() - m_size) / 2.0) + : QPointF(r.x() + (r.width() - m_size) / 2.0, r.y() - (m_size / 2.0)); + + if (isVisible()) { + if (m_animation->state() == QAbstractAnimation::Running) { + m_animation->stop(); + } + + m_animation->setEndValue(newPos); + m_animation->start(); + } else { + setVisible(true); + setPos(newPos); + } + } + +private: + int m_size; + Plasma::Svg *m_svg; + Qt::Orientation m_orientation; + QPropertyAnimation *m_animation; +}; + + +TaskGroupItem::TaskGroupItem(QGraphicsWidget *parent, Tasks *applet) + : AbstractTaskItem(parent, applet), + m_tasksLayout(0), + m_popupMenuTimer(0), + m_lastActivated(-1), + m_activeTaskIndex(0), + m_maximumRows(1), + m_offscreenWidget(0), + m_offscreenLayout(0), + m_collapsed(true), + m_mainLayout(0), + m_popupDialog(0), + m_updateTimer(0), + m_changes(TaskManager::TaskUnchanged), + m_dropIndicator(0) +{ + setAcceptDrops(true); + setFlag(ItemClipsChildrenToShape, true); +} + + +TaskGroupItem::~TaskGroupItem() +{ + if (!m_offscreenLayout && !m_mainLayout) { + // only delete this if we have neither an offscreen layout or a mainlayout + // if we do, then they will delete the layout for us. + delete m_tasksLayout; + } + close(false); +} + +void TaskGroupItem::activate() +{ +} + +void TaskGroupItem::activateOrIconify() +{ + bool includesActive = false; + TaskManager::ItemList items(m_group.data()->members()); + int iconified = 0; + foreach (AbstractGroupableItem * item, items) { + TaskManager::TaskItem *task = qobject_cast(item); + if (task) { + if (task->task()->isIconified()) { + ++ iconified; + } + + if (task->task()->isActive()) { + includesActive = true; + } + } + } + + if (includesActive && items.size() - iconified > iconified) { + // iconify + foreach (TaskManager::AbstractGroupableItem * item, items) { + TaskManager::TaskItem *task = qobject_cast(item); + if (task) { + task->task()->setIconified(true); + } + } + } else { + // activate + QList winOrder(KWindowSystem::stackingOrder()); + const int winCount = winOrder.size(); + TaskManager::TaskItem* sortedItems[winCount]; + + memset(sortedItems, 0, sizeof(TaskManager::TaskItem*) * winCount); + + foreach (TaskManager::AbstractGroupableItem * item, items) { + TaskManager::TaskItem *task = qobject_cast(item); + if (task) { + int index = winOrder.indexOf(task->task()->window()); + if (index != -1) { + sortedItems[index] = task; + } + } + } + + for (int index = 0; index < winCount; ++ index) { + TaskManager::TaskItem* task = sortedItems[index]; + if (task) { + task->task()->activate(); + } + } + } +} + +void TaskGroupItem::close() +{ + close(true); +} + +void TaskGroupItem::close(bool hide) +{ + //kDebug(); + //close the popup if the group is removed + if (m_popupDialog) { + m_popupDialog->hide(); + disconnect(m_popupDialog, 0, 0, 0); + m_popupDialog->deleteLater(); + m_popupDialog = 0; + } + + if (m_group) { + disconnect(m_group.data(), 0, this, 0); + } + + if (m_updateTimer) { + m_updateTimer->stop(); + } + + if (!isRootGroup()) { + unregisterFromHelpers(); + if (hide) { + setVisible(false); + } + } +} + +bool TaskGroupItem::isRootGroup() const +{ + return m_applet == parentWidget(); +} + +void TaskGroupItem::updateTask(::TaskManager::TaskChanges changes) +{ + if (!m_group || isRootGroup()) { + return; + } + + m_changes |= changes; + + if (!m_updateTimer) { + m_updateTimer = new QTimer(this); + m_updateTimer->setInterval(10); + m_updateTimer->setSingleShot(true); + connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(checkUpdates())); + } + + m_updateTimer->start(); +} + +void TaskGroupItem::checkUpdates() +{ + if (!m_group) { + return; + } + + bool needsUpdate = false; + TaskFlags flags = m_flags; + + if (m_changes & TaskManager::StateChanged) { + if (m_group.data()->isActive()) { + flags |= TaskHasFocus; + if (!(m_flags & TaskHasFocus)) { + emit activated(this); + } + } else { + flags &= ~TaskHasFocus; + } + + if (m_group.data()->isMinimized()) { + flags |= TaskIsMinimized; + } else { + flags &= ~TaskIsMinimized; + } + } + + if (m_changes & TaskManager::AttentionChanged) { + if (m_group.data()->demandsAttention()) { + flags |= TaskWantsAttention; + } else { + flags &= ~TaskWantsAttention; + } + } + + if (flags != m_flags) { + needsUpdate = true; + setTaskFlags(flags); + } + + // basic title and icon + if (m_changes & TaskManager::IconChanged) { + needsUpdate = true; + } + + if (m_changes & TaskManager::NameChanged) { + needsUpdate = true; + } + + if (IconTasks::ToolTipManager::self()->isVisible(this) && + (m_changes & TaskManager::IconChanged || + m_changes & TaskManager::NameChanged || + m_changes & TaskManager::DesktopChanged)) { + updateToolTip(); + } + + m_changes = TaskManager::TaskUnchanged; + if (needsUpdate) { + //redraw + queueUpdate(); + } +} + +void TaskGroupItem::updateToolTip() +{ + if (!m_group) { + return; + } + + QWidget *dialog = m_applet->popupDialog(); + + if (dialog && dialog->isVisible()) { + clearToolTip(); + return; + } + + IconTasks::ToolTipContent data; + + data.setClickable(true); +#if KDE_IS_VERSION(4, 7, 0) + data.setInstantPopup(m_applet->instantToolTip()); +#endif + data.setHighlightWindows(m_applet->highlightWindows()); + data.setVertical(Plasma::Vertical == m_applet->formFactor()); + + QMap map; + + if (m_applet->launcherIcons() && m_icon.isNull()) { + KUrl launcherUrl(m_abstractItem->launcherUrl()); + if (launcherUrl.isLocalFile() && KDesktopFile::isDesktopFile(launcherUrl.toLocalFile())) { + KDesktopFile f(launcherUrl.toLocalFile()); + if (f.tryExec()) { + m_icon = KIcon(f.readIcon()); + } + } + } + + foreach (AbstractGroupableItem * item, m_group.data()->members()) { + TaskManager::TaskItem *taskItem = qobject_cast(item); + if (taskItem && taskItem->task()) { + if (m_icon.isNull()) { + m_icon = item->icon(); + } + map.insertMulti(taskItem->id(), + IconTasks::ToolTipContent::Window(taskItem->task()->window(), + item->name(), + m_icon.pixmap(IconTasks::ToolTipContent::iconSize(), IconTasks::ToolTipContent::iconSize()), + taskItem->task()->demandsAttention(), + !m_applet->groupManager().showOnlyCurrentDesktop() || !taskItem->isOnCurrentDesktop() + ? taskItem->task()->desktop() : 0)); + } + } + + data.setWindowDetailsToPreview(map.values()); + + QString key = mediaButtonKey(); + if (!key.isEmpty()) { + data.setPlayState(MediaButtons::self()->playbackStatus(key)); + } + + IconTasks::ToolTipManager::self()->setContent(this, data); +} + +void TaskGroupItem::reload() +{ + if (!group()) { + return; + } + + QHash itemsToRemove = m_groupMembers; + foreach (AbstractGroupableItem * item, group()->members()) { + if (!item) { + kDebug() << "invalid Item"; + continue; + } + + if (itemsToRemove.contains(item)) { + itemsToRemove.insert(item, 0); + } + itemAdded(item); + + if (item->itemType() == TaskManager::GroupItemType) { + TaskGroupItem *group = qobject_cast(abstractTaskItem(item)); + if (group) { + group->reload(); + } + } + } + + QHashIterator it(itemsToRemove); + while (it.hasNext()) { + it.next(); + if (it.key() && it.value()) { + itemRemoved(it.key()); + } + } +} + +void TaskGroupItem::setGroup(TaskManager::GroupPtr group) +{ + //kDebug(); + if (m_group.data() == group) { + kDebug() << "already have this group!"; + return; + } + + if (m_group) { + disconnect(m_group.data(), 0, this, 0); + } + + m_group = group; + m_abstractItem = group; + + if (m_group) { + connect(m_abstractItem, SIGNAL(destroyed(QObject*)), this, SLOT(clearAbstractItem())); + connect(group, SIGNAL(destroyed(QObject*)), this, SLOT(clearGroup())); + connect(group, SIGNAL(itemRemoved(AbstractGroupableItem*)), this, SLOT(itemRemoved(AbstractGroupableItem*))); + connect(group, SIGNAL(itemAdded(AbstractGroupableItem*)), this, SLOT(itemAdded(AbstractGroupableItem*))); + + //connect(group, SIGNAL(destroyed()), this, SLOT(close())); + + connect(group, SIGNAL(changed(::TaskManager::TaskChanges)), this, SLOT(updateTask(::TaskManager::TaskChanges))); + + connect(group, SIGNAL(itemPositionChanged(AbstractGroupableItem*)), this, SLOT(itemPositionChanged(AbstractGroupableItem*))); + } + + //Add already existing items + reload(); + updateTask(::TaskManager::EverythingChanged); + if (!isRootGroup()) { + registerWithHelpers(); + } + //kDebug() << "Task added, isActive = " << task->isActive(); +} + +TaskManager::GroupPtr TaskGroupItem::group() const +{ + return m_group.data(); +} + +void TaskGroupItem::clearGroup() +{ + //now it's useless +} + +void TaskGroupItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *e) +{ + //kDebug(); + if (!KAuthorized::authorizeKAction("kwin_rmb") || !m_group) { + QGraphicsWidget::contextMenuEvent(e); + return; + } + + Q_ASSERT(m_applet); + //we are the master group item + if (isRootGroup()) { + e->ignore(); + return; + } + + QList actionList; + + QAction *a = m_applet->action("configure"); + if (a && a->isEnabled()) { + actionList.append(a); + } + + TaskManager::BasicMenu menu(qobject_cast(this), m_group.data(), &m_applet->groupManager(), actionList, getAppMenu()); + + menu.adjustSize(); + + if (m_applet->formFactor() != Plasma::Vertical) { + menu.setMinimumWidth(size().width()); + } + + Q_ASSERT(m_applet->containment()); + Q_ASSERT(m_applet->containment()->corona()); + stopWindowHoverEffect(); + menu.exec(m_applet->containment()->corona()->popupPosition(this, menu.size())); +} + +QHash TaskGroupItem::members() const +{ + return m_groupMembers; +} + +int TaskGroupItem::count() const +{ + return m_groupMembers.count(); +} + +AbstractTaskItem *TaskGroupItem::createAbstractItem(TaskManager::AbstractGroupableItem *groupableItem) +{ + //kDebug() << "item to create" << groupableItem << endl; + AbstractTaskItem *item = 0; + + if (groupableItem->itemType() == TaskManager::GroupItemType) { + TaskGroupItem *groupItem = new TaskGroupItem(this, m_applet); + groupItem->setGroup(static_cast(groupableItem)); + item = groupItem; + } else if (groupableItem->itemType() == TaskManager::LauncherItemType) { + AppLauncherItem *launcherItem = new AppLauncherItem(this, m_applet, static_cast(groupableItem)); + item = launcherItem; + } else { + TaskManager::TaskItem * taskItem = static_cast(groupableItem); + //if the taskItem is not either a startup o a task, return 0; + if (!taskItem->startup() && !taskItem->task()) { + return item; + } + + WindowTaskItem *windowItem = new WindowTaskItem(this, m_applet); + windowItem->setTask(taskItem); + item = windowItem; + } + + if (m_collapsed) { + item->setPreferredOffscreenSize(); + } + + return item; +} + +void TaskGroupItem::itemAdded(TaskManager::AbstractGroupableItem * groupableItem) +{ + //kDebug(); + if (!m_applet) { + kDebug() << "No applet"; + return; + } + + //returns the corresponding item or creates a new one + AbstractTaskItem *item = m_groupMembers.value(groupableItem); + + if (!item) { + item = createAbstractItem(groupableItem); + + if (item) { + connect(item, SIGNAL(activated(AbstractTaskItem*)), + this, SLOT(updateActive(AbstractTaskItem*))); + + TaskGroupItem *group = qobject_cast(item); + if (group) { + connect(item, SIGNAL(changed()), this, SLOT(relayoutItems())); + } + + if (!isRootGroup()) { + item->setVisible(false); + } + } else { + kDebug() << "invalid Item"; + return; + } + } + + m_groupMembers[groupableItem] = item; + item->setParentItem(this); + + if (m_tasksLayout) { //add to layout either for popup or expanded group + m_tasksLayout->addTaskItem(item); + } else { //collapsed and no layout so far + item->hide(); + QRect rect = iconGeometry(); + item->publishIconGeometry(rect); + } + + if (item->isActive()) { + //kDebug() << "item is Active" ; + m_activeTaskIndex = indexOf(item); + } else if (!m_group || m_group.data()->members().size() == 1) { + m_activeTaskIndex = 0; + } + + if (collapsed()) { + update(); + } +} + +void TaskGroupItem::itemRemoved(TaskManager::AbstractGroupableItem * groupableItem) +{ + //kDebug(); + if (!m_applet) { + kDebug() << "No Applet"; + return; + } + + AbstractTaskItem *item = m_groupMembers.take(groupableItem); + + if (!item) { + kDebug() << "Item not found"; + return; + } + //kDebug() << item->text(); + + disconnect(item, 0, 0, 0); + + if (m_tasksLayout) { + m_tasksLayout->removeTaskItem(item); + + if (m_offscreenWidget) { + m_offscreenWidget->adjustSize(); + } + + if (m_popupDialog && m_popupDialog->isVisible() && + m_applet->containment() && m_applet->containment()->corona()) { + m_popupDialog->move(m_applet->containment()->corona()->popupPosition(this, m_popupDialog->size(), Qt::AlignCenter)); + } + } + + item->close(); + //item->deleteLater(); + QTimer::singleShot(0, item, SLOT(deleteLater())); +} + +bool TaskGroupItem::isWindowItem() const +{ + return false; +} + +bool TaskGroupItem::isActive() const +{ + //kDebug() << "Not Implemented"; + return false; +} + +bool TaskGroupItem::windowPreviewOpen() const +{ + if (KWindowSystem::compositingActive() && isRootGroup()) { + QHashIterator it(m_groupMembers); + + while (it.hasNext()) { + it.next(); + AbstractTaskItem *item = it.value(); + if (!qobject_cast(item) && item->isToolTipVisible()) { + return true; + } + } + } + + return false; +} + +QString TaskGroupItem::appName() const +{ + if (isRootGroup()) { + return text(); + } + + foreach (AbstractTaskItem * member, m_groupMembers) { + QString n(member->appName()); + + if (!n.isEmpty()) { + return n; + } + } + + return QString(); +} + +KUrl TaskGroupItem::launcherUrl() const +{ + if (isRootGroup()) { + return KUrl(); + } + + foreach (AbstractTaskItem * member, m_groupMembers) { + KUrl u(member->launcherUrl()); + + if (u.isValid()) { + return u; + } + } + + return KUrl(); +} + +QString TaskGroupItem::windowClass() const +{ + if (isRootGroup()) { + return QString(); + } + + foreach (AbstractTaskItem * member, m_groupMembers) { + QString c(member->windowClass()); + + if (!c.isEmpty()) { + return c; + } + } + + return QString(); +} + +void TaskGroupItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + if (!m_group) { + return; + } + + event->accept(); +} + +void TaskGroupItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (m_applet->rootGroupItem() == this || !m_group) { + return; + } + + if (event->button() == Qt::LeftButton) { + if (Tasks::GC_MinMax != m_applet->groupClick() || event->modifiers() & Qt::ControlModifier) { + bool usePresentWindows=(event->modifiers()&Qt::ControlModifier || Tasks::GC_PresentWindows == m_applet->groupClick()) && + KWindowSystem::compositingActive() && Plasma::WindowEffects::isEffectAvailable(Plasma::WindowEffects::PresentWindowsGroup); + + if (usePresentWindows) { + // Check all tasks are from this activity! + foreach (AbstractGroupableItem * groupable, m_group.data()->members()) { + TaskItem * item = dynamic_cast(groupable); + if (item && item->task() && !item->task()->isOnCurrentActivity()) { + usePresentWindows=false; + break; + } + } + } + + if (usePresentWindows) { + QList ids; + foreach (AbstractGroupableItem * groupable, m_group.data()->members()) { + if (groupable->itemType() == TaskManager::GroupItemType) { + //TODO: recurse through sub-groups? + } else { + TaskItem * item = dynamic_cast(groupable); + if (item && item->task()) { + ids << item->task()->info().win(); + } + } + } + + Plasma::WindowEffects::presentWindows(m_applet->view()->winId(), ids); + } else { + if (m_popupMenuTimer) { + m_popupMenuTimer->stop(); + } + popupMenu(); + } + } else { + activateOrIconify(); + } + } + + AbstractTaskItem::mouseReleaseEvent(event); +} + +void TaskGroupItem::handleActiveWindowChanged(WId id) +{ + if (!m_popupDialog) { + return; + } + + if (id == m_popupDialog->winId()) { + return; + } + + m_popupDialog->hide(); + + QRect rect = iconGeometry(); + publishIconGeometry(rect); +} + +void TaskGroupItem::popupMenu() +{ + //kDebug(); + if (!m_collapsed) { + return; + } + + if (!m_offscreenWidget) { + foreach (AbstractTaskItem * member, m_groupMembers) { + member->setPreferredOffscreenSize(); + } + + tasksLayout()->invalidate(); + m_tasksLayout->setOrientation(Plasma::Vertical); + m_tasksLayout->setMaximumRows(1); + m_offscreenWidget = new QGraphicsWidget(this); + m_offscreenLayout = new QGraphicsLinearLayout(m_offscreenWidget); + m_offscreenLayout->setContentsMargins(0, 0, 0, 0); //default are 4 on each side + m_offscreenLayout->addItem(tasksLayout()); + m_offscreenWidget->setLayout(m_offscreenLayout); + m_offscreenWidget->adjustSize(); + m_applet->containment()->corona()->addOffscreenWidget(m_offscreenWidget); + m_offscreenLayout->activate(); + } + + if (!m_popupDialog) { + // Initialize popup dialog + m_popupDialog = new Plasma::Dialog(0, Qt::Popup); + KWindowSystem::setType(m_popupDialog->winId(), NET::PopupMenu); + connect(m_popupDialog, SIGNAL(dialogVisible(bool)), this, SLOT(popupVisibilityChanged(bool))); + connect(m_popupDialog, SIGNAL(dialogVisible(bool)), m_applet, SLOT(setPopupDialog(bool))); + connect(KWindowSystem::self(), SIGNAL(activeWindowChanged(WId)), this, SLOT(handleActiveWindowChanged(WId))); + KWindowSystem::setState(m_popupDialog->winId(), NET::SkipTaskbar | NET::SkipPager); + m_popupDialog->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + + int left, top, right, bottom; + m_popupDialog->getContentsMargins(&left, &top, &right, &bottom); + m_offscreenWidget->setMinimumWidth(size().width() - left - right); + m_popupDialog->setGraphicsWidget(m_offscreenWidget); + } + + if (m_popupDialog->isVisible()) { + m_popupDialog->clearFocus(); + if (m_applet->location() != Plasma::Floating) { + m_popupDialog->animatedHide(Plasma::locationToInverseDirection(m_applet->location())); + } else { + m_popupDialog->hide(); + } + } else { + m_tasksLayout->setOrientation(Plasma::Vertical); + m_tasksLayout->setMaximumRows(1); + m_offscreenWidget->layout()->activate(); + + QSizeF sz(m_offscreenWidget->effectiveSizeHint(Qt::PreferredSize)); + foreach (AbstractTaskItem * member, m_groupMembers) { + member->setPreferredOffscreenSize(); + QSizeF m = member->preferredSize(); + if (m.width() > sz.width()) { + sz.setWidth(m.width()); + } + } + + m_offscreenWidget->resize(sz); + m_popupDialog->syncToGraphicsWidget(); + + if (m_applet->containment() && m_applet->containment()->corona()) { + m_popupDialog->move(m_applet->containment()->corona()->popupPosition(this, m_popupDialog->size(), Qt::AlignCenter)); + } + KWindowSystem::setState(m_popupDialog->winId(), NET::SkipTaskbar | NET::SkipPager); + if (m_applet->location() != Plasma::Floating) { + m_popupDialog->animatedShow(Plasma::locationToDirection(m_applet->location())); + } else { + m_popupDialog->show(); + } + + m_popupDialog->raise(); + } +} + +void TaskGroupItem::popupVisibilityChanged(bool visible) +{ + if (!visible) { + QRect rect = iconGeometry(); + publishIconGeometry(rect); + update(); + } +} + +bool TaskGroupItem::focusNextPrevChild(bool next) +{ + return focusSubTask(next, false); +} + +bool TaskGroupItem::focusSubTask(bool next, bool activate) +{ + const int subTasks = totalSubTasks(); + + if (subTasks > 0) { + int index = -1; + + if (subTasks > 1) { + for (int i = 0; i < subTasks; ++i) { + if (selectSubTask(i)->taskFlags() & TaskHasFocus) { + index = i; + break; + } + } + } + + if (next) { + ++index; + + if (index >= subTasks) { + index = 0; + } + } else { + --index; + + if (index < 0) { + index = (subTasks - 1); + } + } + + AbstractTaskItem *taskItem = selectSubTask(index); + + if (taskItem) { + taskItem->setFocus(); + m_activeTaskIndex = index; + } + + if (activate && taskItem) { + stopWindowHoverEffect(); + taskItem->activate(); + } + + return true; + } else { + return false; + } +} + +void TaskGroupItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + if (isRootGroup()) { + return; + } + + if (QPoint(event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < QApplication::startDragDistance()) { + return; + } //Wait a bit before starting drag + + //kDebug(); + if (m_popupMenuTimer) { + //kDebug() << "popupTimer stop"; + m_popupMenuTimer->stop(); + } //Wait a bit before starting drag + AbstractTaskItem::mouseMoveEvent(event); +} + +void TaskGroupItem::resizeEvent(QGraphicsSceneResizeEvent *event) +{ + Q_UNUSED(event) + + if (m_offscreenWidget && m_popupDialog) { + int left, top, right, bottom; + m_popupDialog->getContentsMargins(&left, &top, &right, &bottom); + m_offscreenWidget->setMinimumWidth(size().width() - left - right); + } + + AbstractTaskItem::resizeEvent(event); +} + +void TaskGroupItem::expand() +{ + if (!collapsed()) { + //kDebug() << "already expanded"; + return; + } + + if (m_popupDialog) { + m_popupDialog->hide(); + } + + if (m_offscreenLayout) { + m_offscreenLayout->removeItem(tasksLayout()); + } + + if (!m_mainLayout) { //this layout is needed since we can't take a layout directly from a widget without destroying it + m_mainLayout = new QGraphicsLinearLayout(this); + m_mainLayout->setContentsMargins(0, 0, 0, 0); //default are 4 on each side + setLayout(m_mainLayout); + } + + //set it back from the popup settings (always vertical and 1 row) + tasksLayout()->setOrientation(m_applet->formFactor()); + tasksLayout()->setMaximumRows(m_maximumRows); + + m_mainLayout->addItem(tasksLayout()); + + disconnect(m_applet, SIGNAL(constraintsChanged(Plasma::Constraints)), this, SLOT(constraintsChanged(Plasma::Constraints))); + connect(m_applet, SIGNAL(constraintsChanged(Plasma::Constraints)), this, SLOT(constraintsChanged(Plasma::Constraints))); + //connect(m_tasksLayout, SIGNAL(sizeHintChanged(Qt::SizeHint)), this, SLOT(updatePreferredSize())); + m_collapsed = false; + tasksLayout()->layoutItems(); + //kDebug() << tasksLayout()->preferredSize() << preferredSize() << m_groupMembers.count(); + emit changed(); + checkSettings(); + //kDebug() << "expanded"; +} + +void TaskGroupItem::constraintsChanged(Plasma::Constraints constraints) +{ + //kDebug(); + if (constraints & Plasma::SizeConstraint && m_tasksLayout) { + m_tasksLayout->layoutItems(); + } + + if (constraints & Plasma::FormFactorConstraint && m_tasksLayout) { + m_tasksLayout->setOrientation(m_applet->formFactor()); + if (m_dropIndicator) { + m_dropIndicator->setOrientation(Plasma::Vertical == m_applet->formFactor() ? Qt::Vertical : Qt::Horizontal); + } + } +} + +void TaskGroupItem::relayoutItems() +{ + if (m_tasksLayout) { + m_tasksLayout->layoutItems(); + } +} + +TaskItemLayout *TaskGroupItem::tasksLayout() +{ + if (!m_tasksLayout) { + m_tasksLayout = new TaskItemLayout(this, m_applet); + m_tasksLayout->setMaximumRows(m_maximumRows); + m_tasksLayout->setForceRows(false); // m_forceRows); + m_tasksLayout->setOrientation(m_applet->formFactor()); + } + + return m_tasksLayout; +} + +void TaskGroupItem::collapse() +{ + //kDebug() << (int)this; + if (collapsed()) { + //kDebug() << "already collapsed"; + return; + } + + m_mainLayout->removeItem(tasksLayout()); + if (m_offscreenLayout) { + m_offscreenLayout->addItem(tasksLayout()); + } else { + foreach (AbstractTaskItem * member, m_groupMembers) { + scene()->removeItem(member); + } + } + + //kDebug(); + //delete m_tasksLayout; + disconnect(m_applet, SIGNAL(constraintsChanged(Plasma::Constraints)), this, SLOT(constraintsChanged(Plasma::Constraints))); + m_collapsed = true; + updatePreferredSize(); + //kDebug(); + emit changed(); + checkSettings(); +} + +bool TaskGroupItem::collapsed() const +{ + return m_collapsed; +} + +void TaskGroupItem::toCurrentDesktop() +{ + if (!isRootGroup()) { + foreach (AbstractTaskItem * member, m_groupMembers) { + member->toCurrentDesktop(); + } + } +} + +void TaskGroupItem::updatePreferredSize() +{ + if (m_collapsed) { + foreach (AbstractTaskItem * taskItem, m_groupMembers) { + taskItem->setPreferredOffscreenSize(); + } + + //FIXME: copypaste from abstracttaskitem: to be done better with proper sizeHint() + setPreferredSize(basicPreferredSize()); + } else { + foreach (AbstractTaskItem * taskItem, m_groupMembers) { + taskItem->setPreferredOnscreenSize(); + } + + layout()->invalidate(); + setPreferredSize(layout()->preferredSize()); + //kDebug() << "expanded group" << layout()->preferredSize(); + } + + //kDebug() << preferredSize(); + emit sizeHintChanged(Qt::PreferredSize); +} + +AbstractTaskItem *TaskGroupItem::directMember(AbstractTaskItem *item) +{ + Q_ASSERT(item); + Q_ASSERT(m_group); + TaskManager::AbstractGroupableItem * directMember = m_group.data()->directMember(item->abstractItem()); + if (!directMember) { + kDebug() << "Error" << item->abstractItem(); + } + return abstractTaskItem(directMember); +} + +void TaskGroupItem::paint(QPainter *painter, + const QStyleOptionGraphicsItem *option, + QWidget *widget) +{ + if (collapsed()) { + AbstractTaskItem::paint(painter, option, widget); + } +} + +void TaskGroupItem::itemPositionChanged(AbstractGroupableItem * item) +{ + //kDebug(); + if (!m_tasksLayout) { + return; + } + + Q_ASSERT(item); + + AbstractTaskItem *taskItem = abstractTaskItem(item); + + m_tasksLayout->removeTaskItem(taskItem); + + // NOTE: If the grouping strategy is "only when the taskbar is full", + // removing the task from the layout might cause this group to + // split, and so the task might be removed from the group. + // This will cause deleteLater() to be called on taskItem, and + // we are in danger of inserting a pointer that will soon be + // invalid into the layout. So check that the task item is + // still in the group. + taskItem = abstractTaskItem(item); + if (m_group && taskItem) { + m_tasksLayout->insert(m_group.data()->members().indexOf(item), taskItem); + } +} + + +void TaskGroupItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) +{ + bool shouldIgnore = shouldIgnoreDragEvent(event); + if ((collapsed() && shouldIgnore) || (isRootGroup() && !shouldIgnore)) { + event->ignore(); + //kDebug()<<"Drag enter accepted"; + } else { + event->accept(); + if (!m_popupMenuTimer) { + m_popupMenuTimer = new QTimer(this); + m_popupMenuTimer->setSingleShot(true); + m_popupMenuTimer->setInterval(500); + connect(m_popupMenuTimer, SIGNAL(timeout()), this, SLOT(popupMenu())); + } + m_popupMenuTimer->start(); + } +} + +void TaskGroupItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *) +{ + if (m_popupMenuTimer) { + m_popupMenuTimer->stop(); + } + + if (m_dropIndicator && m_dropIndicator->isVisible()) { + m_dropIndicator->setVisible(false); + } +} + +void TaskGroupItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event) +{ + if (isRootGroup()) { + //#ifndef ICON_TASKS_SHOW_DROP_INDICATOR_FOR_MOVE + int sourceIndex = event->mimeData()->property("icontasks-item-ptr").isValid() + ? m_applet->rootGroupItem()->indexOf((AbstractTaskItem *)(event->mimeData()->property("icontasks-item-ptr").toULongLong()), false) + : -1; + //#else + //int sourceIndex = event->mimeData()->property("icontasks-item-index").isValid() ? event->mimeData()->property("icontasks-item-index").toInt() : -1; + //#endif + bool isDesktopFile = -1 == sourceIndex && event->mimeData()->hasFormat("text/uri-list"); + bool isLauncher = isDesktopFile || (-1 != sourceIndex && sourceIndex < m_applet->groupManager().launcherCount()); + + if (isLauncher && m_applet->groupManager().launchersLocked()) { + return; + } + + if (sourceIndex > -1 || isDesktopFile) { + TaskItemLayout::Insert destIndex = m_tasksLayout->insertionIndexAt(event->pos()); + bool visible = destIndex.index != sourceIndex && destIndex.index >= 0 && (destIndex.geom.x() > 0 || destIndex.geom.y() > 0 || 0 == destIndex.index); + bool moveRight = sourceIndex > -1 && destIndex.index > sourceIndex; + +// qDebug() << event->pos() << sourceIndex << destIndex.index << destIndex.geom; + if (visible && ((isLauncher && destIndex.index - (moveRight ? 1 : 0) < m_applet->groupManager().launcherCount()) || + (!isLauncher && destIndex.index - (moveRight ? 1 : 0) >= m_applet->groupManager().launcherCount()))) { + //#ifndef ICON_TASKS_SHOW_DROP_INDICATOR_FOR_MOVE + if (!isDesktopFile) { + dropEvent(event); + return; + } + //#endif + + if (!m_dropIndicator) { + m_dropIndicator = new DropIndicator(parentItem()); + m_dropIndicator->setOrientation(Plasma::Vertical == m_applet->formFactor() ? Qt::Vertical : Qt::Horizontal); + m_dropIndicator->setVisible(false); + } + + if (!m_dropIndicator->isVisible()) { + m_dropIndicator->setSize((Plasma::Vertical == m_applet->formFactor() ? destIndex.geom.height() : destIndex.geom.width()) / 3.0); + } + + m_dropIndicator->setPosition(QRectF(mapToParent(destIndex.geom.topLeft()), destIndex.geom.size())); + return; + } + } + + if (m_dropIndicator && m_dropIndicator->isVisible()) { + m_dropIndicator->setVisible(false); + } + } +} + +AbstractTaskItem *TaskGroupItem::taskItemForWId(WId id) +{ + QHashIterator it(m_groupMembers); + + while (it.hasNext()) { + it.next(); + AbstractTaskItem *item = it.value(); + TaskGroupItem *group = qobject_cast(item); + + if (group) { + item = group->taskItemForWId(id); + if (item) { + return item; + } + } else { + TaskManager::TaskItem *task = qobject_cast(it.key()); + if (task && task->task() && task->task()->window() == id) { + return item; + } + } + } + + return 0; +} + +static QString agiName(TaskManager::AbstractGroupableItem *i) +{ + if (i->itemType() == TaskManager::TaskItemType && !i->isStartupItem()) { + return static_cast(i)->taskName().toLower(); + } else { + return i->name().toLower(); + } +} + +AbstractTaskItem *TaskGroupItem::matchingItem(TaskManager::AbstractGroupableItem *from) +{ + QHashIterator it(m_groupMembers); + AbstractTaskItem *itm = 0L; + QString n = agiName(from); + KUrl launcherUrl = from->launcherUrl(); + + while (it.hasNext()) { + it.next(); + AbstractGroupableItem *item = it.key(); + AbstractTaskItem *taskItem = it.value(); + QString name = agiName(item); + + if ((name == n || (!launcherUrl.isEmpty() && item->launcherUrl() == launcherUrl)) && + (qobject_cast(taskItem) || !taskItem->busyWidget())) { + itm = taskItem; + } + } + + return itm; +} + +void TaskGroupItem::dropEvent(QGraphicsSceneDragDropEvent *event) +{ + if (m_dropIndicator && m_dropIndicator->isVisible()) { + m_dropIndicator->setVisible(false); + } + + //kDebug() << "TaskItemLayout dropEvent"; + if (event->mimeData()->hasFormat(TaskManager::Task::mimetype()) || + event->mimeData()->hasFormat(TaskManager::Task::groupMimetype())) { + bool ok; + QList ids = TaskManager::Task::idsFromMimeData(event->mimeData(), &ok); + + if (!ok) { + //kDebug() << "FAIL!"; + event->ignore(); + return; + } + + AbstractTaskItem *targetTask = dynamic_cast(scene()->itemAt(mapToScene(event->pos()))); + // kDebug() << "Pos: " << event->pos() << mapToScene(event->pos()) << "item" << scene()->itemAt(mapToScene(event->pos())) << "target Task " << dynamic_cast(targetTask); + + //kDebug() << "got" << ids.count() << "windows"; + foreach (WId id, ids) { + handleDroppedId(id, targetTask, event); + } + + //kDebug() << "TaskItemLayout dropEvent done"; + event->acceptProposedAction(); + } else if (!m_applet->groupManager().launchersLocked() && event->mimeData()->hasFormat("text/uri-list")) { + KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); + foreach (const KUrl & url, urls) { + const bool exists = m_applet->groupManager().launcherExists(url); + if (exists) { + // it exists; if we are doing manual sorting, make sure it is in the right location if + // it is in this group .. otherwise, we can do nothing. + if (m_applet->groupManager().sortingStrategy() == TaskManager::GroupManager::ManualSorting) { + QHashIterator it(m_groupMembers); + while (it.hasNext()) { + it.next(); + if (it.key()->itemType() == TaskManager::LauncherItemType && + it.key()->launcherUrl() == url) { + layoutTaskItem(it.value(), event->pos()); + break; + } + } + } + } else { + m_applet->groupManager().addLauncher(url, QIcon(), QString(), QString(), QString(), m_tasksLayout->insertionIndexAt(event->pos()).index); + } + } + } else { + event->ignore(); + } +} + +void TaskGroupItem::handleDroppedId(WId id, AbstractTaskItem *, QGraphicsSceneDragDropEvent *event) +{ + AbstractTaskItem *taskItem = m_applet->rootGroupItem()->taskItemForWId(id); + + if (!taskItem) { + //kDebug() << "Invalid TaskItem"; + return; + } + + if (!taskItem->parentGroup()) { + //kDebug() << "group invalid"; + return; + } + + TaskManager::GroupPtr group = taskItem->parentGroup()->group(); + + //kDebug() << id << taskItem->text() << (QObject*)targetTask; + + // kDebug() << "first item: " << dynamic_cast(m_taskItems.first()) << "layout widget" << dynamic_cast(this); + if (m_applet->groupManager().sortingStrategy() == TaskManager::GroupManager::ManualSorting) { + //Move action + if (group == m_group.data()) { //same group + //kDebug() << "Drag within group"; + layoutTaskItem(taskItem, event->pos()); + } else if (m_group) { //task item was dragged outside of group -> group move + AbstractTaskItem *directMember = abstractTaskItem(m_group.data()->directMember(group)); + if (directMember) { + layoutTaskItem(directMember, event->pos()); //we need to get the group right under the receiver group + } + } + } +} + +void TaskGroupItem::layoutTaskItem(AbstractTaskItem* item, const QPointF &pos) +{ + if (!m_tasksLayout || !item->abstractItem()) { + return; + } + + int insertIndex = m_tasksLayout->insertionIndexAt(pos).index; + // kDebug() << "Item inserting at: " << insertIndex << "of: " << numberOfItems(); + m_applet->groupManager().manualSortingRequest(item->abstractItem(), insertIndex); +} + + +void TaskGroupItem::updateActive(AbstractTaskItem *task) +{ + if (!m_tasksLayout) { + return; + } + + m_activeTaskIndex = indexOf(task); +} + +int TaskGroupItem::indexOf(AbstractTaskItem *task, bool descendGroups) +{ + if (!m_group || !task) { + //kDebug() << "Error"; + return -1; + } + + int index = 0; + + foreach (AbstractGroupableItem * item, m_group.data()->members()) { + AbstractTaskItem *taskItem = abstractTaskItem(item); + if (!taskItem) { + continue; + } + + if (task == taskItem) { + if (descendGroups) { + TaskGroupItem *groupItem = qobject_cast(taskItem); + if (groupItem) { + int subIndex = groupItem->indexOf(groupItem->activeSubTask()); + if (subIndex == -1) { + index += groupItem->count(); + } else { + return index + subIndex; + } + } + } + + return index; + } + + if (descendGroups) { + TaskGroupItem *groupItem = qobject_cast(taskItem); + if (groupItem) { + int subIndex = groupItem->indexOf(task); + if (subIndex == -1) { + index += groupItem->count(); + } else { + return index + subIndex; + } + } else { + ++index; + } + } else { + ++index; + } + } + + return -1; +} + +AbstractTaskItem * TaskGroupItem::activeSubTask() +{ + if (!m_group) { + return 0; + } + + foreach (AbstractGroupableItem * item, m_group.data()->members()) { + AbstractTaskItem *taskItem = abstractTaskItem(item); + if (taskItem && taskItem->isActive()) { + TaskGroupItem *groupItem = qobject_cast(taskItem); + if (groupItem) { + return groupItem->activeSubTask(); + } + return taskItem; + } + } + + return 0; +} + +int TaskGroupItem::totalSubTasks() +{ + int count = 0; + + foreach (AbstractGroupableItem * item, group()->members()) { + AbstractTaskItem *taskItem = abstractTaskItem(item); + if (taskItem) { + TaskGroupItem *groupItem = qobject_cast(taskItem); + if (groupItem) { + count += groupItem->count(); + } else if (!qobject_cast(taskItem)) { + count++; + } + } + } + return count; +} + +AbstractTaskItem * TaskGroupItem::selectSubTask(int index) +{ + foreach (AbstractGroupableItem * item, group()->members()) { + AbstractTaskItem *taskItem = abstractTaskItem(item); + if (taskItem) { + TaskGroupItem *groupItem = qobject_cast(taskItem); + if (groupItem) { + if (index < groupItem->count()) { + return groupItem->abstractTaskItem(groupItem->group()->members().at(index)); + } else { + index -= groupItem->count(); + } + } else if (qobject_cast(taskItem)) { + continue; + } else if (index == 0) { + return taskItem; + } else { + --index; + } + } + } + return NULL; +} + +void TaskGroupItem::wheelEvent(QGraphicsSceneWheelEvent *event) +{ + focusSubTask((event->delta() < 0), true); +} + +int TaskGroupItem::maxRows() +{ + return m_maximumRows; +} + +void TaskGroupItem::setMaxRows(int rows) +{ + m_maximumRows = rows; + if (m_tasksLayout) { + m_tasksLayout->setMaximumRows(m_maximumRows); + } +} + +int TaskGroupItem::optimumCapacity() +{ + if (m_tasksLayout) { + return m_tasksLayout->maximumRows() * m_tasksLayout->preferredColumns(); + } + + return 1; +} + +AbstractTaskItem* TaskGroupItem::abstractTaskItem(AbstractGroupableItem * item) +{ + if (!item) { + return 0; + } + + AbstractTaskItem *abstractTaskItem = m_groupMembers.value(item); + if (!abstractTaskItem) { + foreach (AbstractTaskItem * taskItem, m_groupMembers) { + TaskGroupItem *group = qobject_cast(taskItem); + if (group) { + abstractTaskItem = group->abstractTaskItem(item); + if (abstractTaskItem) { + break; + } + } + } + } + + //kDebug() << "item not found"; + return abstractTaskItem; +} + +void TaskGroupItem::setAdditionalMimeData(QMimeData* mimeData) +{ + if (m_group) { + m_group.data()->addMimeData(mimeData); + } +} + +void TaskGroupItem::publishIconGeometry() const +{ + // only do this if we are a collapsed group, with a GroupPtr and members + if (!collapsed() || !m_group || m_groupMembers.isEmpty()) { + return; + } + + QRect rect = iconGeometry(); + publishIconGeometry(rect); +} + +void TaskGroupItem::publishIconGeometry(const QRect &rect) const +{ + foreach (AbstractTaskItem * item, m_groupMembers) { + WindowTaskItem *windowItem = qobject_cast(item); + if (windowItem) { + windowItem->publishIconGeometry(rect); + continue; + } + + TaskGroupItem *groupItem = qobject_cast(item); + if (groupItem) { + groupItem->publishIconGeometry(rect); + } + } +} + +QWidget *TaskGroupItem::popupDialog() const +{ + return m_popupDialog; +} + +#include "taskgroupitem.moc" + diff --git a/kdeplasma-addons/applets/icontasks/taskgroupitem.h b/kdeplasma-addons/applets/icontasks/taskgroupitem.h new file mode 100644 index 00000000..d455ec96 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/taskgroupitem.h @@ -0,0 +1,209 @@ +/*************************************************************************** + * Copyright (C) 2007 by Robert Knight * + * Copyright (C) 2008 by Alexis Ménard * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + + +#ifndef TASKGROUPITEM_H +#define TASKGROUPITEM_H + +#include "abstracttaskitem.h" +#include "windowtaskitem.h" +// Own +#include "taskmanager/taskmanager.h" +#include "tasks.h" +#include +#include + +using TaskManager::TaskGroup; +using TaskManager::GroupPtr; +using TaskManager::TaskItem; +using TaskManager::AbstractGroupableItem; + +class TaskItemLayout; +class DropIndicator; +class QGraphicsLinearLayout; + +namespace Plasma +{ +class Dialog; +} +typedef QMap Order; + +/** + * A task item for a TaskGroup. It can be displayed collapsed as single item or expanded as group. + */ +class TaskGroupItem : public AbstractTaskItem +{ + Q_OBJECT + +public: + /** Constructs a new representation for a taskgroup. */ + TaskGroupItem(QGraphicsWidget *parent, Tasks *applet); + virtual ~TaskGroupItem(); + + /** Sets the group represented by this task. */ + void setGroup(TaskManager::GroupPtr); + + /** Returns the group represented by this task. */ + TaskManager::GroupPtr group() const; + + virtual void close(); + + QHash members() const; + int count() const; + AbstractTaskItem * activeSubTask(); + + virtual bool isWindowItem() const; + virtual bool isActive() const; + bool windowPreviewOpen() const; + QString appName() const; + KUrl launcherUrl() const; + QString windowClass() const; + bool collapsed() const; + virtual void toCurrentDesktop(); + + /** Returns Direct Member group if the passed item is in a subgroup */ + AbstractTaskItem *directMember(AbstractTaskItem *); + + /** Maximum number of Rows the group will have */ + int maxRows(); + void setMaxRows(int); + + TaskItemLayout *tasksLayout(); + + int indexOf(AbstractTaskItem *task, bool descendGroups = true); + + int optimumCapacity(); + + AbstractTaskItem* abstractTaskItem(AbstractGroupableItem *); + + void setAdditionalMimeData(QMimeData* mimeData); + void publishIconGeometry() const; + void publishIconGeometry(const QRect &rect) const; + QWidget *popupDialog() const; + AbstractTaskItem *taskItemForWId(WId id); + AbstractTaskItem *matchingItem(TaskManager::AbstractGroupableItem *from); + +private: + void close(bool hide); + +signals: + /** Emitted when a window is selected for activation, minimization, iconification */ + void groupSelected(TaskGroupItem *); + void sizeHintChanged(Qt::SizeHint); + /** informs the parent group about changes */ + void changed(); + +public slots: + virtual void activate(); + + /** Reload all tasks */ + void reload(); + + void expand(); + void collapse(); + void updatePreferredSize(); + void clearGroup(); + bool isRootGroup() const; + +public slots: + void updateActive(AbstractTaskItem *); + void relayoutItems(); + +protected: + void activateOrIconify(); + void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + + void dragEnterEvent(QGraphicsSceneDragDropEvent *event); + void dragLeaveEvent(QGraphicsSceneDragDropEvent *event); + void dragMoveEvent(QGraphicsSceneDragDropEvent *event); + void dropEvent(QGraphicsSceneDragDropEvent *event); + bool focusNextPrevChild(bool next); + + void handleDroppedId(WId id, AbstractTaskItem *targetTask, QGraphicsSceneDragDropEvent *event); + + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void resizeEvent(QGraphicsSceneResizeEvent *event); + + void updateToolTip(); + +protected slots: + virtual void wheelEvent(QGraphicsSceneWheelEvent *event); + +private Q_SLOTS: + void checkUpdates(); + void constraintsChanged(Plasma::Constraints); + void handleActiveWindowChanged(WId id); + + void updateTask(::TaskManager::TaskChanges changes); + + /** Stay informed about changes in group */ + void itemAdded(AbstractGroupableItem *); + void itemRemoved(AbstractGroupableItem *); + + /** Update to new position*/ + void itemPositionChanged(AbstractGroupableItem *); + + void popupMenu(); + /** force a relayout of all items */ + void popupVisibilityChanged(bool visible); + +private: + AbstractTaskItem* createAbstractItem(AbstractGroupableItem * groupableItem); + TaskGroupItem* createNewGroup(QList members); + WindowTaskItem * createWindowTask(TaskManager::TaskItem* task); + TaskGroupItem * createTaskGroup(GroupPtr); + WindowTaskItem *createStartingTask(TaskManager::TaskItem* task); + + void removeItem(AbstractTaskItem *item); + + void layoutTaskItem(AbstractTaskItem* item, const QPointF &pos); + void setSplitIndex(int position); + + QIcon m_icon; + + int totalSubTasks(); + bool focusSubTask(bool next, bool activate); + AbstractTaskItem * selectSubTask(int index); + + QWeakPointer m_group; + + QHash m_groupMembers; + + TaskItemLayout *m_tasksLayout; + QTimer *m_popupMenuTimer; + QHash m_taskOrder; + int m_lastActivated; + int m_activeTaskIndex; + int m_maximumRows; + QGraphicsWidget *m_offscreenWidget; + QGraphicsLinearLayout *m_offscreenLayout; + bool m_collapsed; + QGraphicsLinearLayout *m_mainLayout; + Plasma::Dialog *m_popupDialog; + QTimer *m_updateTimer; + TaskManager::TaskChanges m_changes; + + DropIndicator *m_dropIndicator; +}; + +#endif diff --git a/kdeplasma-addons/applets/icontasks/taskitemlayout.cpp b/kdeplasma-addons/applets/icontasks/taskitemlayout.cpp new file mode 100644 index 00000000..b980fbfc --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/taskitemlayout.cpp @@ -0,0 +1,635 @@ +/*************************************************************************** + * Copyright (C) 2008 by Christian Mollekopf chrigi_1@fastmail.fm * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "taskitemlayout.h" + +//Taskmanager +#include "taskmanager/taskmanager.h" +#include "taskmanager/abstractgroupableitem.h" +#include "taskmanager/groupmanager.h" + +// Qt +#include +#include + +// KDE +#include + +#include + +#include "windowtaskitem.h" +#include "taskgroupitem.h" + +class LauncherSeparator : public QGraphicsWidget +{ +public: + + LauncherSeparator(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0) + : QGraphicsWidget(parent, wFlags) { + m_svg = new Plasma::Svg(); + m_svg->setImagePath("icontasks/launcherseparator"); + m_svg->setContainsMultipleImages(true); + setOrientation(Qt::Horizontal); + } + + ~LauncherSeparator() { + delete m_svg; + } + + void setOrientation(Qt::Orientation orientation) { + m_orientation = orientation; + + if (m_orientation == Qt::Vertical) { + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + } else { + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + } + } + + Qt::Orientation orientation() { + return m_orientation; + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + Q_UNUSED(option); + Q_UNUSED(widget); + + if (m_svg) { + if (m_orientation == Qt::Horizontal) { + m_svg->paint(painter, boundingRect(), "horizontal-separator"); + } else { + m_svg->paint(painter, boundingRect(), "vertical-separator"); + } + } + } + + QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const { + QSizeF hint = QGraphicsWidget::sizeHint(which, constraint); + + if (m_orientation == Qt::Horizontal) { + hint.setWidth(m_svg->elementSize("horizontal-separator").width()); + } else { + hint.setHeight(m_svg->elementSize("vertical-separator").height()); + } + + return hint; + } + +private: + Plasma::Svg *m_svg; + Qt::Orientation m_orientation; +}; + +TaskItemLayout::TaskItemLayout(TaskGroupItem *parent, Tasks *applet) + : QGraphicsGridLayout(0), + m_groupItem(parent), + m_rowSize(1), + m_maxRows(1), + m_forceRows(false), + m_applet(applet), + m_layoutOrientation(Qt::Horizontal), + m_separator(parent->isRootGroup() ? new LauncherSeparator(parent) : 0L) +{ + setContentsMargins(0, 0, 0, 0); + setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); + setMaximumSize(INT_MAX, INT_MAX); + //kDebug(); + foreach (AbstractTaskItem * item, m_groupItem->members()) { + addTaskItem(item); + } + + if (parent->isRootGroup()) { + connect(&m_applet->groupManager(), SIGNAL(launchersChanged()), SLOT(layoutItems())); + } +} + +TaskItemLayout::~TaskItemLayout() +{ +} + +void TaskItemLayout::setOrientation(Plasma::FormFactor orientation) +{ + Qt::Orientation oldOrientation = m_layoutOrientation; + + if (orientation == Plasma::Vertical) { + m_layoutOrientation = Qt::Vertical; + } else { + m_layoutOrientation = Qt::Horizontal; + } + + if (m_separator) { + m_separator->setOrientation(m_layoutOrientation); + } + + if (m_layoutOrientation != oldOrientation) { + layoutItems(); + } +} + +bool TaskItemLayout::separatorVisible() const +{ + return m_separator && m_separator->isVisible(); +} + +void TaskItemLayout::addTaskItem(AbstractTaskItem * item) +{ + //kDebug(); + if (!item) { + return; + } + + if (item->isStartupWithTask()) { + return; + } + + if (m_itemPositions.contains(item)) { + //kDebug() << "already in this layout"; + return; + } + + if (m_groupItem->scene() && !item->scene()) { + //kDebug() << "layout widget got scene"<scene()<< "add item to scene" <scene(); + m_groupItem->scene()->addItem(item); + //kDebug() << "itemScene" << item->scene(); + } + + if (!insert(m_groupItem->indexOf(item, false), item)) { + return; + } + + item->show(); + //kDebug() << "end"; +} + +void TaskItemLayout::removeTaskItem(AbstractTaskItem *item) +{ + if (!remove(item)) { + return; + } + + //kDebug(); + + if (m_groupItem->scene()) { + //kDebug() << "got scene"; + m_groupItem->scene()->removeItem(item); + } else { + kDebug() << "No Scene available"; + } + //kDebug() << "done"; +} + +bool TaskItemLayout::insert(int index, AbstractTaskItem *item) +{ + //kDebug() << item->text() << index; + if (!item) { + kDebug() << "error"; + return false; + } + + int listIndex; + for (listIndex = 0; listIndex < m_itemPositions.size(); listIndex++) { + if (index <= m_groupItem->indexOf(m_itemPositions.at(listIndex), false)) { + break; + } + } + + if (m_itemPositions.removeAll(item) == 0) { + connect(item, SIGNAL(destroyed(AbstractTaskItem*)), this, SLOT(remove(AbstractTaskItem*))); + } + + m_itemPositions.insert(listIndex, item); + + layoutItems(); + return true; +} + +bool TaskItemLayout::remove(AbstractTaskItem* item) +{ + if (!item) { + kDebug() << "null Item"; + layoutItems(); + return false; + } + + disconnect(item, 0, this, 0); + m_itemPositions.removeAll(item); + layoutItems(); + return true; +} + + +/** size including expanded groups*/ +int TaskItemLayout::size() +{ + int groupSize = 0; + + foreach (AbstractTaskItem * item, m_groupItem->members()) { + if (!item->abstractItem()) { + // this item is a startup task or the task no longer exists + kDebug() << "Error, invalid item in groupMembers"; + continue; + } + + if (item->abstractItem()->itemType() == TaskManager::GroupItemType) { + TaskGroupItem *group = static_cast(item); + if (!group->collapsed()) { + TaskItemLayout *layout = dynamic_cast(group->tasksLayout()); + if (!layout) { + kDebug() << "Error group has no layout"; + continue; + } + + // increase number of items since expanded groups occupy several spaces + groupSize += layout->size(); + continue; + } + } + + ++groupSize; + } + + //kDebug() << "group size" << groupSize; + return groupSize; +} + +//return maximum colums set by the user unless the setting is to high and the items would get unusable +int TaskItemLayout::maximumRows() +{ + int maxRows; + if (m_itemPositions.isEmpty()) { + return 1; + } + + if (m_forceRows) { + return m_maxRows; + } + + // in this case rows are columns, columns are rows... + //TODO basicPreferredSize isn't the optimal source here because it changes because of margins probably + QSizeF itemSize = m_itemPositions.first()->basicPreferredSize(); + if (m_layoutOrientation == Qt::Vertical) { + maxRows = qMin(qMax(1, int(m_groupItem->geometry().width() / itemSize.width())), m_maxRows); + } else { + maxRows = qMin(qMax(1, int(m_groupItem->geometry().height() / itemSize.height())), m_maxRows); + } + + //kDebug() << "maximum rows: " << maxRows << m_maxRows << m_groupItem->geometry().height() << itemSize.height(); + return maxRows; +} + +//returns a reasonable amount of columns +int TaskItemLayout::preferredColumns() +{ + if (m_forceRows) { + m_rowSize = 1; + } else { + if (m_itemPositions.isEmpty()) { + return 1; + } + + //TODO basicPreferredSize isn't the optimal source here because it changes because of margins probably + QSizeF itemSize = m_itemPositions.first()->basicPreferredSize(); + //kDebug() << itemSize.width() << m_groupItem->geometry().width(); + if (m_layoutOrientation == Qt::Vertical) { + m_rowSize = qMax(1, int(m_groupItem->geometry().height() / itemSize.height())); + } else { + //Launchers doesn't need the same space as task- and groupitems on horizontal Layouts so the size needs to be adjusted + qreal horizontalSpace = m_groupItem->geometry().width(); + m_rowSize = qMax(1, int(horizontalSpace / itemSize.width())); + } + } + //kDebug() << "preferred columns: " << qMax(1, m_rowSize); + return qMax(1, m_rowSize); +} + +// +QPair TaskItemLayout::gridLayoutSize() +{ + int groupSize = size(); + //the basic settings + int columns = preferredColumns(); + int maxRows = maximumRows(); + + //check for adjustments on columns because there isnt room enough yet for all of the items + while (ceil(static_cast(groupSize) / static_cast(columns)) > maxRows) { + columns++; // more rows needed than allowed so we add some columns instead + } + //kDebug() << "groupWidth" << columns << maxRows << m_maxRows; + int rows; + if (m_forceRows) { + rows = maxRows; + } else { + rows = ceil(static_cast(groupSize) / static_cast(columns)); //actually needed rows + } + + return QPair(columns, rows); +} + + +void TaskItemLayout::layoutItems() +{ + //kDebug(); + + QPair grid = gridLayoutSize(); + int columns = qMax(grid.first, 1); + + //FIXME: resetting column preferred sizesthey shouldn't be taken into account for inexistent ones but they are, probably upstream issue + for (int i = 0; i < columnCount(); ++i) { + setColumnMaximumWidth(i, 0); + setColumnPreferredWidth(i, 0); + } + + for (int i = 0; i < rowCount(); ++i) { + setRowMaximumHeight(i, 0); + setRowPreferredHeight(i, 0); + } + + //clearLayout + if (m_separator) { + m_separator->setVisible(false); + } + while (count()) { + removeAt(0); + } + + QRectF groupRect(m_groupItem->boundingRect()); + qreal cellSize(qMin(m_applet->launcherIcons() || !m_applet->autoIconScaling() ? qreal(272) : qreal(80), qMin(groupRect.width(), groupRect.height()))); + QSizeF maximumCellSize(cellSize, cellSize); + + setHorizontalSpacing(m_applet->spacing()); + setVerticalSpacing(m_applet->spacing()); + + //go through all items of this layoutwidget and populate the layout with items + int numberOfItems = 0; + foreach (AbstractTaskItem * item, m_itemPositions) { + int row; + int col; + if (m_layoutOrientation == Qt::Vertical) { + row = numberOfItems % columns; + col = numberOfItems / columns; + } else { + row = numberOfItems / columns; + col = numberOfItems % columns; + } + + if (m_separator && 1 == m_maxRows && Tasks::Sep_Never != m_applet->showSeparator() && + TaskManager::GroupManager::ManualSorting == m_applet->groupManager().sortingStrategy() && + m_applet->groupManager().launcherCount() && numberOfItems >= m_applet->groupManager().launcherCount() && + !m_separator->isVisible()) { + + // If a group associated with a launcher is split, then there will be more entries than launchers! + // So, we need to check if this item is associated with a launcher... + if (!(item->abstractItem() && m_applet->groupManager().isItemAssociatedWithLauncher(item->abstractItem()))) { + addItem(m_separator, row, col, 1, 1); + m_separator->setVisible(true); + numberOfItems++; + if (m_layoutOrientation == Qt::Vertical) { + row = numberOfItems % columns; + col = numberOfItems / columns; + } else { + row = numberOfItems / columns; + col = numberOfItems % columns; + } + } + } + //not good if we don't recreate the layout every time + //m_layout->setColumnPreferredWidth(col, columnWidth);//Somehow this line is absolutely crucial + //m_layout->setRowPreferredHeight(row, rowHeight);//Somehow this line is absolutely crucial + + + //FIXME: this is a glorious hack + if (maximumCellSize.isValid()) { + if (m_layoutOrientation == Qt::Vertical) { + setRowMaximumHeight(row, maximumCellSize.height()); + setColumnMaximumWidth(col, QWIDGETSIZE_MAX); + } else { + setColumnMaximumWidth(col, maximumCellSize.width()); + setRowMaximumHeight(row, QWIDGETSIZE_MAX); + } + setRowPreferredHeight(row, maximumCellSize.height()); + setColumnPreferredWidth(col, maximumCellSize.width()); + } + + if (item->abstractItem() && + item->abstractItem()->itemType() == TaskManager::GroupItemType) { + + TaskGroupItem *group = static_cast(item); + if (group->collapsed()) { +// group->unsplitGroup(); + addItem(item, row, col, 1, 1); + numberOfItems++; + } else { + TaskItemLayout *layout = group->tasksLayout(); + if (!layout) { + kDebug() << "group has no valid layout"; + continue; + } + + int groupRowWidth = m_layoutOrientation == Qt::Vertical ? layout->numberOfRows() : layout->numberOfColumns(); + + if ((columns - col) < groupRowWidth) { + //we need to split the group + int splitIndex = columns - col;//number of items in group that are on this row + if (m_layoutOrientation == Qt::Vertical) { + addItem(item, row, col, splitIndex, 1); + } else { + addItem(item, row, col, 1, splitIndex); + } + + } else { + if (m_layoutOrientation == Qt::Vertical) { + addItem(item, row, col, groupRowWidth, 1); + } else { + addItem(item, row, col, 1, groupRowWidth); + } + } + + numberOfItems += groupRowWidth; + } + } else { + addItem(item, row, col, 1, 1); + numberOfItems++; + } + + //kDebug() << "addItem at: " << row << col; + } + + if (m_separator && 1 == m_maxRows && Tasks::Sep_Always == m_applet->showSeparator() && !m_separator->isVisible() && + TaskManager::GroupManager::ManualSorting == m_applet->groupManager().sortingStrategy() && + m_applet->groupManager().launcherCount()) { + if (m_layoutOrientation == Qt::Vertical) { + addItem(m_separator, numberOfItems % columns, numberOfItems / columns, 1, 1); + } else { + addItem(m_separator, numberOfItems / columns, numberOfItems % columns, 1, 1); + } + m_separator->setVisible(true); + } + + updatePreferredSize(); + //m_groupItem->setLayout(m_layout); +} + + +void TaskItemLayout::updatePreferredSize() +{ + //kDebug() << "column count: " << m_layout->columnCount(); + bool haveSep = m_separator && m_separator->isVisible(); + + if (count() > (haveSep ? 1 : 0)) { + bool vertical = m_layoutOrientation == Qt::Vertical; + QSizeF s = itemAt(0)->preferredSize(); + QSizeF sepSize = m_separator && m_separator->isVisible() + ? QSizeF(vertical + ? 0 : m_separator->preferredSize().width(), + vertical + ? m_separator->preferredSize().height() : 0) + : QSizeF(0, 0); + //kDebug() << s << columnCount(); + setPreferredSize((s.width() * (columnCount() - (!vertical && haveSep ? 1 : 0))) + sepSize.width(), + (s.height() * (rowCount() - (vertical && haveSep ? 1 : 0))) + sepSize.height()); + } else { + //Empty taskbar, arbitrary small value + kDebug() << "Empty layout!!!!!!!!!!!!!!!!!!"; + if (m_layoutOrientation == Qt::Vertical) { + setPreferredSize(/*m_layout->preferredSize().width()*/10, 10); //since we recreate the layout we don't have the previous values + } else { + setPreferredSize(10, /*m_layout->preferredSize().height()*/10); + } + } + //kDebug() << "preferred size: " << m_layout->preferredSize(); + m_groupItem->updatePreferredSize(); +} + +void TaskItemLayout::setMaximumRows(int rows) +{ + if (rows != m_maxRows) { + m_maxRows = rows; + layoutItems(); + } +} + +void TaskItemLayout::setForceRows(bool forceRows) +{ + m_forceRows = forceRows; +} + +TaskItemLayout::Insert TaskItemLayout::insertionIndexAt(const QPointF &pos) +{ + Insert insert; + int nRows = numberOfRows(); + int nCols = numberOfColumns(); + int row = nRows; + int col = nCols; + bool vertical = Qt::Vertical == m_layoutOrientation; + + insert.index = -1; + + //if pos is (-1,-1) insert at the end of the panel + if (pos.toPoint() == QPoint(-1, -1)) { + kDebug() << "Error"; + return insert; + } else { + QRectF siblingGeometry; + int border = 1 + (m_applet->spacing() / 2.0); + + //get correct row + for (int i = 0; i < nRows; i++) { + if (vertical) { + siblingGeometry = itemAt(0, i)->geometry();//set geometry of single item + if (pos.x() <= (siblingGeometry.right() + border)) { + row = i; + break; + } + } else { + siblingGeometry = itemAt(i, 0)->geometry();//set geometry of single item + if (pos.y() <= (siblingGeometry.bottom() + border)) { + row = i; + break; + } + } + } + + //and column + for (int i = 0; i < nCols; i++) { + if (vertical) { + siblingGeometry = itemAt(i, 0)->geometry();//set geometry of single item + qreal vertMiddle = (siblingGeometry.top() + siblingGeometry.bottom()) / 2.0; + if (pos.y() < vertMiddle) { + col = i; + break; + } + + } else if (itemAt(0, i)) { + siblingGeometry = itemAt(0, i)->geometry();//set geometry of single item + qreal horizMiddle = (siblingGeometry.left() + siblingGeometry.right()) / 2.0; + if (pos.x() < horizMiddle) { + col = i; + break; + } + } + } + } + + insert.index = row * nCols + col; + + // Calculate geometry - used for drop indicator... + if (nCols > 0 && nRows > 0) { + int rowAdjust = row >= nRows ? 1 : 0; + int colAdjust = col >= nCols ? 1 : 0; + QGraphicsLayoutItem *item = itemAt(vertical ? (col - colAdjust) : (row - rowAdjust), vertical ? (row - rowAdjust) : (col - colAdjust)); + + if (item) { + insert.geom = item->geometry(); + if ((rowAdjust && vertical) || (colAdjust && !vertical)) { + insert.geom.adjust(insert.geom.width(), 0, insert.geom.width(), 0); + } + if ((rowAdjust && !vertical) || (colAdjust && vertical)) { + insert.geom.adjust(0, insert.geom.height(), 0, insert.geom.height()); + } + } + } + + if (separatorVisible() && insert.index > m_applet->groupManager().launcherCount()) { + insert.index--; + } + + //kDebug() << "insert Index" << insertIndex; + return insert; +} + +int TaskItemLayout::numberOfRows() +{ + if (m_layoutOrientation == Qt::Vertical) { + return columnCount(); + } else { + return rowCount(); + } +} + +int TaskItemLayout::numberOfColumns() +{ + if (m_layoutOrientation == Qt::Vertical) { + return rowCount(); + } else { + return columnCount(); + } +} + +#include "taskitemlayout.moc" + diff --git a/kdeplasma-addons/applets/icontasks/taskitemlayout.h b/kdeplasma-addons/applets/icontasks/taskitemlayout.h new file mode 100644 index 00000000..64142e1e --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/taskitemlayout.h @@ -0,0 +1,110 @@ +/*************************************************************************** + * Copyright (C) 2008 by Christian Mollekopf chrigi_1@fastmail.fm * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + + +#ifndef TASKITEMLAYOUT_H +#define TASKITEMLAYOUT_H + +//Own +#include "tasks.h" + +// Qt +#include +#include + +class TaskGroupItem; +class AbstractTaskItem; +class LauncherSeparator; + +/** + * A Layout for the expanded group + */ +class TaskItemLayout : public QObject, public QGraphicsGridLayout +{ + Q_OBJECT + +public: + struct Insert { + int index; + QRectF geom; + }; + + TaskItemLayout(TaskGroupItem * parent, Tasks *applet); + ~TaskItemLayout(); + /** insert the item on the index in TaskGroupItem::getMemberList */ + void addTaskItem(AbstractTaskItem*); + void removeTaskItem(AbstractTaskItem*); + /** insert the item on a specific index*/ + bool insert(int index, AbstractTaskItem* item); + + /** returns the insert index for a task drop on pos */ + Insert insertionIndexAt(const QPointF &pos); + /** set the maximum number of rows */ + void setMaximumRows(int); + /** force the layout to use maximumRows setting and fill rows before columns */ + void setForceRows(bool); + + /** the size including expanded groups*/ + int size(); + + /** returns columnCount or rowCount depending on m_applet->formFactor() */ + int numberOfRows(); + /** returns columnCount or rowCount depending on m_applet->formFactor()*/ + int numberOfColumns(); + + /** Returns the preferred number of rows based on the user settings but limited by calculation to honor AbstractGroupableItem::basicPreferredSize()*/ + int maximumRows(); + /** Returns the preferred number of columns calculated on base of AbstractGroupableItem::basicPreferredSize()*/ + int preferredColumns(); + + /** Set the layout Orientation, normally set to formFactor of applet*/ + void setOrientation(Plasma::FormFactor orientation); + + bool separatorVisible() const; + +public Q_SLOTS: + /** Populates the actual QGraphicsGridLayout with items*/ + void layoutItems(); +private: + void adjustStretch(); + void updatePreferredSize(); + +private Q_SLOTS: + bool remove(AbstractTaskItem* item); + +private: + TaskGroupItem *m_groupItem; + QList m_itemPositions; + /** Calculates the number of columns and rows for the layoutItems function and returns */ + QPair gridLayoutSize(); + + /** Limit before row is full, more columns are added if maxRows is exeeded*/ + int m_rowSize; + /** How many rows should be used*/ + int m_maxRows; + + bool m_forceRows; + + Tasks *m_applet; + + Qt::Orientation m_layoutOrientation; + LauncherSeparator *m_separator; +}; + +#endif diff --git a/kdeplasma-addons/applets/icontasks/tasks.cpp b/kdeplasma-addons/applets/icontasks/tasks.cpp new file mode 100644 index 00000000..a2935645 --- /dev/null +++ b/kdeplasma-addons/applets/icontasks/tasks.cpp @@ -0,0 +1,800 @@ +/*************************************************************************** + * Copyright (C) 2007 by Robert Knight * + * Copyright (C) 2008 by Alexis Ménard * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "tooltips/tooltipmanager.h" +// Own +#include "tasks.h" +#include "windowtaskitem.h" +#include "taskgroupitem.h" +#include "jobmanager.h" +#include "dockmanager.h" +#include "mediabuttons.h" +#include "unity.h" +#include "recentdocuments.h" + +//Taskmanager +#include "taskmanager/groupmanager.h" +#include "taskmanager/taskgroup.h" +#include "taskmanager/taskitem.h" + +// KDE +#include +#include +#include + +// Qt +#include +#include +#include +#include +#include +#include + +// Plasma +#include +#include +#include +#include + +static void renameConfig() +{ + // Rename pre0.9 taskmanagerrc to taskmanagerrulesrc + QString oldName = KStandardDirs::locateLocal("config", "taskmanagerrc"); + + if (QFile::exists(oldName)) { + QString newName = KStandardDirs::locateLocal("config", "taskmanagerrulesrc"); + + if (QFile::exists(newName)) { + QFile::remove(oldName); + } else { + QFile::rename(oldName, newName); + } + } +} + +static void setCurrentIndex(QComboBox *combo, int val) +{ + for (int i = 0; i < combo->count(); ++i) { + if (combo->itemData(i).toInt() == val) { + combo->setCurrentIndex(i); + break; + } + } +} + +class GroupManager : public TaskManager::GroupManager +{ +public: + GroupManager(Plasma::Applet *applet) + : TaskManager::GroupManager(applet), + m_applet(applet) { + setGroupingStrategy(GroupManager::ProgramGrouping); + setSortingStrategy(GroupManager::ManualSorting); + setShowOnlyCurrentActivity(true); + setShowOnlyCurrentDesktop(true); + setShowOnlyCurrentScreen(false); + setShowOnlyMinimized(false); + setOnlyGroupWhenFull(false); + setSeparateLaunchers(false); + setForceGrouping(true); + readLauncherConfig(); + } + +protected: + KConfigGroup config() const { + return m_applet->config(); + } + +private: + Plasma::Applet *m_applet; +}; + +static const int constMinSpacing = 0; +static const int constMaxSpacing = 50; +static const int constMinIconScale = 49; +static const int constMaxIconScale = 100; + +Tasks::Tasks(QObject* parent, const QVariantList &arguments) + : Plasma::Applet(parent, arguments), + m_toolTips(TT_Instant), + m_highlightWindows(true), + m_launcherIcons(false), + m_groupClick(GC_PresentWindows), + m_rotate(false), + m_style(Style_Plasma), + m_showSeparator(Sep_WhenNeeded), + m_middleClick(MC_NewInstance), + m_spacing(0), + m_iconScale(constMinIconScale), // constMinIconScale==automatic scaling!!! + m_taskItemBackground(0), + m_progressBar(0), + m_badgeBackground(0), + m_indicators(0), + m_leftMargin(0), + m_topMargin(0), + m_rightMargin(0), + m_bottomMargin(0), + m_offscreenLeftMargin(0), + m_offscreenTopMargin(0), + m_offscreenRightMargin(0), + m_offscreenBottomMargin(0), + m_rootGroupItem(0), + m_groupManager(0), + m_lockAct(0), + m_unlockAct(0), + m_refreshAct(0) +{ + KGlobal::locale()->insertCatalog("icontasks"); + renameConfig(); + setHasConfigurationInterface(true); + setAspectRatioMode(Plasma::IgnoreAspectRatio); + m_screenTimer.setSingleShot(true); + m_screenTimer.setInterval(300); + resize(500, 58); + + setAcceptDrops(true); +} + +Tasks::~Tasks() +{ + JobManager::self()->setEnabled(false); + DockManager::self()->setEnabled(false); + MediaButtons::self()->setEnabled(false); + Unity::self()->setEnabled(false); + RecentDocuments::self()->setEnabled(false); + delete m_rootGroupItem; + delete m_groupManager; + AbstractTaskItem::clearCaches(); +} + +void Tasks::init() +{ + m_groupManager = new GroupManager(this); + Plasma::Containment* appletContainment = containment(); + if (appletContainment) { + m_groupManager->setScreen(appletContainment->screen()); + } + + connect(m_groupManager, SIGNAL(reload()), this, SLOT(reload())); + connect(m_groupManager, SIGNAL(configChanged()), this, SIGNAL(configNeedsSaving())); + + m_rootGroupItem = new TaskGroupItem(this, this); + m_rootGroupItem->expand(); + m_rootGroupItem->setGroup(m_groupManager->rootGroup()); + + connect(m_rootGroupItem, SIGNAL(sizeHintChanged(Qt::SizeHint)), this, SLOT(changeSizeHint(Qt::SizeHint))); + + setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); + setMaximumSize(INT_MAX, INT_MAX); + + layout = new QGraphicsLinearLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + layout->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); + layout->setMaximumSize(INT_MAX, INT_MAX); + layout->setOrientation(Qt::Vertical); + layout->addItem(m_rootGroupItem); + setLayout(layout); + + configChanged(); + if (containment()) { + IconTasks::ToolTipManager::self()->setCorona(containment()->corona()); + } +} + +void Tasks::configChanged() +{ + KConfigGroup cg = config(); + bool changed = false; + + // only update these if they have actually changed, because they make the + // group manager reload its tasks list + const bool showOnlyCurrentDesktop = cg.readEntry("showOnlyCurrentDesktop", m_groupManager->showOnlyCurrentDesktop()); + if (showOnlyCurrentDesktop != m_groupManager->showOnlyCurrentDesktop()) { + m_groupManager->setShowOnlyCurrentDesktop(showOnlyCurrentDesktop); + changed = true; + } + + const bool showOnlyCurrentActivity = cg.readEntry("showOnlyCurrentActivity", m_groupManager->showOnlyCurrentActivity()); + if (showOnlyCurrentActivity != m_groupManager->showOnlyCurrentActivity()) { + m_groupManager->setShowOnlyCurrentActivity(showOnlyCurrentActivity); + changed = true; + } + + const bool showOnlyCurrentScreen = cg.readEntry("showOnlyCurrentScreen", m_groupManager->showOnlyCurrentScreen()); + if (showOnlyCurrentScreen != m_groupManager->showOnlyCurrentScreen()) { + m_groupManager->setShowOnlyCurrentScreen(showOnlyCurrentScreen); + changed = true; + } + + TaskManager::GroupManager::TaskSortingStrategy sortingStrategy = + static_cast( + cg.readEntry("sortingStrategy", + static_cast(m_groupManager->sortingStrategy())) + ); + + if (sortingStrategy != m_groupManager->sortingStrategy()) { + m_groupManager->setSortingStrategy(sortingStrategy); + changed = true; + } + + const int maxRows = cg.readEntry("maxRows", m_rootGroupItem->maxRows()); + if (maxRows != m_rootGroupItem->maxRows()) { + m_rootGroupItem->setMaxRows(maxRows); + changed = true; + } + + const bool launcherIcons = cg.readEntry("launcherIcons", m_launcherIcons); + if (launcherIcons != m_launcherIcons) { + m_launcherIcons = launcherIcons; + changed = true; + } + + const GroupClick groupClick = static_cast(cg.readEntry("groupClick", static_cast(m_groupClick))); + if (groupClick != m_groupClick) { + m_groupClick = groupClick; + changed = true; + } + + const bool rotate = cg.readEntry("rotate", m_rotate); + if (rotate != m_rotate) { + m_rotate = rotate; + changed = true; + } + + const Style style = static_cast