From a11d9240d38809ffbaccbfa8412abe4e35bb1cd3 Mon Sep 17 00:00:00 2001 From: Florent Revest Date: Mon, 19 Feb 2018 14:27:11 +0100 Subject: [PATCH] Initial commit, largely unusable --- .gitignore | 7 + .gitmodules | 3 + LICENSE | 674 ++++++++++++++++++ README.md | 2 + icon.svg | 88 +++ rpm/starfish.spec | 72 ++ starfish.pro | 5 + starfish/.gitignore | 1 + starfish/main.cpp | 50 ++ starfish/qml/cover/CoverPage.qml | 60 ++ starfish/qml/pages/InfoPage.qml | 86 +++ starfish/qml/pages/LoadingPage.qml | 54 ++ starfish/qml/pages/LocationPicker.qml | 126 ++++ starfish/qml/pages/MainMenuPage.qml | 127 ++++ starfish/qml/pages/WatchesPage.qml | 78 ++ starfish/qml/pages/WeatherSettingsDialog.qml | 215 ++++++ starfish/qml/starfish.qml | 103 +++ starfish/servicecontrol.cpp | 124 ++++ starfish/servicecontrol.h | 57 ++ starfish/starfish.desktop | 5 + starfish/starfish.png | Bin 0 -> 3972 bytes starfish/starfish.pro | 41 ++ starfish/starfish.qrc | 5 + starfish/watch.cpp | 86 +++ starfish/watch.h | 68 ++ starfish/watches.cpp | 269 +++++++ starfish/watches.h | 88 +++ starfishd/.gitignore | 1 + starfishd/bluez/bluez_adapter1.cpp | 26 + starfishd/bluez/bluez_adapter1.h | 66 ++ starfishd/bluez/bluez_agentmanager1.cpp | 26 + starfishd/bluez/bluez_agentmanager1.h | 68 ++ starfishd/bluez/bluez_device1.cpp | 26 + starfishd/bluez/bluez_device1.h | 85 +++ starfishd/bluez/bluez_helper.h | 30 + starfishd/bluez/bluezclient.cpp | 146 ++++ starfishd/bluez/bluezclient.h | 67 ++ starfishd/bluez/dbus-shared.h | 36 + starfishd/bluez/freedesktop_objectmanager.cpp | 26 + starfishd/bluez/freedesktop_objectmanager.h | 58 ++ starfishd/bluez/freedesktop_properties.cpp | 26 + starfishd/bluez/freedesktop_properties.h | 71 ++ starfishd/bluez/org.bluez.AgentManager1.xml | 16 + starfishd/dbusinterface.cpp | 139 ++++ starfishd/dbusinterface.h | 94 +++ starfishd/libasteroid | 1 + starfishd/libwatchfish/COPYING | 674 ++++++++++++++++++ starfishd/libwatchfish/calendarevent.cpp | 119 ++++ starfishd/libwatchfish/calendarevent.h | 58 ++ starfishd/libwatchfish/calendarsource.cpp | 113 +++ starfishd/libwatchfish/calendarsource.h | 54 ++ starfishd/libwatchfish/calendarsource_p.h | 52 ++ .../libwatchfish/com.Meego.MainVolume2.xml | 13 + starfishd/libwatchfish/libwatchfish.pri | 38 + starfishd/libwatchfish/libwatchfish.pro | 8 + starfishd/libwatchfish/musiccontroller.cpp | 319 +++++++++ starfishd/libwatchfish/musiccontroller.h | 101 +++ starfishd/libwatchfish/musiccontroller_p.h | 67 ++ starfishd/libwatchfish/notification.cpp | 282 ++++++++ starfishd/libwatchfish/notification.h | 137 ++++ .../libwatchfish/notificationmonitor.cpp | 439 ++++++++++++ starfishd/libwatchfish/notificationmonitor.h | 54 ++ .../libwatchfish/notificationmonitor_p.h | 100 +++ .../org.nemomobile.voicecall.VoiceCall.xml | 69 ++ ....nemomobile.voicecall.VoiceCallManager.xml | 53 ++ .../libwatchfish/voicecallcontroller.cpp | 148 ++++ starfishd/libwatchfish/voicecallcontroller.h | 60 ++ .../libwatchfish/voicecallcontroller_p.h | 72 ++ starfishd/libwatchfish/volumecontroller.cpp | 133 ++++ starfishd/libwatchfish/volumecontroller.h | 65 ++ starfishd/libwatchfish/volumecontroller_p.h | 54 ++ starfishd/libwatchfish/walltimemonitor.cpp | 139 ++++ starfishd/libwatchfish/walltimemonitor.h | 70 ++ starfishd/libwatchfish/walltimemonitor_p.h | 83 +++ starfishd/main.cpp | 36 + starfishd/sailfishplatform.cpp | 103 +++ starfishd/sailfishplatform.h | 66 ++ starfishd/starfishd.pro | 45 ++ starfishd/starfishd.service | 11 + starfishd/watchesmanager.cpp | 79 ++ starfishd/watchesmanager.h | 56 ++ version.pri | 2 + 82 files changed, 7474 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 LICENSE create mode 100644 README.md create mode 100644 icon.svg create mode 100644 rpm/starfish.spec create mode 100644 starfish.pro create mode 100644 starfish/.gitignore create mode 100644 starfish/main.cpp create mode 100644 starfish/qml/cover/CoverPage.qml create mode 100644 starfish/qml/pages/InfoPage.qml create mode 100644 starfish/qml/pages/LoadingPage.qml create mode 100644 starfish/qml/pages/LocationPicker.qml create mode 100644 starfish/qml/pages/MainMenuPage.qml create mode 100644 starfish/qml/pages/WatchesPage.qml create mode 100644 starfish/qml/pages/WeatherSettingsDialog.qml create mode 100644 starfish/qml/starfish.qml create mode 100644 starfish/servicecontrol.cpp create mode 100644 starfish/servicecontrol.h create mode 100644 starfish/starfish.desktop create mode 100644 starfish/starfish.png create mode 100644 starfish/starfish.pro create mode 100644 starfish/starfish.qrc create mode 100644 starfish/watch.cpp create mode 100644 starfish/watch.h create mode 100644 starfish/watches.cpp create mode 100644 starfish/watches.h create mode 100644 starfishd/.gitignore create mode 100644 starfishd/bluez/bluez_adapter1.cpp create mode 100644 starfishd/bluez/bluez_adapter1.h create mode 100644 starfishd/bluez/bluez_agentmanager1.cpp create mode 100644 starfishd/bluez/bluez_agentmanager1.h create mode 100644 starfishd/bluez/bluez_device1.cpp create mode 100644 starfishd/bluez/bluez_device1.h create mode 100644 starfishd/bluez/bluez_helper.h create mode 100644 starfishd/bluez/bluezclient.cpp create mode 100644 starfishd/bluez/bluezclient.h create mode 100644 starfishd/bluez/dbus-shared.h create mode 100644 starfishd/bluez/freedesktop_objectmanager.cpp create mode 100644 starfishd/bluez/freedesktop_objectmanager.h create mode 100644 starfishd/bluez/freedesktop_properties.cpp create mode 100644 starfishd/bluez/freedesktop_properties.h create mode 100644 starfishd/bluez/org.bluez.AgentManager1.xml create mode 100644 starfishd/dbusinterface.cpp create mode 100644 starfishd/dbusinterface.h create mode 160000 starfishd/libasteroid create mode 100644 starfishd/libwatchfish/COPYING create mode 100644 starfishd/libwatchfish/calendarevent.cpp create mode 100644 starfishd/libwatchfish/calendarevent.h create mode 100644 starfishd/libwatchfish/calendarsource.cpp create mode 100644 starfishd/libwatchfish/calendarsource.h create mode 100644 starfishd/libwatchfish/calendarsource_p.h create mode 100644 starfishd/libwatchfish/com.Meego.MainVolume2.xml create mode 100644 starfishd/libwatchfish/libwatchfish.pri create mode 100644 starfishd/libwatchfish/libwatchfish.pro create mode 100644 starfishd/libwatchfish/musiccontroller.cpp create mode 100644 starfishd/libwatchfish/musiccontroller.h create mode 100644 starfishd/libwatchfish/musiccontroller_p.h create mode 100644 starfishd/libwatchfish/notification.cpp create mode 100644 starfishd/libwatchfish/notification.h create mode 100644 starfishd/libwatchfish/notificationmonitor.cpp create mode 100644 starfishd/libwatchfish/notificationmonitor.h create mode 100644 starfishd/libwatchfish/notificationmonitor_p.h create mode 100644 starfishd/libwatchfish/org.nemomobile.voicecall.VoiceCall.xml create mode 100644 starfishd/libwatchfish/org.nemomobile.voicecall.VoiceCallManager.xml create mode 100644 starfishd/libwatchfish/voicecallcontroller.cpp create mode 100644 starfishd/libwatchfish/voicecallcontroller.h create mode 100644 starfishd/libwatchfish/voicecallcontroller_p.h create mode 100644 starfishd/libwatchfish/volumecontroller.cpp create mode 100644 starfishd/libwatchfish/volumecontroller.h create mode 100644 starfishd/libwatchfish/volumecontroller_p.h create mode 100644 starfishd/libwatchfish/walltimemonitor.cpp create mode 100644 starfishd/libwatchfish/walltimemonitor.h create mode 100644 starfishd/libwatchfish/walltimemonitor_p.h create mode 100644 starfishd/main.cpp create mode 100644 starfishd/sailfishplatform.cpp create mode 100644 starfishd/sailfishplatform.h create mode 100644 starfishd/starfishd.pro create mode 100644 starfishd/starfishd.service create mode 100644 starfishd/watchesmanager.cpp create mode 100644 starfishd/watchesmanager.h create mode 100644 version.pri diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..359f5f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +Makefile +*.o +moc_*.cpp +qrc_*.cpp +documentation.list +*.qm +*.pro.user diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..60401c7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "starfishd/libwatchfish"] + path = starfishd/libwatchfish + url = https://git.javispedro.com/libwatchfish.git diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9cecc1d --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. 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 +them 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 prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. 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. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey 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; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If 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 convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU 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 that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + 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. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +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. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + 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 +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 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 . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program 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, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d2ef04d --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Starfish +A SailfishOS synchronization client for [AsteroidOS](http://asteroidos.org/). Forked from [Rockpool](https://github.com/abranson/rockpool). diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..c7202d1 --- /dev/null +++ b/icon.svg @@ -0,0 +1,88 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/rpm/starfish.spec b/rpm/starfish.spec new file mode 100644 index 0000000..94d6ecf --- /dev/null +++ b/rpm/starfish.spec @@ -0,0 +1,72 @@ +Name: starfish + +%{!?qtc_qmake:%define qtc_qmake %qmake} +%{!?qtc_qmake5:%define qtc_qmake5 %qmake5} +%{!?qtc_make:%define qtc_make make} +%{?qtc_builddir:%define _builddir %qtc_builddir} +Summary: Support for AsteroidOS watches in SailfishOS +Version: 1.0 +Release: 1 +Group: Qt/Qt +License: GPL3 +URL: http://asteroidos.org/ +Source0: %{name}-%{version}.tar.xz +Requires: systemd-user-session-targets +Requires: nemo-qml-plugin-dbus-qt5 +BuildRequires: pkgconfig(Qt5DBus) +BuildRequires: pkgconfig(Qt5Bluetooth) +BuildRequires: pkgconfig(Qt5Quick) +BuildRequires: pkgconfig(Qt5Qml) +BuildRequires: pkgconfig(Qt5Core) +BuildRequires: pkgconfig(Qt5Network) +BuildRequires: pkgconfig(Qt5Location) +BuildRequires: pkgconfig(qt5-boostable) +BuildRequires: pkgconfig(mpris-qt5) +BuildRequires: pkgconfig(timed-qt5) +BuildRequires: pkgconfig(mlite5) +BuildRequires: pkgconfig(sailfishapp) >= 0.0.10 +BuildRequires: pkgconfig(icu-i18n) +BuildRequires: desktop-file-utils + +%description +Support for AsteroidOS watches in SailfishOS. + +%prep +%setup -q -n %{name}-%{version} + +%build + +%qtc_qmake5 \ + VERSION='%{version}-%{release}' + +%qtc_make %{?_smp_mflags} + +%install +rm -rf %{buildroot} +%qmake5_install + +mkdir -p %{buildroot}%{_libdir}/systemd/user/user-session.target.wants +ln -s ../starfishd.service %{buildroot}%{_libdir}/systemd/user/user-session.target.wants/ + +desktop-file-install --delete-original \ + --dir %{buildroot}%{_datadir}/applications \ + %{buildroot}%{_datadir}/applications/*.desktop + +%post +grep -q "^/usr/bin/starfishd" /usr/share/mapplauncherd/privileges || echo "/usr/bin/starfishd,cehlmnpu" >> /usr/share/mapplauncherd/privileges +su nemo -c 'systemctl --user daemon-reload' +su nemo -c 'systemctl --user try-restart starfishd.service' +update-desktop-database + +%files +%defattr(-,root,root,-) +%{_bindir} +%{_datadir}/%{name}/qml +%{_datadir}/%{name}/translations +%{_datadir}/applications/%{name}.desktop +%{_datadir}/icons/hicolor/86x86/apps/%{name}.png +%{_datadir}/icons/hicolor/108x108/apps/%{name}.png +%{_datadir}/icons/hicolor/128x128/apps/%{name}.png +%{_datadir}/icons/hicolor/256x256/apps/%{name}.png +%{_libdir}/systemd/user/%{name}d.service +%{_libdir}/systemd/user/user-session.target.wants/%{name}d.service diff --git a/starfish.pro b/starfish.pro new file mode 100644 index 0000000..ea5f83b --- /dev/null +++ b/starfish.pro @@ -0,0 +1,5 @@ +TEMPLATE = subdirs +SUBDIRS = starfish starfishd +OTHER_FILES += \ + README.md \ + rpm/starfish.spec diff --git a/starfish/.gitignore b/starfish/.gitignore new file mode 100644 index 0000000..9ff7f7e --- /dev/null +++ b/starfish/.gitignore @@ -0,0 +1 @@ +/starfish diff --git a/starfish/main.cpp b/starfish/main.cpp new file mode 100644 index 0000000..6c87961 --- /dev/null +++ b/starfish/main.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 + +#include + +#include "servicecontrol.h" +#include "watches.h" +#include "watch.h" + +int main(int argc, char *argv[]) +{ + QScopedPointer app(SailfishApp::application(argc, argv)); + app->setApplicationName("starfish"); + app->setOrganizationName("asteroidos"); + + QTranslator i18n; + i18n.load("starfish_" + QLocale::system().name(), "/usr/share/starfish/translations"); + app->installTranslator(&i18n); + + qmlRegisterUncreatableType("Starfish", 1, 0, "Watch", "Get them from the model"); + qmlRegisterType("Starfish", 1, 0, "Watches"); + qmlRegisterType("Starfish", 1, 0, "ServiceController"); + + QScopedPointer view(SailfishApp::createView()); + view->rootContext()->setContextProperty("version", QStringLiteral(VERSION)); + + view->setSource(SailfishApp::pathTo("qml/starfish.qml")); + view->show(); + + return app->exec(); +} + diff --git a/starfish/qml/cover/CoverPage.qml b/starfish/qml/cover/CoverPage.qml new file mode 100644 index 0000000..e07fc9e --- /dev/null +++ b/starfish/qml/cover/CoverPage.qml @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 2.0 +import Sailfish.Silica 1.0 + +CoverBackground { + property var watch: null + + Image { + fillMode: Image.PreserveAspectCrop + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: label.top + source: "image://theme/icon-m-watch" + } + + Label { + id: label + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: state.top + anchors.bottomMargin: Theme.paddingSmall + text: (watch && watch.name) ? watch.name : qsTr("Watch") + } + + Label { + id: state + anchors.horizontalCenter: parent.horizontalCenter + anchors.top: parent.verticalCenter + color: Theme.highlightColor + text: (watch && watch.connected) ? qsTr("connected") : qsTr("disconnected") + } + onStatusChanged: {if(status===Cover.Activating) watch = starfish.getCurWatch()} + + CoverActionList { + id: coverAction + enabled: (watch && !watch.connected) + + CoverAction { + iconSource: "image://theme/icon-cover-sync" + onTriggered: watch.reconnect(); + } + } +} + diff --git a/starfish/qml/pages/InfoPage.qml b/starfish/qml/pages/InfoPage.qml new file mode 100644 index 0000000..f56c34c --- /dev/null +++ b/starfish/qml/pages/InfoPage.qml @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 2.2 +import Sailfish.Silica 1.0 + +Page { + + SilicaFlickable { + anchors.fill: parent + contentHeight: contentColumn.height + Theme.paddingSmall + anchors.margins: Theme.paddingLarge + + Column { + id: contentColumn + width: parent.width + height: childrenRect.height + spacing: Theme.paddingLarge + + PageHeader { + title: "About Starfish" + } + + Row { + width: parent.width + spacing: Theme.paddingLarge + anchors.margins: Theme.paddingLarge + + Image { + source: "qrc:///starfish.png" + height: Theme.iconSizeLarge + width: height + } + + Label { + text: qsTr("Version %1").arg(version) + font.pixelSize: Theme.fontSizeLarge + } + } + + Separator { + width: parent.width + color: Theme.secondaryHighlightColor + } + + Label { + width: parent.width + text: qsTr("Legal") + font.bold: true + } + + Label { + width: parent.width + font.pixelSize: Theme.fontSizeSmall + text: "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, 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 http://www.gnu.org/licenses." + wrapMode: Text.WordWrap + } + } + } +} + diff --git a/starfish/qml/pages/LoadingPage.qml b/starfish/qml/pages/LoadingPage.qml new file mode 100644 index 0000000..000fb83 --- /dev/null +++ b/starfish/qml/pages/LoadingPage.qml @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 2.2 +import Sailfish.Silica 1.0 + +Page { + id: loadingComponent + property bool wantConnect: true + + Column { + width: parent.width + + PageHeader { + title: "Starfish" + } + + Label { + width: parent.width + horizontalAlignment: Text.AlignHCenter + font.pixelSize: Theme.fontSizeLarge + text: qsTr("Connecting...") + } + + Button { + text: qsTr("Restart Service") + onClicked: starfish.initService() + width: parent.width + } + } + + BusyIndicator { + size: BusyIndicatorSize.Large + anchors.centerIn: parent + running: !watches.connectedToService && loadingComponent.status === PageStatus.Active && wantConnect + } +} + diff --git a/starfish/qml/pages/LocationPicker.qml b/starfish/qml/pages/LocationPicker.qml new file mode 100644 index 0000000..4a52b0a --- /dev/null +++ b/starfish/qml/pages/LocationPicker.qml @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 2.2 +import Sailfish.Silica 1.0 + +Dialog { + id: pickerPage + canAccept: false + property var selected: null + + Column { + width: parent.width + DialogHeader { + title: qsTr("Select Location") + defaultAcceptText: "" + defaultCancelText: qsTr("Cancel") + } + TextField { + width: parent.width + label: qsTr("Location Name") + placeholderText: qsTr("Type in location name") + onTextChanged: getHints(text) + } + + ListModel { + id: locModel + } + + SilicaListView { + id: locPicker + width: parent.width + height: contentItem.childrenRect.height + + ViewPlaceholder { + enabled: locModel.count === 0 + text: qsTr("Matching locations will be appearing as you type") + } + + model: locModel + delegate: ListItem { + id: liLoc + anchors.horizontalCenter: parent.horizontalCenter + width: locPicker.width-Theme.paddingSmall + contentHeight: Theme.itemSizeSmall + Label { + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + text: model.name + } + Column { + anchors.right: parent.right + anchors.top: parent.top + width: parent.width/4 + Row { + Label { + text: "LAT: " + font.pixelSize: Theme.fontSizeTiny + horizontalAlignment: Text.AlignRight + } + Label { + text: model.lat + font.pixelSize: Theme.fontSizeTiny + } + } + Row { + Label { + text: "LON: " + font.pixelSize: Theme.fontSizeTiny + horizontalAlignment: Text.AlignRight + } + Label { + text: model.lng + font.pixelSize: Theme.fontSizeTiny + } + } + } + onClicked: { + selected = model; + pickerPage.canAccept=true; + pickerPage.accept(); + } + } + } + } + function getHints(blah) { + if(blah && blah.length === 0) return; + var url = "http://autocomplete.wunderground.com/aq?query="+blah; + var xhr = new XMLHttpRequest(); + xhr.open("GET",url); + xhr.onreadystatechange = function() { + if(xhr.readyState === xhr.DONE) { + if(xhr.status === 200) { + var json = JSON.parse(xhr.responseText); + if(json.hasOwnProperty("RESULTS") && json.RESULTS.length > 0) { + locModel.clear(); + for(var i=0;i + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 2.2 +import Sailfish.Silica 1.0 +import QtGraphicalEffects 1.0 + +Page { + id: root + property var watch: null + allowedOrientations: Orientation.All + + ListModel { + id: mainMenuModel + dynamicRoles: true + } + + SilicaFlickable { + anchors.fill: parent + + PullDownMenu { + MenuItem { + text: qsTr("About") + onClicked: pageStack.push(Qt.resolvedUrl("InfoPage.qml")) + } + MenuItem { + text: qsTr("Restart service") + onClicked: starfish.restartService() + } + } + + Column { + anchors.fill: parent + spacing: Theme.paddingMedium + + PageHeader { + id: hdr + title: root.watch ? root.watch.name : "" + } + + Row { + height: Theme.iconSizeSmall + spacing: Theme.paddingSmall + + Image { + height: Theme.iconSizeSmall + width: height + source: "image://theme/icon-lock-" + (curWatchConnected ? "transfer" : "warning") + } + + Label { + text: curWatchConnected ? qsTr("Connected") : qsTr("Disconnected") + } + } + + Label { + text: qsTr("Your smartwatch is disconnected. Please make sure it is powered on, within range and it is paired properly in the Bluetooth System Settings.") + width: parent.width + anchors.horizontalCenter: parent.horizontalCenter + wrapMode: Text.WordWrap + visible: !curWatchConnected + font.pixelSize: Theme.fontSizeLarge + horizontalAlignment: Text.AlignHCenter + } + + Button { + text: qsTr("Open Bluetooth Settings") + visible: curWatchConnected + onClicked: starfish.startBT() + anchors.horizontalCenter: parent.horizontalCenter + } + + Repeater { + id: menuRepeater + model: curWatchConnected ? mainMenuModel : null + delegate: ListItem { + contentHeight: Theme.iconSizeMedium + Theme.paddingSmall*2 + Row { + height: Theme.iconSizeMedium + anchors.verticalCenter: parent.verticalCenter + spacing: Theme.paddingSmall + Image { + source: "image://theme/" + model.icon + anchors.verticalCenter: parent.verticalCenter + } + Label { + text: model.text + anchors.verticalCenter: parent.verticalCenter + } + } + + onClicked: { + var options = {} + options["watch"] = root.watch + pageStack.push(Qt.resolvedUrl(model.page), options) + } + } + } + } + } + + Component.onCompleted: { + mainMenuModel.clear() + mainMenuModel.append({ + icon: "icon-m-alarm", + text: qsTr("Weather"), + page: "WeatherSettingsDialog.qml" + }) + } +} + diff --git a/starfish/qml/pages/WatchesPage.qml b/starfish/qml/pages/WatchesPage.qml new file mode 100644 index 0000000..f613273 --- /dev/null +++ b/starfish/qml/pages/WatchesPage.qml @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 2.2 +import Sailfish.Silica 1.0 + +Page { + SilicaListView { + anchors.fill: parent + model: watches + + header: PageHeader { + title: qsTr("Starfish") + description: qsTr("Manage Watches") + } + + PullDownMenu { + MenuItem { + text: qsTr("Bluetooth Settings") + onClicked: starfish.startBT() + } + MenuItem { + text: qsTr("Restart service") + onClicked: starfish.restartService() + } + } + + delegate: ListItem { + contentHeight: Theme.fontSizeMedium*2 + + Label { + text: name + anchors.fill: parent + } + + onClicked: watches.selectWatch(index) + } + } + + ViewPlaceholder { + anchors.fill: parent + enabled: watches.count === 0 + + Label { + text: qsTr("No smartwatches configured yet. Please connect your smartwatch using System Settings.") + font.pixelSize: Theme.fontSizeLarge + width: parent.width-(Theme.paddingSmall*2) + anchors.centerIn: parent + horizontalAlignment: Text.AlignHCenter + wrapMode: Text.WordWrap + } + + Button { + text: qsTr("Open Bluetooth Settings") + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottomMargin: Theme.paddingLarge + anchors.bottom: parent.bottom + onClicked: starfish.startBT() + } + } +} + diff --git a/starfish/qml/pages/WeatherSettingsDialog.qml b/starfish/qml/pages/WeatherSettingsDialog.qml new file mode 100644 index 0000000..beb2738 --- /dev/null +++ b/starfish/qml/pages/WeatherSettingsDialog.qml @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 2.2 +import Sailfish.Silica 1.0 + +Dialog { + id: root + + property var watch: null + canAccept: false + + SilicaFlickable { + id: view + anchors.fill: parent + contentHeight: content.height + Column { + id:content + width: parent.width + + DialogHeader { + title: qsTr("Weather Settings") + defaultAcceptText: qsTr("OK") + defaultCancelText: qsTr("Cancel") + } + + SectionHeader { + text: qsTr("Locations") + } + + ListModel { + id: locations + } + + SilicaListView { + id: locList + width: parent.width + height: contentItem.childrenRect.height + model: locations + delegate: ListItem { + id: liLoc + width: locList.width - Theme.paddingSmall + contentHeight: contentItem.height + anchors.horizontalCenter: parent.horizontalCenter + highlighted: down || menuOpen || !enabled + Column { + id: contentItem + width: parent.width + TextField { + id: leName + width: parent.width + label: qsTr("Location Name") + text: model.name + visible: !liLoc.enabled + } + TextField { + id: leLat + width: parent.width + label: qsTr("Latitude") + text: model.lat + visible: !liLoc.enabled + } + TextField { + id: leLng + width: parent.width + label: qsTr("Longitude") + text: model.lng + visible: !liLoc.enabled + } + Row { + width: parent.width + spacing: Theme.paddingSmall + Button { + text: qsTr("Cancel") + onClicked: liLoc.enabled = true + visible: !liLoc.enabled + width: parent.width/2 - Theme.paddingSmall + } + Button { + text: qsTr("Save Changes") + width: parent.width/2 - Theme.paddingSmall + visible: !liLoc.enabled + onClicked: { + locations.setProperty(index,"name",leName.text); + locations.setProperty(index,"lat",leLat.text); + locations.setProperty(index,"lng",leLng.text); + liLoc.enabled = true; + } + } + } + Row { + width: parent.width + height: Theme.itemSizeSmall + visible: liLoc.enabled + Label { + width: parent.width*0.75 + anchors.verticalCenter: parent.verticalCenter + text: model.name + } + Column { + width: parent.width/4 + anchors.verticalCenter: parent.verticalCenter + Row { + Label { + text: "LAT: " + font.pixelSize: Theme.fontSizeTiny + horizontalAlignment: Text.AlignRight + } + Label { + text: model.lat + font.pixelSize: Theme.fontSizeTiny + } + } + Row { + Label { + text: "LON: " + font.pixelSize: Theme.fontSizeTiny + horizontalAlignment: Text.AlignRight + } + Label { + text: model.lng + font.pixelSize: Theme.fontSizeTiny + } + } + } + } + } + menu: ContextMenu { + MenuItem { + text: qsTr("Edit") + visible: index>0 + onClicked: liLoc.enabled = false + } + MenuItem { + text: qsTr("Move Up") + visible: index>1 + onClicked: {locations.move(index,index-1,1);root.canAccept=true} + } + MenuItem { + text: qsTr("Move Down") + visible: index>0 && index<(locations.count-1) + onClicked: {locations.move(index,index+1,1);root.canAccept=true} + } + MenuItem { + text: qsTr("Delete") + visible: index>0 || locations.count==1 + onClicked: liLoc.remorseAction("Delete?",function(){locations.remove(index);root.canAccept=true}) + } + } + } + } + Button { + width: parent.width + text: qsTr("Add Location") + onClicked: { + if(locations.count>0) { + var locpick = pageStack.push(Qt.resolvedUrl("LocationPicker.qml")); + locpick.accepted.connect(function(){ + locations.append(locpick.selected); + root.canAccept=true; + }); + } else { + locations.append({"name":qsTr("Current Location"),"lat":"n/a","lng":"n/a"}) + } + } + } + } + } + + Component.onCompleted: { + var list = watch.weatherLocations; + locations.clear(); + locStash = []; + for(var i in list) { + var loc = list[i]; + locStash.push(loc); + locations.append({"name":loc[0],"lat":loc[1],"lng":loc[2]}); + console.log("Location",i,loc); + } + } + + onDone: { + if(result === DialogResult.Accepted) { + var ret = []; + var locStore = false; + for(var i=0;i + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 2.2 +import Sailfish.Silica 1.0 +import Starfish 1.0 +import org.nemomobile.dbus 2.0 +import "pages" + +ApplicationWindow { + id: starfish + initialPage: Qt.resolvedUrl("pages/LoadingPage.qml") + cover: Qt.resolvedUrl("cover/CoverPage.qml") + property alias curWatch: watches.currentWatch + property alias curWatchConnected: watches.currentWatchConnected + property var sysProfiles: [ ] + + ServiceController { + id: serviceController + Component.onCompleted: initService() + } + + Watches { + id: watches + onCountChanged: loadStack() + onConnectedToServiceChanged: loadStack() + onCurrentWatchChanged: { + console.log("onCurrentWatchChanged" + curWatch) + loadStack() + } + } + + DBusInterface { + id: lipstick + service: "org.nemomobile.lipstick" + path: "/LauncherModel" + iface: "org.nemomobile.lipstick.LauncherModel" + } + + DBusInterface { + id: jolla + service: "com.jolla.settings" + path: "/com/jolla/settings/ui" + iface: "com.jolla.settings.ui" + } + + function startBT() { + lipstick.typedCall("notifyLaunching",[{"type":"s","value":"jolla-settings.desktop"}], + function(r){jolla.call("showPage",["system_settings/connectivity/bluetooth"])}, + function(e){console.log("Error",e)}) + } + + function initService() { + if (!watches.connectedToService && !serviceController.serviceRunning) { + serviceController.startService(); + } + if (watches.version !== version) { + console.log("Service file version (", version, ") is not equal running service version (", watches.version, "). Restarting service."); + serviceController.restartService(); + } + } + + function restartService() { + serviceController.restartService() + } + + function loadStack() { + if (watches.connectedToService) { + pageStack.clear() + if (curWatch >= 0) + pageStack.push(Qt.resolvedUrl("pages/MainMenuPage.qml"), {watch: getCurWatch()}) + else + pageStack.push(Qt.resolvedUrl("pages/WatchesPage.qml")) + } else { + pageStack.clear(); + pageStack.push(initialPage); + } + } + + Component.onCompleted: loadStack(); + + function getCurWatch() { + if(curWatch >= 0) return watches.get(curWatch); + return null; + } +} + diff --git a/starfish/servicecontrol.cpp b/starfish/servicecontrol.cpp new file mode 100644 index 0000000..5a10827 --- /dev/null +++ b/starfish/servicecontrol.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 "servicecontrol.h" + +#include +#include +#include +#include +#include +#include + +ServiceControl::ServiceControl(QObject *parent) : QObject(parent), + systemd(new QDBusInterface("org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.systemd1.Manager", + QDBusConnection::sessionBus(), this)) +{ + systemd->call("Subscribe"); + + QDBusReply unit = systemd->call("LoadUnit", STARFISHD_SYSTEMD_UNIT); + if (unit.isValid()) { + unitPath = unit.value(); + + getUnitProperties(); + + QDBusConnection::sessionBus().connect( + "org.freedesktop.systemd1", unitPath.path(), + "org.freedesktop.DBus.Properties", "PropertiesChanged", + this, SLOT(onPropertiesChanged(QString,QMap,QStringList))); + } else { + qWarning() << unit.error().message(); + } +} + +void ServiceControl::onPropertiesChanged(QString interface, QMap changed, QStringList invalidated) +{ + qDebug() << Q_FUNC_INFO << interface << changed << invalidated; + if (interface != "org.freedesktop.systemd1.Unit") return; + if (invalidated.contains("UnitFileState") || invalidated.contains("ActiveState")) + getUnitProperties(); +} + +bool ServiceControl::serviceRunning() const +{ + return unitProperties["UnitFileState"].toString() == "enabled"; +} + +bool ServiceControl::setServiceRunning(bool running) +{ + if (running && !serviceRunning()) { + return startService(); + } else if (!running && serviceRunning()) { + return stopService(); + } + return true; // Requested state is already the current state. +} + +bool ServiceControl::startService() +{ + QDBusError reply; + systemd->call("EnableUnitFiles", QStringList() << STARFISHD_SYSTEMD_UNIT, false, true); + if (reply.isValid()) { + qWarning() << reply.message(); + return false; + } else { + systemd->call("Reload"); + systemd->call("StartUnit", STARFISHD_SYSTEMD_UNIT, "replace"); + return true; + } +} + +bool ServiceControl::stopService() +{ + QDBusError reply; + systemd->call("StopUnit", STARFISHD_SYSTEMD_UNIT, "replace"); + systemd->call("DisableUnitFiles", QStringList() << STARFISHD_SYSTEMD_UNIT, false); + if (reply.isValid()) { + qWarning() << reply.message(); + return false; + } else { + systemd->call("Reload"); + return true; + } +} + +bool ServiceControl::restartService() +{ + return stopService() && startService(); +} + +void ServiceControl::getUnitProperties() +{ + QDBusMessage request = QDBusMessage::createMethodCall( + "org.freedesktop.systemd1", unitPath.path(), + "org.freedesktop.DBus.Properties", "GetAll"); + request << "org.freedesktop.systemd1.Unit"; + QDBusReply reply = QDBusConnection::sessionBus().call(request); + if (reply.isValid()) { + QVariantMap newProperties = reply.value(); + bool emitRunningChanged = (unitProperties["ActiveState"] != newProperties["ActiveState"]); + unitProperties = newProperties; + if (emitRunningChanged) emit serviceRunning(); + } else { + qWarning() << reply.error().message(); + } +} + diff --git a/starfish/servicecontrol.h b/starfish/servicecontrol.h new file mode 100644 index 0000000..21f093e --- /dev/null +++ b/starfish/servicecontrol.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 SERVICECONTROL_H +#define SERVICECONTROL_H + +#include +#include + +static const QString STARFISHD_SYSTEMD_UNIT("starfishd.service"); + +class ServiceControl : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool serviceRunning READ serviceRunning WRITE setServiceRunning NOTIFY serviceRunningChanged) + +public: + explicit ServiceControl(QObject *parent = 0); + + bool serviceRunning() const; + bool setServiceRunning(bool running); + Q_INVOKABLE bool startService(); + Q_INVOKABLE bool stopService(); + Q_INVOKABLE bool restartService(); + +private slots: + void getUnitProperties(); + void onPropertiesChanged(QString interface, QMap changed, QStringList invalidated); + +signals: + void serviceRunningChanged(); + +private: + QDBusInterface *systemd; + QDBusObjectPath unitPath; + QVariantMap unitProperties; + +}; + +#endif // SERVICECONTROL_H + diff --git a/starfish/starfish.desktop b/starfish/starfish.desktop new file mode 100644 index 0000000..b0fdfb7 --- /dev/null +++ b/starfish/starfish.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=Starfish +Exec=invoker -s --type=browser -G /usr/bin/starfish +Icon=starfish +Type=Application diff --git a/starfish/starfish.png b/starfish/starfish.png new file mode 100644 index 0000000000000000000000000000000000000000..a06ff6623d67c397b018bf118caa7d08dbcaab65 GIT binary patch literal 3972 zcmV-~4}0*5P)9Zxb@73$B~q*gh@gdP zYXq0JUR#S;l~!96NH8G?U3x+7Z9%LS6;M1|0HMEu z06<0`3qZzR7dmDnyoZJR1avadO0_>h9)E1q2&ld?Fqe@Cls5VBEkRIOFd!L3tUWO? zSOOp&j0{2rKmK0YQV*XO%YfaXalrxFo?7+{J6sTKX- zA8tm$e(~QY+a(W~&)tD#L{!Mc&`|0{)5~`v!p#WSeU;;E`L>QFfdJhN!bt!$NB~#| zb3((V41hiQQ1ST^9lr+AxX?4}&p%+`N(;e$R$2HBp{Q#l(+#0#jeO<-2GhgXh1 zTM)kh!fCM}2P9kql(YhR2F(}6iv^(?z)6IdxRGLBqxLnppwJ#7-yb|f6#LfjxrkeZ z?vW5~e7TJrq{Fo#Ww84y$Jso)?CS}1HvlCH$N+~+KtoDa@Wrx|?S6FCg6WdjsvfMS zi7a5i*aD~Ev7fIPIn1xxUWVjzdjdA#;hOc>Bb5cY4BK`Pl^Ch&R@#E2a16;V$d>3&UCB?a8-|A zb%vDdn6eCxbHh+=MN`4jpVi7GG8h#s_|e#V095p(`%J-gPF)JeQXpM%6t6CY=)Z@?4jk~9jZwFBYCfjD&U-I9%?qi zCGNor^1sSi0`Pw%tT7p|1?L6nL5;QrM%Ugo{c8(}dR|{FJJZfyr3QdKxggV5uIqvd zI7`!q8dh#8IN2r1H5uIqv&mO>3HcZJ@d^^MBkW|%5{}3f%E)D$kb*lDh2yJ@E?7r&y^b&Zsm67-w47;2z?TSFb3DGa$VCi z3pJ$NDL>Yf``#0MuH0xVkYXMLYqL8t1UJ)4%?`K`R&aFQNW~Uh z(-*^8witcA*-o7b+1(2NvA^|+Eks#?^vhcyKoHR8I9aS**M*DVEL(*B*$9sF9{>P! z*FTea#7A{zX$B=#@E%i!E^A< z-l1-}9qjjleVu5koe%G4dra8EN(?^pRt+g@e_&{@2p;SIL$JJv|3iZF!Kh&A>4lGI zlh-J=9;9Ro&WjhoHOqKI)!n!YP1QdD`#lj2fFE7^x5HLAG0qmc54;L@-4DUi7cuGA zhpq!VkaOx}D6SC(ZJ`XZs|o%u-?!Qp8kBbzOd90sR3AlX(nWf39W&;^HQTtSdK%wA z)5e7w)Yu+cAP9Ft2yXYsJK?UoLxUP?ZqkRY{VyS>XcCmXLW6LpTkpAy2Bor~_&ZEk z6n&S};5uf^h3ksNrl5Yk;r6gn6Lo(BVdeV2`UFk23&80QP!f{5jlF3*|JtUGN=mfbU2>*zeWO zMf@Kz`|Rt)*PG|V`_K1GckY4dXLIBYC^AYT{G{2vvgtTR8H|^<8Y-9T@5>sGiovv=LqATn?BqI zrD9Csl?0rly~`Y2$Lw3+y7o?_yV*uf04X+jK6xwZeBLGZ!8!G|xa)I@Cj&A7@1eI1 zDYyHh?Xa1I8|XNW!14Oj;1U{?rDF=N2k3hgf@ut{W7dsuU6(%85UkVAg0SU=lTd)Af+L=9Ppy+qyI6b+?>;9q@&yh<*v~MHvu>!l+-c+*Kyg+aLuv4?{6D5 z5hPR$KD`XiX}1~pGD?7e58lJ?m{4vB6z3_KR&IkT18frl03=ulP^jygs4J^Q1j6ph zSgOQ1{dQB=4?1O>*7s(abl!sWb|BDn5GeSb;b>vd@bTzob5lqO>=EDqn570zN-%57 zEqm_D0<9aLMB9t&(BE6vhdbb|TdYBi49^mVVuZYlR$|EbtBl`&-zK#F>E5`oD_JNe zS+uEI;zfc5KvEc1Zri4{AOaj$&g&|%}stro37ZPT1_gqdM(!?03g#? zp2|%ElC^Ipq|y|XyY0C?fch%jo0fq6fgZcR;a5Wbr7K~dWDaWcjujC~MaVl%DHozq zAix02^x;-LjrNzTG6(g8*Wj+Ih=AI2ZUGP&dilfVpuS&&=Itv&4Ph9jdAJJE0U?6` zt$_Rdnv5v7d;c!DH{P89Y67?*63n6E8!9xSIkWh>W91G{=Ej3h{4B+)Z@^42B-Cxo4dxb7Q7&Ex z2Ydn6L1h?j)l=x$QDYqL#2FYmcNIWNJXi?i{pU|$KW~l+sC95}jewf4`fbhpp++WAtzDkFbHvg^tHX-b6$se}%9V_kb-yyzi5PO$#TYv8 zVa*mGkazWR*r!};9O~Z9aBo?mmC=A2Q&lcNQH4?^B#5G4n~F3QBJ_0QcMxz$l%86s58`V{W-j{`oB;jGw@ zv%haDWb1rqGu&H#8UZz;hh{Zg;E{2a`@E5#FC-C|2+SO+-hE;VdR8nGBM}{YHp5+8 zsegWw+(P=caEv-V&&EE3KHISW;I?gAi?$bkZyD6izt*9pcBTFdqL&$w*1#q3!v&Q` zI^)1H3GMoRh5H+{ZTVgLP~WOUbImI4CsJd3Xc>UZj1P_s9rk3RXHkCm&Ad587#kHD z1wA)nf<{I|F#^2%-U9?7=ZuM|L4C6h%{323O$5&H!fIBCuOC~n|Nj!*Qe}M*LXZwL z7H%IlXl*sm0AM(;o^Q@m->5@N%|mf?6L)J`_>KGG@~SNJ6_*{mTGNH zO0q>K7Q*#0%l|5>{Jg1Gu-ea7Q)pE}R>5V!bwgsf?XOj#wdPk^Ttmp%^3+(kOuVe< zr-$B3_E{o;U<0W~1*CZ{>lyq0j27CrZ9r?)6Y)@AsX}Y@YSRl&66SNwMGMar{^Zj& zMl4D|kPb3i;ckqA+rFa;tyQa2Ud@v-T*AvEF=~ErgecjjvTpj?@-4lml5MuIZ6iPg z;c%h#gd5XSOG{$;V<|9mFs6A?<@Ry!y|;olz*L9l^_sBKpWU_4>R-iMUNi%Yq|*` z!4P_tkEreg&lVU=>$(RGKC|$b`_qOR(|7?Gn94oC;5!Oe|KoqHOty!6UPJ>;xyJ}% zNx`uE@r94qTMAXr6_7qrPwx<)_{u#7DIX)onu6c#?ab7CUNty0BTsC&k|bW2g4VUT zJF3UkMi2aD1S|*phbJCf2B@BhYk)-qm{j{lpfO5a0_yZuyB^k5@sX-$GNdl7$LnG1(8-g1g1JfEI?KNEm*%(JZ}vE0000 + + starfish.png + + diff --git a/starfish/watch.cpp b/starfish/watch.cpp new file mode 100644 index 0000000..04e6999 --- /dev/null +++ b/starfish/watch.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 "watch.h" + +#include +#include + +Watch::Watch(const QDBusObjectPath &path, QObject *parent) : QObject(parent), m_path(path) +{ + m_iface = new QDBusInterface("org.starfish", path.path(), "org.starfish.Watch", QDBusConnection::sessionBus(), this); + + dataChanged(); +} + +void Watch::selectWatch() +{ + m_iface->call("SelectWatch"); +} + +QDBusObjectPath Watch::path() +{ + return m_path; +} + +QString Watch::address() +{ + return m_address; +} + +QString Watch::name() +{ + return m_name; +} + +QString Watch::weatherCityName() +{ + return ""; // TODO +} + +void Watch::setWeatherCityName(const QString &c) +{ + m_iface->call("WeatherSetCityName", c); + emit weatherCityNameChanged(); +} + +quint8 Watch::batteryLevel() { + return 100; // TODO +} + +QVariant Watch::fetchProperty(const QString &propertyName) +{ + QDBusMessage m = m_iface->call(propertyName); + if (m.type() != QDBusMessage::ErrorMessage && m.arguments().count() == 1) + return m.arguments().first(); + + qDebug() << "error getting property:" << propertyName << m.errorMessage(); + return QVariant(); +} + +void Watch::dataChanged() +{ + m_name = fetchProperty("Name").toString(); + m_address = fetchProperty("Address").toString(); +} + +void Watch::requestScreenshot() +{ + m_iface->call("RequestScreenshot"); +} diff --git a/starfish/watch.h b/starfish/watch.h new file mode 100644 index 0000000..48d4cac --- /dev/null +++ b/starfish/watch.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 WATCH_H +#define WATCH_H + +#include +#include + +class Watch : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name CONSTANT) + Q_PROPERTY(QString weatherCityName READ weatherCityName WRITE setWeatherCityName NOTIFY weatherCityNameChanged) + Q_PROPERTY(quint8 batteryLevel READ batteryLevel NOTIFY batteryLevelChanged) + +public: + explicit Watch(const QDBusObjectPath &path, QObject *parent = 0); + + QDBusObjectPath path(); + + void selectWatch(); + QString address(); + QString name(); + + QString weatherCityName(); + quint8 batteryLevel(); + +public slots: + void requestScreenshot(); + void setWeatherCityName(const QString &in); + +signals: + void weatherCityNameChanged(); + void batteryLevelChanged(); + +private: + QVariant fetchProperty(const QString &propertyName); + +private slots: + void dataChanged(); + +private: + QDBusObjectPath m_path; + + QString m_address; + QString m_name; + QDBusInterface *m_iface; +}; + +#endif // WATCH_H + diff --git a/starfish/watches.cpp b/starfish/watches.cpp new file mode 100644 index 0000000..d2f00bd --- /dev/null +++ b/starfish/watches.cpp @@ -0,0 +1,269 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 "watches.h" +#include "watch.h" + +#include +#include +#include +#include +#include +#include + +#define STARFISH_SERVICE QStringLiteral("org.starfish") +#define STARFISH_MANAGER_PATH QStringLiteral("/org/starfish/Manager") +#define STARFISH_MANAGER_INTERFACE QStringLiteral("org.starfish.Manager") + +Watches::Watches(QObject *parent) : QAbstractListModel(parent), m_selectedWatch(-1) +{ + refreshWatches(); + refreshSelectedWatch(); + refreshSelectedWatchConnected(); + m_watcher = new QDBusServiceWatcher(STARFISH_SERVICE, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); + QDBusConnection::sessionBus().connect(STARFISH_SERVICE, STARFISH_MANAGER_PATH, STARFISH_MANAGER_INTERFACE, "WatchesChanged", this, SLOT(refreshWatches())); + QDBusConnection::sessionBus().connect(STARFISH_SERVICE, STARFISH_MANAGER_PATH, STARFISH_MANAGER_INTERFACE, "SelectedWatchChanged", this, SLOT(refreshSelectedWatch())); + QDBusConnection::sessionBus().connect(STARFISH_SERVICE, STARFISH_MANAGER_PATH, STARFISH_MANAGER_INTERFACE, "SelectedWatchConnectedChanged", this, SLOT(refreshSelectedWatchConnected())); + connect(m_watcher, &QDBusServiceWatcher::serviceRegistered, [this]() { + refreshWatches(); + refreshSelectedWatch(); + refreshSelectedWatchConnected(); + QDBusConnection::sessionBus().connect(STARFISH_SERVICE, STARFISH_MANAGER_PATH, STARFISH_MANAGER_INTERFACE, "WatchesChanged", this, SLOT(refreshWatches())); + QDBusConnection::sessionBus().connect(STARFISH_SERVICE, STARFISH_MANAGER_PATH, STARFISH_MANAGER_INTERFACE, "SelectedWatchChanged", this, SLOT(refreshSelectedWatch())); + QDBusConnection::sessionBus().connect(STARFISH_SERVICE, STARFISH_MANAGER_PATH, STARFISH_MANAGER_INTERFACE, "SelectedWatchConnectedChanged", this, SLOT(refreshSelectedWatchConnected())); + }); + connect(m_watcher, &QDBusServiceWatcher::serviceUnregistered, [this]() { + beginResetModel(); + qDeleteAll(m_watches); + m_watches.clear(); + endResetModel(); + m_connectedToService = false; + emit connectedToServiceChanged(); + }); +} + +int Watches::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + return m_watches.count(); +} + +QVariant Watches::data(const QModelIndex &index, int role) const +{ + switch (role) { + case RoleAddress: + return m_watches.at(index.row())->address(); + case RoleName: + return m_watches.at(index.row())->name(); + } + + return QVariant(); +} + +QHash Watches::roleNames() const +{ + QHash roles; + roles.insert(RoleAddress, "address"); + roles.insert(RoleName, "name"); + roles.insert(RoleSerialNumber, "serialNumber"); + return roles; +} + +bool Watches::connectedToService() +{ + return m_connectedToService; +} + +QString Watches::version() const +{ + QDBusInterface iface(STARFISH_SERVICE, STARFISH_MANAGER_PATH, STARFISH_MANAGER_INTERFACE); + if (!iface.isValid()) { + qWarning() << "Could not connect to starfishd."; + return QString(); + } + QDBusMessage reply = iface.call("Version"); + if (reply.type() == QDBusMessage::ErrorMessage) { + qWarning() << "Error refreshing watches:" << reply.errorMessage(); + return QString(); + } + if (reply.arguments().count() == 0) { + qWarning() << "No reply from service."; + return QString(); + } + return reply.arguments().first().toString(); +} + +Watch *Watches::get(int index) const +{ + if (index >= 0 && index < m_watches.count()) + return m_watches.at(index); + + return nullptr; +} + +int Watches::find(const QString &address) const +{ + for (int i = 0; i < m_watches.count(); i++) { + if (m_watches.at(i)->address() == address) + return i; + } + return -1; +} + +void Watches::refreshWatches() +{ + QDBusInterface iface(STARFISH_SERVICE, STARFISH_MANAGER_PATH, STARFISH_MANAGER_INTERFACE); + if (!iface.isValid()) { + qWarning() << "Could not connect to starfishd."; + return; + } + QDBusMessage reply = iface.call("ListWatches"); + if (reply.type() == QDBusMessage::ErrorMessage) { + qWarning() << "Error refreshing watches:" << reply.errorMessage(); + return; + } + if (reply.arguments().count() == 0) { + qWarning() << "No reply from service."; + return; + } + const QDBusArgument &arg = reply.arguments().first().value(); + QStringList availableList; + arg.beginArray(); + while (!arg.atEnd()) { + QDBusObjectPath p; + arg >> p; + if (find(p) == -1) { + Watch *watch = new Watch(p, this); + beginInsertRows(QModelIndex(), m_watches.count(), m_watches.count()); + m_watches.append(watch); + endInsertRows(); + emit countChanged(); + } + availableList << p.path(); + std::sort(m_watches.begin(), m_watches.end(), Watches::sortWatches); + } + arg.endArray(); + + QList toRemove; + foreach (Watch *watch, m_watches) { + bool found = false; + foreach (const QString &path, availableList) { + if (path == watch->path().path()) { + found = true; + break; + } + } + if (!found) + toRemove << watch; + } + + while (!toRemove.isEmpty()) { + Watch *watch = toRemove.takeFirst(); + int idx = m_watches.indexOf(watch); + beginRemoveRows(QModelIndex(), idx, idx); + m_watches.takeAt(idx)->deleteLater(); + endRemoveRows(); + emit countChanged(); + } + + if (!m_connectedToService) { + m_connectedToService = true; + emit connectedToServiceChanged(); + } +} + +void Watches::refreshSelectedWatch() +{ + QDBusInterface iface(STARFISH_SERVICE, STARFISH_MANAGER_PATH, STARFISH_MANAGER_INTERFACE); + if (!iface.isValid()) { + qWarning() << "Could not connect to starfishd."; + return; + } + QDBusMessage reply = iface.call("SelectedWatch"); + if (reply.type() == QDBusMessage::ErrorMessage) { + qWarning() << "Error refreshing watches:" << reply.errorMessage(); + return; + } + if (reply.arguments().count() == 0) { + qWarning() << "No reply from service."; + return; + } + const QDBusObjectPath &p = reply.arguments().first().value(); + int selectedWatch = find(p); + + if(m_selectedWatch != selectedWatch) { + m_selectedWatch = find(p); + emit currentWatchChanged(); + } +} + +void Watches::refreshSelectedWatchConnected() +{ + QDBusInterface iface(STARFISH_SERVICE, STARFISH_MANAGER_PATH, STARFISH_MANAGER_INTERFACE); + if (!iface.isValid()) { + qWarning() << "Could not connect to starfishd."; + return; + } + QDBusMessage reply = iface.call("SelectedWatch"); + if (reply.type() == QDBusMessage::ErrorMessage) { + qWarning() << "Error refreshing watches:" << reply.errorMessage(); + return; + } + if (reply.arguments().count() == 0) { + qWarning() << "No reply from service."; + return; + } + bool connected = reply.arguments().first().toBool(); + + if(m_selectedWatchConnected != connected) { + m_selectedWatchConnected = connected; + emit currentWatchConnectedChanged(); + } +} + +int Watches::currentWatch() +{ + return m_selectedWatch; +} + +bool Watches::currentWatchConnected() +{ + return m_selectedWatchConnected; +} + +bool Watches::sortWatches(Watch *a, Watch *b) +{ + return a->name() < b->name(); +} + +int Watches::find(const QDBusObjectPath &path) const +{ + for (int i = 0; i < m_watches.count(); i++) { + if (m_watches.at(i)->path() == path) + return i; + } + return -1; +} + +void Watches::selectWatch(int index) +{ + Watch *w = get(index); + if(w) + w->selectWatch(); +} diff --git a/starfish/watches.h b/starfish/watches.h new file mode 100644 index 0000000..b9e63d7 --- /dev/null +++ b/starfish/watches.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 WATCHES_H +#define WATCHES_H + +#include +#include +#include +#include + +class Watch; +class QDBusInterface; + +class Watches : public QAbstractListModel +{ + Q_OBJECT + Q_PROPERTY(bool connectedToService READ connectedToService NOTIFY connectedToServiceChanged) + Q_PROPERTY(QString version READ version) + Q_PROPERTY(int count READ rowCount NOTIFY countChanged) + Q_PROPERTY(int currentWatch READ currentWatch NOTIFY currentWatchChanged) + Q_PROPERTY(bool currentWatchConnected READ currentWatchConnected NOTIFY currentWatchConnectedChanged) + +public: + enum Roles { + RoleAddress, + RoleName, + RoleSerialNumber + }; + + Watches(QObject *parent = 0); + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant data(const QModelIndex &index, int role) const override; + QHash roleNames() const override; + + bool connectedToService(); + QString version() const; + + Q_INVOKABLE Watch *get(int index) const; + int find(const QString &address) const; + + Q_INVOKABLE void selectWatch(int index); + + int currentWatch(); + bool currentWatchConnected(); + +signals: + void connectedToServiceChanged(); + void countChanged(); + void currentWatchChanged(); + void currentWatchConnectedChanged(); + +private slots: + void refreshWatches(); + void refreshSelectedWatch(); + void refreshSelectedWatchConnected(); + +private: + int find(const QDBusObjectPath &path) const; + static bool sortWatches(Watch *a, Watch *b); + +private: + bool m_connectedToService = false; + QList m_watches; + QDBusServiceWatcher *m_watcher; + int m_selectedWatch; + bool m_selectedWatchConnected; +}; + +#endif // WATCHES_H + diff --git a/starfishd/.gitignore b/starfishd/.gitignore new file mode 100644 index 0000000..8964fc6 --- /dev/null +++ b/starfishd/.gitignore @@ -0,0 +1 @@ +/starfishd diff --git a/starfishd/bluez/bluez_adapter1.cpp b/starfishd/bluez/bluez_adapter1.cpp new file mode 100644 index 0000000..a386af1 --- /dev/null +++ b/starfishd/bluez/bluez_adapter1.cpp @@ -0,0 +1,26 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp -c BluezAdapter1 -p bluez_adapter1 -v org.bluez.Adapter1.xml + * + * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "bluez_adapter1.h" + +/* + * Implementation of interface class BluezAdapter1 + */ + +BluezAdapter1::BluezAdapter1(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +BluezAdapter1::~BluezAdapter1() +{ +} + diff --git a/starfishd/bluez/bluez_adapter1.h b/starfishd/bluez/bluez_adapter1.h new file mode 100644 index 0000000..8690075 --- /dev/null +++ b/starfishd/bluez/bluez_adapter1.h @@ -0,0 +1,66 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp -c BluezAdapter1 -p bluez_adapter1 -v org.bluez.Adapter1.xml + * + * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef BLUEZ_ADAPTER1_H_1442480417 +#define BLUEZ_ADAPTER1_H_1442480417 + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.bluez.Adapter1 + */ +class BluezAdapter1: public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() + { return "org.bluez.Adapter1"; } + +public: + BluezAdapter1(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + + ~BluezAdapter1(); + +public Q_SLOTS: // METHODS + inline QDBusPendingReply<> RemoveDevice(const QDBusObjectPath &device) + { + QList argumentList; + argumentList << QVariant::fromValue(device); + return asyncCallWithArgumentList(QStringLiteral("RemoveDevice"), argumentList); + } + + inline QDBusPendingReply<> StartDiscovery() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("StartDiscovery"), argumentList); + } + + inline QDBusPendingReply<> StopDiscovery() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("StopDiscovery"), argumentList); + } + +Q_SIGNALS: // SIGNALS +}; + +namespace org { + namespace bluez { + typedef ::BluezAdapter1 Adapter1; + } +} +#endif diff --git a/starfishd/bluez/bluez_agentmanager1.cpp b/starfishd/bluez/bluez_agentmanager1.cpp new file mode 100644 index 0000000..630953b --- /dev/null +++ b/starfishd/bluez/bluez_agentmanager1.cpp @@ -0,0 +1,26 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp -c BluezAgentManager1 -p bluez_agentmanager1 org.bluez.AgentManager1.xml + * + * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "bluez_agentmanager1.h" + +/* + * Implementation of interface class BluezAgentManager1 + */ + +BluezAgentManager1::BluezAgentManager1(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +BluezAgentManager1::~BluezAgentManager1() +{ +} + diff --git a/starfishd/bluez/bluez_agentmanager1.h b/starfishd/bluez/bluez_agentmanager1.h new file mode 100644 index 0000000..5f50e0d --- /dev/null +++ b/starfishd/bluez/bluez_agentmanager1.h @@ -0,0 +1,68 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp -c BluezAgentManager1 -p bluez_agentmanager1 org.bluez.AgentManager1.xml + * + * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef BLUEZ_AGENTMANAGER1_H_1442489332 +#define BLUEZ_AGENTMANAGER1_H_1442489332 + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.bluez.AgentManager1 + */ +class BluezAgentManager1: public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() + { return "org.bluez.AgentManager1"; } + +public: + BluezAgentManager1(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + + ~BluezAgentManager1(); + +public Q_SLOTS: // METHODS + inline QDBusPendingReply<> RegisterAgent(const QDBusObjectPath &agent, const QString &capability) + { + QList argumentList; + argumentList << QVariant::fromValue(agent) << QVariant::fromValue(capability); + return asyncCallWithArgumentList(QStringLiteral("RegisterAgent"), argumentList); + } + + inline QDBusPendingReply<> RequestDefaultAgent(const QDBusObjectPath &agent) + { + QList argumentList; + argumentList << QVariant::fromValue(agent); + return asyncCallWithArgumentList(QStringLiteral("RequestDefaultAgent"), argumentList); + } + + inline QDBusPendingReply<> UnregisterAgent(const QDBusObjectPath &agent) + { + QList argumentList; + argumentList << QVariant::fromValue(agent); + return asyncCallWithArgumentList(QStringLiteral("UnregisterAgent"), argumentList); + } + +Q_SIGNALS: // SIGNALS +}; + +namespace org { + namespace bluez { + typedef ::BluezAgentManager1 AgentManager1; + } +} +#endif diff --git a/starfishd/bluez/bluez_device1.cpp b/starfishd/bluez/bluez_device1.cpp new file mode 100644 index 0000000..b5ee0f8 --- /dev/null +++ b/starfishd/bluez/bluez_device1.cpp @@ -0,0 +1,26 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp -c BluezDevice1 -p bluez_device1 org.bluez.Device1.xml + * + * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "bluez_device1.h" + +/* + * Implementation of interface class BluezDevice1 + */ + +BluezDevice1::BluezDevice1(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +BluezDevice1::~BluezDevice1() +{ +} + diff --git a/starfishd/bluez/bluez_device1.h b/starfishd/bluez/bluez_device1.h new file mode 100644 index 0000000..c9eaa1f --- /dev/null +++ b/starfishd/bluez/bluez_device1.h @@ -0,0 +1,85 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp -c BluezDevice1 -p bluez_device1 org.bluez.Device1.xml + * + * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef BLUEZ_DEVICE1_H_1442480478 +#define BLUEZ_DEVICE1_H_1442480478 + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.bluez.Device1 + */ +class BluezDevice1: public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() + { return "org.bluez.Device1"; } + +public: + BluezDevice1(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + + ~BluezDevice1(); + +public Q_SLOTS: // METHODS + inline QDBusPendingReply<> CancelPairing() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("CancelPairing"), argumentList); + } + + inline QDBusPendingReply<> Connect() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("Connect"), argumentList); + } + + inline QDBusPendingReply<> ConnectProfile(const QString &UUID) + { + QList argumentList; + argumentList << QVariant::fromValue(UUID); + return asyncCallWithArgumentList(QStringLiteral("ConnectProfile"), argumentList); + } + + inline QDBusPendingReply<> Disconnect() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("Disconnect"), argumentList); + } + + inline QDBusPendingReply<> DisconnectProfile(const QString &UUID) + { + QList argumentList; + argumentList << QVariant::fromValue(UUID); + return asyncCallWithArgumentList(QStringLiteral("DisconnectProfile"), argumentList); + } + + inline QDBusPendingReply<> Pair() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("Pair"), argumentList); + } + +Q_SIGNALS: // SIGNALS +}; + +namespace org { + namespace bluez { + typedef ::BluezDevice1 Device1; + } +} +#endif diff --git a/starfishd/bluez/bluez_helper.h b/starfishd/bluez/bluez_helper.h new file mode 100644 index 0000000..363f7ae --- /dev/null +++ b/starfishd/bluez/bluez_helper.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2015 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * 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 BLUEZ_HELPER_H_ +#define BLUEZ_HELPER_H_ + +#include +#include + +typedef QMap InterfaceList; +typedef QMap ManagedObjectList; + +Q_DECLARE_METATYPE(InterfaceList) +Q_DECLARE_METATYPE(ManagedObjectList) + +#endif diff --git a/starfishd/bluez/bluezclient.cpp b/starfishd/bluez/bluezclient.cpp new file mode 100644 index 0000000..1f2ad02 --- /dev/null +++ b/starfishd/bluez/bluezclient.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 "bluezclient.h" +#include "dbus-shared.h" + +#include +#include +#include + +BluezClient::BluezClient(QObject *parent): + QObject(parent), + m_dbus(QDBusConnection::systemBus()), + m_bluezManager("org.bluez", "/", m_dbus) +{ + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + + if (m_bluezManager.isValid()) { + connect(&m_bluezManager, SIGNAL(InterfacesAdded(const QDBusObjectPath&, InterfaceList)), + this, SLOT(slotInterfacesAdded(const QDBusObjectPath&, InterfaceList))); + + connect(&m_bluezManager, SIGNAL(InterfacesRemoved(const QDBusObjectPath&, const QStringList&)), + this, SLOT(slotInterfacesRemoved(const QDBusObjectPath&, const QStringList&))); + + auto objectList = m_bluezManager.GetManagedObjects().argumentAt<0>(); + for (QDBusObjectPath path : objectList.keys()) { + InterfaceList ifaces = objectList.value(path); + if (ifaces.contains(BLUEZ_DEVICE_IFACE)) { + QString candidatePath = path.path(); + + auto properties = ifaces.value(BLUEZ_DEVICE_IFACE); + addDevice(path, properties); + } + } + + if (m_devices.isEmpty()) { + // Try with bluez 4 + QDBusConnection system = QDBusConnection::systemBus(); + + QDBusReply > listAdaptersReply = system.call( + QDBusMessage::createMethodCall("org.bluez", "/", "org.bluez.Manager", + "ListAdapters")); + if (!listAdaptersReply.isValid()) { + qWarning() << listAdaptersReply.error().message(); + return; + } + + QList adapters = listAdaptersReply.value(); + + if (adapters.isEmpty()) { + qWarning() << "No BT adapters found"; + return; + } + + QDBusReply adapterPropertiesReply = system.call( + QDBusMessage::createMethodCall("org.bluez", adapters[0].path(), "org.bluez.Adapter", + "GetProperties")); + if (!adapterPropertiesReply.isValid()) { + qWarning() << adapterPropertiesReply.error().message(); + return; + } + + QList devices; + adapterPropertiesReply.value()["Devices"].value() >> devices; + + foreach (QDBusObjectPath path, devices) { + QDBusReply devicePropertiesReply = system.call( + QDBusMessage::createMethodCall("org.bluez", path.path(), "org.bluez.Device", + "GetProperties")); + if (!devicePropertiesReply.isValid()) { + qCritical() << devicePropertiesReply.error().message(); + continue; + } + + const QVariantMap &dict = devicePropertiesReply.value(); + + QString name = dict["Name"].toString(); + if (true) { // TODO: Filter + addDevice(path, dict); + } + } + } + } +} + +QList BluezClient::pairedWatches() const +{ + QList ret; + if (m_bluezManager.isValid()) { + foreach (const Device &dev, m_devices) { + ret << dev; + } + } + return ret; +} + +void BluezClient::addDevice(const QDBusObjectPath &path, const QVariantMap &properties) +{ + QString address = properties.value("Address").toString(); + QString name = properties.value("Name").toString(); + + if (!m_devices.contains(address)) { // TODO: Filter + Device device; + device.address = QBluetoothAddress(address); + device.name = name; + device.path = path.path(); + m_devices.insert(path.path(), device); + emit devicesChanged(); + } +} + +void BluezClient::slotInterfacesAdded(const QDBusObjectPath &path, InterfaceList ifaces) +{ + if (ifaces.contains(BLUEZ_DEVICE_IFACE)) { + auto properties = ifaces.value(BLUEZ_DEVICE_IFACE); + addDevice(path, properties); + } +} + +void BluezClient::slotInterfacesRemoved(const QDBusObjectPath &path, const QStringList &ifaces) +{ + if (!ifaces.contains(BLUEZ_DEVICE_IFACE)) { + return; + } + if (m_devices.contains(path.path())) { + m_devices.take(path.path()); + emit devicesChanged(); + } +} diff --git a/starfishd/bluez/bluezclient.h b/starfishd/bluez/bluezclient.h new file mode 100644 index 0000000..cb691fd --- /dev/null +++ b/starfishd/bluez/bluezclient.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 BLUEZCLIENT_H +#define BLUEZCLIENT_H + +#include +#include +#include + +#include "bluez_helper.h" +#include "freedesktop_objectmanager.h" +#include "freedesktop_properties.h" +#include "bluez_adapter1.h" +#include "bluez_agentmanager1.h" + +class Device { +public: + QBluetoothAddress address; + QString name; + QString path; +}; + +class BluezClient: public QObject +{ + Q_OBJECT + +public: + BluezClient(QObject *parent = 0); + + QList pairedWatches() const; + +private slots: + void addDevice(const QDBusObjectPath &path, const QVariantMap &properties); + + void slotInterfacesAdded(const QDBusObjectPath&path, InterfaceList ifaces); + void slotInterfacesRemoved(const QDBusObjectPath&path, const QStringList &ifaces); + +signals: + void devicesChanged(); + +private: + QDBusConnection m_dbus; + DBusObjectManagerInterface m_bluezManager; + BluezAdapter1 *m_bluezAdapter = nullptr; + FreeDesktopProperties *m_bluezAdapterProperties = nullptr; + + QHash m_devices; +}; + +#endif // BLUEZCLIENT_H diff --git a/starfishd/bluez/dbus-shared.h b/starfishd/bluez/dbus-shared.h new file mode 100644 index 0000000..01e9699 --- /dev/null +++ b/starfishd/bluez/dbus-shared.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2013-2015 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef USS_DBUS_SHARED_H +#define USS_DBUS_SHARED_H + +#define DBUS_AGENT_PATH "/com/canonical/SettingsBluetoothAgent" +#define DBUS_ADAPTER_AGENT_PATH "/com/canonical/SettingsBluetoothAgent/adapteragent" +#define DBUS_AGENT_CAPABILITY "KeyboardDisplay" + +#define BLUEZ_SERVICE "org.bluez" + +#define BLUEZ_ADAPTER_IFACE "org.bluez.Adapter1" +#define BLUEZ_DEVICE_IFACE "org.bluez.Device1" + +#define watchCall(call, func) \ + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this); \ + QObject::connect(watcher, &QDBusPendingCallWatcher::finished, func) + +#endif // USS_DBUS_SHARED_H diff --git a/starfishd/bluez/freedesktop_objectmanager.cpp b/starfishd/bluez/freedesktop_objectmanager.cpp new file mode 100644 index 0000000..71ca4ce --- /dev/null +++ b/starfishd/bluez/freedesktop_objectmanager.cpp @@ -0,0 +1,26 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp -p freedesktop_objectmanager -i bluez_helper.h -v -c DBusObjectManagerInterface org.freedesktop.DBus.ObjectManager.xml + * + * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "freedesktop_objectmanager.h" + +/* + * Implementation of interface class DBusObjectManagerInterface + */ + +DBusObjectManagerInterface::DBusObjectManagerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +DBusObjectManagerInterface::~DBusObjectManagerInterface() +{ +} + diff --git a/starfishd/bluez/freedesktop_objectmanager.h b/starfishd/bluez/freedesktop_objectmanager.h new file mode 100644 index 0000000..509c5fc --- /dev/null +++ b/starfishd/bluez/freedesktop_objectmanager.h @@ -0,0 +1,58 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp -p freedesktop_objectmanager -i bluez_helper.h -v -c DBusObjectManagerInterface org.freedesktop.DBus.ObjectManager.xml + * + * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef FREEDESKTOP_OBJECTMANAGER_H_1442473386 +#define FREEDESKTOP_OBJECTMANAGER_H_1442473386 + +#include +#include +#include +#include +#include +#include +#include +#include +#include "bluez_helper.h" + +/* + * Proxy class for interface org.freedesktop.DBus.ObjectManager + */ +class DBusObjectManagerInterface: public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() + { return "org.freedesktop.DBus.ObjectManager"; } + +public: + DBusObjectManagerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + + ~DBusObjectManagerInterface(); + +public Q_SLOTS: // METHODS + inline QDBusPendingReply GetManagedObjects() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("GetManagedObjects"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void InterfacesAdded(const QDBusObjectPath &object_path, InterfaceList interfaces_and_properties); + void InterfacesRemoved(const QDBusObjectPath &object_path, const QStringList &interfaces); +}; + +namespace org { + namespace freedesktop { + namespace DBus { + typedef ::DBusObjectManagerInterface ObjectManager; + } + } +} +#endif diff --git a/starfishd/bluez/freedesktop_properties.cpp b/starfishd/bluez/freedesktop_properties.cpp new file mode 100644 index 0000000..c74347c --- /dev/null +++ b/starfishd/bluez/freedesktop_properties.cpp @@ -0,0 +1,26 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp -c FreeDesktopProperties -p freedesktop_properties -v org.freedesktop.DBus.Properties.xml + * + * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "freedesktop_properties.h" + +/* + * Implementation of interface class FreeDesktopProperties + */ + +FreeDesktopProperties::FreeDesktopProperties(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +FreeDesktopProperties::~FreeDesktopProperties() +{ +} + diff --git a/starfishd/bluez/freedesktop_properties.h b/starfishd/bluez/freedesktop_properties.h new file mode 100644 index 0000000..a7a655c --- /dev/null +++ b/starfishd/bluez/freedesktop_properties.h @@ -0,0 +1,71 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp -c FreeDesktopProperties -p freedesktop_properties -v org.freedesktop.DBus.Properties.xml + * + * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef FREEDESKTOP_PROPERTIES_H_1442473392 +#define FREEDESKTOP_PROPERTIES_H_1442473392 + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.DBus.Properties + */ +class FreeDesktopProperties: public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() + { return "org.freedesktop.DBus.Properties"; } + +public: + FreeDesktopProperties(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + + ~FreeDesktopProperties(); + +public Q_SLOTS: // METHODS + inline QDBusPendingReply Get(const QString &interface, const QString &name) + { + QList argumentList; + argumentList << QVariant::fromValue(interface) << QVariant::fromValue(name); + return asyncCallWithArgumentList(QStringLiteral("Get"), argumentList); + } + + inline QDBusPendingReply GetAll(const QString &interface) + { + QList argumentList; + argumentList << QVariant::fromValue(interface); + return asyncCallWithArgumentList(QStringLiteral("GetAll"), argumentList); + } + + inline QDBusPendingReply<> Set(const QString &interface, const QString &name, const QDBusVariant &value) + { + QList argumentList; + argumentList << QVariant::fromValue(interface) << QVariant::fromValue(name) << QVariant::fromValue(value); + return asyncCallWithArgumentList(QStringLiteral("Set"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QString &interface, const QVariantMap &changed_properties, const QStringList &invalidated_properties); +}; + +namespace org { + namespace freedesktop { + namespace DBus { + typedef ::FreeDesktopProperties Properties; + } + } +} +#endif diff --git a/starfishd/bluez/org.bluez.AgentManager1.xml b/starfishd/bluez/org.bluez.AgentManager1.xml new file mode 100644 index 0000000..e535c7e --- /dev/null +++ b/starfishd/bluez/org.bluez.AgentManager1.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + diff --git a/starfishd/dbusinterface.cpp b/starfishd/dbusinterface.cpp new file mode 100644 index 0000000..51ae7f6 --- /dev/null +++ b/starfishd/dbusinterface.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 "dbusinterface.h" +#include "watchesmanager.h" + +#include "libasteroid/watch.h" + +#include +#include + +/* Watch Interface */ + +DBusWatch::DBusWatch(Watch *watch, WatchesManager* wm, QObject *parent): QObject(parent), m_watch(watch), m_wm(wm) +{ + m_screenshotService = wm->screenshotService(); + m_weatherService = wm->weatherService(); + m_batteryService = wm->batteryService(); + connect(m_batteryService, SIGNAL(levelChanged(quint8)), this, SIGNAL(LevelChanged(quint8))); +} + +void DBusWatch::SelectWatch() +{ + m_wm->setDevice(m_watch); +} + +QString DBusWatch::Address() const +{ + return m_watch->getAddress().toString(); +} + +QString DBusWatch::Name() const +{ + return m_watch->getName(); +} + +quint8 DBusWatch::BatteryLevel() +{ + return m_batteryService->level(); +} + +void DBusWatch::RequestScreenshot() +{ + m_screenshotService->requestScreenshot(); +} + +void DBusWatch::WeatherSetCityName(QString cityName) +{ + m_weatherService->setCity(cityName); +} + +/* Manager Interface */ + +DBusInterface::DBusInterface(WatchesManager *wm, QObject *parent) : QObject(parent) +{ + m_watchesManager = wm; + + QDBusConnection::sessionBus().registerService("org.starfish"); + QDBusConnection::sessionBus().registerObject("/org/starfish/Manager", this, QDBusConnection::ExportScriptableSlots|QDBusConnection::ExportScriptableSignals); + + foreach (Watch *watch, m_watchesManager->watches()) + watchAdded(watch); + + connect(m_watchesManager, &WatchesManager::watchAdded, this, &DBusInterface::watchAdded); + connect(m_watchesManager, &WatchesManager::watchRemoved, this, &DBusInterface::watchRemoved); + connect(m_watchesManager, SIGNAL(currentWatchChanged()), this, SIGNAL(SelectedWatchChanged())); + connect(m_watchesManager, SIGNAL(connected()), this, SIGNAL(SelectedWatchConnectedChanged())); + connect(m_watchesManager, SIGNAL(disconnected()), this, SIGNAL(SelectedWatchConnectedChanged())); +} + +QString DBusInterface::Version() +{ + return QStringLiteral(VERSION); +} + +QList DBusInterface::ListWatches() +{ + QList ret; + + foreach (const QString &address, m_dbusWatches.keys()) + ret.append(QDBusObjectPath("/org/starfish/" + address)); + + return ret; +} + +QDBusObjectPath DBusInterface::SelectedWatch() +{ + Watch *cur = m_watchesManager->currentWatch(); + if(cur) { + QString address = cur->getAddress().toString().replace(":", "_"); + return QDBusObjectPath("/org/starfish/" + address); + } else + return QDBusObjectPath("/"); +} + +bool DBusInterface::SelectedWatchConnected() +{ + return m_watchesManager->isConnected(); +} + +void DBusInterface::watchAdded(Watch *watch) +{ + QString address = watch->getAddress().toString().replace(":", "_"); + if (m_dbusWatches.contains(address)) + return; + + DBusWatch *dbusWatch = new DBusWatch(watch, m_watchesManager, this); + m_dbusWatches.insert(address, dbusWatch); + QDBusConnection::sessionBus().registerObject("/org/starfish/" + address, dbusWatch, QDBusConnection::ExportAllContents); + + emit WatchesChanged(); +} + +void DBusInterface::watchRemoved(Watch *watch) +{ + QString address = watch->getAddress().toString().replace(":", "_"); + + QDBusConnection::sessionBus().unregisterObject("/org/starfish/" + address); + m_dbusWatches.remove(address); + + emit WatchesChanged(); +} + diff --git a/starfishd/dbusinterface.h b/starfishd/dbusinterface.h new file mode 100644 index 0000000..560db84 --- /dev/null +++ b/starfishd/dbusinterface.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 DBUSINTERFACE_H +#define DBUSINTERFACE_H + +#include "watchesmanager.h" + +#include +#include +#include + +class Watch; + +class DBusWatch: public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.starfish.Watch") +public: + DBusWatch(Watch *watch, WatchesManager* wm, QObject *parent); + +signals: + void Connected(); + void Disconnected(); + + void LevelChanged(quint8); + +public slots: + void SelectWatch(); + + QString Address() const; + QString Name() const; + + quint8 BatteryLevel(); + void RequestScreenshot(); + void WeatherSetCityName(QString cityName); + +private: + Watch *m_watch; + + WatchesManager* m_wm; + + BatteryService *m_batteryService; + ScreenshotService *m_screenshotService; + WeatherService *m_weatherService; +}; + +class DBusInterface : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.starfish.Manager") + +public: + explicit DBusInterface(WatchesManager *wm, QObject *parent = 0); + +public slots: + Q_SCRIPTABLE QString Version(); + Q_SCRIPTABLE QList ListWatches(); + Q_SCRIPTABLE QDBusObjectPath SelectedWatch(); + Q_SCRIPTABLE bool SelectedWatchConnected(); + +signals: + Q_SCRIPTABLE void WatchesChanged(); + Q_SCRIPTABLE void NameChanged(); + Q_SCRIPTABLE void SelectedWatchChanged(); + Q_SCRIPTABLE void SelectedWatchConnectedChanged(); + +private slots: + void watchAdded(Watch *watch); + void watchRemoved(Watch *watch); + +private: + QHash m_dbusWatches; + WatchesManager *m_watchesManager; +}; + +#endif // DBUSINTERFACE_H + diff --git a/starfishd/libasteroid b/starfishd/libasteroid new file mode 160000 index 0000000..86df336 --- /dev/null +++ b/starfishd/libasteroid @@ -0,0 +1 @@ +Subproject commit 86df3361c937c33e85d6ba41f1666c0d01a7768d diff --git a/starfishd/libwatchfish/COPYING b/starfishd/libwatchfish/COPYING new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/starfishd/libwatchfish/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. 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 +them 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 prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. 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. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey 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; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If 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 convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU 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 that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + 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. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +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. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + 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 +state 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 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 3 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 . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program 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, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/starfishd/libwatchfish/calendarevent.cpp b/starfishd/libwatchfish/calendarevent.cpp new file mode 100644 index 0000000..3e97243 --- /dev/null +++ b/starfishd/libwatchfish/calendarevent.cpp @@ -0,0 +1,119 @@ +#include "calendarevent.h" + +namespace watchfish +{ + +struct CalendarEventData : public QSharedData +{ + QString uid; + QDateTime start; + QDateTime end; + QString title; + QString location; + QString description; + bool allDay; +}; + +CalendarEvent::CalendarEvent() : data(new CalendarEventData) +{ +} + +CalendarEvent::CalendarEvent(const CalendarEvent &rhs) : data(rhs.data) +{ +} + +CalendarEvent &CalendarEvent::operator=(const CalendarEvent &rhs) +{ + if (this != &rhs) + data.operator=(rhs.data); + return *this; +} + +CalendarEvent::~CalendarEvent() +{ +} + +QString CalendarEvent::uid() const +{ + return data->uid; +} + +void CalendarEvent::setUid(const QString &v) +{ + if (data->uid != v) { + data->uid = v; + } +} + + +QDateTime CalendarEvent::start() const +{ + return data->start; +} + +void CalendarEvent::setStart(const QDateTime &v) +{ + if (data->start != v) { + data->start = v; + } +} + +QDateTime CalendarEvent::end() const +{ + return data->end; +} + +void CalendarEvent::setEnd(const QDateTime &v) +{ + if (data->end != v) { + data->end = v; + } +} + +QString CalendarEvent::title() const +{ + return data->title; +} + +void CalendarEvent::setTitle(const QString &v) +{ + if (data->title != v) { + data->title = v; + } +} + +QString CalendarEvent::location() const +{ + return data->location; +} + +void CalendarEvent::setLocation(const QString &v) +{ + if (data->location != v) { + data->location = v; + } +} + +QString CalendarEvent::description() const +{ + return data->description; +} + +void CalendarEvent::setDescription(const QString &v) +{ + if (data->description != v) { + data->description = v; + } +} + +bool CalendarEvent::allDay() const { + return data->allDay; +} + +void CalendarEvent::setAllDay(bool allDay) { + if (data->allDay != allDay) { + data->allDay = allDay; + } +} + +} diff --git a/starfishd/libwatchfish/calendarevent.h b/starfishd/libwatchfish/calendarevent.h new file mode 100644 index 0000000..84c3d7e --- /dev/null +++ b/starfishd/libwatchfish/calendarevent.h @@ -0,0 +1,58 @@ +#ifndef CALENDAREVENT_H +#define CALENDAREVENT_H + +#include +#include +#include + +namespace watchfish +{ + +struct CalendarEventData; + +class CalendarEvent +{ + Q_GADGET + + Q_PROPERTY(QString uid READ uid WRITE setUid) + Q_PROPERTY(QDateTime start READ start WRITE setStart) + Q_PROPERTY(QDateTime end READ end WRITE setEnd) + Q_PROPERTY(QString title READ title WRITE setTitle) + Q_PROPERTY(QString location READ location WRITE setLocation) + Q_PROPERTY(QString description READ description WRITE setDescription) + Q_PROPERTY(bool allDay READ allDay WRITE setAllDay) + +public: + CalendarEvent(); + CalendarEvent(const CalendarEvent &); + CalendarEvent &operator=(const CalendarEvent &); + ~CalendarEvent(); + + QString uid() const; + void setUid(const QString &uid); + + QDateTime start() const; + void setStart(const QDateTime &state); + + QDateTime end() const; + void setEnd(const QDateTime &end); + + QString title() const; + void setTitle(const QString &v); + + QString location() const; + void setLocation(const QString &v); + + QString description() const; + void setDescription(const QString &v); + + bool allDay() const; + void setAllDay(bool allDay); + +private: + QSharedDataPointer data; +}; + +} + +#endif // CALENDAREVENT_H diff --git a/starfishd/libwatchfish/calendarsource.cpp b/starfishd/libwatchfish/calendarsource.cpp new file mode 100644 index 0000000..8a395db --- /dev/null +++ b/starfishd/libwatchfish/calendarsource.cpp @@ -0,0 +1,113 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2016 Javier S. Pedro + * + * 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 3 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 "calendarsource.h" +#include "calendarsource_p.h" + +namespace watchfish +{ + +Q_LOGGING_CATEGORY(calendarSourceCat, "watchfish-CalendarSource") + +CalendarSourcePrivate::CalendarSourcePrivate(CalendarSource *q) + : calendar(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone())), + calendarStorage(calendar->defaultStorage(calendar)), + q_ptr(q) +{ + calendarStorage->registerObserver(this); + if (!calendarStorage->open()) { + qCWarning(calendarSourceCat) << "Cannot open calendar database"; + } +} + +CalendarSourcePrivate::~CalendarSourcePrivate() +{ + calendarStorage->unregisterObserver(this); +} + +void CalendarSourcePrivate::storageModified(mKCal::ExtendedStorage *storage, const QString &info) +{ + Q_Q(CalendarSource); + Q_UNUSED(storage); + qCDebug(calendarSourceCat) << "Storage modified:" << info; + emit q->changed(); +} + +void CalendarSourcePrivate::storageProgress(mKCal::ExtendedStorage *storage, const QString &info) +{ + Q_UNUSED(storage); + Q_UNUSED(info); + // Nothing to do +} + +void CalendarSourcePrivate::storageFinished(mKCal::ExtendedStorage *storage, bool error, const QString &info) +{ + Q_UNUSED(storage); + Q_UNUSED(error); + Q_UNUSED(info); + // Nothing to do +} + +CalendarEvent CalendarSourcePrivate::convertToEvent(const mKCal::ExtendedCalendar::ExpandedIncidence &expanded) +{ + const KCalCore::Incidence::Ptr &incidence = expanded.second; + CalendarEvent event; + + event.setUid(incidence->uid()); + + event.setStart(expanded.first.dtStart); + event.setEnd(expanded.first.dtEnd); + + event.setAllDay(incidence->allDay()); + event.setTitle(incidence->summary()); + event.setLocation(incidence->location()); + + return event; +} + +CalendarSource::CalendarSource(QObject *parent) + : QObject(parent), d_ptr(new CalendarSourcePrivate(this)) +{ +} + +CalendarSource::~CalendarSource() +{ + delete d_ptr; +} + +QList CalendarSource::fetchEvents(const QDate &start, const QDate &end, + bool startInclusive, bool endInclusive) +{ + Q_D(CalendarSource); + int count; + count = d->calendarStorage->loadRecurringIncidences(); + qCDebug(calendarSourceCat) << "Loaded" << count << "recurring events"; + count = d->calendarStorage->load(start, end); + qCDebug(calendarSourceCat) << "Loaded" << count << "normal events"; + + QList events; + QVector incidences = d->calendar->rawExpandedEvents(start, end, startInclusive, endInclusive); + Q_FOREACH(const mKCal::ExtendedCalendar::ExpandedIncidence &expanded, incidences) { + events.append(d->convertToEvent(expanded)); + } + + qCDebug(calendarSourceCat) << "Returning" << events.size() << "events"; + return events; +} + +} diff --git a/starfishd/libwatchfish/calendarsource.h b/starfishd/libwatchfish/calendarsource.h new file mode 100644 index 0000000..981c497 --- /dev/null +++ b/starfishd/libwatchfish/calendarsource.h @@ -0,0 +1,54 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2016 Javier S. Pedro + * + * 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 3 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 WATCHFISH_CALENDARSOURCE_H +#define WATCHFISH_CALENDARSOURCE_H + +#include + +#include "calendarevent.h" + +namespace watchfish +{ + +Q_DECLARE_LOGGING_CATEGORY(calendarSourceCat) + +class CalendarSourcePrivate; + +class CalendarSource : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(CalendarSource) + +public: + explicit CalendarSource(QObject *parent = 0); + ~CalendarSource(); + + Q_INVOKABLE QList fetchEvents(const QDate &start, const QDate &end, + bool startInclusive = false, bool endInclusive = false); + +signals: + void changed(); + +private: + CalendarSourcePrivate * const d_ptr; +}; + +} + +#endif // WATCHFISH_CALENDARSOURCE_H diff --git a/starfishd/libwatchfish/calendarsource_p.h b/starfishd/libwatchfish/calendarsource_p.h new file mode 100644 index 0000000..97b7ef2 --- /dev/null +++ b/starfishd/libwatchfish/calendarsource_p.h @@ -0,0 +1,52 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2016 Javier S. Pedro + * + * 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 3 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 WATCHFISH_CALENDARSOURCE_P_H +#define WATCHFISH_CALENDARSOURCE_P_H + +#include +#include "calendarsource.h" + +namespace watchfish +{ + +class CalendarSourcePrivate : public QObject, public mKCal::ExtendedStorageObserver +{ + Q_OBJECT + +public: + explicit CalendarSourcePrivate(CalendarSource *q); + ~CalendarSourcePrivate(); + + mKCal::ExtendedCalendar::Ptr calendar; + mKCal::ExtendedStorage::Ptr calendarStorage; + + void storageModified(mKCal::ExtendedStorage *storage, const QString &info) Q_DECL_OVERRIDE; + void storageProgress(mKCal::ExtendedStorage *storage, const QString &info) Q_DECL_OVERRIDE; + void storageFinished(mKCal::ExtendedStorage *storage, bool error, const QString &info) Q_DECL_OVERRIDE; + + static CalendarEvent convertToEvent(const mKCal::ExtendedCalendar::ExpandedIncidence &expanded); + +private: + CalendarSource * const q_ptr; + Q_DECLARE_PUBLIC(CalendarSource) +}; + +} + +#endif // WATCHFISH_CALENDARSOURCE_P_H diff --git a/starfishd/libwatchfish/com.Meego.MainVolume2.xml b/starfishd/libwatchfish/com.Meego.MainVolume2.xml new file mode 100644 index 0000000..9b5b941 --- /dev/null +++ b/starfishd/libwatchfish/com.Meego.MainVolume2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/starfishd/libwatchfish/libwatchfish.pri b/starfishd/libwatchfish/libwatchfish.pri new file mode 100644 index 0000000..60a493a --- /dev/null +++ b/starfishd/libwatchfish/libwatchfish.pri @@ -0,0 +1,38 @@ +CONFIG += link_pkgconfig + +contains(WATCHFISH_FEATURES, notificationmonitor) { + PKGCONFIG += dbus-1 + HEADERS += $$PWD/notificationmonitor.h $$PWD/notificationmonitor_p.h $$PWD/notification.h + SOURCES += $$PWD/notificationmonitor.cpp $$PWD/notification.cpp +} + +contains(WATCHFISH_FEATURES, walltime) { + PKGCONFIG += timed-qt5 + HEADERS += $$PWD/walltimemonitor.h $$PWD/walltimemonitor_p.h + SOURCES += $$PWD/walltimemonitor.cpp +} + +contains(WATCHFISH_FEATURES, music) { + PKGCONFIG += mpris-qt5 + HEADERS += $$PWD/musiccontroller.h $$PWD/musiccontroller_p.h + SOURCES += $$PWD/musiccontroller.cpp + DBUS_INTERFACES += $$PWD/com.Meego.MainVolume2.xml +} + +contains(WATCHFISH_FEATURES, calendar) { + PKGCONFIG += libmkcal-qt5 libkcalcoren-qt5 + HEADERS += $$PWD/calendarsource.h $$PWD/calendarsource_p.h $$PWD/calendarevent.h + SOURCES += $$PWD/calendarsource.cpp $$PWD/calendarevent.cpp +} + +contains(WATCHFISH_FEATURES, voicecall) { + HEADERS += $$PWD/voicecallcontroller.h $$PWD/voicecallcontroller_p.h + SOURCES += $$PWD/voicecallcontroller.cpp + DBUS_INTERFACES += org.nemomobile.voicecall.VoiceCallManager.xml org.nemomobile.voicecall.VoiceCall.xml +} + +contains (WATCHFISH_FEATURES, volume) { + HEADERS += $$PWD/volumecontroller.h $$PWD/volumecontroller_p.h + SOURCES += $$PWD/volumecontroller.cpp + DBUS_INTERFACES += $$PWD/com.Meego.MainVolume2.xml +} diff --git a/starfishd/libwatchfish/libwatchfish.pro b/starfishd/libwatchfish/libwatchfish.pro new file mode 100644 index 0000000..246eda2 --- /dev/null +++ b/starfishd/libwatchfish/libwatchfish.pro @@ -0,0 +1,8 @@ +TARGET = watchfish + +TEMPLATE = lib +CONFIG += staticlib +QT += dbus + +WATCHFISH_FEATURES = notificationmonitor walltime music calendar voicecall +include(libwatchfish.pri) diff --git a/starfishd/libwatchfish/musiccontroller.cpp b/starfishd/libwatchfish/musiccontroller.cpp new file mode 100644 index 0000000..638d440 --- /dev/null +++ b/starfishd/libwatchfish/musiccontroller.cpp @@ -0,0 +1,319 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2015 Javier S. Pedro + * + * 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 3 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 +#include + +#include "musiccontroller.h" +#include "musiccontroller_p.h" + +namespace watchfish +{ + +Q_LOGGING_CATEGORY(musicControllerCat, "watchfish-MusicController") + +MusicControllerPrivate::MusicControllerPrivate(MusicController *q) + : manager(new MprisManager(this)), q_ptr(q) +{ + connect(manager, &MprisManager::currentServiceChanged, + this, &MusicControllerPrivate::handleCurrentServiceChanged); + connect(manager, &MprisManager::playbackStatusChanged, + this, &MusicControllerPrivate::handlePlaybackStatusChanged); + connect(manager, &MprisManager::metadataChanged, + this, &MusicControllerPrivate::handleMetadataChanged); + connect(manager, &MprisManager::shuffleChanged, + q, &MusicController::shuffleChanged); + connect(manager, &MprisManager::loopStatusChanged, + q, &MusicController::repeatChanged); +} + +MusicControllerPrivate::~MusicControllerPrivate() +{ +} + +QString MusicControllerPrivate::stripAlbumArtComponent(const QString& component) +{ + static QRegExp rsb("\\[.*\\]"); + static QRegExp rfb("{.*}"); + static QRegExp rrb("\\(.*\\)"); + static QRegExp stripB("^[()_{}[]!@#$^&*+=|\\\\/\"'?<>~`\\s\\t]*"); + static QRegExp stripE("[()_{}[]!@#$^&*+=|\\\\/\"'?<>~`\\s\\t]*$"); + QString s(component); + + if (s.isEmpty()) { + return QString(" "); + } + + s = s.replace(rsb, ""); + s = s.replace(rfb, ""); + s = s.replace(rrb, ""); + s = s.replace(stripB, ""); + s = s.replace(stripE, ""); + s = s.replace(" ", " "); + s = s.replace("\t", " "); + + return s.toLower(); +} + +QString MusicControllerPrivate::findAlbumArt(const QString &artist, const QString &album) +{ + QDir dir(QDir::homePath() + "/.cache/media-art/"); + QByteArray first_hash = QCryptographicHash::hash(stripAlbumArtComponent(artist).toUtf8(), + QCryptographicHash::Md5).toHex(); + QByteArray second_hash = QCryptographicHash::hash(stripAlbumArtComponent(album).toUtf8(), + QCryptographicHash::Md5).toHex(); + QString file = QString("album-%1-%2.jpeg").arg(first_hash.constData()).arg(second_hash.constData()); + qCDebug(musicControllerCat()) << "checking for albumart in" << file; + if (dir.exists(file)) { + return dir.absoluteFilePath(file); + } + + // Now try with an empty artist name + first_hash = QCryptographicHash::hash(QString(" ").toUtf8(), QCryptographicHash::Md5).toHex(); + file = QString("album-%1-%2.jpeg").arg(first_hash.constData()).arg(second_hash.constData()); + qCDebug(musicControllerCat()) << "checking for albumart in" << file; + if (dir.exists(file)) { + return dir.absoluteFilePath(file); + } + + return QString(); +} + +void MusicControllerPrivate::updateStatus() +{ + Q_Q(MusicController); + QString service = manager->currentService(); + MusicController::Status newStatus; + + if (service.isEmpty()) { + newStatus = MusicController::StatusNoPlayer; + } else { + switch (manager->playbackStatus()) { + case Mpris::Playing: + newStatus = MusicController::StatusPlaying; + break; + case Mpris::Paused: + newStatus = MusicController::StatusPaused; + break; + default: + newStatus = MusicController::StatusStopped; + break; + } + } + + if (newStatus != curStatus) { + curStatus = newStatus; + emit q->statusChanged(); + } +} + +void MusicControllerPrivate::updateAlbumArt() +{ + Q_Q(MusicController); + QString newAlbumArt = findAlbumArt(curArtist, curAlbum); + if (newAlbumArt != curAlbumArt) { + curAlbumArt = newAlbumArt; + emit q->albumArtChanged(); + } +} + +void MusicControllerPrivate::updateMetadata() +{ + Q_Q(MusicController); + QVariantMap metadata = manager->metadata(); + bool checkAlbumArt = false; + + qCDebug(musicControllerCat()) << metadata; + + QString newArtist = metadata.value("xesam:artist").toString(), + newAlbum = metadata.value("xesam:album").toString(), + newTitle = metadata.value("xesam:title").toString(); + + if (newArtist != curArtist) { + curArtist = newArtist; + checkAlbumArt = true; + emit q->artistChanged(); + } + + if (newAlbum != curAlbum) { + curAlbum = newAlbum; + checkAlbumArt = true; + emit q->albumChanged(); + } + + if (newTitle != curTitle) { + curTitle = newTitle; + emit q->titleChanged(); + } + + if (checkAlbumArt) { + updateAlbumArt(); + } + + int newDuration = metadata.value("mpris:length").toULongLong() / 1000UL; + if (newDuration != curDuration) { + curDuration = newDuration; + emit q->durationChanged(); + } + + emit q->metadataChanged(); +} + +void MusicControllerPrivate::handleCurrentServiceChanged() +{ + Q_Q(MusicController); + qCDebug(musicControllerCat()) << manager->currentService(); + updateStatus(); + emit q->serviceChanged(); +} + +void MusicControllerPrivate::handlePlaybackStatusChanged() +{ + qCDebug(musicControllerCat()) << manager->playbackStatus(); + updateStatus(); +} + +void MusicControllerPrivate::handleMetadataChanged() +{ + updateMetadata(); +} + +MusicController::MusicController(QObject *parent) + : QObject(parent), d_ptr(new MusicControllerPrivate(this)) +{ +} + +MusicController::~MusicController() +{ + delete d_ptr; +} + +MusicController::Status MusicController::status() const +{ + Q_D(const MusicController); + return d->curStatus; +} + +QString MusicController::service() const +{ + Q_D(const MusicController); + return d->manager->currentService(); +} + +QVariantMap MusicController::metadata() const +{ + Q_D(const MusicController); + return d->manager->metadata(); +} + +QString MusicController::title() const +{ + Q_D(const MusicController); + return d->curTitle; +} + +QString MusicController::album() const +{ + Q_D(const MusicController); + return d->curAlbum; +} + +QString MusicController::artist() const +{ + Q_D(const MusicController); + return d->curArtist; +} + +QString MusicController::albumArt() const +{ + Q_D(const MusicController); + return d->curAlbumArt; +} + +int MusicController::duration() const +{ + Q_D(const MusicController); + return d->curDuration; +} + +MusicController::RepeatStatus MusicController::repeat() const +{ + Q_D(const MusicController); + switch (d->manager->loopStatus()) { + case Mpris::None: + default: + return RepeatNone; + case Mpris::Track: + return RepeatTrack; + case Mpris::Playlist: + return RepeatPlaylist; + } +} + +bool MusicController::shuffle() const +{ + Q_D(const MusicController); + return d->manager->shuffle(); +} + +int MusicController::volume() const +{ + return 100; // TODO volume +} + +void MusicController::play() +{ + Q_D(MusicController); + d->manager->play(); +} + +void MusicController::pause() +{ + Q_D(MusicController); + d->manager->pause(); +} + +void MusicController::playPause() +{ + Q_D(MusicController); + d->manager->playPause(); +} + +void MusicController::next() +{ + Q_D(MusicController); + d->manager->next(); +} + +void MusicController::previous() +{ + Q_D(MusicController); + d->manager->previous(); +} + +void MusicController::volumeUp() +{ + +} + +void MusicController::volumeDown() +{ + +} + +} diff --git a/starfishd/libwatchfish/musiccontroller.h b/starfishd/libwatchfish/musiccontroller.h new file mode 100644 index 0000000..acf5beb --- /dev/null +++ b/starfishd/libwatchfish/musiccontroller.h @@ -0,0 +1,101 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2015 Javier S. Pedro + * + * 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 3 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 WATCHFISH_MUSICCONTROLLER_H +#define WATCHFISH_MUSICCONTROLLER_H + +#include + +namespace watchfish +{ + +Q_DECLARE_LOGGING_CATEGORY(musicControllerCat) + +class MusicControllerPrivate; + +class MusicController : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(MusicController) + Q_ENUMS(Status) + +public: + explicit MusicController(QObject *parent = 0); + ~MusicController(); + + enum Status { + StatusNoPlayer = 0, + StatusStopped, + StatusPaused, + StatusPlaying + }; + + enum RepeatStatus { + RepeatNone = 0, + RepeatTrack, + RepeatPlaylist + }; + + Status status() const; + QString service() const; + + QVariantMap metadata() const; + + QString title() const; + QString album() const; + QString artist() const; + + QString albumArt() const; + + int duration() const; + + RepeatStatus repeat() const; + bool shuffle() const; + + int volume() const; + +public slots: + void play(); + void pause(); + void playPause(); + void next(); + void previous(); + + void volumeUp(); + void volumeDown(); + +signals: + void statusChanged(); + void serviceChanged(); + void metadataChanged(); + void titleChanged(); + void albumChanged(); + void artistChanged(); + void albumArtChanged(); + void durationChanged(); + void repeatChanged(); + void shuffleChanged(); + void volumeChanged(); + +private: + MusicControllerPrivate * const d_ptr; +}; + +} + +#endif // WATCHFISH_MUSICCONTROLLER_H diff --git a/starfishd/libwatchfish/musiccontroller_p.h b/starfishd/libwatchfish/musiccontroller_p.h new file mode 100644 index 0000000..9ade33a --- /dev/null +++ b/starfishd/libwatchfish/musiccontroller_p.h @@ -0,0 +1,67 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2016 Javier S. Pedro + * + * 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 3 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 WATCHFISH_MUSICCONTROLLER_P_H +#define WATCHFISH_MUSICCONTROLLER_P_H + +#include +#include + +#include "musiccontroller.h" + +namespace watchfish +{ + +class MusicControllerPrivate : public QObject +{ + Q_OBJECT + +public: + explicit MusicControllerPrivate(MusicController *q); + ~MusicControllerPrivate(); + +public: + MprisManager *manager; + MusicController::Status curStatus; + QString curTitle; + QString curAlbum; + QString curArtist; + QString curAlbumArt; + int curDuration; + +private: + static QString stripAlbumArtComponent(const QString& component); + static QString findAlbumArt(const QString &artist, const QString &album); + void updateStatus(); + void updateAlbumArt(); + void updateMetadata(); + +private slots: + void handleCurrentServiceChanged(); + void handlePlaybackStatusChanged(); + void handleMetadataChanged(); + +private: + MusicController * const q_ptr; + Q_DECLARE_PUBLIC(MusicController) +}; + +} + +#endif // WATCHFISH_MUSICCONTROLLER_P_H + diff --git a/starfishd/libwatchfish/notification.cpp b/starfishd/libwatchfish/notification.cpp new file mode 100644 index 0000000..76d9be7 --- /dev/null +++ b/starfishd/libwatchfish/notification.cpp @@ -0,0 +1,282 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2015 Javier S. Pedro + * + * 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 3 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 +#include +#include +#include "notification.h" + +namespace watchfish +{ + +namespace +{ +struct Action +{ + QString service; + QString path; + QString iface; + QString method; + QStringList args; +}; +} + +struct NotificationPrivate +{ + uint id; + QString appId; + QString appName; + QString summary; + QString body; + QDateTime timestamp; + QString icon; + QString category; + quint8 urgency; + bool transient; + QString previewSummary; + QString previewBody; + QHash actions; +}; + +Notification::Notification(uint id, QObject *parent) : QObject(parent), d_ptr(new NotificationPrivate) +{ + Q_D(Notification); + d->id = id; + d->urgency = 0; + d->transient = false; +} + +Notification::~Notification() +{ +} + +uint Notification::id() const +{ + Q_D(const Notification); + return d->id; +} + +QString Notification::appId() const +{ + Q_D(const Notification); + return d->appId; +} + +void Notification::setAppId(const QString &appId) +{ + Q_D(Notification); + if (appId != d->appId) { + d->appId = appId; + emit appIdChanged(); + } +} + +QString Notification::appName() const +{ + Q_D(const Notification); + return d->appName; +} + +void Notification::setAppName(const QString &appName) +{ + Q_D(Notification); + if (appName != d->appName) { + d->appName = appName; + emit appNameChanged(); + } +} + +QString Notification::summary() const +{ + Q_D(const Notification); + return d->summary; +} + +void Notification::setSummary(const QString &summary) +{ + Q_D(Notification); + if (summary != d->summary) { + d->summary = summary; + emit summaryChanged(); + } +} + +QString Notification::body() const +{ + Q_D(const Notification); + return d->body; +} + +void Notification::setBody(const QString &body) +{ + Q_D(Notification); + if (body != d->body) { + d->body = body; + emit bodyChanged(); + } +} + +QDateTime Notification::timestamp() const +{ + Q_D(const Notification); + return d->timestamp; +} + +void Notification::setTimestamp(const QDateTime &dt) +{ + Q_D(Notification); + if (dt != d->timestamp) { + d->timestamp = dt; + emit timestampChanged(); + } +} + +QString Notification::icon() const +{ + Q_D(const Notification); + return d->icon; +} + +void Notification::setIcon(const QString &icon) +{ + Q_D(Notification); + if (icon != d->icon) { + d->icon = icon; + emit iconChanged(); + } +} + +QString Notification::category() const +{ + Q_D(const Notification); + return d->category; +} + +void Notification::setCategory(const QString &category) +{ + Q_D(Notification); + if (category != d->category) { + d->category = category; + emit categoryChanged(); + } +} + +int Notification::urgency() const +{ + Q_D(const Notification); + return d->urgency; +} + +void Notification::setUrgency(int urgency) +{ + Q_D(Notification); + if (urgency != d->urgency) { + d->urgency = urgency; + emit urgencyChanged(); + } +} + +bool Notification::transient() const +{ + Q_D(const Notification); + return d->transient; +} + +void Notification::setTransient(bool transient) +{ + Q_D(Notification); + if (transient != d->transient) { + d->transient = transient; + emit transientChanged(); + } +} + +QString Notification::previewSummary() const +{ + Q_D(const Notification); + return d->previewSummary; +} + +void Notification::setPreviewSummary(const QString &summary) +{ + Q_D(Notification); + if (summary != d->previewSummary) { + d->previewSummary = summary; + emit previewSummaryChanged(); + } +} + +QString Notification::previewBody() const +{ + Q_D(const Notification); + return d->previewBody; +} + +void Notification::setPreviewBody(const QString &body) +{ + Q_D(Notification); + if (body != d->previewBody) { + d->previewBody = body; + emit previewBodyChanged(); + } +} + +QStringList Notification::actions() const +{ + Q_D(const Notification); + return d->actions.keys(); +} + +void Notification::addDBusAction(const QString &action, const QString &service, const QString &path, const QString &iface, const QString &method, const QStringList &args) +{ + Q_D(Notification); + Action &a = d->actions[action]; + a.service = service; + a.path = path; + a.iface = iface; + a.method = method; + a.args = args; +} + +void Notification::invokeAction(const QString &action) +{ + Q_D(Notification); + if (d->actions.contains(action)) { + const Action &a = d->actions[action]; + if (!a.service.isEmpty()) { + QDBusMessage msg = QDBusMessage::createMethodCall(a.service, a.path, a.iface, a.method); + foreach (const QString &arg, a.args) { + msg << arg; + } + QDBusConnection::sessionBus().asyncCall(msg); + } + } +} + +void Notification::close() +{ + Q_D(Notification); + QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + "org.freedesktop.Notifications", + "CloseNotification"); + msg << quint32(d->id); + QDBusConnection::sessionBus().asyncCall(msg); +} + +} diff --git a/starfishd/libwatchfish/notification.h b/starfishd/libwatchfish/notification.h new file mode 100644 index 0000000..36690c4 --- /dev/null +++ b/starfishd/libwatchfish/notification.h @@ -0,0 +1,137 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2015 Javier S. Pedro + * + * 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 3 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 WATCHFISH_NOTIFICATION_H +#define WATCHFISH_NOTIFICATION_H + +#include +#include +#include + +namespace watchfish +{ + +class NotificationPrivate; + +class Notification : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(Notification) + + /** Notification ID */ + Q_PROPERTY(uint id READ id CONSTANT) + /** Binary/harbour name of sending program */ + Q_PROPERTY(QString appId READ appId WRITE setAppId NOTIFY appIdChanged) + /** Human readable name of sender program */ + Q_PROPERTY(QString appName READ appName WRITE setAppName NOTIFY appNameChanged) + Q_PROPERTY(QString summary READ summary WRITE setSummary NOTIFY summaryChanged) + Q_PROPERTY(QString body READ body WRITE setBody NOTIFY bodyChanged) + Q_PROPERTY(QDateTime timestamp READ timestamp WRITE setTimestamp NOTIFY timestampChanged) + /** Icon file path */ + Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged) + /** Category ID */ + Q_PROPERTY(QString category READ category WRITE setCategory NOTIFY categoryChanged) + Q_PROPERTY(int urgency READ urgency WRITE setUrgency NOTIFY urgencyChanged) + Q_PROPERTY(bool transient READ transient WRITE setTransient NOTIFY transientChanged) + + /* Nemo stuff */ + Q_PROPERTY(QString previewSummary READ previewSummary WRITE setPreviewSummary NOTIFY previewSummaryChanged) + Q_PROPERTY(QString previewBody READ previewBody WRITE setPreviewBody NOTIFY previewBodyChanged) + + Q_PROPERTY(QStringList actions READ actions NOTIFY actionsChanged) + + Q_ENUMS(CloseReason) + +public: + explicit Notification(uint id, QObject *parent = 0); + ~Notification(); + + enum CloseReason { + Expired = 1, + DismissedByUser = 2, + DismissedByProgram = 3, + ClosedOther = 4 + }; + + uint id() const; + + QString appId() const; + void setAppId(const QString &appId); + + QString appName() const; + void setAppName(const QString &appName); + + QString summary() const; + void setSummary(const QString &summary); + + QString body() const; + void setBody(const QString &body); + + QDateTime timestamp() const; + void setTimestamp(const QDateTime &dt); + + QString icon() const; + void setIcon(const QString &icon); + + QString category() const; + void setCategory(const QString &category); + + int urgency() const; + void setUrgency(int urgency); + + bool transient() const; + void setTransient(bool transient); + + QString previewSummary() const; + void setPreviewSummary(const QString &summary); + + QString previewBody() const; + void setPreviewBody(const QString &body); + + QStringList actions() const; + void addDBusAction(const QString &action, const QString &service, const QString &path, const QString &iface, const QString &method, const QStringList &args = QStringList()); + +public slots: + void invokeAction(const QString &action); + void close(); + +signals: + void appIdChanged(); + void appNameChanged(); + void summaryChanged(); + void bodyChanged(); + void timestampChanged(); + void iconChanged(); + void categoryChanged(); + void urgencyChanged(); + void transientChanged(); + + void previewSummaryChanged(); + void previewBodyChanged(); + + void actionsChanged(); + + void closed(CloseReason reason); + +private: + NotificationPrivate * const d_ptr; +}; + +} + +#endif // WATCHFISH_NOTIFICATION_H diff --git a/starfishd/libwatchfish/notificationmonitor.cpp b/starfishd/libwatchfish/notificationmonitor.cpp new file mode 100644 index 0000000..4b095b9 --- /dev/null +++ b/starfishd/libwatchfish/notificationmonitor.cpp @@ -0,0 +1,439 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2015 Javier S. Pedro + * + * 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 3 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 +#include +#include +#include + +#include "notification.h" +#include "notificationmonitor.h" +#include "notificationmonitor_p.h" + +namespace watchfish +{ + +Q_LOGGING_CATEGORY(notificationMonitorCat, "watchfish-NotificationMonitor") + +QDebug operator<<(QDebug &debug, const ProtoNotification &proto) +{ + QDebugStateSaver saver(debug); + Q_UNUSED(saver); + debug.nospace() << "Notification(appId=" << proto.appId << ", appName=" << proto.appName + << ", summary=" << proto.summary << ", body=" << proto.body + << ", appIcon=" << proto.appIcon + << ", hints=" << proto.hints << ", timeout=" << proto.expireTimeout + << ", actions=" << proto.actions << ")"; + return debug; +} + +NotificationMonitorPrivate::NotificationMonitorPrivate(NotificationMonitor *q) + : q_ptr(q) +{ + DBusError error = DBUS_ERROR_INIT; + _conn = dbus_bus_get_private(DBUS_BUS_SESSION, &error); + if (!_conn) { + qCWarning(notificationMonitorCat) << "Could not connect to the session bus"; + return; + } + + dbus_connection_set_exit_on_disconnect(_conn, FALSE); + + dbus_connection_set_watch_functions(_conn, busWatchAdd, busWatchRemove, + busWatchToggle, this, NULL); + + addMatchRule("type='method_call',interface='org.freedesktop.Notifications',member='Notify',eavesdrop='true'"); + addMatchRule("type='method_return',sender='org.freedesktop.Notifications',eavesdrop='true'"); + addMatchRule("type='signal',sender='org.freedesktop.Notifications',path='/org/freedesktop/Notifications',interface='org.freedesktop.Notifications',member='NotificationClosed'"); + + dbus_bool_t result = dbus_connection_add_filter(_conn, busMessageFilter, + this, NULL); + if (!result) { + qCWarning(notificationMonitorCat) << "Could not add filter"; + } + + qCDebug(notificationMonitorCat) << "Starting notification monitor"; +} + +NotificationMonitorPrivate::~NotificationMonitorPrivate() +{ + QMap::iterator it = _notifs.begin(); + while (it != _notifs.end()) { + delete it.value(); + } + +#if 0 /* No need to remove match rules since we're closing the connection. */ + removeMatchRule("type='method_call',interface='org.freedesktop.Notifications',member='Notify',eavesdrop='true'"); + removeMatchRule("type='method_return',sender='org.freedesktop.Notifications',eavesdrop='true'"); + removeMatchRule("type='signal',sender='org.freedesktop.Notifications',path='/org/freedesktop/Notifications',interface='org.freedesktop.Notifications',member='NotificationClosed'"); +#endif + + dbus_connection_remove_filter(_conn, busMessageFilter, this); + + dbus_connection_close(_conn); + dbus_connection_unref(_conn); +} + +void NotificationMonitorPrivate::processIncomingNotification(quint32 id, const ProtoNotification &proto) +{ + Q_Q(NotificationMonitor); + qCDebug(notificationMonitorCat) << "Incoming notification" << id << proto; + + Notification *n = _notifs.value(id, 0); + + bool is_new_notification = !n; + if (is_new_notification) { + n = new Notification(id, q); + } + + n->setAppId(proto.appId); + n->setAppName(proto.appName); + n->setSummary(proto.summary); + n->setBody(proto.body); + n->setIcon(proto.appIcon); + n->setTransient(proto.hints.value("transient", "false") == "true"); + + // Handle nemo specific stuff + QDateTime timestamp = QDateTime::fromString(proto.hints["x-nemo-timestamp"], Qt::ISODate); + if (timestamp.isValid()) { + n->setTimestamp(timestamp); + } else if (is_new_notification) { + n->setTimestamp(QDateTime::currentDateTime()); + } + + n->setCategory(proto.hints.value("category")); + + n->setPreviewSummary(proto.hints.value("x-nemo-preview-summary")); + n->setPreviewBody(proto.hints.value("x-nemo-preview-body")); + + // Nemo D-Bus actions... + for (int i = 0; i < proto.actions.size(); i += 2) { + const QString &actionName = proto.actions[i]; + QString hintName = QString("x-nemo-remote-action-%1").arg(actionName); + QString remote = proto.hints.value(hintName); + QStringList remoteParts = remote.split(' '); + if (remoteParts.size() >= 4) { + n->addDBusAction(actionName, + remoteParts[0], remoteParts[1], remoteParts[2], remoteParts[3], + remoteParts.mid(4)); + } + } + + if (is_new_notification) { + _notifs.insert(id, n); + emit q->notification(n); + } +} + +void NotificationMonitorPrivate::processCloseNotification(quint32 id, quint32 reason) +{ + qCDebug(notificationMonitorCat) << "Close notification" << id << reason; + Notification *n = _notifs.value(id, 0); + if (n) { + _notifs.remove(id); + emit n->closed(static_cast(reason)); + n->deleteLater(); + } else { + qCDebug(notificationMonitorCat) << " but it is not found"; + } +} + +void NotificationMonitorPrivate::sendMessageWithString(const char *service, const char *path, const char *iface, const char *method, const char *arg) +{ + DBusMessage *msg = dbus_message_new_method_call(service, path, iface, method); + Q_ASSERT(msg); + dbus_message_set_no_reply(msg, TRUE); + dbus_message_append_args(msg, + DBUS_TYPE_STRING, &arg, + DBUS_TYPE_INVALID); + dbus_connection_send(_conn, msg, NULL); + dbus_message_unref(msg); +} + +void NotificationMonitorPrivate::addMatchRule(const char *rule) +{ + sendMessageWithString("org.freedesktop.DBus", "/", + "org.freedesktop.DBus", "AddMatch", rule); +} + +void NotificationMonitorPrivate::removeMatchRule(const char *rule) +{ + sendMessageWithString("org.freedesktop.DBus", "/", + "org.freedesktop.DBus", "RemoveMatch", rule); +} + +ProtoNotification NotificationMonitorPrivate::parseNotifyCall(DBusMessage *msg) const +{ + ProtoNotification proto; + DBusMessageIter iter, sub; + const char *app_name, *app_icon, *summary, *body; + quint32 replaces_id; + qint32 expire_timeout; + + if (strcmp(dbus_message_get_signature(msg), "susssasa{sv}i") != 0) { + qCWarning(notificationMonitorCat) << "Invalid signature"; + return proto; + } + + dbus_message_iter_init(msg, &iter); + Q_ASSERT(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING); + dbus_message_iter_get_basic(&iter, &app_name); + dbus_message_iter_next(&iter); + Q_ASSERT(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_UINT32); + dbus_message_iter_get_basic(&iter, &replaces_id); + dbus_message_iter_next(&iter); + Q_ASSERT(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING); + dbus_message_iter_get_basic(&iter, &app_icon); + dbus_message_iter_next(&iter); + dbus_message_iter_get_basic(&iter, &summary); + dbus_message_iter_next(&iter); + dbus_message_iter_get_basic(&iter, &body); + dbus_message_iter_next(&iter); + + // Add basic notification information + proto.appName = QString::fromUtf8(app_name); + proto.appIcon = QString::fromUtf8(app_icon); + proto.summary = QString::fromUtf8(summary); + proto.body = QString::fromUtf8(body); + + dbus_message_iter_recurse(&iter, &sub); + while (dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRING) { + const char *action; + dbus_message_iter_get_basic(&sub, &action); + proto.actions.append(QString::fromUtf8(action)); + dbus_message_iter_next(&sub); + } + dbus_message_iter_next(&iter); + + // Parse extended information + QHash hints; + dbus_message_iter_recurse(&iter, &sub); + while (dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter entry, value; + const char *key; + + dbus_message_iter_recurse(&sub, &entry); + dbus_message_iter_get_basic(&entry, &key); + dbus_message_iter_next(&entry); + + dbus_message_iter_recurse(&entry, &value); + if (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) { + const char *s; + dbus_message_iter_get_basic(&value, &s); + hints.insert(key, QString::fromUtf8(s)); + } + + dbus_message_iter_next(&sub); + } + + dbus_message_iter_next(&iter); + Q_ASSERT(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT32); + dbus_message_iter_get_basic(&iter, &expire_timeout); + proto.expireTimeout = expire_timeout; + + if (hints.contains("x-nemo-owner")) { + proto.appId = hints["x-nemo-owner"]; + if (proto.appName.isEmpty()) { + // Lookup application name via .desktop file + proto.appName = getAppName(proto.appId); + // Otherwise just use the appId + if (proto.appName.isEmpty()) { + proto.appName = proto.appId; + } + } + } + + // Lookup category info and merge it with the notification info if found. + if (hints.contains("category")) { + proto.hints = getCategoryInfo(hints["category"]); + proto.hints.unite(hints); + } else { + proto.hints = hints; + } + + return proto; +} + +QHash NotificationMonitorPrivate::getCategoryInfo(const QString &category) const +{ + bool in_cache = _categoryCache.contains(category); + bool needs_check = !in_cache || + _categoryCache[category].lastCheckTime.secsTo(QDateTime::currentDateTime()) > CATEGORY_REFRESH_CHECK_TIME; + if (needs_check) { + QFileInfo finfo(QString("%1/%2.conf").arg(CATEGORY_DEFINITION_FILE_DIRECTORY, category)); + if (finfo.exists()) { + NotificationCategoryCacheEntry &entry = _categoryCache[category]; + if (!in_cache || finfo.lastModified() > entry.lastReadTime) { + QSettings settings(finfo.absoluteFilePath(), QSettings::IniFormat); + entry.data.clear(); + foreach (const QString &key, settings.allKeys()) { + entry.data[key] = settings.value(key).toString(); + } + entry.lastReadTime = finfo.lastModified(); + } + entry.lastCheckTime = QDateTime::currentDateTime(); + return entry.data; + } else { + qCWarning(notificationMonitorCat) << "Notification category" << category << "does not exist"; + _categoryCache.remove(category); + return QHash(); + } + } else { + return _categoryCache[category].data; + } +} + +QString NotificationMonitorPrivate::getAppName(const QString &id) const +{ + bool in_cache = _appNameCache.contains(id); + bool needs_check = !in_cache || + _appNameCache[id].lastCheckTime.secsTo(QDateTime::currentDateTime()) > DESKTOP_REFRESH_CHECK_TIME; + if (needs_check) { + AppNameCacheEntry &entry = _appNameCache[id]; + QFileInfo finfo(QString("%1/%2.desktop").arg(DESKTOP_FILE_DIRECTORY, id)); + if (finfo.exists()) { + if (!in_cache || finfo.lastModified() > entry.lastReadTime) { + QSettings settings(finfo.absoluteFilePath(), QSettings::IniFormat); + settings.beginGroup("Desktop Entry"); + entry.name = settings.value("Name").toString(); // TODO Localization + entry.lastReadTime = finfo.lastModified(); + } + } else { + qCWarning(notificationMonitorCat) << "Desktop file for" << id << "does not exist"; + // Cache negative results, since they might be common... + } + entry.lastCheckTime = QDateTime::currentDateTime(); + return entry.name; + } else { + return _appNameCache[id].name; + } +} + +dbus_bool_t NotificationMonitorPrivate::busWatchAdd(DBusWatch *watch, void *data) +{ + NotificationMonitorPrivate *self = static_cast(data); + NotificationMonitor *monitor = self->q_func(); + int socket = dbus_watch_get_socket(watch); + int flags = dbus_watch_get_flags(watch); + + QSocketNotifier::Type type; + switch (flags) { + case DBUS_WATCH_READABLE: + type = QSocketNotifier::Read; + break; + case DBUS_WATCH_WRITABLE: + type = QSocketNotifier::Write; + break; + default: + qCWarning(notificationMonitorCat) << "Can't add this type of watch" << flags; + return FALSE; + } + + QSocketNotifier *notifier = new QSocketNotifier(socket, type, monitor); + dbus_watch_set_data(watch, notifier, NULL); + + notifier->setEnabled(dbus_watch_get_enabled(watch)); + notifier->setProperty("dbus-watch", QVariant::fromValue(watch)); + + notifier->connect(notifier, SIGNAL(activated(int)), + self, SLOT(handleBusSocketActivated())); + + return TRUE; +} + +void NotificationMonitorPrivate::busWatchRemove(DBusWatch *watch, void *data) +{ + QSocketNotifier *notifier = static_cast(dbus_watch_get_data(watch)); + Q_UNUSED(data); + delete notifier; +} + +void NotificationMonitorPrivate::busWatchToggle(DBusWatch *watch, void *data) +{ + QSocketNotifier *notifier = static_cast(dbus_watch_get_data(watch)); + Q_UNUSED(data); + notifier->setEnabled(dbus_watch_get_enabled(watch)); +} + +DBusHandlerResult NotificationMonitorPrivate::busMessageFilter(DBusConnection *conn, DBusMessage *msg, void *user_data) +{ + NotificationMonitorPrivate *self = static_cast(user_data); + DBusError error = DBUS_ERROR_INIT; + Q_UNUSED(conn); + switch (dbus_message_get_type(msg)) { + case DBUS_MESSAGE_TYPE_METHOD_CALL: + if (dbus_message_is_method_call(msg, "org.freedesktop.Notifications", "Notify")) { + quint32 serial = dbus_message_get_serial(msg); + ProtoNotification proto = self->parseNotifyCall(msg); + self->_pendingConfirmation.insert(serial, proto); + } + break; + case DBUS_MESSAGE_TYPE_METHOD_RETURN: + if (self->_pendingConfirmation.contains(dbus_message_get_reply_serial(msg))) { + quint32 id; + if (dbus_message_get_args(msg, &error, DBUS_TYPE_UINT32, &id, DBUS_TYPE_INVALID)) { + ProtoNotification proto = self->_pendingConfirmation.take(dbus_message_get_reply_serial(msg)); + self->processIncomingNotification(id, proto); + } else { + qCWarning(notificationMonitorCat) << "Could not parse notification method return"; + } + } + break; + case DBUS_MESSAGE_TYPE_SIGNAL: + if (dbus_message_is_signal(msg, "org.freedesktop.Notifications", "NotificationClosed")) { + quint32 id, reason; + if (dbus_message_get_args(msg, &error, + DBUS_TYPE_UINT32, &id, + DBUS_TYPE_UINT32, &reason, + DBUS_TYPE_INVALID)) { + self->processCloseNotification(id, reason); + } else { + qCWarning(notificationMonitorCat) << "Failed to parse notification signal arguments"; + } + + } + break; + } + + return DBUS_HANDLER_RESULT_HANDLED; +} + +void NotificationMonitorPrivate::handleBusSocketActivated() +{ + QSocketNotifier *notifier = static_cast(sender()); + DBusWatch *watch = static_cast(notifier->property("dbus-watch").value()); + + dbus_watch_handle(watch, dbus_watch_get_flags(watch)); + + while (dbus_connection_get_dispatch_status(_conn) == DBUS_DISPATCH_DATA_REMAINS) { + dbus_connection_dispatch(_conn); + } +} + +NotificationMonitor::NotificationMonitor(QObject *parent) : + QObject(parent), d_ptr(new NotificationMonitorPrivate(this)) +{ + +} + +NotificationMonitor::~NotificationMonitor() +{ + delete d_ptr; +} + +} diff --git a/starfishd/libwatchfish/notificationmonitor.h b/starfishd/libwatchfish/notificationmonitor.h new file mode 100644 index 0000000..4aad942 --- /dev/null +++ b/starfishd/libwatchfish/notificationmonitor.h @@ -0,0 +1,54 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2015 Javier S. Pedro + * + * 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 3 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 WATCHFISH_NOTIFICATIONMONITOR_H +#define WATCHFISH_NOTIFICATIONMONITOR_H + +#include +#include +#include + +#include "notification.h" + +namespace watchfish +{ + +Q_DECLARE_LOGGING_CATEGORY(notificationMonitorCat) + +class NotificationMonitorPrivate; + +class NotificationMonitor : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(NotificationMonitor) + +public: + explicit NotificationMonitor(QObject *parent = 0); + ~NotificationMonitor(); + +signals: + /** Emitted when a notification arrives. */ + void notification(Notification *n); + +private: + NotificationMonitorPrivate * const d_ptr; +}; + +} + +#endif // WATCHFISH_NOTIFICATIONMONITOR_H diff --git a/starfishd/libwatchfish/notificationmonitor_p.h b/starfishd/libwatchfish/notificationmonitor_p.h new file mode 100644 index 0000000..2f57697 --- /dev/null +++ b/starfishd/libwatchfish/notificationmonitor_p.h @@ -0,0 +1,100 @@ +#ifndef WATCHFISH_NOTIFICATIONMONITOR_P_H +#define WATCHFISH_NOTIFICATIONMONITOR_P_H + +#include +#include + +#include "notificationmonitor.h" + +#define CATEGORY_DEFINITION_FILE_DIRECTORY "/usr/share/lipstick/notificationcategories" +#define CATEGORY_REFRESH_CHECK_TIME 120 + +#define DESKTOP_FILE_DIRECTORY "/usr/share/applications" +#define DESKTOP_REFRESH_CHECK_TIME 120 + +namespace watchfish +{ + +struct NotificationCategoryCacheEntry +{ + QHash data; + QDateTime lastReadTime; + QDateTime lastCheckTime; +}; + +struct AppNameCacheEntry +{ + QString name; + QDateTime lastReadTime; + QDateTime lastCheckTime; +}; + +struct ProtoNotification +{ + QString appId; + QString appName; + QString appIcon; + QString summary; + QString body; + QHash hints; + int expireTimeout; + QStringList actions; +}; + +class NotificationMonitorPrivate : public QObject +{ + Q_OBJECT + +public: + NotificationMonitorPrivate(NotificationMonitor *q); + ~NotificationMonitorPrivate(); + +private: + /** Converts a ProtoNotification into a Notification object and raises it. */ + void processIncomingNotification(quint32 id, const ProtoNotification &proto); + /** Raises appropiate notification signal. */ + void processCloseNotification(quint32 id, quint32 reason); + + /** Sends a D-Bus message for a method call with a single string argument. */ + void sendMessageWithString(const char *service, const char *path, const char *iface, const char *method, const char *arg); + /** Adds a D-Bus filter match rule. */ + void addMatchRule(const char *rule); + void removeMatchRule(const char *rule); + + /** Converts a fdo Notification D-Bus message into a ProtoNotification object. */ + ProtoNotification parseNotifyCall(DBusMessage *msg) const; + + QHash getCategoryInfo(const QString &s) const; + + QString getAppName(const QString &id) const; + + static dbus_bool_t busWatchAdd(DBusWatch *watch, void *data); + static void busWatchRemove(DBusWatch *watch, void *data); + static void busWatchToggle(DBusWatch *watch, void *data); + + static DBusHandlerResult busMessageFilter(DBusConnection *conn, DBusMessage *msg, void *user_data); + +private slots: + void handleBusSocketActivated(); + +private: + NotificationMonitor * const q_ptr; + Q_DECLARE_PUBLIC(NotificationMonitor) + + /** The current set of monitored notifications, indexed by id. */ + QMap _notifs; + /** Low level dbus connection used for sniffing. */ + DBusConnection *_conn; + /** Serials of DBUS method calls of which we are expecting a reply. */ + QHash _pendingConfirmation; + /** Cache of notification category info. */ + mutable QHash _categoryCache; + /** Cache of application names. */ + mutable QHash _appNameCache; +}; + + +} + +#endif // WATCHFISH_NOTIFICATIONMONITOR_P_H + diff --git a/starfishd/libwatchfish/org.nemomobile.voicecall.VoiceCall.xml b/starfishd/libwatchfish/org.nemomobile.voicecall.VoiceCall.xml new file mode 100644 index 0000000..6693af2 --- /dev/null +++ b/starfishd/libwatchfish/org.nemomobile.voicecall.VoiceCall.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/starfishd/libwatchfish/org.nemomobile.voicecall.VoiceCallManager.xml b/starfishd/libwatchfish/org.nemomobile.voicecall.VoiceCallManager.xml new file mode 100644 index 0000000..cfdbae5 --- /dev/null +++ b/starfishd/libwatchfish/org.nemomobile.voicecall.VoiceCallManager.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/starfishd/libwatchfish/voicecallcontroller.cpp b/starfishd/libwatchfish/voicecallcontroller.cpp new file mode 100644 index 0000000..5e3487e --- /dev/null +++ b/starfishd/libwatchfish/voicecallcontroller.cpp @@ -0,0 +1,148 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2016 Javier S. Pedro + * + * 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 3 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 "voicecallcontroller.h" +#include "voicecallcontroller_p.h" + +namespace watchfish +{ + +Q_LOGGING_CATEGORY(voiceCallControllerCat, "watchfish-VoiceCallController") + +VoiceCallControllerPrivate::VoiceCallControllerPrivate(VoiceCallController *q) + : vcm(new OrgNemomobileVoicecallVoiceCallManagerInterface("org.nemomobile.voicecall", + "/", QDBusConnection::sessionBus(), this)), + activeCall(0), + curInCall(false), curRinging(false), + q_ptr(q) +{ + connect(vcm, &OrgNemomobileVoicecallVoiceCallManagerInterface::activeVoiceCallChanged, + this, &VoiceCallControllerPrivate::handleActiveVoiceCallChanged); + handleActiveVoiceCallChanged(); +} + +VoiceCallControllerPrivate::~VoiceCallControllerPrivate() +{ + delete activeCall; +} + +void VoiceCallControllerPrivate::handleActiveVoiceCallChanged() +{ + delete activeCall; + QString id = vcm->activeVoiceCall(); + qCDebug(voiceCallControllerCat) << "Active voice call changed" << id; + if (!id.isEmpty()) { + activeCall = new OrgNemomobileVoicecallVoiceCallInterface("org.nemomobile.voicecall", + QString("/calls/%1").arg(id), vcm->connection(), this); + connect(activeCall, &OrgNemomobileVoicecallVoiceCallInterface::statusChanged, + this, &VoiceCallControllerPrivate::handleActiveVoiceCallStatusChanged); + connect(activeCall, &OrgNemomobileVoicecallVoiceCallInterface::lineIdChanged, + this, &VoiceCallControllerPrivate::handleActiveVoiceCallLineIdChanged); + VoiceCallStatus status = static_cast(activeCall->status()); + setCallerId(activeCall->lineId()); + setCallStatus(status); + qDebug() << "Status of new call:" << status << curCallerId; + } else { + activeCall = 0; + setCallStatus(STATUS_NULL); + setCallerId(QString()); + } +} + +void VoiceCallControllerPrivate::handleActiveVoiceCallStatusChanged(int status, const QString &statusText) +{ + qCDebug(voiceCallControllerCat) << "Status changed:" << status << statusText; + setCallStatus(static_cast(status)); +} + +void VoiceCallControllerPrivate::handleActiveVoiceCallLineIdChanged(const QString &lineId) +{ + qCDebug(voiceCallControllerCat) << "LineID changed:" << lineId; + setCallerId(lineId); +} + +void VoiceCallControllerPrivate::setCallStatus(VoiceCallStatus status) +{ + Q_Q(VoiceCallController); + const bool oldInCall = curInCall, oldRinging = curRinging; + switch (status) { + case STATUS_INCOMING: + curInCall = true; + curRinging = true; + break; + case STATUS_ACTIVE: + case STATUS_HELD: + case STATUS_DIALING: + case STATUS_ALERTING: + case STATUS_WAITING: + curInCall = true; + curRinging = false; + break; + case STATUS_DISCONNECTED: + case STATUS_NULL: + default: + curInCall = false; + curRinging = false; + break; + } + if (oldInCall != curInCall) { + emit q->inCallChanged(); + } + if (oldRinging != curRinging) { + emit q->ringingChanged(); + } +} + +void VoiceCallControllerPrivate::setCallerId(const QString &callerId) +{ + Q_Q(VoiceCallController); + if (callerId != curCallerId) { + curCallerId = callerId; + emit q->callerIdChanged(); + } +} + +VoiceCallController::VoiceCallController(QObject *parent) + : QObject(parent), d_ptr(new VoiceCallControllerPrivate(this)) +{ +} + +VoiceCallController::~VoiceCallController() +{ + delete d_ptr; +} + +bool VoiceCallController::inCall() const +{ + Q_D(const VoiceCallController); + return d->curInCall; +} + +bool VoiceCallController::ringing() const +{ + Q_D(const VoiceCallController); + return d->curRinging; +} + +QString VoiceCallController::callerId() const +{ + Q_D(const VoiceCallController); + return d->curCallerId; +} + +} diff --git a/starfishd/libwatchfish/voicecallcontroller.h b/starfishd/libwatchfish/voicecallcontroller.h new file mode 100644 index 0000000..c374a41 --- /dev/null +++ b/starfishd/libwatchfish/voicecallcontroller.h @@ -0,0 +1,60 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2016 Javier S. Pedro + * + * 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 3 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 WATCHFISH_VOICECALLCONTROLLER_H +#define WATCHFISH_VOICECALLCONTROLLER_H + +#include + +namespace watchfish +{ + +Q_DECLARE_LOGGING_CATEGORY(voiceCallControllerCat) + +class VoiceCallControllerPrivate; + +class VoiceCallController : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(VoiceCallController) + + Q_PROPERTY(bool inCall READ inCall NOTIFY inCallChanged) + Q_PROPERTY(bool ringing READ ringing NOTIFY ringingChanged) + Q_PROPERTY(QString callerId READ callerId NOTIFY callerIdChanged) + +public: + explicit VoiceCallController(QObject *parent = 0); + ~VoiceCallController(); + + bool inCall() const; + bool ringing() const; + + QString callerId() const; + +signals: + void inCallChanged(); + void ringingChanged(); + void callerIdChanged(); + +private: + VoiceCallControllerPrivate * const d_ptr; +}; + +} + +#endif // WATCHFISH_VOICECALLCONTROLLER_H diff --git a/starfishd/libwatchfish/voicecallcontroller_p.h b/starfishd/libwatchfish/voicecallcontroller_p.h new file mode 100644 index 0000000..624e615 --- /dev/null +++ b/starfishd/libwatchfish/voicecallcontroller_p.h @@ -0,0 +1,72 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2016 Javier S. Pedro + * + * 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 3 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 WATCHFISH_VOICECALLCONTROLLER_P_H +#define WATCHFISH_VOICECALLCONTROLLER_P_H + +#include "voicecallcontroller.h" +#include "voicecall_interface.h" +#include "voicecallmanager_interface.h" + +namespace watchfish +{ + +enum VoiceCallStatus { + STATUS_NULL, + STATUS_ACTIVE, + STATUS_HELD, + STATUS_DIALING, + STATUS_ALERTING, + STATUS_INCOMING, + STATUS_WAITING, + STATUS_DISCONNECTED +}; + +class VoiceCallControllerPrivate : public QObject +{ + Q_OBJECT + +public: + explicit VoiceCallControllerPrivate(VoiceCallController *q); + ~VoiceCallControllerPrivate(); + +public slots: + void handleActiveVoiceCallChanged(); + void handleActiveVoiceCallStatusChanged(int status, const QString &statusName); + void handleActiveVoiceCallLineIdChanged(const QString &lineId); + +public: + OrgNemomobileVoicecallVoiceCallManagerInterface *vcm; + OrgNemomobileVoicecallVoiceCallInterface *activeCall; + + bool curInCall; + bool curRinging; + QString curCallerId; + + void setCallStatus(VoiceCallStatus status); + void setCallerId(const QString &callerId); + +private: + VoiceCallController * const q_ptr; + Q_DECLARE_PUBLIC(VoiceCallController) +}; + +} + +#endif // WATCHFISH_VOICECALLCONTROLLER_P_H + diff --git a/starfishd/libwatchfish/volumecontroller.cpp b/starfishd/libwatchfish/volumecontroller.cpp new file mode 100644 index 0000000..5fc19f5 --- /dev/null +++ b/starfishd/libwatchfish/volumecontroller.cpp @@ -0,0 +1,133 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2016 Javier S. Pedro + * + * 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 3 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 "volumecontroller.h" +#include "volumecontroller_p.h" + +namespace watchfish +{ + +Q_LOGGING_CATEGORY(volumeControllerCat, "watchfish-VolumeController") + +static const char *VOLUME_SERVICE = "com.Meego.MainVolume2"; +static const char *VOLUME_PATH = "/com/meego/mainvolume2"; + +VolumeControllerPrivate::VolumeControllerPrivate(VolumeController *q) + : volume(0), + curValue(0), curMaximum(0), + q_ptr(q) +{ + const QString address = connectionAddress(); + QDBusConnection connection = QDBusConnection::connectToPeer(address, "pulse"); + + volume = new ComMeegoMainVolume2Interface(VOLUME_SERVICE, VOLUME_PATH, connection, this); + + connect(volume, &ComMeegoMainVolume2Interface::StepsUpdated, + this, &VolumeControllerPrivate::handleStepsUpdated); + if (volume->isValid()) { + handleStepsUpdated(volume->stepCount(), volume->currentStep()); + } +} + +VolumeControllerPrivate::~VolumeControllerPrivate() +{ +} + +QString VolumeControllerPrivate::connectionAddress() +{ + if (qEnvironmentVariableIsSet("PULSE_DBUS_SERVER")) { + return QString::fromLocal8Bit(qgetenv("PULSE_DBUS_SERVER")); + } else { + QDBusConnection bus = QDBusConnection::sessionBus(); + QDBusMessage message = QDBusMessage::createMethodCall("org.pulseaudio.Server", "/org/pulseaudio/server_lookup1", + "org.freedesktop.DBus.Properties", "Get"); + message.setArguments(QVariantList() << "org.PulseAudio.ServerLookup1" << "Address"); + QDBusMessage reply = bus.call(message); + if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() > 0) { + return reply.arguments().first().value().variant().toString(); + } + } + + return QString(); +} + +void VolumeControllerPrivate::handleStepsUpdated(uint StepCount, uint CurrentStep) +{ + Q_Q(VolumeController); + qCDebug(volumeControllerCat) << "updated stuff"; + const int oldValue = curValue, oldMaximum = curMaximum; + curValue = CurrentStep; + curMaximum = StepCount; + if (oldMaximum != 0) { + qCDebug(volumeControllerCat) << "Volume updated" << curValue << "/" << curMaximum; + } + if (curMaximum != oldMaximum) { + emit q->maximumChanged(); + } + if (curValue != oldValue) { + emit q->valueChanged(); + } +} + +VolumeController::VolumeController(QObject *parent) + : QObject(parent), d_ptr(new VolumeControllerPrivate(this)) +{ +} + +VolumeController::~VolumeController() +{ +} + +int VolumeController::value() const +{ + Q_D(const VolumeController); + return d->volume->currentStep(); +} + +int VolumeController::minimum() const +{ + return 0; +} + +int VolumeController::maximum() const +{ + Q_D(const VolumeController); + return d->volume->stepCount(); +} + +void VolumeController::setValue(int v) +{ + Q_D(const VolumeController); + qCDebug(volumeControllerCat) << "Setting volume to" << v; + if (!d->volume->isValid()) { + qCWarning(volumeControllerCat) << "Lost connection to volume interface"; + } + d->volume->setCurrentStep(v); +} + +void VolumeController::up() +{ + setValue(value() + 1); +} + +void VolumeController::down() +{ + setValue(value() - 1); +} + +} diff --git a/starfishd/libwatchfish/volumecontroller.h b/starfishd/libwatchfish/volumecontroller.h new file mode 100644 index 0000000..d92d6a2 --- /dev/null +++ b/starfishd/libwatchfish/volumecontroller.h @@ -0,0 +1,65 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2016 Javier S. Pedro + * + * 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 3 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 WATCHFISH_VOLUMECONTROLLER_H +#define WATCHFISH_VOLUMECONTROLLER_H + +#include + +namespace watchfish +{ + +Q_DECLARE_LOGGING_CATEGORY(volumeControllerCat) + +class VolumeControllerPrivate; + +class VolumeController : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(VolumeController) + + Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged) + Q_PROPERTY(int minimum READ minimum NOTIFY minimumChanged) + Q_PROPERTY(int maximum READ maximum NOTIFY maximumChanged) + +public: + explicit VolumeController(QObject *parent = 0); + ~VolumeController(); + + int value() const; + int minimum() const; + int maximum() const; + + void setValue(int v); + +public slots: + void up(); + void down(); + +signals: + void valueChanged(); + void minimumChanged(); + void maximumChanged(); + +private: + VolumeControllerPrivate * const d_ptr; +}; + +} + +#endif // WATCHFISH_VOLUMECONTROLLER_H diff --git a/starfishd/libwatchfish/volumecontroller_p.h b/starfishd/libwatchfish/volumecontroller_p.h new file mode 100644 index 0000000..bd3babc --- /dev/null +++ b/starfishd/libwatchfish/volumecontroller_p.h @@ -0,0 +1,54 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2016 Javier S. Pedro + * + * 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 3 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 WATCHFISH_VOLUMECONTROLLER_P_H +#define WATCHFISH_VOLUMECONTROLLER_P_H + +#include +#include "mainvolume2_interface.h" +#include "volumecontroller.h" + +namespace watchfish +{ + +class VolumeControllerPrivate : public QObject +{ + Q_OBJECT + +public: + explicit VolumeControllerPrivate(VolumeController *q); + ~VolumeControllerPrivate(); + + ComMeegoMainVolume2Interface *volume; + + int curValue; + int curMaximum; + + static QString connectionAddress(); + +public slots: + void handleStepsUpdated(uint StepCount, uint CurrentStep); + +private: + VolumeController * const q_ptr; + Q_DECLARE_PUBLIC(VolumeController) +}; + +} + +#endif // WATCHFISH_VOLUMECONTROLLER_P_H diff --git a/starfishd/libwatchfish/walltimemonitor.cpp b/starfishd/libwatchfish/walltimemonitor.cpp new file mode 100644 index 0000000..78d500b --- /dev/null +++ b/starfishd/libwatchfish/walltimemonitor.cpp @@ -0,0 +1,139 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2015 Javier S. Pedro + * + * 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 3 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 . + */ + +/* + * Parts of this file based on nemo-qml-plugin-time + * Copyright (C) 2012 Jolla Ltd. + * Contact: Martin Jones + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Jolla Ltd. nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#include + +#include "walltimemonitor.h" +#include "walltimemonitor_p.h" + +namespace watchfish +{ + +Q_LOGGING_CATEGORY(walltimeMonitorCat, "watchfish-WallTimeMonitor") + +WallTimeMonitorPrivate::WallTimeMonitorPrivate(WallTimeMonitor *q) + : q_ptr(q) +{ + Maemo::Timed::Interface ifc; + ifc.settings_changed_connect(this, SLOT(handleTimedSettingsChanged(Maemo::Timed::WallClock::Info,bool))); + + QDBusReply reply = ifc.get_wall_clock_info_sync(); + if (reply.isValid()) { + info = reply.value(); + } else { + qCWarning(walltimeMonitorCat) << "D-Bus error while contacting timed:" << reply.error().message(); + } +} + +WallTimeMonitorPrivate::~WallTimeMonitorPrivate() +{ + Maemo::Timed::Interface ifc; + ifc.settings_changed_disconnect(this, SLOT(handleTimedSettingsChanged(Maemo::Timed::WallClock::Info,bool))); +} + +void WallTimeMonitorPrivate::handleTimedSettingsChanged(const Maemo::Timed::WallClock::Info &newInfo, bool timeChanged) +{ + Q_Q(WallTimeMonitor); + + bool tzChange = newInfo.humanReadableTz() != info.humanReadableTz(); + bool tzaChange = newInfo.tzAbbreviation() != info.tzAbbreviation(); + bool tzoChange = newInfo.secondsEastOfGmt() != info.secondsEastOfGmt(); + bool hourModeChange = newInfo.flagFormat24() != info.flagFormat24(); + + info = newInfo; + + if (tzChange) + emit q->timezoneChanged(); + if (tzaChange) + emit q->timezoneAbbreviationChanged(); + if (tzoChange) + emit q->timezoneOffsetFromUtcChanged(); + if (timeChanged) + emit q->systemTimeChanged(); + if (tzChange || tzaChange || tzoChange || timeChanged || hourModeChange) + emit q->timeChanged(); +} + +WallTimeMonitor::WallTimeMonitor(QObject *parent) + : QObject(parent), d_ptr(new WallTimeMonitorPrivate(this)) +{ + +} + +WallTimeMonitor::~WallTimeMonitor() +{ + delete d_ptr; +} + +QDateTime WallTimeMonitor::time() const +{ + return QDateTime::currentDateTime(); +} + +QString WallTimeMonitor::timezone() const +{ + Q_D(const WallTimeMonitor); + return d->info.humanReadableTz(); +} + +QString WallTimeMonitor::timezoneAbbreviation() const +{ + Q_D(const WallTimeMonitor); + return d->info.tzAbbreviation(); +} + +int WallTimeMonitor::timezoneOffsetFromUtc() const +{ + Q_D(const WallTimeMonitor); + return d->info.secondsEastOfGmt(); +} + +} diff --git a/starfishd/libwatchfish/walltimemonitor.h b/starfishd/libwatchfish/walltimemonitor.h new file mode 100644 index 0000000..8001b02 --- /dev/null +++ b/starfishd/libwatchfish/walltimemonitor.h @@ -0,0 +1,70 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2015 Javier S. Pedro + * + * 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 3 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 WATCHFISH_WALLTIMEMONITOR_H +#define WATCHFISH_WALLTIMEMONITOR_H + +#include +#include +#include + +namespace watchfish +{ + +Q_DECLARE_LOGGING_CATEGORY(walltimeMonitorCat) + +class WallTimeMonitorPrivate; + +class WallTimeMonitor : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(WallTimeMonitor) + + Q_PROPERTY(QDateTime time READ time NOTIFY timeChanged) + Q_PROPERTY(QString timezone READ timezone NOTIFY timezoneChanged) + Q_PROPERTY(QString timezoneAbbreviation READ timezoneAbbreviation NOTIFY timezoneAbbreviationChanged) + Q_PROPERTY(int timezoneOffsetFromUtc READ timezoneOffsetFromUtc NOTIFY timezoneOffsetFromUtcChanged) + +public: + explicit WallTimeMonitor(QObject *parent = 0); + ~WallTimeMonitor(); + + /** Gets the current wall clock time. */ + QDateTime time() const; + + /** Gets the current timezone name as an IANA ID, e.g. America/Buenos_Aires. */ + QString timezone() const; + /** Gets the current timezone abbreviation, e.g. CET. */ + QString timezoneAbbreviation() const; + /** Gets the current offset from UTC including any possible DST. */ + int timezoneOffsetFromUtc() const; + +signals: + void systemTimeChanged(); + void timeChanged(); + void timezoneChanged(); + void timezoneAbbreviationChanged(); + void timezoneOffsetFromUtcChanged(); + +private: + WallTimeMonitorPrivate * const d_ptr; +}; + +} + +#endif // WATCHFISH_WALLTIMEMONITOR_H diff --git a/starfishd/libwatchfish/walltimemonitor_p.h b/starfishd/libwatchfish/walltimemonitor_p.h new file mode 100644 index 0000000..e95c100 --- /dev/null +++ b/starfishd/libwatchfish/walltimemonitor_p.h @@ -0,0 +1,83 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2015 Javier S. Pedro + * + * 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 3 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 . + */ + +/* + * Parts of this file based on nemo-qml-plugin-time + * Copyright (C) 2012 Jolla Ltd. + * Contact: Martin Jones + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Jolla Ltd. nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#ifndef WATCHFISH_WALLTIMEMONITOR_P_H +#define WATCHFISH_WALLTIMEMONITOR_P_H + +#include +#include + +#include "walltimemonitor.h" + +namespace watchfish +{ + +class WallTimeMonitorPrivate : public QObject +{ + Q_OBJECT + +public: + WallTimeMonitorPrivate(WallTimeMonitor *q); + ~WallTimeMonitorPrivate(); + + Maemo::Timed::WallClock::Info info; + +private slots: + void handleTimedSettingsChanged(const Maemo::Timed::WallClock::Info & newInfo, bool timeChanged); + +private: + WallTimeMonitor * const q_ptr; + Q_DECLARE_PUBLIC(WallTimeMonitor) +}; + +} + +#endif // WATCHFISH_WALLTIMEMONITOR_P_H diff --git a/starfishd/main.cpp b/starfishd/main.cpp new file mode 100644 index 0000000..0c006a5 --- /dev/null +++ b/starfishd/main.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 +#include "dbusinterface.h" +#include "sailfishplatform.h" +#include "watchesmanager.h" + +Q_DECL_EXPORT int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + + QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); + + WatchesManager *watchesManager = new WatchesManager(); + SailfishPlatform *platform = new SailfishPlatform(watchesManager); + DBusInterface *dbusInterface = new DBusInterface(watchesManager); + + return a.exec(); +} diff --git a/starfishd/sailfishplatform.cpp b/starfishd/sailfishplatform.cpp new file mode 100644 index 0000000..6b9b03f --- /dev/null +++ b/starfishd/sailfishplatform.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 "sailfishplatform.h" + +#include "libwatchfish/musiccontroller.h" +#include "libwatchfish/notificationmonitor.h" +#include "libwatchfish/walltimemonitor.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +SailfishPlatform::SailfishPlatform(WatchesManager *wm, QObject *parent) : QObject(parent) +{ + qDBusRegisterMetaType>(); + + m_timeService = wm->timeService(); + m_wallTimeMonitor = new watchfish::WallTimeMonitor(this); + connect(m_wallTimeMonitor, &watchfish::WallTimeMonitor::timeChanged, this, &SailfishPlatform::onTimeChanged); + + m_notificationService = wm->notificationService(); + m_notificationMonitor = new watchfish::NotificationMonitor(this); + connect(m_notificationMonitor, &watchfish::NotificationMonitor::notification, this, &SailfishPlatform::newNotification); + + m_mediaService = wm->mediaService(); + m_musicController = new watchfish::MusicController(this); + connect(m_musicController, SIGNAL(statusChanged()), SLOT(updateMusicStatus())); + connect(m_musicController, SIGNAL(titleChanged()), SLOT(updateMusicTitle())); + connect(m_musicController, SIGNAL(albumChanged()), SLOT(updateMusicAlbum())); + connect(m_musicController, SIGNAL(artistChanged()), SLOT(updateMusicArtist())); + connect(m_mediaService, SIGNAL(play()), m_musicController, SLOT(play())); + connect(m_mediaService, SIGNAL(pause()), m_musicController, SLOT(play())); + connect(m_mediaService, SIGNAL(next()), m_musicController, SLOT(next())); + connect(m_mediaService, SIGNAL(previous()), m_musicController, SLOT(previous())); +} + +SailfishPlatform::~SailfishPlatform() +{ + delete m_musicController; + delete m_notificationMonitor; + delete m_wallTimeMonitor; +} + +void SailfishPlatform::onTimeChanged() { + m_timeService->setTime(QDateTime()); +} + +void SailfishPlatform::newNotification(watchfish::Notification *notification) +{ + if (!notification->category().endsWith(".group")) { + connect(notification, SIGNAL(closed(CloseReason)), this, SLOT(onNotificationClosed(CloseReason))); + m_notificationService->insertNotification(notification->appId(), notification->id(), notification->appName(), "ios-mail", notification->summary(), notification->body(), NotificationService::Strong); + } +} + +void SailfishPlatform::onNotificationClosed(watchfish::Notification::CloseReason) +{ + watchfish::Notification *notif = (watchfish::Notification *)sender(); + m_notificationService->removeNotification(notif->id()); +} + +void SailfishPlatform::updateMusicStatus() +{ + m_mediaService->setPlaying(m_musicController->status() == watchfish::MusicController::StatusPlaying); +} + +void SailfishPlatform::updateMusicTitle() +{ + m_mediaService->setTitle(m_musicController->title()); +} + +void SailfishPlatform::updateMusicAlbum() +{ + m_mediaService->setAlbum(m_musicController->album()); +} + +void SailfishPlatform::updateMusicArtist() +{ + m_mediaService->setArtist(m_musicController->artist()); +} diff --git a/starfishd/sailfishplatform.h b/starfishd/sailfishplatform.h new file mode 100644 index 0000000..d2af067 --- /dev/null +++ b/starfishd/sailfishplatform.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 SAILFISHPLATFORM_H +#define SAILFISHPLATFORM_H + +#include + +#include "libwatchfish/musiccontroller.h" +#include "libwatchfish/notificationmonitor.h" +#include "libwatchfish/walltimemonitor.h" + +#include +#include +#include + +#include "watchesmanager.h" + +class SailfishPlatform : public QObject, QDBusContext +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Notifications") + +public: + SailfishPlatform(WatchesManager *wm, QObject *parent = 0); + ~SailfishPlatform(); + +public slots: + void onTimeChanged(); + + void newNotification(watchfish::Notification *notification); + void onNotificationClosed(watchfish::Notification::CloseReason); + + void updateMusicStatus(); + void updateMusicTitle(); + void updateMusicAlbum(); + void updateMusicArtist(); + +private: + watchfish::MusicController *m_musicController; + watchfish::NotificationMonitor *m_notificationMonitor; + watchfish::WallTimeMonitor *m_wallTimeMonitor; + + TimeService *m_timeService; + MediaService *m_mediaService; + NotificationService *m_notificationService; +}; + +#endif // SAILFISHPLATFORM_H + diff --git a/starfishd/starfishd.pro b/starfishd/starfishd.pro new file mode 100644 index 0000000..b8e6a2e --- /dev/null +++ b/starfishd/starfishd.pro @@ -0,0 +1,45 @@ +QT += core bluetooth dbus +QT -= gui + +WATCHFISH_FEATURES = notificationmonitor walltime music + +include(../version.pri) +include(libwatchfish/libwatchfish.pri) +include(libasteroid/libasteroid.pri) + +TARGET = starfishd + +CONFIG += c++11 +CONFIG += console +CONFIG += link_pkgconfig + +PKGCONFIG += qt5-boostable + +SOURCES += main.cpp \ + sailfishplatform.cpp \ + watchesmanager.cpp \ + dbusinterface.cpp \ + bluez/bluezclient.cpp \ + bluez/bluez_agentmanager1.cpp \ + bluez/bluez_adapter1.cpp \ + bluez/bluez_device1.cpp \ + bluez/freedesktop_objectmanager.cpp \ + bluez/freedesktop_properties.cpp + +HEADERS += \ + sailfishplatform.h \ + watchesmanager.h \ + dbusinterface.h \ + bluez/bluezclient.h \ + bluez/bluez_agentmanager1.h \ + bluez/bluez_adapter1.h \ + bluez/bluez_device1.h \ + bluez/freedesktop_objectmanager.h \ + bluez/freedesktop_properties.h + +INSTALLS += target systemd + +systemd.files = $${TARGET}.service +systemd.path = /usr/lib/systemd/user + +target.path = /usr/bin diff --git a/starfishd/starfishd.service b/starfishd/starfishd.service new file mode 100644 index 0000000..2ec1a2a --- /dev/null +++ b/starfishd/starfishd.service @@ -0,0 +1,11 @@ +[Unit] +Description=Starfish daemon for AsteroidOS smartwatches +Requires=dbus.socket bluetooth.target booster-qt5.service +After=pre-user-session.target lipstick.service dbus.socket bluetooth.target booster-qt5.service + +[Service] +ExecStart=/usr/bin/invoker -o --type=qt5 /usr/bin/starfishd +Restart=always + +[Install] +WantedBy=user-session.target diff --git a/starfishd/watchesmanager.cpp b/starfishd/watchesmanager.cpp new file mode 100644 index 0000000..44328c5 --- /dev/null +++ b/starfishd/watchesmanager.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 "watchesmanager.h" + +#include "libasteroid/watch.h" + +WatchesManager::WatchesManager(QObject *parent) : WatchConnection(parent) +{ + m_bluezClient = new BluezClient(this); + connect(m_bluezClient, &BluezClient::devicesChanged, this, &WatchesManager::loadWatches); + loadWatches(); +} + +QList WatchesManager::watches() const +{ + return m_watches; +} + +void WatchesManager::loadWatches() +{ + quint32 classOfDevice = QBluetoothDeviceInfo::WearableWristWatch << 2 | QBluetoothDeviceInfo::WearableDevice << 8; + + QList pairedWatches = m_bluezClient->pairedWatches(); + foreach (const Device &device, pairedWatches) { + Watch *w = get(device.address); + if (!w) { + w = new Watch(QBluetoothDeviceInfo(device.address, device.name, classOfDevice)); + m_watches.append(w); + emit watchAdded(w); + } + } + + QList watchesToRemove; + foreach (Watch *w, m_watches) { + bool found = false; + foreach (const Device &dev, pairedWatches) { + if (dev.address == w->getAddress()) { + found = true; + break; + } + } + if (!found) + watchesToRemove << w; + } + + while (!watchesToRemove.isEmpty()) { + Watch *w = watchesToRemove.takeFirst(); + m_watches.removeOne(w); + emit watchRemoved(w); + w->deleteLater(); + } +} + +Watch* WatchesManager::get(const QBluetoothAddress &address) +{ + for (int i = 0; i < m_watches.count(); i++) { + if (m_watches.at(i)->getAddress() == address) { + return m_watches.at(i); + } + } + return nullptr; +} diff --git a/starfishd/watchesmanager.h b/starfishd/watchesmanager.h new file mode 100644 index 0000000..748b8c0 --- /dev/null +++ b/starfishd/watchesmanager.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2018 - Florent Revest + * 2016 - Andrew Branson + * Ruslan N. Marchenko + * + * 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 3 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 WATCHESMANAGER_H +#define WATCHESMANAGER_H + +#include +#include + +#include +#include + +#include + +class Watch; + +class WatchesManager : public WatchConnection +{ + Q_OBJECT + +public: + explicit WatchesManager(QObject *parent = 0); + + QList watches() const; + Watch* get(const QBluetoothAddress &address); + +signals: + void watchAdded(Watch *watch); + void watchRemoved(Watch *watch); + +private slots: + void loadWatches(); + +private: + QList m_watches; + BluezClient *m_bluezClient; +}; + +#endif // WATCHESMANAGER_H + diff --git a/version.pri b/version.pri new file mode 100644 index 0000000..1c42433 --- /dev/null +++ b/version.pri @@ -0,0 +1,2 @@ +VERSION = "1.0" +DEFINES += VERSION=\\\"$$VERSION\\\"