./ 0000755 0000041 0000041 00000000000 14061437245 011251 5 ustar www-data www-data ./CMakeLists.txt 0000644 0000041 0000041 00000003476 14061437245 014023 0 ustar www-data www-data project (indicator-session C CXX)
cmake_minimum_required (VERSION 2.8.9)
set (PROJECT_VERSION "13.10.1")
set (PACKAGE ${CMAKE_PROJECT_NAME})
set (GETTEXT_PACKAGE indicator-session)
##
## GNU standard installation directories
##
include (GNUInstallDirs)
if (EXISTS "/etc/debian_version") # Workaround for libexecdir on debian
set (CMAKE_INSTALL_LIBEXECDIR "${CMAKE_INSTALL_LIBDIR}")
set (CMAKE_INSTALL_FULL_LIBEXECDIR "${CMAKE_INSTALL_FULL_LIBDIR}")
endif ()
set (CMAKE_INSTALL_PKGLIBEXECDIR "${CMAKE_INSTALL_LIBEXECDIR}/${CMAKE_PROJECT_NAME}")
set (CMAKE_INSTALL_FULL_PKGLIBEXECDIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}/${CMAKE_PROJECT_NAME}")
##
## Check for prerequisites
##
find_package (PkgConfig REQUIRED)
include (FindPkgConfig)
pkg_check_modules (SERVICE REQUIRED
glib-2.0>=2.36
gio-unix-2.0>=2.36
libwhoopsie)
include_directories(SYSTEM ${SERVICE_INCLUDE_DIRS})
set (CC_WARNING_ARGS " -Wall -pedantic -Wextra -Wno-missing-field-initializers")
set (ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${PROJECT_VERSION})
add_custom_target (dist
COMMAND bzr export --root=${ARCHIVE_NAME} ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.gz
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_custom_target (cppcheck COMMAND cppcheck --enable=all -q --error-exitcode=2 --inline-suppr
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/tests)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/src)
include_directories (${CMAKE_CURRENT_BINARY_DIR}/src)
add_subdirectory (src)
add_subdirectory (data)
add_subdirectory (po)
# testing & coverage
enable_testing ()
add_subdirectory (tests)
find_package(CoverageReport)
ENABLE_COVERAGE_REPORT(
TARGETS ${COVERAGE_TARGETS}
TESTS ${COVERAGE_TEST_TARGETS}
FILTER /usr/include ${CMAKE_BINARY_DIR}/*
)
./NEWS 0000644 0000041 0000041 00000001711 14061437245 011750 0 ustar www-data www-data 12.10.4
- The Restart menuitem wasn't accessible via the HUD. (LP: #1058148)
- Fix g_critical() warnings on startup caused by updating menuitems too soon
12.10.3
- By default, use 'Shut Down' instead of 'Switch Off' (LP: #1029036)
- 12.10.0 showed "Guest user" even when disabled in lightdm (LP: #1049902)
- Provide a fallback if theme's missing the session menu icon (LP: #1029036)
- Fix some strings that hadn't been marked for translation
12.10.2
- Add an 'Online Accounts' menuitem (LP: #1044464)
- Add disposition highlighting to the indicator icon (LP: #1044015)
- Fix build issue in the unit tests directory (LP: #1040678)
- Remove the Restart button from the shutdown dialog (LP: #1027952)
12.10.1
- Fix user menuitems' icon sizes (LP: #1024395)
- Make explicit in configure.ac that we need a newer glib (LP: #1023533)
- Separate testing-strings into a separate Makefile.am for reuse
12.10.0
- First version of the 12.10 System Menu redesign
./INSTALL 0000644 0000041 0000041 00000004551 14061437245 012307 0 ustar www-data www-data #
# Copyright (C) 2013 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 .
#
Compile-time build dependencies
-------------------------------
- gettext (gettext 0.18.1.1-10ubuntu3 or later)
- glib (libglib2.0, 2.35.4 or later)
- cmake (cmake, 2.8.9 or later)
- cmake-extras (cmake-extras, 0.10 or later)
- gcovr (gcovr, 2.4 or later)
- lcov (lcov, 1.9 or later)
- google test (googletest or google-mock, 1.6.0 or later)
- cppcheck (cppcheck)
Runtime DBus dependencies
-------------------------
- com.canonical.indicators.webcredentials
- org.freedesktop.Accounts
- org.freedesktop.Accounts.User
- org.freedesktop.DisplayManager.Seat
- org.freedesktop.login1.Manager
- org.freedesktop.login1.Seat
- org.freedesktop.login1.User
- org.gnome.ScreenSaver
- org.gnome.SessionManager
- org.gnome.SessionManager.EndSessionDialog
Building the code
-----------------
The simplest case is:
$ cd indicator-session-X.Y.Z
$ mkdir build
$ cd build
$ cmake ..
$ make
Running the tests
-----------------
$ cd indicator-session-X.Y.Z
$ mkdir build
$ cd build
$ cmake ..
$ make
$ make test
$ make cppcheck
Generating Test Coverage Reports
--------------------------------
$ cd indicator-session-X.Y.Z
$ mkdir build-coverage
$ cd build-coverage
$ cmake -DCMAKE_BUILD_TYPE=coverage ..
$ make
$ make coverage-html
Installation
------------
what gets installed
LC_ALL=C /usr/bin/intltool-merge -x -u --no-translations com.canonical.indicator.session.gschema.xml.in com.canonical.indicator.session.gschema.xml
FIXME: not tested
To get files that form part of an installation, run a "make install"
in the build directory. By default, this installs them in the "install"
subdirectory of the build directory. If you want to install into a
different directory, use
$ cmake -DCMAKE_INSTALL_PREFIX=/usr/local # Or wherever...
$ make release
$ make install
./README 0000644 0000041 0000041 00000004136 14061437245 012135 0 ustar www-data www-data Indicator-Session is the the session menu indicator for Unity.
Its behavior and features are listed at https://wiki.ubuntu.com/SystemMenu.
For instructions on building and running built-in tests, see the INSTALL file.
Notes for Client Renderers
--------------------------
Indicator-Session has two custom menuitems: the Guest and User switchers.
As per the https://wiki.ubuntu.com/SystemMenu specification, both need four
visual components: (1) an Active Session Mark, the user's (2) icon, (3) name,
and (4) a Logged In Mark.
== User menuitems have "x-canonical-type" set to "indicator.user-menu-item"
Their four visual components are determined by:
1. You can test for the Action Session Mark by checking the action's state.
The state is a dicionary whose "active-user" key yields the current
session's owner's username. If it matches the username in this menuitem's
"target" attribute, show the Active Session Mark.
2. The icon is stored in the menuitem's "icon" attribute. If none is set,
the client should use a fallback icon such as "avatar-default."
3. The name is stored in the menuitem's "label" attribute.
4. You can test for the Logged In Mark by checking the action's state.
The state is a dictionary whose "logged-in-users" key will give
an array of usernames. If the array contains the username in this
menuitem's "target" attribute, show the Logged In Mark.
== The Guest switcher has "x-canonical-type" set to "indicator.guest-menu-item"
action. Its four visual components are determined by:
1. You can test for the Active Session Mark by checking the action's state.
The state is a dictionary whose "is-active" key yields a boolean.
If the boolean is true, show the Active Session Mark.
2. The guest user should use a fallback icon such as "avatar-default."
3. The name ("Guest") is stored in the menuitem's "label" attribute.
4. You can test for the Logged In Mark by checking the action's state.
The state is a dictionary whose "is-logged-in" key yields a boolean.
If the boolean is true, show the Logged In Mark.
./COPYING 0000644 0000041 0000041 00000104374 14061437245 012315 0 ustar www-data www-data
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
.
./src/ 0000755 0000041 0000041 00000000000 14061437252 012036 5 ustar www-data www-data ./src/CMakeLists.txt 0000644 0000041 0000041 00000002136 14061437245 014602 0 ustar www-data www-data add_subdirectory (backend-dbus)
add_library (libindicatorsessionservice STATIC
actions.c
actions.h
guest.c
guest.h
service.c
service.h
users.c
users.h)
include_directories(${SERVICE_INCLUDE_DIRS})
link_directories(${SERVICE_LIBRARY_DIRS})
set (SERVICE_EXEC "indicator-session-service")
set_property (SOURCE main.c
APPEND PROPERTY COMPILE_DEFINITIONS
GETTEXT_PACKAGE="${GETTEXT_PACKAGE}"
GNOMELOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}")
add_executable (${SERVICE_EXEC} main.c)
target_link_libraries (${SERVICE_EXEC} libindicatorsessionservice backenddbus ${SERVICE_LIBRARIES})
install (TARGETS ${SERVICE_EXEC} RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_PKGLIBEXECDIR})
# common properties
set_property (TARGET libindicatorsessionservice ${SERVICE_EXEC}
APPEND_STRING PROPERTY COMPILE_FLAGS
" ${CC_WARNING_ARGS}")
# coverage reporting
set(COVERAGE_TARGETS
${COVERAGE_TARGETS}
libindicatorsessionservice
${SERVICE_EXEC}
PARENT_SCOPE
)
./src/service.c 0000644 0000041 0000041 00000132707 14061437252 013654 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 "backend.h"
#include "service.h"
#define BUS_NAME "com.canonical.indicator.session"
#define BUS_PATH "/com/canonical/indicator/session"
#define ICON_DEFAULT "system-devices-panel"
#define ICON_INFO "system-devices-panel-information"
#define ICON_ALERT "system-devices-panel-alert"
/* signals enum */
enum
{
NAME_LOST,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
enum
{
PROP_0,
PROP_MAX_USERS,
PROP_LAST
};
static GParamSpec * properties[PROP_LAST];
enum
{
SECTION_HEADER = (1<<0),
SECTION_ADMIN = (1<<1),
SECTION_SETTINGS = (1<<2),
SECTION_SWITCH = (1<<3),
SECTION_LOGOUT = (1<<4),
SECTION_SESSION = (1<<5)
};
enum
{
PROFILE_DESKTOP,
PROFILE_GREETER,
PROFILE_LOCKSCREEN,
N_PROFILES
};
static const char * const menu_names[N_PROFILES] =
{
"desktop",
"desktop_greeter",
"desktop_lockscreen"
};
static const char * const usage_mode_schema_name = "com.canonical.Unity8";
struct ProfileMenuInfo
{
/* the root level -- the header is the only child of this */
GMenu * menu;
/* parent of the sections. This is the header's submenu */
GMenu * submenu;
guint export_id;
};
struct _IndicatorSessionServicePrivate
{
guint own_id;
guint max_users;
IndicatorSessionUsers * backend_users;
IndicatorSessionGuest * backend_guest;
IndicatorSessionActions * backend_actions;
GSettings * indicator_settings;
GSettings * keybinding_settings;
GSettings * usage_mode_settings;
GSimpleActionGroup * actions;
guint actions_export_id;
struct ProfileMenuInfo menus[N_PROFILES];
GSimpleAction * header_action;
GSimpleAction * user_switcher_action;
GSimpleAction * guest_switcher_action;
GSimpleAction * usage_mode_action;
GHashTable * users;
GHashTable * reported_users;
guint rebuild_id;
int rebuild_flags;
GDBusConnection * conn;
GCancellable * cancellable;
GVariant * default_icon_serialized;
};
typedef IndicatorSessionServicePrivate priv_t;
G_DEFINE_TYPE_WITH_PRIVATE (IndicatorSessionService, indicator_session_service, G_TYPE_OBJECT)
static const char * get_current_real_name (IndicatorSessionService * self);
/***
****
***/
static void rebuild_now (IndicatorSessionService * self, int section);
static void rebuild_soon (IndicatorSessionService * self, int section);
static inline void
rebuild_header_soon (IndicatorSessionService * self)
{
rebuild_soon (self, SECTION_HEADER);
}
static inline void
rebuild_switch_section_soon (IndicatorSessionService * self)
{
rebuild_soon (self, SECTION_SWITCH);
}
static inline void
rebuild_logout_section_soon (IndicatorSessionService * self)
{
rebuild_soon (self, SECTION_LOGOUT);
}
static inline void
rebuild_session_section_soon (IndicatorSessionService * self)
{
rebuild_soon (self, SECTION_SESSION);
}
static inline void
rebuild_settings_section_soon (IndicatorSessionService * self)
{
rebuild_soon (self, SECTION_SETTINGS);
}
static inline void
rebuild_admin_section_soon (IndicatorSessionService * self)
{
rebuild_soon (self, SECTION_ADMIN);
}
/***
****
***/
static gboolean
show_user_list (IndicatorSessionService * self)
{
return g_settings_get_boolean (self->priv->indicator_settings,
"user-show-menu");
}
static GVariant *
action_state_for_header (IndicatorSessionService * self)
{
const priv_t * const p = self->priv;
gboolean show_name;
const gchar * real_name;
const gchar * label;
gchar * a11y;
GVariantBuilder b;
GVariant * state;
show_name = g_settings_get_boolean (p->indicator_settings,
"show-real-name-on-panel");
real_name = get_current_real_name (self);
label = show_name && real_name ? real_name : "";
if (*label)
{
/* Translators: the name of the menu ("System"), then the user's name */
a11y = g_strdup_printf (_("System, %s"), label);
}
else
{
a11y = g_strdup (_("System"));
}
/* build the state */
g_variant_builder_init (&b, G_VARIANT_TYPE("a{sv}"));
g_variant_builder_add (&b, "{sv}", "accessible-desc", g_variant_new_string (a11y));
g_variant_builder_add (&b, "{sv}", "icon", p->default_icon_serialized);
if (label && *label)
g_variant_builder_add (&b, "{sv}", "label", g_variant_new_string (label));
g_variant_builder_add (&b, "{sv}", "visible", g_variant_new_boolean (TRUE));
state = g_variant_builder_end (&b);
/* cleanup */
g_free (a11y);
return state;
}
static void
update_header_action (IndicatorSessionService * self)
{
g_simple_action_set_state (self->priv->header_action, action_state_for_header (self));
}
/***
**** USERS
***/
static GMenuModel * create_switch_section (IndicatorSessionService * self, int profile);
static void
add_user (IndicatorSessionService * self, guint uid)
{
IndicatorSessionUser * u;
if ((u = indicator_session_users_get_user (self->priv->backend_users, uid)))
{
/* update our user table */
g_hash_table_insert (self->priv->users, GUINT_TO_POINTER(uid), u);
/* queue rebuilds for the affected sections */
rebuild_switch_section_soon (self);
if (u->is_current_user)
rebuild_header_soon (self);
}
}
static void
on_user_added (IndicatorSessionUsers * backend_users G_GNUC_UNUSED,
guint uid,
gpointer gself)
{
add_user (INDICATOR_SESSION_SERVICE(gself), uid);
}
static void
on_user_changed (IndicatorSessionUsers * backend_users G_GNUC_UNUSED,
guint uid,
gpointer gself)
{
add_user (INDICATOR_SESSION_SERVICE(gself), uid);
}
static void
maybe_add_users (IndicatorSessionService * self)
{
if (show_user_list (self))
{
GList * uids, * l;
uids = indicator_session_users_get_uids (self->priv->backend_users);
for (l=uids; l!=NULL; l=l->next)
add_user (self, GPOINTER_TO_UINT(l->data));
g_list_free (uids);
}
}
static void
user_show_menu_changed (IndicatorSessionService * self)
{
if (show_user_list (self))
maybe_add_users (self);
else
g_hash_table_remove_all (self->priv->users);
rebuild_switch_section_soon (self);
}
static void
on_user_removed (IndicatorSessionUsers * backend_users G_GNUC_UNUSED,
guint uid,
gpointer gself)
{
IndicatorSessionService * self = INDICATOR_SESSION_SERVICE (gself);
g_return_if_fail (self != NULL);
/* update our user table */
g_hash_table_remove (self->priv->users, GUINT_TO_POINTER(uid));
/* enqueue rebuilds for the affected sections */
rebuild_switch_section_soon (self);
}
static const char *
get_user_label (const IndicatorSessionUser * user)
{
const char * c;
/* if real_name exists and is printable, use it */
c = user->real_name;
if ((c != NULL) && g_utf8_validate(c, -1, NULL))
{
while (*c != '\0')
{
if (g_unichar_isgraph(g_utf8_get_char(c)))
return user->real_name;
c = g_utf8_next_char(c);
}
}
/* otherwise, use this as a fallback */
return user->user_name;
}
static const char *
get_current_real_name (IndicatorSessionService * self)
{
GHashTableIter iter;
gpointer key, value;
/* is it the guest? */
if (indicator_session_guest_is_active (self->priv->backend_guest))
return _("Guest");
/* is it a user? */
g_hash_table_iter_init (&iter, self->priv->users);
while (g_hash_table_iter_next (&iter, &key, &value))
{
IndicatorSessionUser * user = value;
if (user->is_current_user)
return get_user_label (user);
}
return "";
}
/***
****
***/
static GHashTable*
get_os_release (void)
{
static const char * const os_release = "/etc/os-release";
GHashTable * hash;
GIOChannel * io;
hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
if ((io = g_io_channel_new_file (os_release, "r", NULL)))
{
GString * key = g_string_new (NULL);
for (;;)
{
GIOStatus status;
char * in;
GError * error;
gchar * val;
/* read a line */
status = g_io_channel_read_line_string (io, key, NULL, NULL);
if (status == G_IO_STATUS_EOF)
break;
/* ignore blank lines & comments */
if (!key->len || key->str[0]=='#')
continue;
/* split into key=value */
in = strchr(key->str, '=');
if (!in)
continue;
*in++ = '\0';
/* unmunge the value component */
g_strstrip(in); /* eat linefeed */
error = NULL;
val = g_shell_unquote (in, &error);
if (error != NULL)
{
g_warning("Unable to unquote \"%s\": %s", in, error->message);
val = g_strdup(in);
g_clear_error(&error);
}
g_debug("from \"%s\": key [%s] val [%s]", os_release, key->str, val);
g_hash_table_insert (hash, g_strdup(key->str), val); /* hash owns val now */
}
g_string_free(key, TRUE);
g_io_channel_unref(io);
}
return hash;
}
static const char*
get_distro_name (void)
{
static char * distro_name = NULL;
if (distro_name == NULL)
{
GHashTable * os_release = get_os_release();
gpointer value = g_hash_table_lookup(os_release, "NAME");
if (value == NULL)
value = "Ubuntu"; /* fallback value */
distro_name = g_strdup(value);
g_hash_table_destroy(os_release);
}
return distro_name;
}
static gboolean
usage_mode_to_action_state(GValue *value,
GVariant *variant,
gpointer unused G_GNUC_UNUSED)
{
const gchar* usage_mode = g_variant_get_string(variant, NULL);
GVariant* ret_var = g_variant_new_boolean(g_strcmp0(usage_mode, "Windowed") == 0 ? TRUE : FALSE);
g_value_set_variant(value, ret_var);
return TRUE;
}
static GVariant*
action_state_to_usage_mode(const GValue *value,
const GVariantType * unused_expected_type G_GNUC_UNUSED,
gpointer unused G_GNUC_UNUSED)
{
GVariant* var = g_value_get_variant(value);
GVariant* ret = g_variant_new_string(g_variant_get_boolean(var) == TRUE ? "Windowed" : "Staged");
return ret;
}
static void
on_usage_mode_setting_changed (gpointer gself)
{
rebuild_admin_section_soon((IndicatorSessionService*)(gself));
}
static GMenuModel *
create_admin_section (IndicatorSessionService * self)
{
GMenu * menu;
priv_t * p = self->priv;
gchar * help_label = g_strdup_printf(_("%s Help…"), get_distro_name());
menu = g_menu_new ();
if (g_getenv ("MIR_SOCKET") != NULL) {
g_menu_append (menu, _("About This Device…"), "indicator.about");
} else {
g_menu_append (menu, _("About This Computer"), "indicator.about");
}
g_menu_append (menu, help_label, "indicator.help");
g_free (help_label);
if (p->usage_mode_action && g_getenv ("MIR_SOCKET") != NULL) // only under unity8
{
GMenuItem * menu_item = NULL;
menu_item = g_menu_item_new(_("Desktop Mode"), "indicator.usage-mode");
g_menu_item_set_attribute(menu_item, "x-canonical-type", "s", "com.canonical.indicator.switch");
g_menu_append_item(menu, menu_item);
g_object_unref(menu_item);
}
return G_MENU_MODEL (menu);
}
static GMenuModel *
create_settings_section (IndicatorSessionService * self)
{
GMenu * menu;
priv_t * p = self->priv;
menu = g_menu_new ();
g_menu_append (menu, _("System Settings…"), "indicator.settings");
if (indicator_session_actions_has_online_account_error (p->backend_actions))
g_menu_append (menu, _("Online Accounts…"), "indicator.online-accounts");
return G_MENU_MODEL (menu);
}
/**
* The switch-to-guest action's state is a dictionary with these entries:
* - "is-active" (boolean)
* - "is-logged-in" (boolean)
*/
static GVariant *
create_guest_switcher_state (IndicatorSessionService * self)
{
GVariant * val;
GVariantBuilder b;
IndicatorSessionGuest * const g = self->priv->backend_guest;
g_variant_builder_init (&b, G_VARIANT_TYPE ("a{sv}"));
val = g_variant_new_boolean (indicator_session_guest_is_active (g));
g_variant_builder_add (&b, "{sv}", "is-active", val);
val = g_variant_new_boolean (indicator_session_guest_is_logged_in (g));
g_variant_builder_add (&b, "{sv}", "is-logged-in", val);
return g_variant_builder_end (&b);
}
/**
* The switch-to-user action's state is a dictionary with these entries:
* - "active-user" (username string)
* - "logged-in-users" (array of username strings)
*/
static GVariant *
create_user_switcher_state (IndicatorSessionService * self)
{
GVariantBuilder a;
GVariantBuilder b;
GVariant * val;
GHashTableIter ht_iter;
gpointer ht_value;
const char * current_user;
current_user = "";
g_variant_builder_init (&a, G_VARIANT_TYPE("as"));
g_hash_table_iter_init (&ht_iter, self->priv->users);
while (g_hash_table_iter_next (&ht_iter, NULL, &ht_value))
{
const IndicatorSessionUser * u = ht_value;
if (u->is_current_user)
current_user = u->user_name;
if (u->is_logged_in)
g_variant_builder_add (&a, "s", u->user_name);
}
g_variant_builder_init (&b, G_VARIANT_TYPE("a{sv}"));
val = g_variant_new_string (current_user);
g_variant_builder_add (&b, "{sv}", "active-user", val);
val = g_variant_builder_end (&a);
g_variant_builder_add (&b, "{sv}", "logged-in-users", val);
return g_variant_builder_end (&b);
}
static void
update_switch_actions (IndicatorSessionService * self)
{
g_simple_action_set_state (self->priv->guest_switcher_action,
create_guest_switcher_state (self));
g_simple_action_set_state (self->priv->user_switcher_action,
create_user_switcher_state (self));
}
static gboolean
use_ellipsis (IndicatorSessionService * self)
{
/* does the backend support confirmation prompts? */
if (!indicator_session_actions_can_prompt (self->priv->backend_actions))
return FALSE;
/* has the user disabled prompts? */
if (g_settings_get_boolean (self->priv->indicator_settings,
"suppress-logout-restart-shutdown"))
return FALSE;
return TRUE;
}
/* lower index == more useful.
When there are too many users for the menu,
we use this to decide which to cull. */
static int
compare_users_by_usefulness (gconstpointer ga, gconstpointer gb)
{
const IndicatorSessionUser * a = *(const IndicatorSessionUser**)ga;
const IndicatorSessionUser * b = *(const IndicatorSessionUser**)gb;
if (a->is_current_user != b->is_current_user)
return a->is_current_user ? -1 : 1;
if (a->is_logged_in != b->is_logged_in)
return a->is_logged_in ? -1 : 1;
if (a->login_frequency != b->login_frequency)
return a->login_frequency > b->login_frequency ? -1 : 1;
return 0;
}
/* sorting them for display in the menu */
static int
compare_users_by_label (gconstpointer ga, gconstpointer gb)
{
int i;
const IndicatorSessionUser * a = *(const IndicatorSessionUser**)ga;
const IndicatorSessionUser * b = *(const IndicatorSessionUser**)gb;
if ((i = g_strcmp0 (get_user_label (a), get_user_label (b))))
return i;
return g_strcmp0 (a->user_name, b->user_name);
}
static GVariant *
serialize_icon_file (const gchar * filename)
{
GVariant * serialized_icon = NULL;
if (filename != NULL)
{
GFile * file = g_file_new_for_path (filename);
GIcon * icon = g_file_icon_new (file);
serialized_icon = g_icon_serialize (icon);
g_object_unref (icon);
g_object_unref (file);
}
return serialized_icon;
}
static void
report_unusable_user (IndicatorSessionService * self, const IndicatorSessionUser * u)
{
const priv_t * const p = self->priv;
gpointer key;
g_return_if_fail(u != NULL);
key = GUINT_TO_POINTER(u->uid);
if (!g_hash_table_contains (p->reported_users, key))
{
gchar * uid_str = g_strdup_printf("%u", u->uid);
const char * properties[] = {
"uid", uid_str,
"icon_file", (u->icon_file ? u->icon_file : "(null)"),
"is_current_user", (u->is_current_user ? "true" : "false"),
"is_logged_in", (u->is_logged_in ? "true" : "false"),
"real_name", (u->real_name ? u->real_name : "(null)"),
"user_name", (u->user_name ? u->user_name : "(null)"),
NULL
};
whoopsie_report_recoverable_problem("indicator-session-unknown-user-error", 0, FALSE, properties);
/* mark it as reported so that we'll only report it once */
g_hash_table_add (p->reported_users, key);
g_free (uid_str);
}
}
static GMenuModel *
create_switch_section (IndicatorSessionService * self, int profile)
{
GMenu * menu;
GMenuItem * item = NULL;
gboolean want_accel;
guint i;
gpointer guser;
GHashTableIter iter;
GPtrArray * users;
const priv_t * const p = self->priv;
const gboolean ellipsis = use_ellipsis (self);
menu = g_menu_new ();
/* lockswitch */
if (indicator_session_users_is_live_session (p->backend_users))
{
const char * action = "indicator.switch-to-screensaver";
item = g_menu_item_new (_("Start Screen Saver"), action);
want_accel = TRUE;
}
else if (profile == PROFILE_LOCKSCREEN ||
indicator_session_guest_is_active (p->backend_guest))
{
const char * action = "indicator.switch-to-greeter";
if (indicator_session_actions_can_switch (p->backend_actions))
item = g_menu_item_new (ellipsis ? _("Switch Account…")
: _("Switch Account"), action);
want_accel = FALSE;
}
else
{
const char * lock_switch_action = "indicator.switch-to-screensaver";
const char * switch_action = "indicator.switch-to-greeter";
if (g_hash_table_size (p->users) > 1 &&
indicator_session_actions_can_switch (p->backend_actions))
{
if (indicator_session_actions_can_lock (p->backend_actions))
item = g_menu_item_new (ellipsis ? _("Lock/Switch Account…")
: _("Lock/Switch Account"), lock_switch_action);
else
item = g_menu_item_new (ellipsis ? _("Switch Account…")
: _("Switch Account"), switch_action);
}
else if (indicator_session_actions_can_lock (p->backend_actions))
item = g_menu_item_new (_("Lock"), lock_switch_action);
want_accel = TRUE;
}
if (item)
{
if (want_accel)
{
GVariant * value = g_settings_get_value (p->keybinding_settings, "screensaver");
if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING_ARRAY))
{
const gchar ** strs = g_variant_get_strv (value, NULL);
if (strs)
g_menu_item_set_attribute (item, "accel", "s", strs[0]);
g_free (strs);
}
else
{
const gchar * str = g_variant_get_string (value, NULL);
g_menu_item_set_attribute (item, "accel", "s", str);
}
g_variant_unref (value);
}
g_menu_append_item (menu, item);
g_object_unref (item);
}
if (!indicator_session_actions_can_switch (p->backend_actions))
return G_MENU_MODEL (menu);
if (indicator_session_guest_is_allowed (p->backend_guest))
{
GMenuItem *item;
item = g_menu_item_new (_("Guest Session"), "indicator.switch-to-guest");
g_menu_item_set_attribute (item, "x-canonical-type", "s", "indicator.guest-menu-item");
g_menu_append_item (menu, item);
g_object_unref (item);
}
/* if we need to show the user list, build an array of all the users we know
* of, otherwise get out now */
if (!show_user_list (self))
return G_MENU_MODEL (menu);
users = g_ptr_array_new ();
g_hash_table_iter_init (&iter, p->users);
while (g_hash_table_iter_next (&iter, NULL, &guser))
g_ptr_array_add (users, guser);
/* if there are too many users, cull out the less interesting ones */
if (users->len > p->max_users)
{
g_ptr_array_sort (users, compare_users_by_usefulness);
g_ptr_array_set_size (users, p->max_users);
}
/* sort the users by name */
g_ptr_array_sort (users, compare_users_by_label);
/* add the users */
for (i=0; ilen; ++i)
{
const IndicatorSessionUser * u = g_ptr_array_index (users, i);
const char * label;
GVariant * serialized_icon;
if (profile == PROFILE_LOCKSCREEN && u->is_current_user)
continue;
/* Sometimes we get a user without a username? bus hiccup.
I can't reproduce it, but let's not confuse users with
a meaningless menuitem. (see bug #1263228) */
label = get_user_label (u);
if (!label || !*label)
{
report_unusable_user (self, u);
continue;
}
item = g_menu_item_new (label, NULL);
g_menu_item_set_action_and_target (item, "indicator.switch-to-user", "s", u->user_name);
g_menu_item_set_attribute (item, "x-canonical-type", "s", "indicator.user-menu-item");
if ((serialized_icon = serialize_icon_file (u->icon_file)))
{
g_menu_item_set_attribute_value (item, G_MENU_ATTRIBUTE_ICON, serialized_icon);
g_variant_unref (serialized_icon);
}
g_menu_append_item (menu, item);
g_object_unref (item);
}
/* cleanup */
g_ptr_array_free (users, TRUE);
return G_MENU_MODEL (menu);
}
static GMenuModel *
create_logout_section (IndicatorSessionService * self)
{
GMenu * menu;
const priv_t * const p = self->priv;
const gboolean ellipsis = use_ellipsis (self);
menu = g_menu_new ();
if (indicator_session_actions_can_logout (p->backend_actions))
{
const char * label = ellipsis ? _("Log Out…") : _("Log Out");
g_menu_append (menu, label, "indicator.logout");
}
return G_MENU_MODEL (menu);
}
static GMenuModel *
create_session_section (IndicatorSessionService * self, int profile)
{
GMenu * menu;
const priv_t * const p = self->priv;
GSettings * const s = p->indicator_settings;
const gboolean ellipsis = use_ellipsis (self);
menu = g_menu_new ();
if (indicator_session_actions_can_suspend (p->backend_actions))
g_menu_append (menu, _("Suspend"), "indicator.suspend");
if (indicator_session_actions_can_hibernate (p->backend_actions))
g_menu_append (menu, _("Hibernate"), "indicator.hibernate");
if (profile != PROFILE_LOCKSCREEN &&
indicator_session_actions_can_reboot (p->backend_actions))
{
const char * label = ellipsis ? _("Restart…") : _("Restart");
g_menu_append (menu, label, "indicator.reboot");
}
if (profile != PROFILE_LOCKSCREEN &&
!g_settings_get_boolean (s, "suppress-shutdown-menuitem"))
{
const char * label = ellipsis ? _("Shut Down…") : _("Shut Down");
g_menu_append (menu, label, "indicator.power-off");
}
return G_MENU_MODEL (menu);
}
static void
create_menu (IndicatorSessionService * self, int profile)
{
GMenu * menu;
GMenu * submenu;
GMenuItem * header;
GMenuModel * sections[16];
int i;
int n = 0;
g_assert (0<=profile && profilepriv->menus[profile].menu == NULL);
if (profile == PROFILE_DESKTOP)
{
sections[n++] = create_admin_section (self);
sections[n++] = create_settings_section (self);
sections[n++] = create_switch_section (self, profile);
sections[n++] = create_logout_section (self);
sections[n++] = create_session_section (self, profile);
}
else if (profile == PROFILE_GREETER)
{
sections[n++] = create_session_section (self, profile);
}
else if (profile == PROFILE_LOCKSCREEN)
{
sections[n++] = create_switch_section (self, profile);
sections[n++] = create_session_section (self, profile);
}
/* add sections to the submenu */
submenu = g_menu_new ();
for (i=0; ipriv->menus[profile].menu = menu;
self->priv->menus[profile].submenu = submenu;
}
/***
**** GActions
***/
static IndicatorSessionActions *
get_backend_actions (gpointer gself)
{
return INDICATOR_SESSION_SERVICE(gself)->priv->backend_actions;
}
static void
on_about_activated (GSimpleAction * a G_GNUC_UNUSED,
GVariant * param G_GNUC_UNUSED,
gpointer gself)
{
indicator_session_actions_about (get_backend_actions(gself));
}
static void
on_online_accounts_activated (GSimpleAction * a G_GNUC_UNUSED,
GVariant * param G_GNUC_UNUSED,
gpointer gself)
{
indicator_session_actions_online_accounts (get_backend_actions(gself));
}
static void
on_help_activated (GSimpleAction * a G_GNUC_UNUSED,
GVariant * param G_GNUC_UNUSED,
gpointer gself)
{
indicator_session_actions_help (get_backend_actions(gself));
}
static void
on_settings_activated (GSimpleAction * a G_GNUC_UNUSED,
GVariant * param G_GNUC_UNUSED,
gpointer gself)
{
indicator_session_actions_settings (get_backend_actions(gself));
}
static void
on_logout_activated (GSimpleAction * a G_GNUC_UNUSED,
GVariant * param G_GNUC_UNUSED,
gpointer gself)
{
indicator_session_actions_logout (get_backend_actions(gself));
}
static void
on_suspend_activated (GSimpleAction * a G_GNUC_UNUSED,
GVariant * param G_GNUC_UNUSED,
gpointer gself)
{
indicator_session_actions_suspend (get_backend_actions(gself));
}
static void
on_hibernate_activated (GSimpleAction * a G_GNUC_UNUSED,
GVariant * param G_GNUC_UNUSED,
gpointer gself)
{
indicator_session_actions_hibernate (get_backend_actions(gself));
}
static void
on_reboot_activated (GSimpleAction * action G_GNUC_UNUSED,
GVariant * param G_GNUC_UNUSED,
gpointer gself)
{
indicator_session_actions_reboot (get_backend_actions(gself));
}
static void
on_power_off_activated (GSimpleAction * a G_GNUC_UNUSED,
GVariant * param G_GNUC_UNUSED,
gpointer gself)
{
indicator_session_actions_power_off (get_backend_actions(gself));
}
static void
on_guest_activated (GSimpleAction * a G_GNUC_UNUSED,
GVariant * param G_GNUC_UNUSED,
gpointer gself)
{
indicator_session_actions_switch_to_guest (get_backend_actions(gself));
}
static void
on_screensaver_activated (GSimpleAction * a G_GNUC_UNUSED,
GVariant * param G_GNUC_UNUSED,
gpointer gself)
{
indicator_session_actions_switch_to_screensaver (get_backend_actions(gself));
}
static void
on_greeter_activated (GSimpleAction * a G_GNUC_UNUSED,
GVariant * param G_GNUC_UNUSED,
gpointer gself)
{
indicator_session_actions_switch_to_greeter (get_backend_actions(gself));
}
static void
on_user_activated (GSimpleAction * a G_GNUC_UNUSED,
GVariant * param,
gpointer gself)
{
const char * username = g_variant_get_string (param, NULL);
indicator_session_actions_switch_to_username (get_backend_actions(gself),
username);
}
static void
init_gactions (IndicatorSessionService * self)
{
GVariant * v;
GSimpleAction * a;
priv_t * p = self->priv;
GActionEntry entries[] = {
{ "about", on_about_activated },
{ "help", on_help_activated },
{ "hibernate", on_hibernate_activated },
{ "logout", on_logout_activated },
{ "online-accounts", on_online_accounts_activated },
{ "reboot", on_reboot_activated },
{ "settings", on_settings_activated },
{ "switch-to-screensaver", on_screensaver_activated },
{ "switch-to-greeter", on_greeter_activated },
{ "suspend", on_suspend_activated },
{ "power-off", on_power_off_activated }
};
p->actions = g_simple_action_group_new ();
g_action_map_add_action_entries (G_ACTION_MAP(p->actions),
entries,
G_N_ELEMENTS(entries),
self);
/* add switch-to-guest action */
v = create_guest_switcher_state (self);
a = g_simple_action_new_stateful ("switch-to-guest", NULL, v);
g_signal_connect (a, "activate", G_CALLBACK(on_guest_activated), self);
g_action_map_add_action (G_ACTION_MAP (p->actions), G_ACTION(a));
p->guest_switcher_action = a;
/* add switch-to-user action... parameter is the username */
v = create_user_switcher_state (self);
a = g_simple_action_new_stateful ("switch-to-user", G_VARIANT_TYPE_STRING, v);
g_signal_connect (a, "activate", G_CALLBACK(on_user_activated), self);
g_action_map_add_action (G_ACTION_MAP (p->actions), G_ACTION(a));
p->user_switcher_action = a;
/* add usage-mode action */
if (p->usage_mode_settings)
{
a = g_simple_action_new_stateful("usage-mode",
NULL,
g_variant_new_boolean(FALSE));
g_settings_bind_with_mapping(p->usage_mode_settings, "usage-mode",
a, "state",
G_SETTINGS_BIND_DEFAULT,
usage_mode_to_action_state,
action_state_to_usage_mode,
NULL,
NULL);
g_action_map_add_action(G_ACTION_MAP(p->actions), G_ACTION(a));
g_signal_connect_swapped(p->usage_mode_settings, "changed::usage-mode",
G_CALLBACK(on_usage_mode_setting_changed), self);
p->usage_mode_action = a;
}
/* add the header action */
a = g_simple_action_new_stateful ("_header", NULL,
action_state_for_header (self));
g_action_map_add_action (G_ACTION_MAP (p->actions), G_ACTION(a));
p->header_action = a;
rebuild_now (self, SECTION_HEADER);
}
/***
****
***/
/**
* A small helper function for rebuild_now().
* - removes the previous section
* - adds and unrefs the new section
*/
static void
rebuild_section (GMenu * parent, int pos, GMenuModel * new_section)
{
g_menu_remove (parent, pos);
g_menu_insert_section (parent, pos, NULL, new_section);
g_object_unref (new_section);
}
static void
rebuild_now (IndicatorSessionService * self, int sections)
{
priv_t * p = self->priv;
struct ProfileMenuInfo * desktop = &p->menus[PROFILE_DESKTOP];
struct ProfileMenuInfo * greeter = &p->menus[PROFILE_GREETER];
struct ProfileMenuInfo * lockscreen = &p->menus[PROFILE_LOCKSCREEN];
if (sections & SECTION_HEADER)
{
update_header_action (self);
}
if (sections & SECTION_ADMIN)
{
rebuild_section (desktop->submenu, 0, create_admin_section(self));
}
if (sections & SECTION_SETTINGS)
{
rebuild_section (desktop->submenu, 1, create_settings_section(self));
}
if (sections & SECTION_SWITCH)
{
rebuild_section (desktop->submenu, 2, create_switch_section(self, PROFILE_DESKTOP));
rebuild_section (lockscreen->submenu, 0, create_switch_section(self, PROFILE_LOCKSCREEN));
update_switch_actions (self);
}
if (sections & SECTION_LOGOUT)
{
rebuild_section (desktop->submenu, 3, create_logout_section(self));
}
if (sections & SECTION_SESSION)
{
rebuild_section (desktop->submenu, 4, create_session_section(self, PROFILE_DESKTOP));
rebuild_section (greeter->submenu, 0, create_session_section(self, PROFILE_GREETER));
rebuild_section (lockscreen->submenu, 1, create_session_section(self, PROFILE_LOCKSCREEN));
}
}
static int
rebuild_timeout_func (IndicatorSessionService * self)
{
priv_t * p = self->priv;
rebuild_now (self, p->rebuild_flags);
p->rebuild_flags = 0;
p->rebuild_id = 0;
return G_SOURCE_REMOVE;
}
static void
rebuild_soon (IndicatorSessionService * self, int section)
{
priv_t * p = self->priv;
p->rebuild_flags |= section;
if (p->rebuild_id == 0)
{
/* Change events seem to come over the bus in small bursts. This msec
value is an arbitrary number that tries to be large enough to fold
multiple events into a single rebuild, but small enough that the
user won't notice any lag. */
static const int REBUILD_INTERVAL_MSEC = 500;
p->rebuild_id = g_timeout_add (REBUILD_INTERVAL_MSEC,
(GSourceFunc)rebuild_timeout_func,
self);
}
}
/***
**** GDBus
***/
static void
on_bus_acquired (GDBusConnection * connection,
const gchar * name,
gpointer gself)
{
int i;
guint id;
GError * err = NULL;
IndicatorSessionService * self = INDICATOR_SESSION_SERVICE(gself);
priv_t * p = self->priv;
g_debug ("bus acquired: %s", name);
p->conn = g_object_ref (connection);
/* export the actions */
if ((id = g_dbus_connection_export_action_group (connection,
BUS_PATH,
G_ACTION_GROUP (p->actions),
&err)))
{
p->actions_export_id = id;
}
else
{
g_warning ("cannot export action group: %s", err->message);
g_clear_error (&err);
}
/* export the menus */
for (i=0; imenus[i];
if (menu->menu == NULL)
create_menu (self, i);
if ((id = g_dbus_connection_export_menu_model (connection,
path,
G_MENU_MODEL (menu->menu),
&err)))
{
menu->export_id = id;
}
else
{
g_warning ("cannot export %s menu: %s", menu_names[i], err->message);
g_clear_error (&err);
}
g_free (path);
}
}
static void
unexport (IndicatorSessionService * self)
{
int i;
priv_t * p = self->priv;
/* unexport the menus */
for (i=0; ipriv->menus[i].export_id;
if (*id)
{
g_dbus_connection_unexport_menu_model (p->conn, *id);
*id = 0;
}
}
/* unexport the actions */
if (p->actions_export_id)
{
g_dbus_connection_unexport_action_group (p->conn, p->actions_export_id);
p->actions_export_id = 0;
}
}
static void
on_name_lost (GDBusConnection * connection G_GNUC_UNUSED,
const gchar * name,
gpointer gself)
{
IndicatorSessionService * self = INDICATOR_SESSION_SERVICE (gself);
g_debug ("%s %s name lost %s", G_STRLOC, G_STRFUNC, name);
unexport (self);
g_signal_emit (self, signals[NAME_LOST], 0, NULL);
}
static gboolean
desktop_is_unity (void)
{
const gchar * xdg_current_desktop;
gchar ** desktop_names;
int i;
xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
if (xdg_current_desktop == NULL)
return FALSE;
desktop_names = g_strsplit (xdg_current_desktop, ":", 0);
for (i = 0; desktop_names[i]; ++i)
{
if (g_strcmp0 (desktop_names[i], "Unity") == 0)
{
g_strfreev (desktop_names);
return TRUE;
}
}
g_strfreev (desktop_names);
return FALSE;
}
/***
****
***/
static void
/* cppcheck-suppress unusedFunction */
indicator_session_service_init (IndicatorSessionService * self)
{
priv_t * p;
gpointer gp;
GIcon * icon;
GSettingsSchema * usage_mode_schema;
/* init our priv pointer */
p = indicator_session_service_get_instance_private (self);
p->indicator_settings = g_settings_new ("com.canonical.indicator.session");
if (desktop_is_unity ())
p->keybinding_settings = g_settings_new ("com.canonical.unity.settings-daemon.plugins.media-keys");
else
p->keybinding_settings = g_settings_new ("org.gnome.settings-daemon.plugins.media-keys");
/* Only use unity8 schema if it's installed; this avoids a hard dependency
on unity8-schemas */
usage_mode_schema = g_settings_schema_source_lookup (g_settings_schema_source_get_default (),
usage_mode_schema_name, TRUE);
if (usage_mode_schema)
{
p->usage_mode_settings = g_settings_new (usage_mode_schema_name);
g_settings_schema_unref (usage_mode_schema);
}
self->priv = p;
/* init the backend objects */
p->cancellable = g_cancellable_new ();
backend_get (p->cancellable, &p->backend_actions,
&p->backend_users,
&p->backend_guest);
icon = g_themed_icon_new_with_default_fallbacks (ICON_DEFAULT);
p->default_icon_serialized = g_icon_serialize (icon);
g_object_unref (icon);
/* init our key-to-User table */
p->users = g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
(GDestroyNotify)indicator_session_user_free);
p->reported_users = g_hash_table_new (g_direct_hash, g_direct_equal);
maybe_add_users (self);
init_gactions (self);
/* watch for changes in backend_users */
gp = p->backend_users;
g_signal_connect (gp, INDICATOR_SESSION_USERS_SIGNAL_USER_ADDED,
G_CALLBACK(on_user_added), self);
g_signal_connect (gp, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED,
G_CALLBACK(on_user_changed), self);
g_signal_connect (gp, INDICATOR_SESSION_USERS_SIGNAL_USER_REMOVED,
G_CALLBACK(on_user_removed), self);
g_signal_connect_swapped (gp, "notify::is-live-session",
G_CALLBACK(rebuild_switch_section_soon), self);
/* watch for changes in backend_guest */
gp = p->backend_guest;
g_signal_connect_swapped (gp, "notify::guest-is-active-session",
G_CALLBACK(rebuild_header_soon), self);
g_signal_connect_swapped (gp, "notify",
G_CALLBACK(rebuild_switch_section_soon), self);
/* watch for updates in backend_actions */
gp = p->backend_actions;
g_signal_connect_swapped (gp, "notify",
G_CALLBACK(rebuild_switch_section_soon), self);
g_signal_connect_swapped (gp, "notify",
G_CALLBACK(rebuild_logout_section_soon), self);
g_signal_connect_swapped (gp, "notify",
G_CALLBACK(rebuild_session_section_soon), self);
g_signal_connect_swapped (gp, "notify::has-online-account-error",
G_CALLBACK(rebuild_header_soon), self);
g_signal_connect_swapped (gp, "notify::has-online-account-error",
G_CALLBACK(rebuild_settings_section_soon), self);
/* watch for changes in the indicator's settings */
gp = p->indicator_settings;
g_signal_connect_swapped (gp, "changed::suppress-logout-restart-shutdown",
G_CALLBACK(rebuild_switch_section_soon), self);
g_signal_connect_swapped (gp, "changed::suppress-logout-restart-shutdown",
G_CALLBACK(rebuild_logout_section_soon), self);
g_signal_connect_swapped (gp, "changed::suppress-logout-restart-shutdown",
G_CALLBACK(rebuild_session_section_soon), self);
g_signal_connect_swapped (gp, "changed::suppress-shutdown-menuitem",
G_CALLBACK(rebuild_session_section_soon), self);
g_signal_connect_swapped (gp, "changed::show-real-name-on-panel",
G_CALLBACK(rebuild_header_soon), self);
g_signal_connect_swapped (gp, "changed::user-show-menu",
G_CALLBACK(user_show_menu_changed), self);
/* watch for changes to the lock keybinding */
gp = p->keybinding_settings;
g_signal_connect_swapped (gp, "changed::screensaver",
G_CALLBACK(rebuild_switch_section_soon), self);
self->priv->own_id = g_bus_own_name (G_BUS_TYPE_SESSION,
BUS_NAME,
G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
on_bus_acquired,
NULL,
on_name_lost,
self,
NULL);
}
/***
**** GObject plumbing: properties
***/
static void
my_get_property (GObject * o,
guint property_id,
GValue * value,
GParamSpec * pspec)
{
IndicatorSessionService * self = INDICATOR_SESSION_SERVICE (o);
switch (property_id)
{
case PROP_MAX_USERS:
g_value_set_uint (value, self->priv->max_users);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
}
}
static void
my_set_property (GObject * o,
guint property_id,
const GValue * value,
GParamSpec * pspec)
{
IndicatorSessionService * self = INDICATOR_SESSION_SERVICE (o);
switch (property_id)
{
case PROP_MAX_USERS:
self->priv->max_users = g_value_get_uint (value);
rebuild_switch_section_soon (self);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
}
}
/***
**** GObject plumbing: life cycle
***/
static void
my_dispose (GObject * o)
{
int i;
IndicatorSessionService * self = INDICATOR_SESSION_SERVICE(o);
priv_t * p = self->priv;
if (p->own_id)
{
g_bus_unown_name (p->own_id);
p->own_id = 0;
}
unexport (self);
if (p->cancellable != NULL)
{
g_cancellable_cancel (p->cancellable);
g_clear_object (&p->cancellable);
}
if (p->rebuild_id)
{
g_source_remove (p->rebuild_id);
p->rebuild_id = 0;
}
g_clear_pointer (&p->users, g_hash_table_destroy);
g_clear_pointer (&p->reported_users, g_hash_table_destroy);
g_clear_object (&p->backend_users);
g_clear_object (&p->backend_guest);
g_clear_object (&p->backend_actions);
g_clear_object (&p->indicator_settings);
g_clear_object (&p->keybinding_settings);
g_clear_object (&p->usage_mode_settings);
g_clear_object (&p->actions);
for (i=0; imenus[i].menu);
g_clear_object (&p->header_action);
g_clear_object (&p->user_switcher_action);
g_clear_object (&p->guest_switcher_action);
g_clear_object (&p->usage_mode_action);
g_clear_object (&p->conn);
g_clear_pointer (&p->default_icon_serialized, g_variant_unref);
G_OBJECT_CLASS (indicator_session_service_parent_class)->dispose (o);
}
static void
/* cppcheck-suppress unusedFunction */
indicator_session_service_class_init (IndicatorSessionServiceClass * klass)
{
GObjectClass * object_class = G_OBJECT_CLASS (klass);
object_class->dispose = my_dispose;
object_class->get_property = my_get_property;
object_class->set_property = my_set_property;
signals[NAME_LOST] = g_signal_new (INDICATOR_SESSION_SERVICE_SIGNAL_NAME_LOST,
G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (IndicatorSessionServiceClass, name_lost),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
properties[PROP_0] = NULL;
properties[PROP_MAX_USERS] = g_param_spec_uint ("max-users",
"Max Users",
"Max visible users",
0, INT_MAX, 12,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PROP_LAST, properties);
}
IndicatorSessionService *
indicator_session_service_new (void)
{
GObject * o = g_object_new (INDICATOR_TYPE_SESSION_SERVICE, NULL);
return INDICATOR_SESSION_SERVICE (o);
}
./src/users.h 0000644 0000041 0000041 00000011660 14061437245 013356 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 __USERS_H__
#define __USERS_H__
#include
#include
G_BEGIN_DECLS
#define INDICATOR_TYPE_SESSION_USERS (indicator_session_users_get_type())
#define INDICATOR_SESSION_USERS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_SESSION_USERS, IndicatorSessionUsers))
#define INDICATOR_SESSION_USERS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_SESSION_USERS, IndicatorSessionUsersClass))
#define INDICATOR_SESSION_USERS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), INDICATOR_TYPE_SESSION_USERS, IndicatorSessionUsersClass))
#define INDICATOR_IS_SESSION_USERS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_SESSION_USERS))
typedef struct _IndicatorSessionUser IndicatorSessionUser;
typedef struct _IndicatorSessionUsers IndicatorSessionUsers;
typedef struct _IndicatorSessionUsersClass IndicatorSessionUsersClass;
/**
* A base class for monitoring the system's users and active sessions.
* Use backend.h's get_backend() to get an instance.
*/
struct _IndicatorSessionUsers
{
/*< private >*/
GObject parent;
};
struct _IndicatorSessionUser
{
gboolean is_current_user;
gboolean is_logged_in;
guint uid;
guint64 login_frequency;
gchar * user_name;
gchar * real_name;
gchar * icon_file;
};
/* signal keys */
#define INDICATOR_SESSION_USERS_SIGNAL_USER_ADDED "user-added"
#define INDICATOR_SESSION_USERS_SIGNAL_USER_REMOVED "user-removed"
#define INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED "user-changed"
/* property keys */
#define INDICATOR_SESSION_USERS_PROP_IS_LIVE_SESSION "is-live-session"
struct _IndicatorSessionUsersClass
{
GObjectClass parent_class;
/* signals */
void (* user_added) (IndicatorSessionUsers * self,
guint uid);
void (* user_removed) (IndicatorSessionUsers * self,
guint uid);
void (* user_changed) (IndicatorSessionUsers * self,
guint uid);
/* pure virtual functions */
gboolean (* is_live_session) (IndicatorSessionUsers * self);
GList* (* get_uids) (IndicatorSessionUsers * self);
IndicatorSessionUser * (* get_user) (IndicatorSessionUsers * self,
guint uid);
void ( * activate_user) (IndicatorSessionUsers * self,
guint uid);
};
/***
****
***/
GType indicator_session_users_get_type (void);
/* emits the "user-added" signal */
void indicator_session_users_added (IndicatorSessionUsers * self,
guint uid);
/* emits the "user-removed" signal */
void indicator_session_users_removed (IndicatorSessionUsers * self,
guint uid);
/* emits the "user-changed" signal */
void indicator_session_users_changed (IndicatorSessionUsers * self,
guint uid);
/* notify listeners of a change to the 'is-live-session' property */
void indicator_session_users_notify_is_live_session (IndicatorSessionUsers * self);
/***
****
***/
gboolean indicator_session_users_is_live_session (IndicatorSessionUsers * users);
/**
* Get a list of the users to show in the indicator
*
* Return value: (transfer container): a GList of guint user ids.
* Free with g_slist_free() when done.
*/
GList * indicator_session_users_get_uids (IndicatorSessionUsers * users);
/**
* Get information about a particular user.
*
* Return value: (transfer full): an IndicatorSessionUser struct
* populated with information about the specified user.
* Free with indicator_session_user_free() when done.
*/
IndicatorSessionUser *
indicator_session_users_get_user (IndicatorSessionUsers * users,
guint uid);
/* frees a IndicatorSessionUser struct */
void indicator_session_user_free (IndicatorSessionUser * user);
/* activate to a different session */
void indicator_session_users_activate_user (IndicatorSessionUsers * self,
guint uid);
G_END_DECLS
#endif
./src/actions.h 0000644 0000041 0000041 00000016205 14061437245 013655 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 __INDICATOR_SESSION_ACTIONS_H__
#define __INDICATOR_SESSION_ACTIONS_H__
#include
#include
G_BEGIN_DECLS
/* standard GObject macros */
#define INDICATOR_TYPE_SESSION_ACTIONS (indicator_session_actions_get_type())
#define INDICATOR_SESSION_ACTIONS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_SESSION_ACTIONS, IndicatorSessionActions))
#define INDICATOR_SESSION_ACTIONS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_SESSION_ACTIONS, IndicatorSessionActionsClass))
#define INDICATOR_SESSION_ACTIONS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), INDICATOR_TYPE_SESSION_ACTIONS, IndicatorSessionActionsClass))
#define INDICATOR_IS_SESSION_ACTIONS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_SESSION_ACTIONS))
typedef struct _IndicatorSessionActions IndicatorSessionActions;
typedef struct _IndicatorSessionActionsClass IndicatorSessionActionsClass;
/* property keys */
#define INDICATOR_SESSION_ACTIONS_PROP_CAN_LOCK "can-lock"
#define INDICATOR_SESSION_ACTIONS_PROP_CAN_LOGOUT "can-logout"
#define INDICATOR_SESSION_ACTIONS_PROP_CAN_REBOOT "can-reboot"
#define INDICATOR_SESSION_ACTIONS_PROP_CAN_SWITCH "can-switch"
#define INDICATOR_SESSION_ACTIONS_PROP_CAN_SUSPEND "can-suspend"
#define INDICATOR_SESSION_ACTIONS_PROP_CAN_HIBERNATE "can-hibernate"
#define INDICATOR_SESSION_ACTIONS_PROP_CAN_PROMPT "can-show-end-session-dialog"
#define INDICATOR_SESSION_ACTIONS_PROP_HAS_ONLINE_ACCOUNT_ERROR "has-online-account-error"
/**
* A base class for invoking and getting state information on system actions.
* Use backend.h's get_backend() to get an instance.
*/
struct _IndicatorSessionActions
{
/*< private >*/
GObject parent;
};
struct _IndicatorSessionActionsClass
{
GObjectClass parent_class;
/* pure virtual functions */
gboolean (*can_lock) (IndicatorSessionActions * self);
gboolean (*can_logout) (IndicatorSessionActions * self);
gboolean (*can_reboot) (IndicatorSessionActions * self);
gboolean (*can_switch) (IndicatorSessionActions * self);
gboolean (*can_suspend) (IndicatorSessionActions * self);
gboolean (*can_hibernate) (IndicatorSessionActions * self);
gboolean (*can_prompt) (IndicatorSessionActions * self);
gboolean (*has_online_account_error) (IndicatorSessionActions * self);
void (*suspend) (IndicatorSessionActions * self);
void (*hibernate) (IndicatorSessionActions * self);
void (*logout) (IndicatorSessionActions * self);
void (*reboot) (IndicatorSessionActions * self);
void (*power_off) (IndicatorSessionActions * self);
void (*help) (IndicatorSessionActions * self);
void (*about) (IndicatorSessionActions * self);
void (*settings) (IndicatorSessionActions * self);
void (*online_accounts) (IndicatorSessionActions * self);
void (*switch_to_greeter) (IndicatorSessionActions * self);
void (*switch_to_screensaver) (IndicatorSessionActions * self);
void (*switch_to_guest) (IndicatorSessionActions * self);
void (*switch_to_username) (IndicatorSessionActions * self,
const gchar * username);
};
/***
****
***/
GType indicator_session_actions_get_type (void);
gboolean indicator_session_actions_can_lock (IndicatorSessionActions * self);
gboolean indicator_session_actions_can_logout (IndicatorSessionActions * self);
gboolean indicator_session_actions_can_reboot (IndicatorSessionActions * self);
gboolean indicator_session_actions_can_switch (IndicatorSessionActions * self);
gboolean indicator_session_actions_can_suspend (IndicatorSessionActions * self);
gboolean indicator_session_actions_can_hibernate (IndicatorSessionActions * self);
gboolean indicator_session_actions_can_prompt (IndicatorSessionActions * self);
gboolean indicator_session_actions_has_online_account_error (IndicatorSessionActions * self);
void indicator_session_actions_notify_can_lock (IndicatorSessionActions * self);
void indicator_session_actions_notify_can_logout (IndicatorSessionActions * self);
void indicator_session_actions_notify_can_reboot (IndicatorSessionActions * self);
void indicator_session_actions_notify_can_switch (IndicatorSessionActions * self);
void indicator_session_actions_notify_can_suspend (IndicatorSessionActions * self);
void indicator_session_actions_notify_can_hibernate (IndicatorSessionActions * self);
void indicator_session_actions_notify_can_prompt (IndicatorSessionActions * self);
void indicator_session_actions_notify_has_online_account_error (IndicatorSessionActions * self);
void indicator_session_actions_lock (IndicatorSessionActions * self);
void indicator_session_actions_suspend (IndicatorSessionActions * self);
void indicator_session_actions_hibernate (IndicatorSessionActions * self);
void indicator_session_actions_logout (IndicatorSessionActions * self);
void indicator_session_actions_reboot (IndicatorSessionActions * self);
void indicator_session_actions_power_off (IndicatorSessionActions * self);
void indicator_session_actions_help (IndicatorSessionActions * self);
void indicator_session_actions_about (IndicatorSessionActions * self);
void indicator_session_actions_settings (IndicatorSessionActions * self);
void indicator_session_actions_online_accounts (IndicatorSessionActions * self);
void indicator_session_actions_switch_to_screensaver (IndicatorSessionActions * self);
void indicator_session_actions_switch_to_greeter (IndicatorSessionActions * self);
void indicator_session_actions_switch_to_guest (IndicatorSessionActions * self);
void indicator_session_actions_switch_to_username (IndicatorSessionActions * self,
const gchar * username);
G_END_DECLS
#endif /* __INDICATOR_SESSION_ACTIONS_H__ */
./src/guest.h 0000644 0000041 0000041 00000006062 14061437245 013344 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 __GUEST_H__
#define __GUEST_H__
#include
#include
G_BEGIN_DECLS
#define INDICATOR_TYPE_SESSION_GUEST (indicator_session_guest_get_type())
#define INDICATOR_SESSION_GUEST(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_SESSION_GUEST, IndicatorSessionGuest))
#define INDICATOR_SESSION_GUEST_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_SESSION_GUEST, IndicatorSessionGuestClass))
#define INDICATOR_SESSION_GUEST_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), INDICATOR_TYPE_SESSION_GUEST, IndicatorSessionGuestClass))
#define INDICATOR_IS_SESSION_GUEST(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_SESSION_GUEST))
typedef struct _IndicatorSessionGuest IndicatorSessionGuest;
typedef struct _IndicatorSessionGuestClass IndicatorSessionGuestClass;
GType indicator_session_guest_get_type (void);
/**
* A base class for getting state information about the system's guest user.
* Use backend.h's get_backend() to get an instance.
*/
struct _IndicatorSessionGuest
{
/*< private >*/
GObject parent;
};
/* properties */
#define INDICATOR_SESSION_GUEST_PROPERTY_ALLOWED "guest-is-allowed"
#define INDICATOR_SESSION_GUEST_PROPERTY_LOGGED_IN "guest-is-logged-in"
#define INDICATOR_SESSION_GUEST_PROPERTY_ACTIVE "guest-is-active-session"
struct _IndicatorSessionGuestClass
{
GObjectClass parent_class;
/* virtual functions */
gboolean (* is_allowed) (IndicatorSessionGuest * self);
gboolean (* is_logged_in) (IndicatorSessionGuest * self);
gboolean (* is_active) (IndicatorSessionGuest * self);
void (* switch_to_guest) (IndicatorSessionGuest * self);
};
gboolean indicator_session_guest_is_allowed (IndicatorSessionGuest * self);
gboolean indicator_session_guest_is_logged_in (IndicatorSessionGuest * self);
gboolean indicator_session_guest_is_active (IndicatorSessionGuest * self);
void indicator_session_guest_switch_to_guest (IndicatorSessionGuest * self);
/**
* Emit 'notify' signals for the corresponding properties.
* These functions should only be called by IndicatorSessionGuest implementations.
*/
void indicator_session_guest_notify_allowed (IndicatorSessionGuest * self);
void indicator_session_guest_notify_logged_in (IndicatorSessionGuest * self);
void indicator_session_guest_notify_active (IndicatorSessionGuest * self);
G_END_DECLS
#endif
./src/service.h 0000644 0000041 0000041 00000004416 14061437245 013656 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 __INDICATOR_SESSION_SERVICE_H__
#define __INDICATOR_SESSION_SERVICE_H__
#include
#include
G_BEGIN_DECLS
/* standard GObject macros */
#define INDICATOR_TYPE_SESSION_SERVICE (indicator_session_service_get_type())
#define INDICATOR_SESSION_SERVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_SESSION_SERVICE, IndicatorSessionService))
#define INDICATOR_SESSION_SERVICE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_SESSION_SERVICE, IndicatorSessionServiceClass))
#define INDICATOR_SESSION_SERVICE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), INDICATOR_TYPE_SESSION_SERVICE, IndicatorSessionServiceClass))
#define INDICATOR_IS_SESSION_SERVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_SESSION_SERVICE))
typedef struct _IndicatorSessionService IndicatorSessionService;
typedef struct _IndicatorSessionServiceClass IndicatorSessionServiceClass;
typedef struct _IndicatorSessionServicePrivate IndicatorSessionServicePrivate;
/* signal keys */
#define INDICATOR_SESSION_SERVICE_SIGNAL_NAME_LOST "name-lost"
/**
* The Indicator Session Service.
*/
struct _IndicatorSessionService
{
/*< private >*/
GObject parent;
IndicatorSessionServicePrivate * priv;
};
struct _IndicatorSessionServiceClass
{
GObjectClass parent_class;
/* signals */
void (* name_lost)(IndicatorSessionService * self);
};
/***
****
***/
GType indicator_session_service_get_type (void);
IndicatorSessionService * indicator_session_service_new (void);
G_END_DECLS
#endif /* __INDICATOR_SESSION_SERVICE_H__ */
./src/main.c 0000644 0000041 0000041 00000003455 14061437245 013137 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 /* exit() */
#include
#include
#include "service.h"
/***
****
***/
static void
on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop)
{
g_warning ("exiting: service couldn't acquire, or lost ownership of, busname");
g_main_loop_quit (loop);
}
int
main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED)
{
GMainLoop * loop;
IndicatorSessionService * service;
/* Work around a deadlock in glib's type initialization. It can be
* removed when https://bugzilla.gnome.org/show_bug.cgi?id=674885 is
* fixed.
*/
g_type_ensure (G_TYPE_DBUS_CONNECTION);
/* boilerplate i18n */
setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
textdomain (GETTEXT_PACKAGE);
/* run */
service = indicator_session_service_new ();
loop = g_main_loop_new (NULL, FALSE);
g_signal_connect (service, INDICATOR_SESSION_SERVICE_SIGNAL_NAME_LOST,
G_CALLBACK(on_name_lost), loop);
g_main_loop_run (loop);
/* cleanup */
g_clear_object (&service);
g_main_loop_unref (loop);
return 0;
}
./src/actions.c 0000644 0000041 0000041 00000027027 14061437245 013654 0 ustar www-data www-data
/*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 "actions.h"
/***
**** GObject Boilerplate
***/
G_DEFINE_TYPE (IndicatorSessionActions, indicator_session_actions, G_TYPE_OBJECT)
enum
{
PROP_0,
PROP_CAN_SWITCH,
PROP_CAN_HIBERNATE,
PROP_CAN_SUSPEND,
PROP_CAN_LOCK,
PROP_CAN_LOGOUT,
PROP_CAN_REBOOT,
PROP_CAN_PROMPT,
PROP_HAS_ONLINE_ACCOUNT_ERROR,
PROP_LAST
};
static GParamSpec *properties[PROP_LAST];
static void
my_get_property (GObject * o,
guint property_id,
GValue * value,
GParamSpec * pspec)
{
IndicatorSessionActions * self = INDICATOR_SESSION_ACTIONS (o);
switch (property_id)
{
case PROP_CAN_SWITCH:
g_value_set_boolean (value, indicator_session_actions_can_switch (self));
break;
case PROP_CAN_HIBERNATE:
g_value_set_boolean (value, indicator_session_actions_can_hibernate (self));
break;
case PROP_CAN_SUSPEND:
g_value_set_boolean (value, indicator_session_actions_can_suspend (self));
break;
case PROP_CAN_LOCK:
g_value_set_boolean (value, indicator_session_actions_can_lock (self));
break;
case PROP_CAN_LOGOUT:
g_value_set_boolean (value, indicator_session_actions_can_logout (self));
break;
case PROP_CAN_REBOOT:
g_value_set_boolean (value, indicator_session_actions_can_reboot (self));
break;
case PROP_CAN_PROMPT:
g_value_set_boolean (value, indicator_session_actions_can_prompt (self));
break;
case PROP_HAS_ONLINE_ACCOUNT_ERROR:
g_value_set_boolean (value, indicator_session_actions_has_online_account_error (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
}
}
static void
/* cppcheck-suppress unusedFunction */
indicator_session_actions_class_init (IndicatorSessionActionsClass * klass)
{
GObjectClass * object_class;
const GParamFlags flags = G_PARAM_READABLE | G_PARAM_STATIC_STRINGS;
object_class = G_OBJECT_CLASS (klass);
object_class->get_property = my_get_property;
klass->can_lock = NULL;
klass->can_logout = NULL;
klass->can_reboot = NULL;
klass->can_switch = NULL;
klass->can_suspend = NULL;
klass->can_hibernate = NULL;
klass->has_online_account_error = NULL;
klass->logout = NULL;
klass->suspend = NULL;
klass->hibernate = NULL;
klass->reboot = NULL;
klass->power_off = NULL;
klass->switch_to_screensaver = NULL;
klass->switch_to_greeter = NULL;
klass->switch_to_guest = NULL;
klass->switch_to_username = NULL;
/* properties */
properties[PROP_0] = NULL;
properties[PROP_CAN_SWITCH] =
g_param_spec_boolean (INDICATOR_SESSION_ACTIONS_PROP_CAN_SWITCH,
"Can Switch Sessions",
"Whether or not the system services allow session switching",
TRUE, flags);
properties[PROP_CAN_HIBERNATE] =
g_param_spec_boolean (INDICATOR_SESSION_ACTIONS_PROP_CAN_HIBERNATE,
"Can Hibernate",
"Whether or not the system services allow the user to hibernate",
TRUE, flags);
properties[PROP_CAN_SUSPEND] =
g_param_spec_boolean (INDICATOR_SESSION_ACTIONS_PROP_CAN_SUSPEND,
"Can Suspend",
"Whether or not the system services allow the user to suspend",
TRUE, flags);
properties[PROP_CAN_LOCK] =
g_param_spec_boolean (INDICATOR_SESSION_ACTIONS_PROP_CAN_LOCK,
"Can Lock",
"Whether or not the system services allow the user to lock the screen",
TRUE, flags);
properties[PROP_CAN_LOGOUT] =
g_param_spec_boolean (INDICATOR_SESSION_ACTIONS_PROP_CAN_LOGOUT,
"Can Logout",
"Whether or not the system services allow the user to logout",
TRUE, flags);
properties[PROP_CAN_REBOOT] =
g_param_spec_boolean (INDICATOR_SESSION_ACTIONS_PROP_CAN_REBOOT,
"Can Reboot",
"Whether or not the system services allow the user to reboot",
TRUE, flags);
properties[PROP_CAN_PROMPT] =
g_param_spec_boolean (INDICATOR_SESSION_ACTIONS_PROP_CAN_PROMPT,
"Can Show End Session Dialog",
"Whether or not we can show an End Session dialog",
TRUE, flags);
properties[PROP_HAS_ONLINE_ACCOUNT_ERROR] =
g_param_spec_boolean (INDICATOR_SESSION_ACTIONS_PROP_HAS_ONLINE_ACCOUNT_ERROR,
"Has Online Account Error",
"Whether or not an online account setting requires attention from the user",
FALSE, flags);
g_object_class_install_properties (object_class, PROP_LAST, properties);
}
static void
/* cppcheck-suppress unusedFunction */
indicator_session_actions_init (IndicatorSessionActions * self G_GNUC_UNUSED)
{
}
/***
****
***/
gboolean
indicator_session_actions_can_lock (IndicatorSessionActions * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_ACTIONS (self), FALSE);
return INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->can_lock (self);
}
gboolean
indicator_session_actions_can_logout (IndicatorSessionActions * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_ACTIONS (self), FALSE);
return INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->can_logout (self);
}
gboolean
indicator_session_actions_can_reboot (IndicatorSessionActions * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_ACTIONS (self), FALSE);
return INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->can_reboot (self);
}
gboolean
indicator_session_actions_can_switch (IndicatorSessionActions * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_ACTIONS (self), FALSE);
return INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->can_switch (self);
}
gboolean
indicator_session_actions_can_suspend (IndicatorSessionActions * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_ACTIONS (self), FALSE);
return INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->can_suspend (self);
}
gboolean
indicator_session_actions_can_hibernate (IndicatorSessionActions * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_ACTIONS (self), FALSE);
return INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->can_hibernate (self);
}
gboolean
indicator_session_actions_can_prompt (IndicatorSessionActions * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_ACTIONS (self), FALSE);
return INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->can_prompt (self);
}
gboolean
indicator_session_actions_has_online_account_error (IndicatorSessionActions * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_ACTIONS (self), FALSE);
return INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->has_online_account_error (self);
}
/***
****
***/
void
indicator_session_actions_online_accounts (IndicatorSessionActions * self)
{
g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->online_accounts (self);
}
void
indicator_session_actions_settings (IndicatorSessionActions * self)
{
g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->settings (self);
}
void
indicator_session_actions_logout (IndicatorSessionActions * self)
{
g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->logout (self);
}
void
indicator_session_actions_power_off (IndicatorSessionActions * self)
{
g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->power_off (self);
}
void
indicator_session_actions_help (IndicatorSessionActions * self)
{
g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->help (self);
}
void
indicator_session_actions_about (IndicatorSessionActions * self)
{
g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->about (self);
}
void
indicator_session_actions_reboot (IndicatorSessionActions * self)
{
g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->reboot (self);
}
void
indicator_session_actions_suspend (IndicatorSessionActions * self)
{
g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->suspend (self);
}
void
indicator_session_actions_hibernate (IndicatorSessionActions * self)
{
g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->hibernate (self);
}
void
indicator_session_actions_switch_to_screensaver (IndicatorSessionActions * self)
{
g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->switch_to_screensaver (self);
}
void
indicator_session_actions_switch_to_greeter (IndicatorSessionActions * self)
{
g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->switch_to_greeter (self);
}
void
indicator_session_actions_switch_to_guest (IndicatorSessionActions * self)
{
g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->switch_to_guest (self);
}
void
indicator_session_actions_switch_to_username (IndicatorSessionActions * self,
const gchar * username)
{
g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->switch_to_username (self, username);
}
/***
****
***/
static void
notify_func (IndicatorSessionActions * self, int prop)
{
g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
g_debug ("%s %s emitting '%s' prop notify", G_STRLOC, G_STRFUNC, properties[prop]->name);
g_object_notify_by_pspec (G_OBJECT(self), properties[prop]);
}
void
indicator_session_actions_notify_can_lock (IndicatorSessionActions * self)
{
notify_func (self, PROP_CAN_LOCK);
}
void
indicator_session_actions_notify_can_logout (IndicatorSessionActions * self)
{
notify_func (self, PROP_CAN_LOGOUT);
}
void
indicator_session_actions_notify_can_reboot (IndicatorSessionActions * self)
{
notify_func (self, PROP_CAN_REBOOT);
}
void
indicator_session_actions_notify_can_switch (IndicatorSessionActions * self)
{
notify_func (self, PROP_CAN_SWITCH);
}
void
indicator_session_actions_notify_can_suspend (IndicatorSessionActions * self)
{
notify_func (self, PROP_CAN_SUSPEND);
}
void
indicator_session_actions_notify_can_hibernate (IndicatorSessionActions * self)
{
notify_func (self, PROP_CAN_HIBERNATE);
}
void
indicator_session_actions_notify_can_prompt (IndicatorSessionActions * self)
{
notify_func (self, PROP_CAN_PROMPT);
}
void
indicator_session_actions_notify_has_online_account_error (IndicatorSessionActions * self)
{
notify_func (self, PROP_HAS_ONLINE_ACCOUNT_ERROR);
}
./src/users.c 0000644 0000041 0000041 00000013465 14061437245 013356 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 "users.h"
/* signals enum */
enum
{
USER_ADDED,
USER_REMOVED,
USER_CHANGED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (IndicatorSessionUsers, indicator_session_users, G_TYPE_OBJECT)
enum
{
PROP_0,
PROP_IS_LIVE_SESSION,
PROP_LAST
};
static GParamSpec *properties[PROP_LAST];
static void
my_get_property (GObject * o,
guint property_id,
GValue * value,
GParamSpec * pspec)
{
IndicatorSessionUsers * self = INDICATOR_SESSION_USERS (o);
switch (property_id)
{
case PROP_IS_LIVE_SESSION:
g_value_set_boolean (value, indicator_session_users_is_live_session (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
}
}
static void
/* cppcheck-suppress unusedFunction */
indicator_session_users_class_init (IndicatorSessionUsersClass * klass)
{
GObjectClass * object_class;
const GParamFlags flags = G_PARAM_READABLE | G_PARAM_STATIC_STRINGS;
object_class = G_OBJECT_CLASS (klass);
object_class->get_property = my_get_property;
signals[USER_ADDED] = g_signal_new (INDICATOR_SESSION_USERS_SIGNAL_USER_ADDED,
G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (IndicatorSessionUsersClass, user_added),
NULL, NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1, G_TYPE_UINT);
signals[USER_REMOVED] = g_signal_new (INDICATOR_SESSION_USERS_SIGNAL_USER_REMOVED,
G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (IndicatorSessionUsersClass, user_removed),
NULL, NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1, G_TYPE_UINT);
signals[USER_CHANGED] = g_signal_new (INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED,
G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (IndicatorSessionUsersClass, user_changed),
NULL, NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1, G_TYPE_UINT);
properties[PROP_IS_LIVE_SESSION] =
g_param_spec_boolean (INDICATOR_SESSION_USERS_PROP_IS_LIVE_SESSION,
"Is Live Session",
"Whether or this is a 'live session', such as booting from a live CD",
FALSE, flags);
g_object_class_install_properties (object_class, PROP_LAST, properties);
}
static void
/* cppcheck-suppress unusedFunction */
indicator_session_users_init (IndicatorSessionUsers * self G_GNUC_UNUSED)
{
}
/***
**** Virtual Functions
***/
GList *
indicator_session_users_get_uids (IndicatorSessionUsers * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_USERS (self), NULL);
return INDICATOR_SESSION_USERS_GET_CLASS (self)->get_uids (self);
}
IndicatorSessionUser *
indicator_session_users_get_user (IndicatorSessionUsers * self,
guint uid)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_USERS (self), NULL);
return INDICATOR_SESSION_USERS_GET_CLASS (self)->get_user (self, uid);
}
void
indicator_session_users_activate_user (IndicatorSessionUsers * self,
guint uid)
{
g_return_if_fail (INDICATOR_IS_SESSION_USERS (self));
INDICATOR_SESSION_USERS_GET_CLASS (self)->activate_user (self, uid);
}
gboolean
indicator_session_users_is_live_session (IndicatorSessionUsers * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_USERS (self), FALSE);
return INDICATOR_SESSION_USERS_GET_CLASS (self)->is_live_session (self);
}
void
indicator_session_user_free (IndicatorSessionUser * user)
{
g_return_if_fail (user != NULL);
g_free (user->real_name);
g_free (user->user_name);
g_free (user->icon_file);
g_free (user);
}
/***
**** Signal Convenience
***/
void
indicator_session_users_added (IndicatorSessionUsers * self, guint uid)
{
g_return_if_fail (INDICATOR_IS_SESSION_USERS (self));
g_signal_emit (self, signals[USER_ADDED], 0, uid);
}
void
indicator_session_users_removed (IndicatorSessionUsers * self, guint uid)
{
g_return_if_fail (INDICATOR_IS_SESSION_USERS (self));
g_signal_emit (self, signals[USER_REMOVED], 0, uid);
}
void
indicator_session_users_changed (IndicatorSessionUsers * self, guint uid)
{
g_return_if_fail (INDICATOR_IS_SESSION_USERS (self));
g_signal_emit (self, signals[USER_CHANGED], 0, uid);
}
void
indicator_session_users_notify_is_live_session (IndicatorSessionUsers * self)
{
g_return_if_fail (INDICATOR_IS_SESSION_USERS (self));
g_object_notify_by_pspec (G_OBJECT(self), properties[PROP_IS_LIVE_SESSION]);
}
./src/backend.h 0000644 0000041 0000041 00000003034 14061437245 013600 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 __INDICATOR_SESSION_BACKEND_H__
#define __INDICATOR_SESSION_BACKEND_H__
#include /* GCancellable */
#include "actions.h"
#include "guest.h"
#include "users.h"
G_BEGIN_DECLS
/**
* Gets instances of the backend abstract base classes.
* These are how IndicatorSystemService knows what's happening on the system.
*
* This function isn't defined in libindicatorsessionservice.
* Instead, one of two implementations is statically linked at build time:
* one for production in libbackenddbus (in src/backend-dbus/) or
* one for testing in libbackendmock (in tests/).
*/
void backend_get (GCancellable * cancellable,
IndicatorSessionActions ** setme_actions,
IndicatorSessionUsers ** setme_users,
IndicatorSessionGuest ** setme_guest);
G_END_DECLS
#endif
./src/backend-dbus/ 0000755 0000041 0000041 00000000000 14061437252 014360 5 ustar www-data www-data ./src/backend-dbus/org.freedesktop.login1.Seat.xml 0000644 0000041 0000041 00000001746 14061437245 022300 0 ustar www-data www-data
./src/backend-dbus/CMakeLists.txt 0000644 0000041 0000041 00000004412 14061437245 017123 0 ustar www-data www-data find_package(GDbus REQUIRED)
add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-display-manager
org.freedesktop
org.freedesktop.DisplayManager.Seat.xml)
add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-webcredentials
com.canonical.indicators
com.canonical.indicators.webcredentials.xml)
add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-accounts
org.freedesktop
org.freedesktop.Accounts.xml)
add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-user
org.freedesktop
org.freedesktop.Accounts.User.xml)
add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-login1-manager
org.freedesktop
org.freedesktop.login1.Manager.xml)
add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-login1-seat
org.freedesktop
org.freedesktop.login1.Seat.xml)
add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-login1-user
org.freedesktop
org.freedesktop.login1.User.xml)
add_gdbus_codegen (BACKEND_GENERATED_SOURCES gnome-screen-saver
org
org.gnome.ScreenSaver.xml)
add_gdbus_codegen (BACKEND_GENERATED_SOURCES gnome-session-manager
org
org.gnome.SessionManager.xml)
add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-end-session-dialog
org.gnome.SessionManager
org.gnome.SessionManager.EndSessionDialog.xml)
add_gdbus_codegen (BACKEND_GENERATED_SOURCES unity-session
com.canonical
com.canonical.Unity.Session.xml)
set (SOURCES actions.c guest.c users.c backend-dbus.c utils.c)
# add warnings/coverage info on handwritten files
# but not the autogenerated ones...
set_source_files_properties (${SOURCES}
PROPERTIES COMPILE_FLAGS " ${CC_WARNING_ARGS}")
# add the bin dir to our include path s.t. our code can find the autogenerated header files
include_directories (${CMAKE_CURRENT_BINARY_DIR} ${SERVICE_INCLUDE_DIRS})
add_library (backenddbus STATIC ${SOURCES} ${BACKEND_GENERATED_SOURCES})
# coverage reporting
set(COVERAGE_TARGETS
${COVERAGE_TARGETS}
backenddbus
PARENT_SCOPE
)
./src/backend-dbus/users.h 0000644 0000041 0000041 00000005125 14061437252 015675 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 __USERS_DBUS_H__
#define __USERS_DBUS_H__
#include
#include
#include "../users.h" /* parent class */
#include "dbus-accounts.h"
#include "dbus-login1-manager.h"
#include "dbus-login1-seat.h"
#include "dbus-display-manager.h"
G_BEGIN_DECLS
#define INDICATOR_TYPE_SESSION_USERS_DBUS (indicator_session_users_dbus_get_type())
#define INDICATOR_SESSION_USERS_DBUS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_SESSION_USERS_DBUS, IndicatorSessionUsersDbus))
#define INDICATOR_SESSION_USERS_DBUS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_SESSION_USERS_DBUS, IndicatorSessionUsersDbusClass))
#define INDICATOR_IS_SESSION_USERS_DBUS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_SESSION_USERS_DBUS))
typedef struct _IndicatorSessionUsersDbus IndicatorSessionUsersDbus;
typedef struct _IndicatorSessionUsersDbusPrivate IndicatorSessionUsersDbusPrivate;
typedef struct _IndicatorSessionUsersDbusClass IndicatorSessionUsersDbusClass;
/**
* An implementation of IndicatorSessionUsers that gets its user information
* from org.freedesktop.login1 and org.freedesktop.Accounts over DBus.
*/
struct _IndicatorSessionUsersDbus
{
/*< private >*/
IndicatorSessionUsers parent;
IndicatorSessionUsersDbusPrivate * priv;
};
struct _IndicatorSessionUsersDbusClass
{
IndicatorSessionUsersClass parent_class;
};
GType indicator_session_users_dbus_get_type (void);
IndicatorSessionUsers * indicator_session_users_dbus_new (void);
void indicator_session_users_dbus_set_proxies (IndicatorSessionUsersDbus *,
Login1Manager *,
Login1Seat *,
DisplayManagerSeat *,
Accounts *);
G_END_DECLS
#endif
./src/backend-dbus/actions.h 0000644 0000041 0000041 00000005340 14061437252 016173 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 __INDICATOR_SESSION_ACTIONS_DBUS_H__
#define __INDICATOR_SESSION_ACTIONS_DBUS_H__
#include
#include
#include "../actions.h" /* parent class */
#include "dbus-login1-manager.h"
#include "dbus-login1-seat.h"
#include "dbus-display-manager.h"
G_BEGIN_DECLS
#define INDICATOR_TYPE_SESSION_ACTIONS_DBUS (indicator_session_actions_dbus_get_type())
#define INDICATOR_SESSION_ACTIONS_DBUS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_SESSION_ACTIONS_DBUS, IndicatorSessionActionsDbus))
#define INDICATOR_SESSION_ACTIONS_DBUS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_SESSION_ACTIONS_DBUS, IndicatorSessionActionsDbusClass))
#define INDICATOR_IS_SESSION_ACTIONS_DBUS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_SESSION_ACTIONS_DBUS))
typedef struct _IndicatorSessionActionsDbus IndicatorSessionActionsDbus;
typedef struct _IndicatorSessionActionsDbusPrivate IndicatorSessionActionsDbusPrivate;
typedef struct _IndicatorSessionActionsDbusClass IndicatorSessionActionsDbusClass;
/**
* An implementation of IndicatorSessionActions that gets its user information
* from org.freedesktop.login1 org.freedesktop.DisplayManager over DBus.
*/
struct _IndicatorSessionActionsDbus
{
/*< private >*/
IndicatorSessionActions parent;
IndicatorSessionActionsDbusPrivate * priv;
};
struct _IndicatorSessionActionsDbusClass
{
IndicatorSessionActionsClass parent_class;
};
GType indicator_session_actions_dbus_get_type (void);
IndicatorSessionActions * indicator_session_actions_dbus_new (void);
void indicator_session_actions_dbus_set_proxies (IndicatorSessionActionsDbus * self,
Login1Manager * login1_manager,
Login1Seat * login1_seat,
DisplayManagerSeat * dm_seat);
G_END_DECLS
#endif /* __INDICATOR_SESSION_ACTIONS_DBUS_H__ */
./src/backend-dbus/org.freedesktop.Accounts.xml 0000644 0000041 0000041 00000015325 14061437245 021771 0 ustar www-data www-data
Object paths of cached users
Lists users which have logged into the system locally before.
This is not meant to return an exhaustive list of all users.
It is possible for FindUserByName()
to return a user that's not on the list.
The uid to look up
Object path of user
Finds a user by uid.
if no user with the given uid exists
The username to look up
Object path of user
Finds a user by its username.
if no user with the given username exists
The username for the new user
The real name for the new user
Object path of the new user
The account type, encoded as an integer
Creates a new user account.
The accountType argument can take the following values:
0
Standard user
1
Administrator
2
Supervised user
The caller needs the org.freedesktop.accounts.user-administration PolicyKit authorization.
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
The uid to delete
Whether to remove the users files
Deletes a user account.
The caller needs the org.freedesktop.accounts.user-administration PolicyKit authorization.
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
Object path of the user that was added.
Emitted when a user is added.
Object path of the user that was deleted.
Emitted when a user is deleted.
Object path of the user that was changed.
Emitted when a user is changed.
The version of the running daemon.
./src/backend-dbus/org.freedesktop.DisplayManager.Seat.xml 0000644 0000041 0000041 00000001607 14061437245 024003 0 ustar www-data www-data
./src/backend-dbus/org.gnome.ScreenSaver.xml 0000644 0000041 0000041 00000000574 14061437245 021224 0 ustar www-data www-data
./src/backend-dbus/guest.h 0000644 0000041 0000041 00000005042 14061437252 015661 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 __GUEST_DBUS_H__
#define __GUEST_DBUS_H__
#include
#include
#include "../guest.h" /* parent class */
#include "dbus-login1-manager.h"
#include "dbus-login1-seat.h"
#include "dbus-display-manager.h"
G_BEGIN_DECLS
#define INDICATOR_TYPE_SESSION_GUEST_DBUS (indicator_session_guest_dbus_get_type())
#define INDICATOR_SESSION_GUEST_DBUS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_SESSION_GUEST_DBUS, IndicatorSessionGuestDbus))
#define INDICATOR_SESSION_GUEST_DBUS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_SESSION_GUEST_DBUS, IndicatorSessionGuestDbusClass))
#define INDICATOR_IS_SESSION_GUEST_DBUS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_SESSION_GUEST_DBUS))
typedef struct _IndicatorSessionGuestDbus IndicatorSessionGuestDbus;
typedef struct _IndicatorSessionGuestDbusPrivate IndicatorSessionGuestDbusPrivate;
typedef struct _IndicatorSessionGuestDbusClass IndicatorSessionGuestDbusClass;
/**
* An implementation of IndicatorSessionGuest that gets its user information
* from org.freedesktop.login1 and org.freedesktop.Accounts over DBus.
*/
struct _IndicatorSessionGuestDbus
{
/*< private >*/
IndicatorSessionGuest parent;
IndicatorSessionGuestDbusPrivate * priv;
};
struct _IndicatorSessionGuestDbusClass
{
IndicatorSessionGuestClass parent_class;
};
GType indicator_session_guest_dbus_get_type (void);
IndicatorSessionGuest * indicator_session_guest_dbus_new (void);
void indicator_session_guest_dbus_set_proxies (IndicatorSessionGuestDbus * self,
Login1Manager * login1_manager,
Login1Seat * login1_seat,
DisplayManagerSeat * display_manager_seat);
G_END_DECLS
#endif
./src/backend-dbus/org.gnome.SessionManager.EndSessionDialog.xml 0000644 0000041 0000041 00000003650 14061437245 025111 0 ustar www-data www-data
The type of dialog to show.
0 for logout, 1 for shutdown, 2 for restart.
Timestamp of the user-initiated event which triggered
the call, or 0 if the call was not triggered by an event.
The number of seconds which the dialog should stay open
before automatic action is taken.
The object paths of all inhibitors that are registered
for the action.
This function opens a dialog which asks the user for confirmation
of a logout, poweroff or reboot action. The dialog has a timeout
after which the action is automatically taken, and it should show
the inhibitors to the user.
./src/backend-dbus/backend-dbus.h 0000644 0000041 0000041 00000002247 14061437245 017062 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 __INDICATOR_SESSION_BACKEND_DESKTOP_H__
#define __INDICATOR_SESSION_BACKEND_DESKTOP_H__
#include /* GCancellable */
#include "../actions.h"
#include "../guest.h"
#include "../users.h"
G_BEGIN_DECLS
void backend_get (GCancellable * cancellable,
IndicatorSessionActions ** setme_actions,
IndicatorSessionUsers ** setme_users,
IndicatorSessionGuest ** setme_guest);
G_END_DECLS
#endif
./src/backend-dbus/org.freedesktop.login1.Manager.xml 0000644 0000041 0000041 00000017420 14061437245 022752 0 ustar www-data www-data
./src/backend-dbus/org.gnome.SessionManager.xml 0000644 0000041 0000041 00000037350 14061437245 021724 0 ustar www-data www-data
The variable name
The value
Adds the variable name to the application launch environment with the specified value. May only be used during the Session Manager initialization phase.
The locale category
The value
Reads the current state of the specific locale category.
The error message
Whether the error should be treated as fatal
May be used by applications launched during the Session Manager initialization phase to indicate there was a problem.
The application identifier
Client startup identifier
The object path of the newly registered client
Register the caller as a Session Management client.
The object path of the client
Unregister the specified client from Session Management.
The application identifier
The toplevel X window identifier
The reason for the inhibit
Flags that specify what should be inhibited
The cookie
Proactively indicates that the calling application is performing an action that should not be interrupted and sets a reason to be displayed to the user when an interruption is about to take placea.
Applications should invoke this method when they begin an operation that
should not be interrupted, such as creating a CD or DVD. The types of actions
that may be blocked are specified by the flags parameter. When the application
completes the operation it should call Uninhibit()
or disconnect from the session bus.
Applications should not expect that they will always be able to block the
action. In most cases, users will be given the option to force the action
to take place.
Reasons should be short and to the point.
The flags parameter must include at least one of the following:
1
Inhibit logging out
2
Inhibit user switching
4
Inhibit suspending the session or computer
8
Inhibit the session being marked as idle
16
Inhibit auto-mounting removable media for the session
Values for flags may be bitwise or'ed together.
The returned cookie is used to uniquely identify this request. It should be used
as an argument to Uninhibit() in
order to remove the request.
The cookie
Cancel a previous call to Inhibit() identified by the cookie.
Flags that spefify what should be inhibited
Returns TRUE if any of the operations in the bitfield flags are inhibited
Determine if operation(s) specified by the flags
are currently inhibited. Flags are same as those accepted
by the
Inhibit()
method.
an array of client IDs
This gets a list of all the Clients
that are currently known to the session manager.
Each Client ID is an D-Bus object path for the object that implements the
Client interface.
org.gnome.SessionManager.Client
an array of inhibitor IDs
This gets a list of all the Inhibitors
that are currently known to the session manager.
Each Inhibitor ID is an D-Bus object path for the object that implements the
Inhibitor interface.
org.gnome.SessionManager.Inhibitor
The autostart condition string
True if condition is handled, false otherwise
Allows the caller to determine whether the session manager is
handling changes to the specified autostart condition.
Request a shutdown dialog.
Request a reboot dialog.
True if shutdown is available to the user, false otherwise
Allows the caller to determine whether or not it's okay to show
a shutdown option in the UI
The type of logout that is being requested
Request a logout dialog
Allowed values for the mode parameter are:
0
Normal.
1
No confirmation inferface should be shown.
2
Forcefully logout. No confirmation will be shown and any inhibitors will be ignored.
Values for flags may be bitwise or'ed together.
True if the session has entered the Running phase, false otherwise
Allows the caller to determine whether the session manager
has entered the Running phase, in case the client missed the
SessionRunning signal.
The object path for the added client
Emitted when a client has been added to the session manager.
The object path for the removed client
Emitted when a client has been removed from the session manager.
The object path for the added inhibitor
Emitted when an inhibitor has been added to the session manager.
The object path for the removed inhibitor
Emitted when an inhibitor has been removed from the session manager.
Indicates the session has entered the Running phase.
Indicates the session is about to end.
The name of the session that has been loaded.
If true, the session is currently in the
foreground and available for user input.
A bitmask of flags to indicate which actions
are inhibited. See the Inhibit() function's description
for a list of possible values.
./src/backend-dbus/org.freedesktop.login1.User.xml 0000644 0000041 0000041 00000004255 14061437245 022320 0 ustar www-data www-data
./src/backend-dbus/backend-dbus.c 0000644 0000041 0000041 00000007113 14061437245 017052 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 "actions.h"
#include "backend-dbus.h"
#include "guest.h"
#include "users.h"
#include "utils.h"
struct dbus_world_data
{
GCancellable * cancellable;
IndicatorSessionActionsDbus * actions;
IndicatorSessionUsersDbus * users;
IndicatorSessionGuestDbus * guest;
};
static void
on_proxies_ready (Login1Manager * login1_manager,
Login1Seat * login1_seat,
DisplayManagerSeat * display_manager_seat,
Accounts * account_manager,
GCancellable * cancellable,
gpointer gdata)
{
struct dbus_world_data * data = gdata;
if (!g_cancellable_is_cancelled (cancellable))
{
if (data->actions != NULL)
indicator_session_actions_dbus_set_proxies (data->actions,
login1_manager,
login1_seat,
display_manager_seat);
if (data->users != NULL)
indicator_session_users_dbus_set_proxies (data->users,
login1_manager,
login1_seat,
display_manager_seat,
account_manager);
if (data->guest != NULL)
indicator_session_guest_dbus_set_proxies (data->guest,
login1_manager,
login1_seat,
display_manager_seat);
}
g_free (data);
}
/***
****
***/
void
backend_get (GCancellable * cancellable,
IndicatorSessionActions ** setme_actions,
IndicatorSessionUsers ** setme_users,
IndicatorSessionGuest ** setme_guest)
{
struct dbus_world_data * data;
data = g_new0 (struct dbus_world_data, 1);
if (setme_actions != NULL)
{
IndicatorSessionActions * actions;
actions = indicator_session_actions_dbus_new ();
data->actions = INDICATOR_SESSION_ACTIONS_DBUS (actions);
*setme_actions = actions;
}
if (setme_users != NULL)
{
IndicatorSessionUsers * users;
users = indicator_session_users_dbus_new ();
data->users = INDICATOR_SESSION_USERS_DBUS (users);
*setme_users = users;
}
if (setme_guest != NULL)
{
IndicatorSessionGuest * guest;
guest = indicator_session_guest_dbus_new ();
data->guest = INDICATOR_SESSION_GUEST_DBUS (guest);
*setme_guest = guest;
}
data->cancellable = g_object_ref (cancellable);
indicator_session_util_get_session_proxies (on_proxies_ready,
data->cancellable,
data);
}
./src/backend-dbus/utils.h 0000644 0000041 0000041 00000003427 14061437245 015701 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 __DBUS_UTILS_H__
#define __DBUS_UTILS_H__
#include
#include
#include "dbus-accounts.h"
#include "dbus-display-manager.h"
#include "dbus-login1-manager.h"
#include "dbus-login1-seat.h"
typedef void (*indicator_session_util_session_proxies_func)(
Login1Manager * login1_manager,
Login1Seat * login1_seat,
DisplayManagerSeat * display_manager_seat,
Accounts * account_manager,
GCancellable * cancellable,
gpointer user_data);
/**
* Both users-dbus and guest-dbus need some of these proxies.
* Getting them all involves a lot of steps, so instead of repeating
* ourselves, the common dbus steps are extracted to this func.
*/
void indicator_session_util_get_session_proxies (
indicator_session_util_session_proxies_func func,
GCancellable * cancellable,
gpointer user_data);
#endif
./src/backend-dbus/actions.c 0000644 0000041 0000041 00000104362 14061437252 016172 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 "dbus-end-session-dialog.h"
#include "dbus-login1-manager.h"
#include "dbus-webcredentials.h"
#include "gnome-screen-saver.h"
#include "gnome-session-manager.h"
#include "unity-session.h"
#include "actions.h"
enum
{
END_SESSION_TYPE_LOGOUT = 0,
END_SESSION_TYPE_SHUTDOWN,
END_SESSION_TYPE_REBOOT
};
struct _IndicatorSessionActionsDbusPrivate
{
GCancellable * cancellable;
GSettings * lockdown_settings;
GSettings * indicator_settings;
GnomeScreenSaver * screen_saver;
GnomeSessionManager * session_manager;
UnitySession * unity_session;
Login1Manager * login1_manager;
GCancellable * login1_manager_cancellable;
Login1Seat * login1_seat;
DisplayManagerSeat * dm_seat;
GCancellable * dm_seat_cancellable;
Webcredentials * webcredentials;
EndSessionDialog * end_session_dialog;
char * zenity;
gboolean can_suspend;
gboolean can_hibernate;
gboolean seat_allows_activation;
};
typedef IndicatorSessionActionsDbusPrivate priv_t;
G_DEFINE_TYPE_WITH_PRIVATE (IndicatorSessionActionsDbus, indicator_session_actions_dbus, INDICATOR_TYPE_SESSION_ACTIONS)
/***
****
***/
static void
log_and_clear_error (GError ** err, const char * loc, const char * func)
{
if (*err)
{
if (!g_error_matches (*err, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("%s %s: %s", loc, func, (*err)->message);
g_clear_error (err);
}
}
/***
****
***/
typedef enum
{
PROMPT_NONE,
PROMPT_WITH_ZENITY,
PROMPT_WITH_UNITY,
PROMPT_WITH_MATE
}
prompt_status_t;
static gboolean
have_mate_program (const gchar *program)
{
const gchar *xdg_current_desktop;
g_auto(GStrv) desktop_names = NULL;
xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
if (xdg_current_desktop != NULL) {
desktop_names = g_strsplit (xdg_current_desktop, ":", 0);
if (g_strv_contains ((const gchar * const *) desktop_names, "MATE")) {
g_autofree gchar *path = g_find_program_in_path (program);
return path != NULL;
}
}
return FALSE;
}
static prompt_status_t
get_prompt_status (IndicatorSessionActionsDbus * self)
{
prompt_status_t prompt = PROMPT_NONE;
const priv_t * p = self->priv;
if (!g_settings_get_boolean (p->indicator_settings, "suppress-logout-restart-shutdown"))
{
/* can we use the MATE prompt? */
if ((prompt == PROMPT_NONE) && have_mate_program ("mate-session-save"))
prompt = PROMPT_WITH_MATE;
/* can we use the Unity prompt? */
if ((prompt == PROMPT_NONE) && p && p->end_session_dialog)
{
GDBusProxy * proxy = G_DBUS_PROXY (p->end_session_dialog);
char * name = g_dbus_proxy_get_name_owner (proxy);
if (name != NULL)
prompt = PROMPT_WITH_UNITY;
g_free (name);
}
/* can we use zenity? */
if ((prompt == PROMPT_NONE) && p && p->zenity)
prompt = PROMPT_WITH_ZENITY;
}
return prompt;
}
/***
****
***/
static void
on_seat_notify_multi_session (IndicatorSessionActionsDbus * self)
{
priv_t * p = self->priv;
gboolean b;
b = login1_seat_get_can_multi_session (p->login1_seat);
if (p->seat_allows_activation != b)
{
p->seat_allows_activation = b;
indicator_session_actions_notify_can_switch (INDICATOR_SESSION_ACTIONS(self));
}
}
static void
set_login1_seat (IndicatorSessionActionsDbus * self, Login1Seat * seat)
{
priv_t * p = self->priv;
if (p->login1_seat != NULL)
{
g_signal_handlers_disconnect_by_data (p->login1_seat, self);
g_clear_object (&p->login1_seat);
}
if (seat != NULL)
{
p->login1_seat = g_object_ref (seat);
g_signal_connect_swapped (seat, "notify::can-multi-session",
G_CALLBACK(on_seat_notify_multi_session), self);
}
}
/***
****
***/
static void
set_dm_seat (IndicatorSessionActionsDbus * self, DisplayManagerSeat * seat)
{
priv_t * p = self->priv;
if (p->dm_seat != NULL)
{
g_cancellable_cancel (p->dm_seat_cancellable);
g_clear_object (&p->dm_seat_cancellable);
g_clear_object (&p->dm_seat);
}
if (seat != NULL)
{
p->dm_seat = g_object_ref (seat);
p->dm_seat_cancellable = g_cancellable_new ();
}
}
static void
on_screensaver_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gself)
{
GError * err;
GnomeScreenSaver * ss;
err = NULL;
ss = gnome_screen_saver_proxy_new_for_bus_finish (res, &err);
if (err == NULL)
{
INDICATOR_SESSION_ACTIONS_DBUS(gself)->priv->screen_saver = ss;
}
log_and_clear_error (&err, G_STRLOC, G_STRFUNC);
}
static void
on_unity_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gself)
{
GError * err;
UnitySession * us;
err = NULL;
us = unity_session_proxy_new_for_bus_finish (res, &err);
if (err == NULL)
{
INDICATOR_SESSION_ACTIONS_DBUS(gself)->priv->unity_session = us;
}
log_and_clear_error (&err, G_STRLOC, G_STRFUNC);
}
static void
on_can_suspend_ready (GObject * o, GAsyncResult * res, gpointer gself)
{
char * str;
GError * err;
str = NULL;
err = NULL;
login1_manager_call_can_suspend_finish (LOGIN1_MANAGER(o), &str, res, &err);
if (err == NULL)
{
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(gself)->priv;
const gboolean b = !g_strcmp0 (str, "yes") || !g_strcmp0 (str, "challenge");
if (p->can_suspend != b)
{
p->can_suspend = b;
indicator_session_actions_notify_can_suspend (gself);
}
g_free (str);
}
log_and_clear_error (&err, G_STRLOC, G_STRFUNC);
}
static void
on_can_hibernate_ready (GObject * o, GAsyncResult * res, gpointer gself)
{
gchar * str;
GError * err;
str = NULL;
err = NULL;
login1_manager_call_can_hibernate_finish (LOGIN1_MANAGER(o), &str, res, &err);
if (err == NULL)
{
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(gself)->priv;
const gboolean b = !g_strcmp0 (str, "yes") || !g_strcmp0 (str, "challenge");
if (p->can_hibernate != b)
{
p->can_hibernate = b;
indicator_session_actions_notify_can_hibernate (gself);
}
g_free (str);
}
log_and_clear_error (&err, G_STRLOC, G_STRFUNC);
}
static void
set_login1_manager (IndicatorSessionActionsDbus * self,
Login1Manager * login1_manager)
{
priv_t * p = self->priv;
if (p->login1_manager != NULL)
{
g_cancellable_cancel (p->login1_manager_cancellable);
g_clear_object (&p->login1_manager_cancellable);
g_clear_object (&p->login1_manager);
}
if (login1_manager != NULL)
{
p->login1_manager_cancellable = g_cancellable_new ();
p->login1_manager = g_object_ref (login1_manager);
login1_manager_call_can_suspend (p->login1_manager,
p->login1_manager_cancellable,
on_can_suspend_ready,
self);
login1_manager_call_can_hibernate (p->login1_manager,
p->login1_manager_cancellable,
on_can_hibernate_ready,
self);
}
}
static void
on_session_manager_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gself)
{
GError * err;
GnomeSessionManager * sm;
err = NULL;
sm = gnome_session_manager_proxy_new_for_bus_finish (res, &err);
if (err == NULL)
{
INDICATOR_SESSION_ACTIONS_DBUS(gself)->priv->session_manager = sm;
}
log_and_clear_error (&err, G_STRLOC, G_STRFUNC);
}
static void
on_webcredentials_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gself)
{
GError * err;
Webcredentials * webcredentials;
err = NULL;
webcredentials = webcredentials_proxy_new_for_bus_finish (res, &err);
if (err == NULL)
{
INDICATOR_SESSION_ACTIONS_DBUS(gself)->priv->webcredentials = webcredentials;
g_signal_connect_swapped (webcredentials, "notify::error-status",
G_CALLBACK(indicator_session_actions_notify_has_online_account_error), gself);
if (webcredentials_get_error_status (webcredentials))
indicator_session_actions_notify_has_online_account_error (gself);
}
log_and_clear_error (&err, G_STRLOC, G_STRFUNC);
}
static void
on_end_session_dialog_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gself)
{
GError * err;
EndSessionDialog * end_session_dialog;
err = NULL;
end_session_dialog = end_session_dialog_proxy_new_for_bus_finish (res, &err);
if (err == NULL)
{
INDICATOR_SESSION_ACTIONS_DBUS(gself)->priv->end_session_dialog = end_session_dialog;
g_signal_connect_swapped (end_session_dialog, "notify::g-name-owner",
G_CALLBACK(indicator_session_actions_notify_can_switch), gself);
indicator_session_actions_notify_can_prompt (INDICATOR_SESSION_ACTIONS(gself));
indicator_session_actions_notify_can_reboot (INDICATOR_SESSION_ACTIONS(gself));
}
log_and_clear_error (&err, G_STRLOC, G_STRFUNC);
}
/***
**** Virtual Functions
***/
static gboolean
my_can_lock (IndicatorSessionActions * self)
{
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
return !g_settings_get_boolean (p->lockdown_settings, "disable-lock-screen");
}
static gboolean
my_can_logout (IndicatorSessionActions * self)
{
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
if (g_settings_get_boolean (p->indicator_settings, "suppress-logout-menuitem"))
return FALSE;
if (g_settings_get_boolean (p->lockdown_settings, "disable-log-out"))
return FALSE;
return TRUE;
}
static gboolean
my_can_reboot (IndicatorSessionActions * actions)
{
IndicatorSessionActionsDbus * self = INDICATOR_SESSION_ACTIONS_DBUS(actions);
priv_t * p = self->priv;
if (g_settings_get_boolean (p->indicator_settings, "suppress-restart-menuitem"))
return FALSE;
if (g_settings_get_boolean (p->indicator_settings, "force-restart-menuitem"))
return TRUE;
/* Shutdown and Restart are the same dialog prompt in Unity,
so disable the redundant 'Restart' menuitem in that mode */
if (!g_settings_get_boolean (p->indicator_settings, "suppress-shutdown-menuitem"))
if (get_prompt_status(self) == PROMPT_WITH_UNITY)
return FALSE;
return TRUE;
}
static gboolean
my_can_switch (IndicatorSessionActions * self)
{
const priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
return p->seat_allows_activation
&& !g_settings_get_boolean (p->lockdown_settings, "disable-user-switching");
}
static gboolean
my_can_suspend (IndicatorSessionActions * self)
{
const priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
return p && p->can_suspend;
}
static gboolean
my_can_hibernate (IndicatorSessionActions * self)
{
const priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
return p && p->can_hibernate;
}
static gboolean
my_can_prompt (IndicatorSessionActions * self)
{
return get_prompt_status(INDICATOR_SESSION_ACTIONS_DBUS(self)) != PROMPT_NONE;
}
static gboolean
my_has_online_account_error (IndicatorSessionActions * self)
{
const priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
return p && (p->webcredentials) && (webcredentials_get_error_status (p->webcredentials));
}
static void
my_suspend (IndicatorSessionActions * self)
{
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
g_return_if_fail (p->login1_manager != NULL);
login1_manager_call_suspend (p->login1_manager,
TRUE,
p->login1_manager_cancellable,
NULL,
NULL);
}
static void
my_hibernate (IndicatorSessionActions * self)
{
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
g_return_if_fail (p->login1_manager != NULL);
login1_manager_call_hibernate (p->login1_manager,
TRUE,
p->login1_manager_cancellable,
NULL,
NULL);
}
/***
**** End Session Dialog
***/
static gboolean
is_owned_proxy (gpointer proxy)
{
gboolean owned = FALSE;
if ((proxy != NULL) && G_IS_DBUS_PROXY (proxy))
{
char * name_owner = g_dbus_proxy_get_name_owner (proxy);
if (name_owner != NULL)
{
owned = TRUE;
g_free (name_owner);
}
}
return owned;
}
static void
on_gnome_logout_response (GObject * o,
GAsyncResult * res,
gpointer unused G_GNUC_UNUSED)
{
GError * err = NULL;
gnome_session_manager_call_logout_finish (GNOME_SESSION_MANAGER(o), res, &err);
log_and_clear_error (&err, G_STRLOC, G_STRFUNC);
}
static gboolean
logout_now_gnome_session_manager (IndicatorSessionActionsDbus * self)
{
gboolean logout_called = FALSE;
priv_t * p = self->priv;
if (is_owned_proxy (p->session_manager))
{
g_debug ("%s: calling gnome_session_manager_call_logout()", G_STRFUNC);
gnome_session_manager_call_logout (p->session_manager,
1, /* don't prompt */
p->cancellable,
on_gnome_logout_response,
self);
logout_called = TRUE;
}
return logout_called;
}
static void
on_unity_logout_response (GObject * o,
GAsyncResult * res,
gpointer gself)
{
GError * error;
error = NULL;
unity_session_call_request_logout_finish (UNITY_SESSION(o), res, &error);
if (error != NULL)
{
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{
g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, error->message);
logout_now_gnome_session_manager(gself);
}
g_clear_error (&error);
}
}
static gboolean
logout_now_unity (IndicatorSessionActionsDbus * self)
{
priv_t * p = self->priv;
gboolean called = FALSE;
if (is_owned_proxy (p->unity_session))
{
called = TRUE;
g_debug ("calling unity_session_call_request_logout()");
unity_session_call_request_logout (p->unity_session,
p->cancellable,
on_unity_logout_response,
self);
}
return called;
}
static void
logout_now (IndicatorSessionActionsDbus * self)
{
if (!logout_now_unity(self) && !logout_now_gnome_session_manager(self))
{
g_critical("%s can't logout: no Unity nor GNOME session proxy", G_STRFUNC);
}
}
static void
on_reboot_response (GObject * o,
GAsyncResult * res,
gpointer unused G_GNUC_UNUSED)
{
GError * err = NULL;
login1_manager_call_reboot_finish (LOGIN1_MANAGER(o), res, &err);
if (err != NULL)
{
g_warning ("Unable to reboot: %s", err->message);
g_error_free (err);
}
}
static void
reboot_now (IndicatorSessionActionsDbus * self)
{
priv_t * p = self->priv;
g_return_if_fail (p->login1_manager != NULL);
login1_manager_call_reboot (p->login1_manager,
FALSE,
p->login1_manager_cancellable,
on_reboot_response,
NULL);
}
static void
power_off_now (IndicatorSessionActionsDbus * self)
{
priv_t * p = self->priv;
g_return_if_fail (p->login1_manager != NULL);
login1_manager_call_power_off (p->login1_manager,
FALSE,
p->login1_manager_cancellable,
NULL,
NULL);
}
static void
stop_listening_to_dialog (IndicatorSessionActionsDbus * self)
{
g_signal_handlers_disconnect_by_data (self->priv->end_session_dialog, self);
}
static void
on_end_session_dialog_canceled (IndicatorSessionActionsDbus * self)
{
stop_listening_to_dialog (self);
}
static void
on_end_session_dialog_closed (IndicatorSessionActionsDbus * self)
{
stop_listening_to_dialog (self);
}
static void
on_open_end_session_dialog_ready (GObject * o,
GAsyncResult * res,
gpointer gself G_GNUC_UNUSED)
{
GError * err = NULL;
end_session_dialog_call_open_finish (END_SESSION_DIALOG(o), res, &err);
if (err != NULL)
{
if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("%s %s: %s", G_STRFUNC, G_STRLOC, err->message);
/* Treat errors as user confirmation.
Otherwise how will the user ever log out? */
logout_now(INDICATOR_SESSION_ACTIONS_DBUS(gself));
g_clear_error(&err);
}
}
static void
show_unity_end_session_dialog (IndicatorSessionActionsDbus * self, int type)
{
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
gpointer o = p->end_session_dialog;
const char * inhibitor_paths[] = { NULL };
g_assert (o != NULL);
g_signal_connect_swapped (o, "confirmed-logout", G_CALLBACK(logout_now), self);
g_signal_connect_swapped (o, "confirmed-reboot", G_CALLBACK(reboot_now), self);
g_signal_connect_swapped (o, "confirmed-shutdown", G_CALLBACK(power_off_now), self);
g_signal_connect_swapped (o, "canceled", G_CALLBACK(on_end_session_dialog_canceled), self);
g_signal_connect_swapped (o, "closed", G_CALLBACK(on_end_session_dialog_closed), self);
end_session_dialog_call_open (p->end_session_dialog, type, 0, 0, inhibitor_paths,
p->cancellable,
on_open_end_session_dialog_ready,
self);
}
static gboolean
zenity_question (IndicatorSessionActionsDbus * self,
const char * icon_name,
const char * title,
const char * text,
const char * ok_label,
const char * cancel_label)
{
char * command_line;
int exit_status;
GError * error;
gboolean confirmed;
command_line = g_strdup_printf ("%s"
" --question"
" --icon-name=\"%s\""
" --title=\"%s\""
" --text=\"%s\""
" --ok-label=\"%s\""
" --cancel-label=\"%s\""
" --no-wrap",
self->priv->zenity,
icon_name,
title,
text,
ok_label,
cancel_label);
/* Treat errors as user confirmation.
Otherwise how will the user ever log out? */
exit_status = -1;
error = NULL;
if (!g_spawn_command_line_sync (command_line, NULL, NULL, &exit_status, &error))
{
confirmed = TRUE;
}
else
{
confirmed = g_spawn_check_exit_status (exit_status, &error);
}
log_and_clear_error (&error, G_STRLOC, G_STRFUNC);
g_free (command_line);
return confirmed;
}
static void
run_outside_app (const char * cmd)
{
GError * err = NULL;
g_debug ("%s calling \"%s\"", G_STRFUNC, cmd);
g_spawn_command_line_async (cmd, &err);
log_and_clear_error (&err, G_STRLOC, G_STRFUNC);
}
static void
my_logout (IndicatorSessionActions * actions)
{
IndicatorSessionActionsDbus * self = INDICATOR_SESSION_ACTIONS_DBUS (actions);
switch (get_prompt_status (self))
{
case PROMPT_WITH_UNITY:
show_unity_end_session_dialog (self, END_SESSION_TYPE_LOGOUT);
break;
case PROMPT_WITH_MATE:
/* --logout-dialog presents Logout and (if available) Switch User options */
run_outside_app ("mate-session-save --logout-dialog");
break;
case PROMPT_NONE:
logout_now (self);
break;
case PROMPT_WITH_ZENITY:
{
const char * primary = _("Are you sure you want to close all programs and log out?");
const char * secondary = _("Some software updates won't be applied until the computer next restarts.");
char * text = g_strdup_printf ("%s\n \n%s", primary, secondary);
gboolean confirmed = zenity_question (self,
"system-log-out",
_("Log Out"),
text,
_("Log Out"),
_("Cancel"));
g_free (text);
if (confirmed)
logout_now (self);
break;
}
}
}
static void
my_reboot (IndicatorSessionActions * actions)
{
IndicatorSessionActionsDbus * self = INDICATOR_SESSION_ACTIONS_DBUS (actions);
switch (get_prompt_status (self))
{
case PROMPT_WITH_UNITY:
show_unity_end_session_dialog (self, END_SESSION_TYPE_REBOOT);
break;
case PROMPT_WITH_MATE:
/* --shutdown-dialog presents Restart, Shutdown and (if available) Suspend options */
run_outside_app ("mate-session-save --shutdown-dialog");
break;
case PROMPT_NONE:
reboot_now (self);
break;
case PROMPT_WITH_ZENITY:
if (zenity_question (self,
"system-restart",
_("Restart"),
_("Are you sure you want to close all programs and restart the computer?"),
_("Restart"),
_("Cancel")))
reboot_now (self);
break;
}
}
static void
my_power_off (IndicatorSessionActions * actions)
{
IndicatorSessionActionsDbus * self = INDICATOR_SESSION_ACTIONS_DBUS (actions);
switch (get_prompt_status (self))
{
case PROMPT_WITH_UNITY:
/* NB: TYPE_REBOOT instead of TYPE_SHUTDOWN because
the latter adds lock & logout options in Unity... */
show_unity_end_session_dialog (self, END_SESSION_TYPE_REBOOT);
break;
case PROMPT_WITH_MATE:
/* --shutdown-dialog presents Restart, Shutdown and (if available) Suspend options */
run_outside_app ("mate-session-save --shutdown-dialog");
break;
case PROMPT_WITH_ZENITY:
if (zenity_question (self,
"system-shutdown",
_("Shut Down"),
_("Are you sure you want to close all programs and shut down the computer?"),
_("Shut Down"),
_("Cancel")))
power_off_now (self);
break;
case PROMPT_NONE:
power_off_now (self);
break;
}
}
/***
****
***/
static void
my_help (IndicatorSessionActions * self G_GNUC_UNUSED)
{
if (have_mate_program ("yelp"))
run_outside_app ("yelp help:mate-user-guide");
else
run_outside_app ("yelp");
}
static gboolean
have_unity_control_center (void)
{
gchar *path;
const gchar *xdg_current_desktop;
gchar **desktop_names;
gboolean have_ucc;
gboolean is_unity;
int i;
is_unity = FALSE;
xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
if (xdg_current_desktop != NULL) {
desktop_names = g_strsplit (xdg_current_desktop, ":", 0);
for (i = 0; desktop_names[i]; ++i) {
if (!g_strcmp0 (desktop_names[i], "Unity")) {
is_unity = TRUE;
}
}
g_strfreev (desktop_names);
}
if (!is_unity)
return FALSE;
path = g_find_program_in_path ("unity-control-center");
have_ucc = path != NULL;
g_free (path);
return have_ucc;
}
static void
my_settings (IndicatorSessionActions * self G_GNUC_UNUSED)
{
if (have_unity_control_center ())
run_outside_app ("unity-control-center");
else if (have_mate_program ("mate-control-center"))
run_outside_app ("mate-control-center");
else
run_outside_app ("gnome-control-center");
}
static void
my_online_accounts (IndicatorSessionActions * self G_GNUC_UNUSED)
{
if (have_unity_control_center ())
run_outside_app ("unity-control-center credentials");
else
run_outside_app ("gnome-control-center online-accounts");
}
static void
my_about (IndicatorSessionActions * self G_GNUC_UNUSED)
{
if (have_unity_control_center ())
run_outside_app ("unity-control-center info");
else if (have_mate_program ("mate-system-monitor"))
run_outside_app ("mate-system-monitor --show-system-tab");
else
run_outside_app ("gnome-control-center info-overview");
}
/***
****
***/
static void
lock_current_session (IndicatorSessionActions * self, gboolean immediate)
{
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
if (is_owned_proxy (p->unity_session))
{
if (immediate)
{
unity_session_call_prompt_lock (p->unity_session, p->cancellable, NULL, NULL);
}
else
{
unity_session_call_lock (p->unity_session, p->cancellable, NULL, NULL);
}
}
else if (have_mate_program ("mate-screensaver-command"))
{
run_outside_app ("mate-screensaver-command --lock");
}
else
{
g_return_if_fail (p->screen_saver != NULL);
gnome_screen_saver_call_lock (p->screen_saver, p->cancellable, NULL, NULL);
}
}
static void
my_switch_to_screensaver (IndicatorSessionActions * self)
{
lock_current_session (self, FALSE);
}
static void
my_switch_to_greeter (IndicatorSessionActions * self)
{
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
g_return_if_fail (p->dm_seat != NULL);
lock_current_session (self, TRUE);
display_manager_seat_call_switch_to_greeter (p->dm_seat,
p->dm_seat_cancellable,
NULL, NULL);
}
static void
my_switch_to_guest (IndicatorSessionActions * self)
{
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
g_return_if_fail (p->dm_seat != NULL);
lock_current_session (self, TRUE);
display_manager_seat_call_switch_to_guest (p->dm_seat, "",
p->dm_seat_cancellable,
NULL, NULL);
}
static void
my_switch_to_username (IndicatorSessionActions * self, const char * username)
{
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
g_return_if_fail (p->dm_seat != NULL);
lock_current_session (self, TRUE);
display_manager_seat_call_switch_to_user (p->dm_seat, username, "",
p->dm_seat_cancellable,
NULL, NULL);
}
static void
my_dispose (GObject * o)
{
IndicatorSessionActionsDbus * self = INDICATOR_SESSION_ACTIONS_DBUS (o);
priv_t * p = self->priv;
if (p->cancellable != NULL)
{
g_cancellable_cancel (p->cancellable);
g_clear_object (&p->cancellable);
}
if (p->indicator_settings != NULL)
{
g_signal_handlers_disconnect_by_data (p->indicator_settings, self);
g_clear_object (&p->indicator_settings);
}
if (p->lockdown_settings != NULL)
{
g_signal_handlers_disconnect_by_data (p->lockdown_settings, self);
g_clear_object (&p->lockdown_settings);
}
if (p->webcredentials != NULL)
{
g_signal_handlers_disconnect_by_data (p->webcredentials, self);
g_clear_object (&p->webcredentials);
}
if (p->end_session_dialog != NULL)
{
stop_listening_to_dialog (self);
g_clear_object (&p->end_session_dialog);
}
g_clear_object (&p->screen_saver);
g_clear_object (&p->session_manager);
g_clear_object (&p->unity_session);
set_dm_seat (self, NULL);
set_login1_manager (self, NULL);
set_login1_seat (self, NULL);
G_OBJECT_CLASS (indicator_session_actions_dbus_parent_class)->dispose (o);
}
static void
my_finalize (GObject * o)
{
IndicatorSessionActionsDbus * self = INDICATOR_SESSION_ACTIONS_DBUS (o);
priv_t * p = self->priv;
g_free (p->zenity);
}
/***
**** GObject Boilerplate
***/
static void
/* cppcheck-suppress unusedFunction */
indicator_session_actions_dbus_class_init (IndicatorSessionActionsDbusClass * klass)
{
GObjectClass * object_class;
IndicatorSessionActionsClass * actions_class;
object_class = G_OBJECT_CLASS (klass);
object_class->dispose = my_dispose;
object_class->finalize = my_finalize;
actions_class = INDICATOR_SESSION_ACTIONS_CLASS (klass);
actions_class->can_lock = my_can_lock;
actions_class->can_logout = my_can_logout;
actions_class->can_reboot = my_can_reboot;
actions_class->can_switch = my_can_switch;
actions_class->can_suspend = my_can_suspend;
actions_class->can_hibernate = my_can_hibernate;
actions_class->can_prompt = my_can_prompt;
actions_class->has_online_account_error = my_has_online_account_error;
actions_class->logout = my_logout;
actions_class->suspend = my_suspend;
actions_class->hibernate = my_hibernate;
actions_class->reboot = my_reboot;
actions_class->power_off = my_power_off;
actions_class->settings = my_settings;
actions_class->online_accounts = my_online_accounts;
actions_class->help = my_help;
actions_class->about = my_about;
actions_class->switch_to_screensaver = my_switch_to_screensaver;
actions_class->switch_to_greeter = my_switch_to_greeter;
actions_class->switch_to_guest = my_switch_to_guest;
actions_class->switch_to_username = my_switch_to_username;
}
static void
/* cppcheck-suppress unusedFunction */
indicator_session_actions_dbus_init (IndicatorSessionActionsDbus * self)
{
priv_t * p;
GSettings * s;
p = indicator_session_actions_dbus_get_instance_private (self);
p->cancellable = g_cancellable_new ();
p->seat_allows_activation = TRUE;
self->priv = p;
p->zenity = g_find_program_in_path ("zenity");
s = g_settings_new ("org.gnome.desktop.lockdown");
g_signal_connect_swapped (s, "changed::disable-lock-screen",
G_CALLBACK(indicator_session_actions_notify_can_lock), self);
g_signal_connect_swapped (s, "changed::disable-log-out",
G_CALLBACK(indicator_session_actions_notify_can_logout), self);
g_signal_connect_swapped (s, "changed::disable-user-switching",
G_CALLBACK(indicator_session_actions_notify_can_switch), self);
p->lockdown_settings = s;
s = g_settings_new ("com.canonical.indicator.session");
g_signal_connect_swapped (s, "changed::suppress-logout-restart-shutdown",
G_CALLBACK(indicator_session_actions_notify_can_prompt), self);
g_signal_connect_swapped (s, "changed::suppress-logout-restart-shutdown",
G_CALLBACK(indicator_session_actions_notify_can_reboot), self);
g_signal_connect_swapped (s, "changed::suppress-restart-menuitem",
G_CALLBACK(indicator_session_actions_notify_can_reboot), self);
g_signal_connect_swapped (s, "changed::suppress-shutdown-menuitem",
G_CALLBACK(indicator_session_actions_notify_can_reboot), self);
g_signal_connect_swapped (s, "changed::force-restart-menuitem",
G_CALLBACK(indicator_session_actions_notify_can_reboot), self);
p->indicator_settings = s;
gnome_screen_saver_proxy_new_for_bus (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
"org.gnome.ScreenSaver",
"/org/gnome/ScreenSaver",
p->cancellable,
on_screensaver_proxy_ready,
self);
unity_session_proxy_new_for_bus (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
"com.canonical.Unity",
"/com/canonical/Unity/Session",
p->cancellable,
on_unity_proxy_ready,
self);
gnome_session_manager_proxy_new_for_bus (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
"org.gnome.SessionManager",
"/org/gnome/SessionManager",
p->cancellable,
on_session_manager_proxy_ready,
self);
webcredentials_proxy_new_for_bus (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
"com.canonical.indicators.webcredentials",
"/com/canonical/indicators/webcredentials",
p->cancellable,
on_webcredentials_proxy_ready,
self);
end_session_dialog_proxy_new_for_bus (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
"com.canonical.Unity",
"/org/gnome/SessionManager/EndSessionDialog",
p->cancellable,
on_end_session_dialog_proxy_ready,
self);
}
/***
**** Public
***/
IndicatorSessionActions *
indicator_session_actions_dbus_new (void)
{
gpointer o = g_object_new (INDICATOR_TYPE_SESSION_ACTIONS_DBUS, NULL);
return INDICATOR_SESSION_ACTIONS (o);
}
void
indicator_session_actions_dbus_set_proxies (IndicatorSessionActionsDbus * self,
Login1Manager * login1_manager,
Login1Seat * login1_seat,
DisplayManagerSeat * dm_seat)
{
g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS_DBUS(self));
set_login1_manager (self, login1_manager);
set_login1_seat (self, login1_seat);
set_dm_seat (self, dm_seat);
}
./src/backend-dbus/users.c 0000644 0000041 0000041 00000045730 14061437252 015676 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 "dbus-user.h"
#include "users.h"
struct _IndicatorSessionUsersDbusPrivate
{
Login1Manager * login1_manager;
Login1Seat * login1_seat;
DisplayManagerSeat * dm_seat;
Accounts * accounts;
/* hash table of int uids to UserRecord* */
GHashTable * uid_to_account;
/* a hashset of int uids of users who are logged in */
GHashTable * logins;
/* the user-id of the owner of the active session */
guint active_uid;
/* true if this is a live session */
gboolean is_live;
GCancellable * cancellable;
guint update_list_tag;
};
typedef IndicatorSessionUsersDbusPrivate priv_t;
G_DEFINE_TYPE_WITH_PRIVATE (IndicatorSessionUsersDbus, indicator_session_users_dbus, INDICATOR_TYPE_SESSION_USERS)
/***
****
***/
struct UserRecord
{
AccountsUser * user;
gulong signal_id;
};
struct UserRecord *
user_record_new (AccountsUser * user, gulong signal_id)
{
struct UserRecord * rec;
rec = g_new (struct UserRecord, 1);
rec->user = g_object_ref (user);
rec->signal_id = signal_id;
return rec;
}
static void
user_record_free (struct UserRecord * rec)
{
g_signal_handler_disconnect (rec->user, rec->signal_id);
g_object_unref (G_OBJECT (rec->user));
g_free (rec);
}
/***
****
***/
/* get our private org.freedesktop.Accounts.User proxy for the given uid */
static AccountsUser *
get_user_for_uid (IndicatorSessionUsersDbus * self, guint uid)
{
struct UserRecord * rec;
if ((rec = g_hash_table_lookup (self->priv->uid_to_account,
GUINT_TO_POINTER(uid))))
return rec->user;
return NULL;
}
static gboolean
is_tracked_uid (IndicatorSessionUsersDbus * self, guint uid)
{
return get_user_for_uid (self, uid) != NULL;
}
static void
emit_user_added (IndicatorSessionUsersDbus * self, guint32 uid)
{
if (is_tracked_uid (self, uid))
indicator_session_users_added (INDICATOR_SESSION_USERS(self), uid);
}
static void
emit_user_changed (IndicatorSessionUsersDbus * self, guint32 uid)
{
if (is_tracked_uid (self, uid))
indicator_session_users_changed (INDICATOR_SESSION_USERS(self), uid);
}
static void
emit_user_removed (IndicatorSessionUsersDbus * self, guint32 uid)
{
indicator_session_users_removed (INDICATOR_SESSION_USERS(self), uid);
}
/***
****
***/
static void
set_is_live_session_flag (IndicatorSessionUsersDbus * self, gboolean b)
{
priv_t * p = self->priv;
if (p->is_live != b)
{
p->is_live = b;
indicator_session_users_notify_is_live_session (INDICATOR_SESSION_USERS (self));
}
}
static void
set_active_uid (IndicatorSessionUsersDbus * self, guint uid)
{
priv_t * p = self->priv;
if (p->active_uid != uid)
{
const guint old_uid = p->active_uid;
p->active_uid = uid;
emit_user_changed (self, old_uid);
emit_user_changed (self, uid);
}
}
static void
set_logins (IndicatorSessionUsersDbus * self, GHashTable * logins)
{
GHashTable * old_logins = self->priv->logins;
gpointer uid;
GHashTableIter iter;
self->priv->logins = g_hash_table_ref (logins);
/* fire 'user changed' event for users who logged out */
g_hash_table_iter_init (&iter, old_logins);
while ((g_hash_table_iter_next (&iter, &uid, NULL)))
if (!g_hash_table_contains (logins, uid))
emit_user_changed (self, GPOINTER_TO_UINT(uid));
/* fire 'user changed' event for users who logged in */
g_hash_table_iter_init (&iter, logins);
while ((g_hash_table_iter_next (&iter, &uid, NULL)))
if (!g_hash_table_contains (old_logins, uid))
emit_user_changed (self, GPOINTER_TO_UINT(uid));
g_hash_table_destroy (old_logins);
}
/***
**** User Account Tracking
***/
static void create_user_proxy_for_path (IndicatorSessionUsersDbus *, const char *);
/* called when a user proxy gets the 'Changed' signal */
static void
on_user_changed (AccountsUser * user, gpointer gself)
{
/* Accounts.User doesn't update properties in the standard way,
* so create a new proxy to pull in the new properties.
* The older proxy is freed when it's replaced in our accounts hash */
const char * path = g_dbus_proxy_get_object_path (G_DBUS_PROXY(user));
create_user_proxy_for_path (gself, path);
}
static void
track_user (IndicatorSessionUsersDbus * self,
AccountsUser * user)
{
const guint32 uid = accounts_user_get_uid (user);
priv_t * p = self->priv;
gulong id;
const gboolean already_had_user = is_tracked_uid (self, uid);
id = g_signal_connect (user, "changed", G_CALLBACK(on_user_changed), self);
g_hash_table_insert (p->uid_to_account,
GUINT_TO_POINTER (uid),
user_record_new (user, id));
if (already_had_user)
emit_user_changed (self, uid);
else
emit_user_added (self, uid);
}
static void
untrack_user (IndicatorSessionUsersDbus * self,
const gchar * path)
{
guint uid;
gpointer key;
gpointer val;
GHashTableIter iter;
priv_t * p = self->priv;
/* find the uid matching this object path */
uid = 0;
g_hash_table_iter_init (&iter, p->uid_to_account);
while (!uid && g_hash_table_iter_next (&iter, &key, &val))
{
struct UserRecord * rec = val;
GDBusProxy * proxy = G_DBUS_PROXY (rec->user);
if (!g_strcmp0 (path, g_dbus_proxy_get_object_path (proxy)))
uid = GPOINTER_TO_UINT (key);
}
if (uid)
{
g_hash_table_remove (p->uid_to_account, GUINT_TO_POINTER(uid));
emit_user_removed (self, uid);
}
}
/* We got a new org.freedesktop.Accounts.User proxy.
If it's one we want to remember, pass it to track_user() */
static void
on_user_proxy_ready (GObject * o G_GNUC_UNUSED,
GAsyncResult * res,
gpointer self)
{
GError * err;
AccountsUser * user;
err = NULL;
user = accounts_user_proxy_new_for_bus_finish (res, &err);
if (err != NULL)
{
if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("%s: %s", G_STRFUNC, err->message);
g_error_free (err);
}
else
{
if (!accounts_user_get_system_account (user))
track_user (self, user);
g_object_unref (user);
}
}
static void
create_user_proxy_for_path (IndicatorSessionUsersDbus * self,
const char * path)
{
accounts_user_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
"org.freedesktop.Accounts",
path,
self->priv->cancellable,
on_user_proxy_ready, self);
}
/* create proxy objects for everything in Account's user-list */
static void
on_user_list_ready (GObject * o, GAsyncResult * res, gpointer gself)
{
GError * err;
gchar ** paths;
err = NULL;
paths = NULL;
accounts_call_list_cached_users_finish (ACCOUNTS(o), &paths, res, &err);
if (err != NULL)
{
if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, err->message);
g_error_free (err);
}
else
{
int i;
for (i=0; paths && paths[i]; ++i)
create_user_proxy_for_path (gself, paths[i]);
g_strfreev (paths);
}
}
static void
set_account_manager (IndicatorSessionUsersDbus * self, Accounts * a)
{
priv_t * p = self->priv;
if (p->accounts != NULL)
{
g_signal_handlers_disconnect_by_data (p->accounts, self);
g_clear_object (&p->accounts);
}
if (a != NULL)
{
p->accounts = g_object_ref (a);
accounts_call_list_cached_users (a,
self->priv->cancellable,
on_user_list_ready,
self);
g_signal_connect_swapped (a, "user-added",
G_CALLBACK(create_user_proxy_for_path), self);
g_signal_connect_swapped (a, "user-deleted",
G_CALLBACK(untrack_user), self);
}
}
/***
****
***/
/* Based on the login1 manager's list of current sessions,
update our 'logins', 'is_live', and 'active_uid' fields */
static void
on_login1_manager_session_list_ready (GObject * o,
GAsyncResult * res,
gpointer gself)
{
GVariant * sessions;
GError * err;
sessions = NULL;
err = NULL;
login1_manager_call_list_sessions_finish (LOGIN1_MANAGER(o),
&sessions,
res,
&err);
if (err != NULL)
{
if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("%s: %s", G_STRFUNC, err->message);
g_error_free (err);
}
else
{
const gchar * const current_seat_id = g_getenv ("XDG_SEAT");
const gchar * const current_session_id = g_getenv ("XDG_SESSION_ID");
IndicatorSessionUsersDbus * self = INDICATOR_SESSION_USERS_DBUS (gself);
const gchar * session_id = NULL;
guint32 uid = 0;
const gchar * user_name = NULL;
const gchar * seat_id = NULL;
const gchar * path = NULL;
gboolean is_live_session = FALSE;
GHashTable * logins = g_hash_table_new (g_direct_hash, g_direct_equal);
GVariantIter iter;
g_variant_iter_init (&iter, sessions);
while (g_variant_iter_loop (&iter, "(&su&s&s&o)", &session_id,
&uid,
&user_name,
&seat_id,
&path))
{
/* only track sessions on our seat */
if (g_strcmp0 (seat_id, current_seat_id))
continue;
if (!g_strcmp0 (session_id, current_session_id))
{
set_active_uid (self, uid);
if ((uid==999) && !g_strcmp0 (user_name, "ubuntu"))
is_live_session = TRUE;
}
g_hash_table_add (logins, GINT_TO_POINTER(uid));
}
set_is_live_session_flag (self, is_live_session);
set_logins (self, logins);
g_hash_table_unref (logins);
g_variant_unref (sessions);
}
}
static void
update_session_list (IndicatorSessionUsersDbus * self)
{
priv_t * p = self->priv;
if (p->login1_manager != NULL)
{
login1_manager_call_list_sessions (p->login1_manager,
p->cancellable,
on_login1_manager_session_list_ready,
self);
}
}
static gboolean
on_update_session_list_timer (gpointer gself)
{
IndicatorSessionUsersDbus * self = INDICATOR_SESSION_USERS_DBUS (gself);
update_session_list (self);
self->priv->update_list_tag = 0;
return G_SOURCE_REMOVE;
}
/* A dead session can still show up in list-sessions for a few seconds.
So just to be safe, queue up a rebuild for a few seconds from now */
static void
update_session_list_twice (IndicatorSessionUsersDbus * self)
{
priv_t * p = self->priv;
update_session_list (self);
if (p->update_list_tag == 0)
p->update_list_tag = g_timeout_add_seconds (5,
on_update_session_list_timer,
self);
}
static void
set_login1_manager (IndicatorSessionUsersDbus * self,
Login1Manager * login1_manager)
{
priv_t * p = self->priv;
if (p->login1_manager != NULL)
{
g_signal_handlers_disconnect_by_data (p->login1_manager, self);
g_clear_object (&p->login1_manager);
}
if (login1_manager != NULL)
{
p->login1_manager = g_object_ref (login1_manager);
g_signal_connect_swapped (login1_manager, "session-new",
G_CALLBACK(update_session_list), self);
g_signal_connect_swapped (login1_manager, "session-removed",
G_CALLBACK(update_session_list_twice), self);
g_signal_connect_swapped (login1_manager, "user-new",
G_CALLBACK(update_session_list), self);
g_signal_connect_swapped (login1_manager, "user-removed",
G_CALLBACK(update_session_list_twice), self);
update_session_list (self);
}
}
static void
set_login1_seat (IndicatorSessionUsersDbus * self,
Login1Seat * login1_seat)
{
priv_t * p = self->priv;
if (p->login1_seat != NULL)
{
g_signal_handlers_disconnect_by_data (p->login1_seat, self);
g_clear_object (&p->login1_seat);
}
if (login1_seat != NULL)
{
p->login1_seat = g_object_ref (login1_seat);
g_signal_connect_swapped (login1_seat, "notify::active-session",
G_CALLBACK(update_session_list), self);
update_session_list (self);
}
}
static void
set_display_manager_seat (IndicatorSessionUsersDbus * self,
DisplayManagerSeat * dm_seat)
{
priv_t * p = self->priv;
g_clear_object (&p->dm_seat);
if (dm_seat != NULL)
p->dm_seat = g_object_ref (dm_seat);
}
/***
**** IndicatorSessionUsers virtual functions
***/
/* switch to (or create) a session for the specified user */
static void
my_activate_user (IndicatorSessionUsers * users, guint uid)
{
IndicatorSessionUsersDbus * self = INDICATOR_SESSION_USERS_DBUS(users);
priv_t * p = self->priv;
AccountsUser * au;
const char * username;
au = get_user_for_uid (self, uid);
username = au ? accounts_user_get_user_name (au) : NULL;
if (!username)
{
g_warning ("%s %s can't find user '%u'", G_STRLOC, G_STRFUNC, uid);
}
else
{
g_return_if_fail (p->dm_seat != NULL);
display_manager_seat_call_switch_to_user (p->dm_seat,
username,
"",
p->cancellable,
NULL,
NULL);
}
}
/* returns true if this is a live session */
static gboolean
my_is_live_session (IndicatorSessionUsers * users)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_USERS_DBUS(users), FALSE);
return INDICATOR_SESSION_USERS_DBUS(users)->priv->is_live;
}
/* get a list of our user ids */
static GList *
my_get_uids (IndicatorSessionUsers * users)
{
IndicatorSessionUsersDbus * self = INDICATOR_SESSION_USERS_DBUS (users);
return g_hash_table_get_keys (self->priv->uid_to_account);
}
/* build a new struct populated with info on the specified user */
static IndicatorSessionUser *
my_get_user (IndicatorSessionUsers * users, guint uid)
{
IndicatorSessionUsersDbus * self = INDICATOR_SESSION_USERS_DBUS (users);
priv_t * p = self->priv;
IndicatorSessionUser * ret;
AccountsUser * au;
ret = NULL;
au = get_user_for_uid (self, uid);
if (au && !accounts_user_get_system_account(au))
{
g_assert (uid == accounts_user_get_uid (au));
ret = g_new0 (IndicatorSessionUser, 1);
ret->uid = uid;
ret->user_name = g_strdup (accounts_user_get_user_name (au));
ret->real_name = g_strdup (accounts_user_get_real_name (au));
ret->icon_file = g_strdup (accounts_user_get_icon_file (au));
ret->login_frequency = accounts_user_get_login_frequency (au);
ret->is_logged_in = g_hash_table_contains (p->logins, GINT_TO_POINTER(uid));
ret->is_current_user = uid == p->active_uid;
}
return ret;
}
/***
**** GObject virtual functions
***/
static void
my_dispose (GObject * o)
{
IndicatorSessionUsersDbus * self = INDICATOR_SESSION_USERS_DBUS (o);
priv_t * p = self->priv;
if (p->update_list_tag != 0)
{
g_source_remove (p->update_list_tag);
p->update_list_tag = 0;
}
if (p->cancellable)
{
g_cancellable_cancel (p->cancellable);
g_clear_object (&p->cancellable);
}
set_account_manager (self, NULL);
set_display_manager_seat (self, NULL);
set_login1_seat (self, NULL);
set_login1_manager (self, NULL);
g_hash_table_remove_all (p->uid_to_account);
G_OBJECT_CLASS (indicator_session_users_dbus_parent_class)->dispose (o);
}
static void
my_finalize (GObject * o)
{
IndicatorSessionUsersDbus * self = INDICATOR_SESSION_USERS_DBUS (o);
priv_t * p = self->priv;
g_hash_table_destroy (p->logins);
g_hash_table_destroy (p->uid_to_account);
G_OBJECT_CLASS (indicator_session_users_dbus_parent_class)->finalize (o);
}
static void
indicator_session_users_dbus_class_init (IndicatorSessionUsersDbusClass * klass)
{
GObjectClass * object_class;
IndicatorSessionUsersClass * users_class;
object_class = G_OBJECT_CLASS (klass);
object_class->dispose = my_dispose;
object_class->finalize = my_finalize;
users_class = INDICATOR_SESSION_USERS_CLASS (klass);
users_class->is_live_session = my_is_live_session;
users_class->get_uids = my_get_uids;
users_class->get_user = my_get_user;
users_class->activate_user = my_activate_user;
}
static void
indicator_session_users_dbus_init (IndicatorSessionUsersDbus * self)
{
priv_t * p;
p = indicator_session_users_dbus_get_instance_private (self);
self->priv = p;
p->cancellable = g_cancellable_new ();
p->uid_to_account = g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
(GDestroyNotify)user_record_free);
p->logins = g_hash_table_new (g_direct_hash, g_direct_equal);
}
/***
**** Public
***/
IndicatorSessionUsers *
indicator_session_users_dbus_new (void)
{
gpointer o = g_object_new (INDICATOR_TYPE_SESSION_USERS_DBUS, NULL);
return INDICATOR_SESSION_USERS (o);
}
void
indicator_session_users_dbus_set_proxies (IndicatorSessionUsersDbus * self,
Login1Manager * login1_manager,
Login1Seat * login1_seat,
DisplayManagerSeat * dm_seat,
Accounts * accounts)
{
g_return_if_fail (INDICATOR_IS_SESSION_USERS_DBUS (self));
set_login1_manager (self, login1_manager);
set_login1_seat (self, login1_seat);
set_display_manager_seat (self, dm_seat);
set_account_manager (self, accounts);
}
./src/backend-dbus/com.canonical.Unity.Session.xml 0000644 0000041 0000041 00000000711 14061437245 022340 0 ustar www-data www-data
./src/backend-dbus/org.freedesktop.Accounts.User.xml 0000644 0000041 0000041 00000060112 14061437245 022700 0 ustar www-data www-data
The new username.
Sets the users username. Note that it is usually not allowed
to have multiple users with the same username.
The caller needs one of the following PolicyKit authorizations:
org.freedesktop.accounts.user-administration
To change the username of any user
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
The new name, typically in the form "Firstname Lastname".
Sets the users real name.
The caller needs one of the following PolicyKit authorizations:
org.freedesktop.accounts.change-own-user-data
To change his own name
org.freedesktop.accounts.user-administration
To change the name of another user
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
The new email address.
Sets the users email address.
Note that setting an email address in the AccountsService is
not the same as configuring a mail client. Mail clients might
default to email address that is configured here, though.
The caller needs one of the following PolicyKit authorizations:
org.freedesktop.accounts.change-own-user-data
To change his own email address
org.freedesktop.accounts.user-administration
To change the email address of another user
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
The new language, as a locale specification like "de_DE.UTF-8".
Sets the users language.
The expectation is that display managers will start the
users session with this locale.
The caller needs one of the following PolicyKit authorizations:
org.freedesktop.accounts.change-own-user-data
To change his own language
org.freedesktop.accounts.user-administration
To change the language of another user
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
The new xsession to start (e.g. "gnome")
Sets the users x session.
The expectation is that display managers will log the user in to this
specified session, if available.
The caller needs one of the following PolicyKit authorizations:
org.freedesktop.accounts.change-own-user-data
To change his own language
org.freedesktop.accounts.user-administration
To change the language of another user
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
The new location as a freeform string.
Sets the users location.
The caller needs one of the following PolicyKit authorizations:
org.freedesktop.accounts.change-own-user-data
To change his own location
org.freedesktop.accounts.user-administration
To change the location of another user
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
The new homedir as an absolute path.
Sets the users home directory.
Note that changing the users home directory moves all the content
from the old location to the new one, and is potentially an
expensive operation.
The caller needs one of the following PolicyKit authorizations:
org.freedesktop.accounts.user-administration
To change the home directory of a user
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
The new user shell.
Sets the users shell.
Note that setting the shell to a non-allowed program may
prevent the user from logging in.
The caller needs one of the following PolicyKit authorizations:
org.freedesktop.accounts.user-administration
To change the shell of a user
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
The absolute filename of a png file to use as the users icon.
Sets the users icon.
The caller needs one of the following PolicyKit authorizations:
org.freedesktop.accounts.change-own-user-data
To change his own icon
org.freedesktop.accounts.user-administration
To change the icon of another user
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
Whether to lock or unlock the users account.
Locks or unlocks a users account.
Locking an account prevents the user from logging in.
The caller needs one of the following PolicyKit authorizations:
org.freedesktop.accounts.user-administration
To lock or unlock user accounts
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
The new account type, encoded as an integer:
0
Standard user
1
Administrator
Changes the users account type.
The caller needs one of the following PolicyKit authorizations:
org.freedesktop.accounts.user-administration
To change an account type
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
The new password mode, encoded as an integer:
0
Regular password
1
Password must be set at next login
2
No password
Changes the users password mode.
Note that changing the password mode has the side-effect of
unlocking the account.
The caller needs one of the following PolicyKit authorizations:
org.freedesktop.accounts.user-administration
To change a users password mode
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
The crypted password.
The password hint.
Sets a new password for this user.
Note that setting a password has the side-effect of
unlocking the account.
The caller needs one of the following PolicyKit authorizations:
org.freedesktop.accounts.user-administration
To change the password of a user
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
Whether to enable automatic login for this user.
Enables or disables automatic login for a user.
Note that usually only one user can have automatic login
enabled, so turning it on for a user will disable it for
the previously configured autologin user.
The caller needs one of the following PolicyKit authorizations:
org.freedesktop.accounts.set-login-option
To change the login screen configuration
if the caller lacks the appropriate PolicyKit authorization
if the operation failed
The uid of the user.
The username of the user.
The users real name.
The users account type, encoded as an integer:
0
Standard user
1
Administrator
The users home directory.
The users shell.
The email address.
The users language, as a locale specification like "de_DE.UTF-8".
The users x session.
The users location.
How often the user has logged in.
The filename of a png file containing the users icon.
Whether the users account is locked.
The password mode for the user account, encoded as an integer:
0
Regular password
1
Password must be set at next login
2
No password
The password hint for the user.
Whether automatic login is enabled for the user.
Whether this is a 'system' account, like 'root' or 'nobody'.
System accounts should normally not appear in lists of
users, and ListCachedUsers will not include such accounts.
Emitted when the user is changed.
./src/backend-dbus/utils.c 0000644 0000041 0000041 00000014052 14061437245 015670 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 "utils.h"
/***
**** indicator_session_util_get_session_proxies()
***/
struct session_proxy_data
{
Login1Manager * login1_manager;
Login1Seat * login1_seat;
DisplayManagerSeat * dm_seat;
Accounts * account_manager;
GCancellable * cancellable;
int pending;
indicator_session_util_session_proxies_func callback;
gpointer user_data;
};
static void
on_proxy_ready_impl (struct session_proxy_data * data,
gsize member_offset,
GError * err,
gpointer proxy)
{
if (err != NULL)
{
if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, err->message);
g_error_free (err);
}
else
{
*((gpointer*)G_STRUCT_MEMBER_P(data, member_offset)) = proxy;
}
if (!--data->pending)
{
data->callback (data->login1_manager,
data->login1_seat,
data->dm_seat,
data->account_manager,
data->cancellable,
data->user_data);
g_clear_object (&data->login1_manager);
g_clear_object (&data->login1_seat);
g_clear_object (&data->dm_seat);
g_clear_object (&data->account_manager);
g_clear_object (&data->cancellable);
g_free (data);
}
}
static void
on_display_manager_seat_proxy_ready (GObject * o G_GNUC_UNUSED,
GAsyncResult * res,
gpointer gdata)
{
gsize offset = G_STRUCT_OFFSET (struct session_proxy_data, dm_seat);
GError * err = NULL;
gpointer proxy = display_manager_seat_proxy_new_for_bus_finish (res, &err);
on_proxy_ready_impl (gdata, offset, err, proxy);
}
static void
on_login1_seat_ready (GObject * o G_GNUC_UNUSED,
GAsyncResult * res,
gpointer gdata)
{
gsize offset = G_STRUCT_OFFSET (struct session_proxy_data, login1_seat);
GError * err = NULL;
gpointer proxy = login1_seat_proxy_new_for_bus_finish (res, &err);
on_proxy_ready_impl (gdata, offset, err, proxy);
}
static void
on_login1_manager_ready (GObject * o G_GNUC_UNUSED,
GAsyncResult * res,
gpointer gdata)
{
gsize offset = G_STRUCT_OFFSET (struct session_proxy_data, login1_manager);
GError * err = NULL;
gpointer proxy = login1_manager_proxy_new_for_bus_finish (res, &err);
on_proxy_ready_impl (gdata, offset, err, proxy);
}
static void
on_accounts_proxy_ready (GObject * o G_GNUC_UNUSED,
GAsyncResult * res,
gpointer gdata)
{
gsize offset = G_STRUCT_OFFSET (struct session_proxy_data, account_manager);
GError * err = NULL;
gpointer proxy = accounts_proxy_new_for_bus_finish (res, &err);
on_proxy_ready_impl (gdata, offset, err, proxy);
}
/* helper utility to get the dbus proxies used by the backend-dbus classes */
void
indicator_session_util_get_session_proxies (
indicator_session_util_session_proxies_func func,
GCancellable * cancellable,
gpointer user_data)
{
struct session_proxy_data * data;
const char * str;
data = g_new0 (struct session_proxy_data, 1);
data->callback = func;
data->user_data = user_data;
data->cancellable = g_object_ref (cancellable);
/* login1 */
data->pending++;
login1_manager_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
"org.freedesktop.login1",
"/org/freedesktop/login1",
data->cancellable,
on_login1_manager_ready, data);
/* login1 seat */
if ((str = g_getenv ("XDG_SEAT")))
{
char * path;
data->pending++;
path = g_strconcat ("/org/freedesktop/login1/seat/", str, NULL);
login1_seat_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
"org.freedesktop.login1",
path,
data->cancellable,
on_login1_seat_ready,
data);
g_free (path);
}
/* Accounts */
data->pending++;
accounts_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
"org.freedesktop.Accounts",
"/org/freedesktop/Accounts",
data->cancellable,
on_accounts_proxy_ready, data);
/* DisplayManager seat */
if ((str = g_getenv ("XDG_SEAT_PATH")))
{
data->pending++;
display_manager_seat_proxy_new_for_bus (
G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
"org.freedesktop.DisplayManager",
str,
data->cancellable,
on_display_manager_seat_proxy_ready, data);
}
}
./src/backend-dbus/com.canonical.indicators.webcredentials.xml 0000644 0000041 0000041 00000005547 14061437245 024753 0 ustar www-data www-data
./src/backend-dbus/guest.c 0000644 0000041 0000041 00000024457 14061437252 015667 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 "guest.h"
struct _IndicatorSessionGuestDbusPrivate
{
GCancellable * cancellable;
Login1Manager * login1_manager;
Login1Seat * login1_seat;
DisplayManagerSeat * dm_seat;
gboolean guest_is_active;
gboolean guest_is_logged_in;
gboolean guest_is_allowed;
};
typedef IndicatorSessionGuestDbusPrivate priv_t;
G_DEFINE_TYPE_WITH_PRIVATE (IndicatorSessionGuestDbus, indicator_session_guest_dbus, INDICATOR_TYPE_SESSION_GUEST)
/***
****
***/
static void
set_guest_is_allowed_flag (IndicatorSessionGuestDbus * self, gboolean b)
{
priv_t * p = self->priv;
if (p->guest_is_allowed != b)
{
p->guest_is_allowed = b;
indicator_session_guest_notify_allowed (INDICATOR_SESSION_GUEST (self));
}
}
static void
set_guest_is_logged_in_flag (IndicatorSessionGuestDbus * self, gboolean b)
{
priv_t * p = self->priv;
if (p->guest_is_logged_in != b)
{
p->guest_is_logged_in = b;
indicator_session_guest_notify_logged_in (INDICATOR_SESSION_GUEST (self));
}
}
static void
set_guest_is_active_flag (IndicatorSessionGuestDbus * self, gboolean b)
{
priv_t * p = self->priv;
if (p->guest_is_active != b)
{
p->guest_is_active = b;
indicator_session_guest_notify_active (INDICATOR_SESSION_GUEST(self));
}
}
/***
****
***/
/* walk the sessions to see if guest is logged in or active */
static void
on_login1_manager_session_list_ready (GObject * o,
GAsyncResult * res,
gpointer gself)
{
GVariant * sessions;
GError * err;
sessions = NULL;
err = NULL;
login1_manager_call_list_sessions_finish (LOGIN1_MANAGER(o),
&sessions,
res,
&err);
if (err != NULL)
{
if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("%s: %s", G_STRFUNC, err->message);
g_error_free (err);
}
else
{
const gchar * const current_seat_id = g_getenv ("XDG_SEAT");
const gchar * const current_session_id = g_getenv ("XDG_SESSION_ID");
gboolean is_logged_in = FALSE;
gboolean is_active = FALSE;
const gchar * session_id = NULL;
guint32 uid = 0;
const gchar * user_name = NULL;
const gchar * seat_id = NULL;
GVariantIter iter;
g_variant_iter_init (&iter, sessions);
while (g_variant_iter_loop (&iter, "(&su&s&so)", &session_id,
&uid,
&user_name,
&seat_id,
NULL))
{
gboolean is_current_session;
gboolean is_guest;
is_current_session = !g_strcmp0 (current_seat_id, seat_id)
&& !g_strcmp0 (current_session_id, session_id);
is_guest = g_str_has_prefix (user_name, "guest-")
&& (uid < 1000);
if (is_guest)
{
is_logged_in = TRUE;
is_active = is_current_session;
}
}
set_guest_is_logged_in_flag (gself, is_logged_in);
set_guest_is_active_flag (gself, is_active);
g_variant_unref (sessions);
}
}
static void
update_session_list (IndicatorSessionGuestDbus * self)
{
priv_t * p = self->priv;
if (p->login1_manager != NULL)
{
login1_manager_call_list_sessions (p->login1_manager,
p->cancellable,
on_login1_manager_session_list_ready,
self);
}
}
static void
set_login1_manager (IndicatorSessionGuestDbus * self,
Login1Manager * login1_manager)
{
priv_t * p = self->priv;
if (p->login1_manager != NULL)
{
g_signal_handlers_disconnect_by_data (p->login1_manager, self);
g_clear_object (&p->login1_manager);
}
if (login1_manager != NULL)
{
p->login1_manager = g_object_ref (login1_manager);
g_signal_connect_swapped (login1_manager, "session-new",
G_CALLBACK(update_session_list), self);
g_signal_connect_swapped (login1_manager, "session-removed",
G_CALLBACK(update_session_list), self);
update_session_list (self);
}
}
static void
set_login1_seat (IndicatorSessionGuestDbus * self,
Login1Seat * login1_seat)
{
priv_t * p = self->priv;
if (p->login1_seat != NULL)
{
g_signal_handlers_disconnect_by_data (p->login1_seat, self);
g_clear_object (&p->login1_seat);
}
if (login1_seat != NULL)
{
p->login1_seat = g_object_ref (login1_seat);
g_signal_connect_swapped (login1_seat, "notify::active-session",
G_CALLBACK(update_session_list), self);
update_session_list (self);
}
}
/***
****
***/
static void
on_switch_to_guest_done (GObject * o,
GAsyncResult * res,
gpointer unused G_GNUC_UNUSED)
{
GError * err;
err = NULL;
display_manager_seat_call_switch_to_guest_finish (DISPLAY_MANAGER_SEAT(o),
res,
&err);
if (err != NULL)
{
if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, err->message);
g_error_free (err);
}
}
static void
my_switch_to_guest (IndicatorSessionGuest * guest)
{
IndicatorSessionGuestDbus * self = INDICATOR_SESSION_GUEST_DBUS(guest);
g_return_if_fail (self != NULL);
g_return_if_fail (self->priv->dm_seat != NULL);
display_manager_seat_call_switch_to_guest (self->priv->dm_seat,
"",
self->priv->cancellable,
on_switch_to_guest_done,
self);
}
static void
on_notify_has_guest_account (DisplayManagerSeat * dm_seat,
GParamSpec * pspec G_GNUC_UNUSED,
IndicatorSessionGuestDbus * self)
{
gboolean guest_exists = display_manager_seat_get_has_guest_account (dm_seat);
set_guest_is_allowed_flag (self, guest_exists);
}
static void
set_display_manager_seat (IndicatorSessionGuestDbus * self,
DisplayManagerSeat * dm_seat)
{
priv_t * p = self->priv;
if (p->dm_seat != NULL)
{
g_signal_handlers_disconnect_by_data (p->dm_seat, self);
g_clear_object (&p->dm_seat);
}
if (dm_seat != NULL)
{
p->dm_seat = g_object_ref (dm_seat);
g_signal_connect (dm_seat, "notify::has-guest-account",
G_CALLBACK(on_notify_has_guest_account), self);
on_notify_has_guest_account (dm_seat, NULL, self);
}
}
/***
**** IndiatorSessionGuest Virtual Functions
***/
static gboolean
my_is_allowed (IndicatorSessionGuest * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_GUEST_DBUS(self), FALSE);
return INDICATOR_SESSION_GUEST_DBUS(self)->priv->guest_is_allowed;
}
static gboolean
my_is_logged_in (IndicatorSessionGuest * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_GUEST_DBUS(self), FALSE);
return INDICATOR_SESSION_GUEST_DBUS(self)->priv->guest_is_logged_in;
}
static gboolean
my_is_active (IndicatorSessionGuest * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_GUEST_DBUS(self), FALSE);
return INDICATOR_SESSION_GUEST_DBUS(self)->priv->guest_is_active;
}
/***
**** GObject Virtual Functions
***/
static void
my_dispose (GObject * o)
{
IndicatorSessionGuestDbus * self = INDICATOR_SESSION_GUEST_DBUS (o);
if (self->priv->cancellable != NULL)
{
g_cancellable_cancel (self->priv->cancellable);
g_clear_object (&self->priv->cancellable);
}
set_login1_seat (self, NULL);
set_login1_manager (self, NULL);
set_display_manager_seat (self, NULL);
G_OBJECT_CLASS (indicator_session_guest_dbus_parent_class)->dispose (o);
}
/***
**** Instantiation
***/
static void
indicator_session_guest_dbus_class_init (IndicatorSessionGuestDbusClass * klass)
{
GObjectClass * object_class;
IndicatorSessionGuestClass * guest_class;
object_class = G_OBJECT_CLASS (klass);
object_class->dispose = my_dispose;
guest_class = INDICATOR_SESSION_GUEST_CLASS (klass);
guest_class->is_allowed = my_is_allowed;
guest_class->is_logged_in = my_is_logged_in;
guest_class->is_active = my_is_active;
guest_class->switch_to_guest = my_switch_to_guest;
}
static void
indicator_session_guest_dbus_init (IndicatorSessionGuestDbus * self)
{
priv_t * p;
p = indicator_session_guest_dbus_get_instance_private (self);
p->cancellable = g_cancellable_new ();
self->priv = p;
}
/***
**** Public
***/
IndicatorSessionGuest *
indicator_session_guest_dbus_new (void)
{
gpointer o = g_object_new (INDICATOR_TYPE_SESSION_GUEST_DBUS, NULL);
return INDICATOR_SESSION_GUEST (o);
}
void
indicator_session_guest_dbus_set_proxies (IndicatorSessionGuestDbus * self,
Login1Manager * login1_manager,
Login1Seat * login1_seat,
DisplayManagerSeat * dm_seat)
{
g_return_if_fail (INDICATOR_IS_SESSION_GUEST_DBUS(self));
set_login1_manager (self, login1_manager);
set_login1_seat (self, login1_seat);
set_display_manager_seat (self, dm_seat);
}
./src/guest.c 0000644 0000041 0000041 00000011535 14061437245 013340 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 "guest.h"
G_DEFINE_TYPE (IndicatorSessionGuest,
indicator_session_guest,
G_TYPE_OBJECT)
enum
{
PROP_0,
PROP_ALLOWED,
PROP_LOGGED_IN,
PROP_ACTIVE,
PROP_LAST
};
static GParamSpec *properties[PROP_LAST];
static void
my_get_property (GObject * o,
guint property_id,
GValue * value,
GParamSpec * pspec)
{
IndicatorSessionGuest * self = INDICATOR_SESSION_GUEST (o);
switch (property_id)
{
case PROP_ALLOWED:
g_value_set_boolean (value, indicator_session_guest_is_allowed (self));
break;
case PROP_LOGGED_IN:
g_value_set_boolean (value, indicator_session_guest_is_logged_in (self));
break;
case PROP_ACTIVE:
g_value_set_boolean (value, indicator_session_guest_is_active (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
}
}
static void
my_dispose (GObject *object)
{
G_OBJECT_CLASS (indicator_session_guest_parent_class)->dispose (object);
}
static void
/* cppcheck-suppress unusedFunction */
indicator_session_guest_class_init (IndicatorSessionGuestClass * klass)
{
GObjectClass * object_class;
const GParamFlags flags = G_PARAM_READABLE | G_PARAM_STATIC_STRINGS;
object_class = G_OBJECT_CLASS (klass);
object_class->get_property = my_get_property;
object_class->dispose = my_dispose;
klass->is_allowed = NULL;
klass->is_logged_in = NULL;
klass->is_active = NULL;
klass->switch_to_guest = NULL;
properties[PROP_0] = NULL;
properties[PROP_ALLOWED] =
g_param_spec_boolean (INDICATOR_SESSION_GUEST_PROPERTY_ALLOWED,
"Is Allowed",
"Whether or not a Guest user is allowed",
FALSE, flags);
properties[PROP_LOGGED_IN] =
g_param_spec_boolean (INDICATOR_SESSION_GUEST_PROPERTY_LOGGED_IN,
"Is Logged In",
"Whether or not the Guest account is logged in",
FALSE, flags);
properties[PROP_ACTIVE] =
g_param_spec_boolean (INDICATOR_SESSION_GUEST_PROPERTY_ACTIVE,
"Is Active",
"If the Guest account has the current session",
FALSE, flags);
g_object_class_install_properties (object_class, PROP_LAST, properties);
}
static void
/* cppcheck-suppress unusedFunction */
indicator_session_guest_init (IndicatorSessionGuest *self G_GNUC_UNUSED)
{
}
/***
****
***/
gboolean
indicator_session_guest_is_active (IndicatorSessionGuest * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_GUEST (self), FALSE);
return INDICATOR_SESSION_GUEST_GET_CLASS (self)->is_active (self);
}
gboolean
indicator_session_guest_is_allowed (IndicatorSessionGuest * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_GUEST (self), FALSE);
return INDICATOR_SESSION_GUEST_GET_CLASS (self)->is_allowed (self);
}
gboolean
indicator_session_guest_is_logged_in (IndicatorSessionGuest * self)
{
g_return_val_if_fail (INDICATOR_IS_SESSION_GUEST (self), FALSE);
return INDICATOR_SESSION_GUEST_GET_CLASS (self)->is_logged_in (self);
}
/***
****
***/
static void
notify_func (IndicatorSessionGuest * self, int prop)
{
g_return_if_fail (INDICATOR_IS_SESSION_GUEST (self));
g_debug ("%s %s emitting '%s' prop notify", G_STRLOC, G_STRFUNC, properties[prop]->name);
g_object_notify_by_pspec (G_OBJECT(self), properties[prop]);
}
void
indicator_session_guest_notify_active (IndicatorSessionGuest * self)
{
notify_func (self, PROP_ACTIVE);
}
void
indicator_session_guest_notify_allowed (IndicatorSessionGuest * self)
{
notify_func (self, PROP_ALLOWED);
}
void
indicator_session_guest_notify_logged_in (IndicatorSessionGuest * self)
{
notify_func (self, PROP_LOGGED_IN);
}
/***
****
***/
void
indicator_session_guest_switch_to_guest (IndicatorSessionGuest * self)
{
gboolean allowed;
g_return_if_fail (INDICATOR_IS_SESSION_GUEST (self));
g_object_get (self, INDICATOR_SESSION_GUEST_PROPERTY_ALLOWED, &allowed, NULL);
g_return_if_fail (allowed);
INDICATOR_SESSION_GUEST_GET_CLASS (self)->switch_to_guest (self);
}
./MERGE-REVIEW 0000644 0000041 0000041 00000001416 14061437245 013034 0 ustar www-data www-data
This documents the expections that the project has on what both submitters
and reviewers should ensure that they've done for a merge into the project.
== Submitter Responsibilities ==
* Ensure the project compiles and the test suite executes without error
* Ensure that non-obvious code has comments explaining it
* If the change works on specific profiles, please include those in the merge description.
== Reviewer Responsibilities ==
* Did the Jenkins build compile? Pass? Run unit tests successfully?
* Are there appropriate tests to cover any new functionality?
* If the description says this effects the phone profile:
* Run tests indicator-session/unity8*
* If the description says this effects the desktop profile:
* Run tests indicator-session/unity7*
./tests/ 0000755 0000041 0000041 00000000000 14061437252 012411 5 ustar www-data www-data ./tests/backend-mock.h 0000644 0000041 0000041 00000002102 14061437245 015075 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 __BACKEND_MOCK_H__
#define __BACKEND_MOCK_H__
#include /* GCancellable */
#include "actions.h"
#include "guest.h"
#include "users.h"
G_BEGIN_DECLS
extern GSettings * mock_settings;
extern IndicatorSessionActions * mock_actions;
extern IndicatorSessionUsers * mock_users;
extern IndicatorSessionGuest * mock_guest;
G_END_DECLS
#endif
./tests/CMakeLists.txt 0000644 0000041 0000041 00000005366 14061437245 015165 0 ustar www-data www-data find_package(GMock)
include_directories(${GMOCK_INCLUDE_DIRS})
# build the necessary schemas
set_directory_properties (PROPERTIES
ADDITIONAL_MAKE_CLEAN_FILES gschemas.compiled)
set_source_files_properties (gschemas.compiled GENERATED)
# GSettings:
# compile the schemas our tests use (indicator-session's, lockdown, media-keys)
# into a gschemas.compiled file in this directory, and help the tests to find
# that file by setting -DSCHEMA_DIR
set (SCHEMA_DIR ${CMAKE_CURRENT_BINARY_DIR})
add_definitions(-DSCHEMA_DIR="${SCHEMA_DIR}")
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_schemas
OUTPUT_VARIABLE COMPILE_SCHEMA_EXECUTABLE
OUTPUT_STRIP_TRAILING_WHITESPACE)
add_custom_command (OUTPUT gschemas.compiled
DEPENDS ${CMAKE_BINARY_DIR}/data/com.canonical.indicator.session.gschema.xml
${CMAKE_SOURCE_DIR}/tests/com.canonical.indicator.session.backendmock.gschema.xml
${CMAKE_SOURCE_DIR}/tests/org.gnome.desktop.lockdown.gschema.xml
${CMAKE_SOURCE_DIR}/tests/org.gnome.settings-daemon.plugins.media-keys.gschema.xml
COMMAND cp -f ${CMAKE_BINARY_DIR}/data/*gschema.xml ${SCHEMA_DIR}
COMMAND cp -f ${CMAKE_SOURCE_DIR}/tests/*gschema.xml ${SCHEMA_DIR}
COMMAND ${COMPILE_SCHEMA_EXECUTABLE} ${SCHEMA_DIR})
# DBus Activation
configure_file (indicator-session.service.in indicator-session.service)
add_definitions(-DINDICATOR_SERVICE_DIR="${CMAKE_CURRENT_BINARY_DIR}")
# look for hearder in our src dir, and also in the directories where we autogenerate files...
include_directories (${CMAKE_SOURCE_DIR}/src)
include_directories (${CMAKE_CURRENT_BINARY_DIR} ${SERVICE_INCLUDE_DIRS})
# backendmock
add_library (backendmock STATIC
backend-mock-actions.c
backend-mock-actions.h
backend-mock.c
backend-mock.h
backend-mock-guest.c
backend-mock-guest.h
backend-mock-users.c
backend-mock-users.h)
set_target_properties (backendmock PROPERTIES COMPILE_FLAGS " ${CC_WARNING_ARGS}")
# test-service
add_executable (test-service
test-service.cc
gschemas.compiled)
set_target_properties (test-service PROPERTIES COMPILE_FLAGS " ${CC_WARNING_ARGS} -std=c++0x")
add_test (test-service test-service)
add_dependencies (test-service libindicatorsessionservice backendmock)
target_link_libraries (test-service libindicatorsessionservice backendmock ${SERVICE_LIBRARIES} ${GMOCK_LIBRARIES})
add_subdirectory (backend-dbus)
# coverage reporting
set(COVERAGE_TEST_TARGETS
${COVERAGE_TEST_TARGETS}
test-service
PARENT_SCOPE
)
./tests/backend-mock-users.h 0000644 0000041 0000041 00000004517 14061437252 016246 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 __USERS_MOCK_H__
#define __USERS_MOCK_H__
#include
#include
#include "users.h" /* parent class */
G_BEGIN_DECLS
#define INDICATOR_TYPE_SESSION_USERS_MOCK (indicator_session_users_mock_get_type())
#define INDICATOR_SESSION_USERS_MOCK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_SESSION_USERS_MOCK, IndicatorSessionUsersMock))
#define INDICATOR_SESSION_USERS_MOCK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_SESSION_USERS_MOCK, IndicatorSessionUsersMockClass))
#define INDICATOR_IS_SESSION_USERS_MOCK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_SESSION_USERS_MOCK))
typedef struct _IndicatorSessionUsersMock IndicatorSessionUsersMock;
typedef struct _IndicatorSessionUsersMockPrivate IndicatorSessionUsersMockPrivate;
typedef struct _IndicatorSessionUsersMockClass IndicatorSessionUsersMockClass;
/**
* An implementation of IndicatorSessionUsers that lies about everything.
*/
struct _IndicatorSessionUsersMock
{
/*< private >*/
IndicatorSessionUsers parent;
IndicatorSessionUsersMockPrivate * priv;
};
struct _IndicatorSessionUsersMockClass
{
IndicatorSessionUsersClass parent_class;
};
GType indicator_session_users_mock_get_type (void);
IndicatorSessionUsers * indicator_session_users_mock_new (void);
void indicator_session_users_mock_add_user (IndicatorSessionUsersMock * self,
IndicatorSessionUser * user);
void indicator_session_users_mock_remove_user (IndicatorSessionUsersMock * self,
guint uid);
G_END_DECLS
#endif
./tests/indicator-session.service.in 0000644 0000041 0000041 00000000170 14061437245 020035 0 ustar www-data www-data [D-BUS Service]
Name=com.canonical.indicator.session-test
Exec=${CMAKE_BINARY_DIR}/src/indicator-session-service --mock
./tests/backend-mock-guest.h 0000644 0000041 0000041 00000004014 14061437252 016224 0 ustar www-data www-data /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* 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 warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 __GUEST_MOCK_H__
#define __GUEST_MOCK_H__
#include
#include
#include "guest.h" /* parent class */
G_BEGIN_DECLS
#define INDICATOR_TYPE_SESSION_GUEST_MOCK (indicator_session_guest_mock_get_type())
#define INDICATOR_SESSION_GUEST_MOCK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_SESSION_GUEST_MOCK, IndicatorSessionGuestMock))
#define INDICATOR_SESSION_GUEST_MOCK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_SESSION_GUEST_MOCK, IndicatorSessionGuestMockClass))
#define INDICATOR_IS_SESSION_GUEST_MOCK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_SESSION_GUEST_MOCK))
typedef struct _IndicatorSessionGuestMock IndicatorSessionGuestMock;
typedef struct _IndicatorSessionGuestMockPrivate IndicatorSessionGuestMockPrivate;
typedef struct _IndicatorSessionGuestMockClass IndicatorSessionGuestMockClass;
/**
* An implementation of IndicatorSessionGuest that lies about everything.
*/
struct _IndicatorSessionGuestMock
{
/*< private >*/
IndicatorSessionGuest parent;
IndicatorSessionGuestMockPrivate * priv;
};
struct _IndicatorSessionGuestMockClass
{
IndicatorSessionGuestClass parent_class;
};
GType indicator_session_guest_mock_get_type (void);
IndicatorSessionGuest * indicator_session_guest_mock_new (void);
G_END_DECLS
#endif
./tests/org.gnome.settings-daemon.plugins.media-keys.gschema.xml 0000644 0000041 0000041 00000017753 14061437245 025262 0 ustar www-data www-data
true
Activation of this plugin
Whether this plugin would be activated by gnome-settings-daemon or not
[]
Custom keybindings
List of custom keybindings
'XF86Calculator'
Launch calculator
Binding to launch the calculator.
'XF86Mail'
Launch email client
Binding to launch the email client.
'XF86Eject'
Eject
Binding to eject an optical disc.
''
Launch help browser
Binding to launch the help browser.
'XF86Explorer'
Home folder
Binding to open the Home folder.
'XF86AudioMedia'
Launch media player
Binding to launch the media player.
'XF86AudioNext'
Next track
Binding to skip to next track.
'XF86AudioPause'
Pause playback
Binding to pause playback.
'XF86AudioPlay'
Play (or play/pause)
Binding to start playback (or toggle play/pause).
'<Control><Alt>Delete'
Log out
Binding to log out.
'XF86AudioPrev'
Previous track
Binding to skip to previous track.
98
Priority to use for this plugin
Priority to use for this plugin in gnome-settings-daemon startup queue
'<Control><Alt>l'
Lock screen
Binding to lock the screen.
'XF86Search'
Search
Binding to launch the search tool.
'XF86AudioStop'
Stop playback
Binding to stop playback.
'XF86AudioLowerVolume'
Volume down
Binding to lower the system volume.
'XF86AudioMute'
Volume mute
Binding to mute the system volume.
'XF86AudioRaiseVolume'
Volume up
Binding to raise the system volume.
'Print'
Take a screenshot
Binding to take a screenshot.
'<Alt>Print'
Take a screenshot of a window
Binding to take a screenshot of a window.
'<Shift>Print'
Take a screenshot of an area
Binding to take a screenshot of an area.
'<Ctrl>Print'
Copy a screenshot to clipboard
Binding to copy a screenshot to clipboard.
'<Ctrl><Alt>Print'
Copy a screenshot of a window to clipboard
Binding to copy a screenshot of a window to clipboard.
'<Ctrl><Shift>Print'
Copy a screenshot of an area to clipboard
Binding to copy a screenshot of an area to clipboard.
'<Primary><Alt>t'
Launch terminal
Binding to launch the terminal.
'XF86WWW'
Launch web browser
Binding to launch the web browser.
''
Toggle magnifier
Binding to show the screen magnifier
''
Toggle screen reader
Binding to start the screen reader
''
Toggle on-screen keyboard
Binding to show the on-screen keyboard
''
Increase text size
Binding to increase the text size
''
Decrease text size
Binding to decrease the text size
''
Toggle contrast
Binding to toggle the interface contrast
''
Magnifier zoom in
Binding for the magnifier to zoom in
''
Magnifier zoom out
Binding for the magnifier to zoom out
''
Name
Name of the custom binding
''
Binding
Binding for the custom binding
''
Command
Command to run when the binding is invoked