Merge lp:~dobey/indicator-printers/cpp-refactor into lp:indicator-printers

Proposed by dobey
Status: Rejected
Rejected by: dobey
Proposed branch: lp:~dobey/indicator-printers/cpp-refactor
Merge into: lp:indicator-printers
Diff against target: 5377 lines (+3048/-2007)
57 files modified
.bzrignore (+2/-0)
AUTHORS (+0/-2)
CMakeLists.txt (+54/-0)
COPYING (+674/-0)
Makefile.am (+0/-6)
Makefile.am.coverage (+0/-48)
autogen.sh (+0/-9)
cmake/GdbusCodegen.cmake (+36/-0)
configure.ac (+0/-105)
data/CMakeLists.txt (+64/-0)
data/Makefile.am (+0/-55)
data/com.canonical.indicator.printers (+20/-0)
data/indicator-printers.desktop.in (+0/-8)
data/upstart/Makefile.am (+0/-17)
data/upstart/indicator-printers.desktop.in (+0/-9)
debian/control (+17/-20)
debian/copyright (+1/-2)
debian/rules (+1/-16)
debian/watch (+0/-2)
m4/gcov.m4 (+0/-86)
po/CMakeLists.txt (+12/-0)
po/POTFILES.in (+0/-6)
src/CMakeLists.txt (+62/-0)
src/actions-live.cpp (+104/-0)
src/actions-live.h (+54/-0)
src/actions.cpp (+73/-0)
src/actions.h (+57/-0)
src/client.h (+56/-0)
src/cups-client.cpp (+328/-0)
src/cups-client.h (+65/-0)
src/exporter.cpp (+158/-0)
src/exporter.h (+60/-0)
src/indicator-menu-item.c (+0/-404)
src/indicator-menu-item.h (+0/-82)
src/indicator-printers-menu.c (+0/-339)
src/indicator-printers-menu.h (+0/-77)
src/indicator-printers-service.c (+0/-206)
src/indicator-printers.c (+0/-311)
src/indicator-printers.h (+0/-70)
src/job.h (+50/-0)
src/main.cpp (+60/-0)
src/menu.cpp (+291/-0)
src/menu.h (+57/-0)
src/printer.h (+44/-0)
src/spawn-printer-settings.c (+0/-35)
src/spawn-printer-settings.h (+0/-11)
src/utils.cpp (+37/-0)
src/utils.h (+32/-0)
test/Makefile.am (+0/-29)
test/mock-cups-notifier.c (+0/-52)
tests/CMakeLists.txt (+26/-0)
tests/actions-mock.h (+36/-0)
tests/client-mock.h (+54/-0)
tests/glib-fixture.h (+220/-0)
tests/test_exporter.cpp (+110/-0)
tests/test_menu.cpp (+100/-0)
tests/test_utils.cpp (+33/-0)
To merge this branch: bzr merge lp:~dobey/indicator-printers/cpp-refactor
Reviewer Review Type Date Requested Status
unity-api-1-bot continuous-integration Approve
Charles Kerr (community) Approve
Review via email: mp+314115@code.launchpad.net

Commit message

Update printing indicator to work under Unity 8 with new design.

To post a comment you must log in.
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :
review: Needs Fixing (continuous-integration)
113. By dobey

Fix control file.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :
review: Needs Fixing (continuous-integration)
114. By dobey

Add missing dbus dep.

115. By dobey

Specify unisgned in exporter test comparison.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:115
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-printers-ci/5/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/1309
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1316
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1094
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1094/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1094
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1094/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1094
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1094/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1094
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1094/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1094
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1094/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1094
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1094/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-printers-ci/5/rebuild

review: Approve (continuous-integration)
116. By dobey

Add missing pragma to utils.h

117. By dobey

Remove more obsolete code.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:117
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-printers-ci/6/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/1317
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1324
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1101
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1101/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1101
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1101/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1101
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1101/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1101
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1101/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1101
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1101/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1101
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1101/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-printers-ci/6/rebuild

review: Approve (continuous-integration)
118. By dobey

It's 2017 now.
Also Lars is not upstream contact any more.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:118
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-printers-ci/7/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/1323
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1330
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1107
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1107/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1107
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1107/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1107
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1107/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1107
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1107/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1107
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1107/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1107
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1107/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-printers-ci/7/rebuild

review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Looking good. Comments inline, mostly minor, also a NF or two

review: Needs Fixing
119. By dobey

Fixes from review.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:119
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-printers-ci/8/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/1336
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1343
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1121
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1121/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1121
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1121/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1121
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1121/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1121
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1121/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1121
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1121/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1121
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1121/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-printers-ci/8/rebuild

review: Approve (continuous-integration)
Revision history for this message
dobey (dobey) wrote :
Download full text (5.7 KiB)

On Mon, 2017-01-09 at 20:19 +0000, Charles Kerr wrote:
> Since we're dealing with autogenerated code in this repo (from gdbus-
> codegen), it would be better to set these arguments in another
> variable and including it for human-written code.
>
> That way we won't break on warnings out of our control in the future
> if we want to increase the warnings (or if the compilers increase
> them automatically).

I think the extra variables and managing the generated sources
separately is a bit complicated for this here. Since the generated code
is always C, and the hand-written code is C++, I just made the split
there and only specify the extra warnings for C++ code, as we should
not be writing any pure C. This simplifies the cmake a decent bit.

> > +    //url_dispatch_send(url.c_str(), nullptr, nullptr);
> NF: Probably should do something here?

I've left this commented for the MVP as it's still not entirely clear
if we need to actually open any URLs from the indicator yet, and I
didn't want to add the dependency, only to remove it in another branch
or two. We still need some clarification from design on what various
bits are supposed to actually do.

> If g_getenv() somehow returns NULL, then g_strsplit() will also
> return NULL, causing desktop_names[0] to be a nullptr dereference.
>
> NF in datetime as well :P

I don't think this is an issue since the code is checking if the result
of g_getenv() is nullptr before trying to g_strsplit. So I've left it
as-is.

> > +void LiveActions::open_settings_app()
> Is this used at all? I thought Design didn't want a Settings option
> in the print indicator
>
> If that's the case do we need Actions

I think we need some clarification from design on what we really need
to do here, but I suspect there will indeed be some room for
simplification here, once we get the clarity we need.

> > +    void cancel_subscription()
> looks like this isn't called from production code.
>
> * If it's not needed, let's remove it
>
> * If it only needs to be called for shutdown cleanup, e.g. from
> CupsClient::Impl::~Impl(), let's make private and remove
> cancel_subscription() from Client base
>
> * If client code should be using it now, let's keep it public and add
> the client calls.

Just wrote this in a way that makes sense to me as a library API, based
on what the existing code was doing. We might be able to simplify, but
I left this as-is for now, in case we need to use it from higher level,
pending more clarity on design.

> This seems like the only place where renew_subscription() is called
>
> IMO renew_subscription should be private to CupsClient::Impl and not
> in the Client API
>
> Actually it might be best if Client didn't have any of the three
> subscription methods, is there any downside to CupsClient::Impl
> creating a subscription automatically in the ctor instead of when the
> bus is acquired?

Possibly room for fair bit of privitization here. See previous comment.
Maybe can clean up after clarification on bits of design.

> (bikeshed) slightly cleaner to use a uniform initializer for these?

Probably would be. Just didn't bother writing the ctors for the
structs, for "simplicity" at the moment.

> t...

Read more...

Revision history for this message
Charles Kerr (charlesk) wrote :

Thanks for the other fixes.

>> If that's the case do we need Actions
>
> I think we need some clarification from design on what we really need
> to do here, but I suspect there will indeed be some room for
> simplification here, once we get the clarity we need.

I'm unsure what you're advocating here, do you want to land as-is
or put on hold until after we talk to Design?

It seems pointless to land Actions and LiveActions if none of the
actions are ever used.

>> Actually it might be best if Client didn't have any of the three
>> subscription methods, is there any downside to CupsClient::Impl
>> creating a subscription automatically in the ctor instead of when the
>> bus is acquired?
>
> Possibly room for fair bit of privitization here. See previous comment.
> Maybe can clean up after clarification on bits of design.

I don't see what Design has to do with removing implementation
details from Client's public methods.

review: Needs Information
120. By dobey

Add gcovr to build-depends.

121. By dobey

Fix libexcdir replacement.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:120
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-printers-ci/9/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/1337
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1344
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1122
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1122/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1122
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1122/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1122
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1122/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1122
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1122/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1122
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1122/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1122
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1122/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-printers-ci/9/rebuild

review: Approve (continuous-integration)
Revision history for this message
dobey (dobey) wrote :

On Tue, 2017-01-10 at 21:18 +0000, Charles Kerr wrote:
> Review: Needs Information
>
> Thanks for the other fixes.
>
> >
> > >
> > > If that's the case do we need Actions
> > I think we need some clarification from design on what we really
> > need
> > to do here, but I suspect there will indeed be some room for
> > simplification here, once we get the clarity we need.
> I'm unsure what you're advocating here, do you want to land as-is
> or put on hold until after we talk to Design?

Either is fine with me. There's currently no way to configure printers
under Unity8 or actually print anything from any Unity8 apps (I'm not
sure if stuff in libertine or u7 apps as snaps work either, but again
no way to configure a printer, so catch 22), so I don't think there's a
major need to land this. But I would prefer to avoid having the branch
get much larger than it is.

> It seems pointless to land Actions and LiveActions if none of the
> actions are ever used.

Indeed. The design is to have pause/resume sort of actions in the menu,
which I presume would require Actions, even if the don't open external
apps or such. But my understanding of how that works in indicators is
still fairly limited.

> >
> > >
> > > Actually it might be best if Client didn't have any of the three
> > > subscription methods, is there any downside to CupsClient::Impl
> > > creating a subscription automatically in the ctor instead of when
> > > the
> > > bus is acquired?
> > Possibly room for fair bit of privitization here. See previous
> > comment.
> > Maybe can clean up after clarification on bits of design.
> I don't see what Design has to do with removing implementation
> details from Client's public methods.

Well if the result of the design means we need to change stuff around
and actually call them, it wouldn't make sense to make them private,
and then go have to make them public again either. Having them public
makes it easier to write integration tests for the code. And really,
it's a private static library, so "public" is only just so here.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:121
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-printers-ci/10/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/1338/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1345
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1123
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1123/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1123
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1123/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1123
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1123/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1123/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1123
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1123/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1123
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1123/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-printers-ci/10/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

OK. Agreed wrt needing Design to weigh in on actions.

Assuming there's a followup branch adding testing, e.g. cups, this branch is a good interim step.

review: Approve
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:121
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-printers-ci/11/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/1344
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1351
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1129
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1129/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1129
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1129/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1129
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1129/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1129
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1129/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1129
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1129/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1129
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1129/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-printers-ci/11/rebuild

review: Approve (continuous-integration)

Unmerged revisions

121. By dobey

Fix libexcdir replacement.

120. By dobey

Add gcovr to build-depends.

119. By dobey

Fixes from review.

118. By dobey

It's 2017 now.
Also Lars is not upstream contact any more.

117. By dobey

Remove more obsolete code.

116. By dobey

Add missing pragma to utils.h

115. By dobey

Specify unisgned in exporter test comparison.

114. By dobey

Add missing dbus dep.

113. By dobey

Fix control file.

112. By dobey

Change main title to Printing to match design.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2012-02-02 14:49:11 +0000
3+++ .bzrignore 2017-01-10 21:54:44 +0000
4@@ -27,3 +27,5 @@
5 src/*.lo
6 src/cups-notifier.[ch]
7
8+build/
9+
10
11=== removed file 'AUTHORS'
12--- AUTHORS 2012-01-11 14:29:38 +0000
13+++ AUTHORS 1970-01-01 00:00:00 +0000
14@@ -1,2 +0,0 @@
15-Lars Uebernickel <lars.uebernickel@canonical.com>
16-
17
18=== added file 'CMakeLists.txt'
19--- CMakeLists.txt 1970-01-01 00:00:00 +0000
20+++ CMakeLists.txt 2017-01-10 21:54:44 +0000
21@@ -0,0 +1,54 @@
22+project(indicator-printers C CXX)
23+cmake_minimum_required(VERSION 2.8.9)
24+
25+### Need to have own copy of gdbuscodegen module
26+list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
27+
28+### Install path variables
29+include (GNUInstallDirs)
30+if (EXISTS "/etc/debian_version") # Workaround for libexecdir on debian
31+ set (CMAKE_INSTALL_LIBEXECDIR "${CMAKE_INSTALL_LIBDIR}")
32+ set (CMAKE_INSTALL_FULL_LIBEXECDIR "${CMAKE_INSTALL_FULL_LIBDIR}")
33+endif ()
34+set (CMAKE_INSTALL_PKGLIBEXECDIR "${CMAKE_INSTALL_LIBEXECDIR}/${CMAKE_PROJECT_NAME}")
35+set (CMAKE_INSTALL_FULL_PKGLIBEXECDIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}/${CMAKE_PROJECT_NAME}")
36+
37+### Always Be Testing
38+enable_testing()
39+
40+### Set variables for our binary build targets
41+set(SERVICE_LIB_NAME "indicator-printers")
42+set(SERVICE_EXEC_NAME "indicator-printers-service")
43+
44+### Some default compile flags
45+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g -fPIC")
46+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -g -Wextra -Wall -Werror -Werror=conversion-null -Wno-ignored-qualifiers -fPIC")
47+
48+### Find deps
49+find_package(PkgConfig REQUIRED)
50+find_package(Intltool REQUIRED)
51+find_package(Threads)
52+
53+pkg_check_modules(SERVICE_DEPS REQUIRED
54+ gio-unix-2.0>=2.36
55+ glib-2.0>=2.36
56+ properties-cpp
57+)
58+
59+### Find libcups
60+find_program(CUPS_CONFIG cups-config)
61+execute_process(COMMAND ${CUPS_CONFIG} --cflags OUTPUT_VARIABLE CUPS_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
62+execute_process(COMMAND ${CUPS_CONFIG} --libs OUTPUT_VARIABLE CUPS_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
63+
64+### Add sub-directories
65+add_subdirectory(data)
66+add_subdirectory(src)
67+add_subdirectory(tests)
68+
69+### Enable coverage reporting
70+find_package(CoverageReport)
71+ENABLE_COVERAGE_REPORT(
72+ TARGETS ${SERVICE_LIB_NAME} ${SERVICE_EXEC_NAME}
73+ TESTS test-libindicator-printers
74+ FILTER /usr/include ${CMAKE_BINARY_DIR}/*
75+)
76
77=== added file 'COPYING'
78--- COPYING 1970-01-01 00:00:00 +0000
79+++ COPYING 2017-01-10 21:54:44 +0000
80@@ -0,0 +1,674 @@
81+ GNU GENERAL PUBLIC LICENSE
82+ Version 3, 29 June 2007
83+
84+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
85+ Everyone is permitted to copy and distribute verbatim copies
86+ of this license document, but changing it is not allowed.
87+
88+ Preamble
89+
90+ The GNU General Public License is a free, copyleft license for
91+software and other kinds of works.
92+
93+ The licenses for most software and other practical works are designed
94+to take away your freedom to share and change the works. By contrast,
95+the GNU General Public License is intended to guarantee your freedom to
96+share and change all versions of a program--to make sure it remains free
97+software for all its users. We, the Free Software Foundation, use the
98+GNU General Public License for most of our software; it applies also to
99+any other work released this way by its authors. You can apply it to
100+your programs, too.
101+
102+ When we speak of free software, we are referring to freedom, not
103+price. Our General Public Licenses are designed to make sure that you
104+have the freedom to distribute copies of free software (and charge for
105+them if you wish), that you receive source code or can get it if you
106+want it, that you can change the software or use pieces of it in new
107+free programs, and that you know you can do these things.
108+
109+ To protect your rights, we need to prevent others from denying you
110+these rights or asking you to surrender the rights. Therefore, you have
111+certain responsibilities if you distribute copies of the software, or if
112+you modify it: responsibilities to respect the freedom of others.
113+
114+ For example, if you distribute copies of such a program, whether
115+gratis or for a fee, you must pass on to the recipients the same
116+freedoms that you received. You must make sure that they, too, receive
117+or can get the source code. And you must show them these terms so they
118+know their rights.
119+
120+ Developers that use the GNU GPL protect your rights with two steps:
121+(1) assert copyright on the software, and (2) offer you this License
122+giving you legal permission to copy, distribute and/or modify it.
123+
124+ For the developers' and authors' protection, the GPL clearly explains
125+that there is no warranty for this free software. For both users' and
126+authors' sake, the GPL requires that modified versions be marked as
127+changed, so that their problems will not be attributed erroneously to
128+authors of previous versions.
129+
130+ Some devices are designed to deny users access to install or run
131+modified versions of the software inside them, although the manufacturer
132+can do so. This is fundamentally incompatible with the aim of
133+protecting users' freedom to change the software. The systematic
134+pattern of such abuse occurs in the area of products for individuals to
135+use, which is precisely where it is most unacceptable. Therefore, we
136+have designed this version of the GPL to prohibit the practice for those
137+products. If such problems arise substantially in other domains, we
138+stand ready to extend this provision to those domains in future versions
139+of the GPL, as needed to protect the freedom of users.
140+
141+ Finally, every program is threatened constantly by software patents.
142+States should not allow patents to restrict development and use of
143+software on general-purpose computers, but in those that do, we wish to
144+avoid the special danger that patents applied to a free program could
145+make it effectively proprietary. To prevent this, the GPL assures that
146+patents cannot be used to render the program non-free.
147+
148+ The precise terms and conditions for copying, distribution and
149+modification follow.
150+
151+ TERMS AND CONDITIONS
152+
153+ 0. Definitions.
154+
155+ "This License" refers to version 3 of the GNU General Public License.
156+
157+ "Copyright" also means copyright-like laws that apply to other kinds of
158+works, such as semiconductor masks.
159+
160+ "The Program" refers to any copyrightable work licensed under this
161+License. Each licensee is addressed as "you". "Licensees" and
162+"recipients" may be individuals or organizations.
163+
164+ To "modify" a work means to copy from or adapt all or part of the work
165+in a fashion requiring copyright permission, other than the making of an
166+exact copy. The resulting work is called a "modified version" of the
167+earlier work or a work "based on" the earlier work.
168+
169+ A "covered work" means either the unmodified Program or a work based
170+on the Program.
171+
172+ To "propagate" a work means to do anything with it that, without
173+permission, would make you directly or secondarily liable for
174+infringement under applicable copyright law, except executing it on a
175+computer or modifying a private copy. Propagation includes copying,
176+distribution (with or without modification), making available to the
177+public, and in some countries other activities as well.
178+
179+ To "convey" a work means any kind of propagation that enables other
180+parties to make or receive copies. Mere interaction with a user through
181+a computer network, with no transfer of a copy, is not conveying.
182+
183+ An interactive user interface displays "Appropriate Legal Notices"
184+to the extent that it includes a convenient and prominently visible
185+feature that (1) displays an appropriate copyright notice, and (2)
186+tells the user that there is no warranty for the work (except to the
187+extent that warranties are provided), that licensees may convey the
188+work under this License, and how to view a copy of this License. If
189+the interface presents a list of user commands or options, such as a
190+menu, a prominent item in the list meets this criterion.
191+
192+ 1. Source Code.
193+
194+ The "source code" for a work means the preferred form of the work
195+for making modifications to it. "Object code" means any non-source
196+form of a work.
197+
198+ A "Standard Interface" means an interface that either is an official
199+standard defined by a recognized standards body, or, in the case of
200+interfaces specified for a particular programming language, one that
201+is widely used among developers working in that language.
202+
203+ The "System Libraries" of an executable work include anything, other
204+than the work as a whole, that (a) is included in the normal form of
205+packaging a Major Component, but which is not part of that Major
206+Component, and (b) serves only to enable use of the work with that
207+Major Component, or to implement a Standard Interface for which an
208+implementation is available to the public in source code form. A
209+"Major Component", in this context, means a major essential component
210+(kernel, window system, and so on) of the specific operating system
211+(if any) on which the executable work runs, or a compiler used to
212+produce the work, or an object code interpreter used to run it.
213+
214+ The "Corresponding Source" for a work in object code form means all
215+the source code needed to generate, install, and (for an executable
216+work) run the object code and to modify the work, including scripts to
217+control those activities. However, it does not include the work's
218+System Libraries, or general-purpose tools or generally available free
219+programs which are used unmodified in performing those activities but
220+which are not part of the work. For example, Corresponding Source
221+includes interface definition files associated with source files for
222+the work, and the source code for shared libraries and dynamically
223+linked subprograms that the work is specifically designed to require,
224+such as by intimate data communication or control flow between those
225+subprograms and other parts of the work.
226+
227+ The Corresponding Source need not include anything that users
228+can regenerate automatically from other parts of the Corresponding
229+Source.
230+
231+ The Corresponding Source for a work in source code form is that
232+same work.
233+
234+ 2. Basic Permissions.
235+
236+ All rights granted under this License are granted for the term of
237+copyright on the Program, and are irrevocable provided the stated
238+conditions are met. This License explicitly affirms your unlimited
239+permission to run the unmodified Program. The output from running a
240+covered work is covered by this License only if the output, given its
241+content, constitutes a covered work. This License acknowledges your
242+rights of fair use or other equivalent, as provided by copyright law.
243+
244+ You may make, run and propagate covered works that you do not
245+convey, without conditions so long as your license otherwise remains
246+in force. You may convey covered works to others for the sole purpose
247+of having them make modifications exclusively for you, or provide you
248+with facilities for running those works, provided that you comply with
249+the terms of this License in conveying all material for which you do
250+not control copyright. Those thus making or running the covered works
251+for you must do so exclusively on your behalf, under your direction
252+and control, on terms that prohibit them from making any copies of
253+your copyrighted material outside their relationship with you.
254+
255+ Conveying under any other circumstances is permitted solely under
256+the conditions stated below. Sublicensing is not allowed; section 10
257+makes it unnecessary.
258+
259+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
260+
261+ No covered work shall be deemed part of an effective technological
262+measure under any applicable law fulfilling obligations under article
263+11 of the WIPO copyright treaty adopted on 20 December 1996, or
264+similar laws prohibiting or restricting circumvention of such
265+measures.
266+
267+ When you convey a covered work, you waive any legal power to forbid
268+circumvention of technological measures to the extent such circumvention
269+is effected by exercising rights under this License with respect to
270+the covered work, and you disclaim any intention to limit operation or
271+modification of the work as a means of enforcing, against the work's
272+users, your or third parties' legal rights to forbid circumvention of
273+technological measures.
274+
275+ 4. Conveying Verbatim Copies.
276+
277+ You may convey verbatim copies of the Program's source code as you
278+receive it, in any medium, provided that you conspicuously and
279+appropriately publish on each copy an appropriate copyright notice;
280+keep intact all notices stating that this License and any
281+non-permissive terms added in accord with section 7 apply to the code;
282+keep intact all notices of the absence of any warranty; and give all
283+recipients a copy of this License along with the Program.
284+
285+ You may charge any price or no price for each copy that you convey,
286+and you may offer support or warranty protection for a fee.
287+
288+ 5. Conveying Modified Source Versions.
289+
290+ You may convey a work based on the Program, or the modifications to
291+produce it from the Program, in the form of source code under the
292+terms of section 4, provided that you also meet all of these conditions:
293+
294+ a) The work must carry prominent notices stating that you modified
295+ it, and giving a relevant date.
296+
297+ b) The work must carry prominent notices stating that it is
298+ released under this License and any conditions added under section
299+ 7. This requirement modifies the requirement in section 4 to
300+ "keep intact all notices".
301+
302+ c) You must license the entire work, as a whole, under this
303+ License to anyone who comes into possession of a copy. This
304+ License will therefore apply, along with any applicable section 7
305+ additional terms, to the whole of the work, and all its parts,
306+ regardless of how they are packaged. This License gives no
307+ permission to license the work in any other way, but it does not
308+ invalidate such permission if you have separately received it.
309+
310+ d) If the work has interactive user interfaces, each must display
311+ Appropriate Legal Notices; however, if the Program has interactive
312+ interfaces that do not display Appropriate Legal Notices, your
313+ work need not make them do so.
314+
315+ A compilation of a covered work with other separate and independent
316+works, which are not by their nature extensions of the covered work,
317+and which are not combined with it such as to form a larger program,
318+in or on a volume of a storage or distribution medium, is called an
319+"aggregate" if the compilation and its resulting copyright are not
320+used to limit the access or legal rights of the compilation's users
321+beyond what the individual works permit. Inclusion of a covered work
322+in an aggregate does not cause this License to apply to the other
323+parts of the aggregate.
324+
325+ 6. Conveying Non-Source Forms.
326+
327+ You may convey a covered work in object code form under the terms
328+of sections 4 and 5, provided that you also convey the
329+machine-readable Corresponding Source under the terms of this License,
330+in one of these ways:
331+
332+ a) Convey the object code in, or embodied in, a physical product
333+ (including a physical distribution medium), accompanied by the
334+ Corresponding Source fixed on a durable physical medium
335+ customarily used for software interchange.
336+
337+ b) Convey the object code in, or embodied in, a physical product
338+ (including a physical distribution medium), accompanied by a
339+ written offer, valid for at least three years and valid for as
340+ long as you offer spare parts or customer support for that product
341+ model, to give anyone who possesses the object code either (1) a
342+ copy of the Corresponding Source for all the software in the
343+ product that is covered by this License, on a durable physical
344+ medium customarily used for software interchange, for a price no
345+ more than your reasonable cost of physically performing this
346+ conveying of source, or (2) access to copy the
347+ Corresponding Source from a network server at no charge.
348+
349+ c) Convey individual copies of the object code with a copy of the
350+ written offer to provide the Corresponding Source. This
351+ alternative is allowed only occasionally and noncommercially, and
352+ only if you received the object code with such an offer, in accord
353+ with subsection 6b.
354+
355+ d) Convey the object code by offering access from a designated
356+ place (gratis or for a charge), and offer equivalent access to the
357+ Corresponding Source in the same way through the same place at no
358+ further charge. You need not require recipients to copy the
359+ Corresponding Source along with the object code. If the place to
360+ copy the object code is a network server, the Corresponding Source
361+ may be on a different server (operated by you or a third party)
362+ that supports equivalent copying facilities, provided you maintain
363+ clear directions next to the object code saying where to find the
364+ Corresponding Source. Regardless of what server hosts the
365+ Corresponding Source, you remain obligated to ensure that it is
366+ available for as long as needed to satisfy these requirements.
367+
368+ e) Convey the object code using peer-to-peer transmission, provided
369+ you inform other peers where the object code and Corresponding
370+ Source of the work are being offered to the general public at no
371+ charge under subsection 6d.
372+
373+ A separable portion of the object code, whose source code is excluded
374+from the Corresponding Source as a System Library, need not be
375+included in conveying the object code work.
376+
377+ A "User Product" is either (1) a "consumer product", which means any
378+tangible personal property which is normally used for personal, family,
379+or household purposes, or (2) anything designed or sold for incorporation
380+into a dwelling. In determining whether a product is a consumer product,
381+doubtful cases shall be resolved in favor of coverage. For a particular
382+product received by a particular user, "normally used" refers to a
383+typical or common use of that class of product, regardless of the status
384+of the particular user or of the way in which the particular user
385+actually uses, or expects or is expected to use, the product. A product
386+is a consumer product regardless of whether the product has substantial
387+commercial, industrial or non-consumer uses, unless such uses represent
388+the only significant mode of use of the product.
389+
390+ "Installation Information" for a User Product means any methods,
391+procedures, authorization keys, or other information required to install
392+and execute modified versions of a covered work in that User Product from
393+a modified version of its Corresponding Source. The information must
394+suffice to ensure that the continued functioning of the modified object
395+code is in no case prevented or interfered with solely because
396+modification has been made.
397+
398+ If you convey an object code work under this section in, or with, or
399+specifically for use in, a User Product, and the conveying occurs as
400+part of a transaction in which the right of possession and use of the
401+User Product is transferred to the recipient in perpetuity or for a
402+fixed term (regardless of how the transaction is characterized), the
403+Corresponding Source conveyed under this section must be accompanied
404+by the Installation Information. But this requirement does not apply
405+if neither you nor any third party retains the ability to install
406+modified object code on the User Product (for example, the work has
407+been installed in ROM).
408+
409+ The requirement to provide Installation Information does not include a
410+requirement to continue to provide support service, warranty, or updates
411+for a work that has been modified or installed by the recipient, or for
412+the User Product in which it has been modified or installed. Access to a
413+network may be denied when the modification itself materially and
414+adversely affects the operation of the network or violates the rules and
415+protocols for communication across the network.
416+
417+ Corresponding Source conveyed, and Installation Information provided,
418+in accord with this section must be in a format that is publicly
419+documented (and with an implementation available to the public in
420+source code form), and must require no special password or key for
421+unpacking, reading or copying.
422+
423+ 7. Additional Terms.
424+
425+ "Additional permissions" are terms that supplement the terms of this
426+License by making exceptions from one or more of its conditions.
427+Additional permissions that are applicable to the entire Program shall
428+be treated as though they were included in this License, to the extent
429+that they are valid under applicable law. If additional permissions
430+apply only to part of the Program, that part may be used separately
431+under those permissions, but the entire Program remains governed by
432+this License without regard to the additional permissions.
433+
434+ When you convey a copy of a covered work, you may at your option
435+remove any additional permissions from that copy, or from any part of
436+it. (Additional permissions may be written to require their own
437+removal in certain cases when you modify the work.) You may place
438+additional permissions on material, added by you to a covered work,
439+for which you have or can give appropriate copyright permission.
440+
441+ Notwithstanding any other provision of this License, for material you
442+add to a covered work, you may (if authorized by the copyright holders of
443+that material) supplement the terms of this License with terms:
444+
445+ a) Disclaiming warranty or limiting liability differently from the
446+ terms of sections 15 and 16 of this License; or
447+
448+ b) Requiring preservation of specified reasonable legal notices or
449+ author attributions in that material or in the Appropriate Legal
450+ Notices displayed by works containing it; or
451+
452+ c) Prohibiting misrepresentation of the origin of that material, or
453+ requiring that modified versions of such material be marked in
454+ reasonable ways as different from the original version; or
455+
456+ d) Limiting the use for publicity purposes of names of licensors or
457+ authors of the material; or
458+
459+ e) Declining to grant rights under trademark law for use of some
460+ trade names, trademarks, or service marks; or
461+
462+ f) Requiring indemnification of licensors and authors of that
463+ material by anyone who conveys the material (or modified versions of
464+ it) with contractual assumptions of liability to the recipient, for
465+ any liability that these contractual assumptions directly impose on
466+ those licensors and authors.
467+
468+ All other non-permissive additional terms are considered "further
469+restrictions" within the meaning of section 10. If the Program as you
470+received it, or any part of it, contains a notice stating that it is
471+governed by this License along with a term that is a further
472+restriction, you may remove that term. If a license document contains
473+a further restriction but permits relicensing or conveying under this
474+License, you may add to a covered work material governed by the terms
475+of that license document, provided that the further restriction does
476+not survive such relicensing or conveying.
477+
478+ If you add terms to a covered work in accord with this section, you
479+must place, in the relevant source files, a statement of the
480+additional terms that apply to those files, or a notice indicating
481+where to find the applicable terms.
482+
483+ Additional terms, permissive or non-permissive, may be stated in the
484+form of a separately written license, or stated as exceptions;
485+the above requirements apply either way.
486+
487+ 8. Termination.
488+
489+ You may not propagate or modify a covered work except as expressly
490+provided under this License. Any attempt otherwise to propagate or
491+modify it is void, and will automatically terminate your rights under
492+this License (including any patent licenses granted under the third
493+paragraph of section 11).
494+
495+ However, if you cease all violation of this License, then your
496+license from a particular copyright holder is reinstated (a)
497+provisionally, unless and until the copyright holder explicitly and
498+finally terminates your license, and (b) permanently, if the copyright
499+holder fails to notify you of the violation by some reasonable means
500+prior to 60 days after the cessation.
501+
502+ Moreover, your license from a particular copyright holder is
503+reinstated permanently if the copyright holder notifies you of the
504+violation by some reasonable means, this is the first time you have
505+received notice of violation of this License (for any work) from that
506+copyright holder, and you cure the violation prior to 30 days after
507+your receipt of the notice.
508+
509+ Termination of your rights under this section does not terminate the
510+licenses of parties who have received copies or rights from you under
511+this License. If your rights have been terminated and not permanently
512+reinstated, you do not qualify to receive new licenses for the same
513+material under section 10.
514+
515+ 9. Acceptance Not Required for Having Copies.
516+
517+ You are not required to accept this License in order to receive or
518+run a copy of the Program. Ancillary propagation of a covered work
519+occurring solely as a consequence of using peer-to-peer transmission
520+to receive a copy likewise does not require acceptance. However,
521+nothing other than this License grants you permission to propagate or
522+modify any covered work. These actions infringe copyright if you do
523+not accept this License. Therefore, by modifying or propagating a
524+covered work, you indicate your acceptance of this License to do so.
525+
526+ 10. Automatic Licensing of Downstream Recipients.
527+
528+ Each time you convey a covered work, the recipient automatically
529+receives a license from the original licensors, to run, modify and
530+propagate that work, subject to this License. You are not responsible
531+for enforcing compliance by third parties with this License.
532+
533+ An "entity transaction" is a transaction transferring control of an
534+organization, or substantially all assets of one, or subdividing an
535+organization, or merging organizations. If propagation of a covered
536+work results from an entity transaction, each party to that
537+transaction who receives a copy of the work also receives whatever
538+licenses to the work the party's predecessor in interest had or could
539+give under the previous paragraph, plus a right to possession of the
540+Corresponding Source of the work from the predecessor in interest, if
541+the predecessor has it or can get it with reasonable efforts.
542+
543+ You may not impose any further restrictions on the exercise of the
544+rights granted or affirmed under this License. For example, you may
545+not impose a license fee, royalty, or other charge for exercise of
546+rights granted under this License, and you may not initiate litigation
547+(including a cross-claim or counterclaim in a lawsuit) alleging that
548+any patent claim is infringed by making, using, selling, offering for
549+sale, or importing the Program or any portion of it.
550+
551+ 11. Patents.
552+
553+ A "contributor" is a copyright holder who authorizes use under this
554+License of the Program or a work on which the Program is based. The
555+work thus licensed is called the contributor's "contributor version".
556+
557+ A contributor's "essential patent claims" are all patent claims
558+owned or controlled by the contributor, whether already acquired or
559+hereafter acquired, that would be infringed by some manner, permitted
560+by this License, of making, using, or selling its contributor version,
561+but do not include claims that would be infringed only as a
562+consequence of further modification of the contributor version. For
563+purposes of this definition, "control" includes the right to grant
564+patent sublicenses in a manner consistent with the requirements of
565+this License.
566+
567+ Each contributor grants you a non-exclusive, worldwide, royalty-free
568+patent license under the contributor's essential patent claims, to
569+make, use, sell, offer for sale, import and otherwise run, modify and
570+propagate the contents of its contributor version.
571+
572+ In the following three paragraphs, a "patent license" is any express
573+agreement or commitment, however denominated, not to enforce a patent
574+(such as an express permission to practice a patent or covenant not to
575+sue for patent infringement). To "grant" such a patent license to a
576+party means to make such an agreement or commitment not to enforce a
577+patent against the party.
578+
579+ If you convey a covered work, knowingly relying on a patent license,
580+and the Corresponding Source of the work is not available for anyone
581+to copy, free of charge and under the terms of this License, through a
582+publicly available network server or other readily accessible means,
583+then you must either (1) cause the Corresponding Source to be so
584+available, or (2) arrange to deprive yourself of the benefit of the
585+patent license for this particular work, or (3) arrange, in a manner
586+consistent with the requirements of this License, to extend the patent
587+license to downstream recipients. "Knowingly relying" means you have
588+actual knowledge that, but for the patent license, your conveying the
589+covered work in a country, or your recipient's use of the covered work
590+in a country, would infringe one or more identifiable patents in that
591+country that you have reason to believe are valid.
592+
593+ If, pursuant to or in connection with a single transaction or
594+arrangement, you convey, or propagate by procuring conveyance of, a
595+covered work, and grant a patent license to some of the parties
596+receiving the covered work authorizing them to use, propagate, modify
597+or convey a specific copy of the covered work, then the patent license
598+you grant is automatically extended to all recipients of the covered
599+work and works based on it.
600+
601+ A patent license is "discriminatory" if it does not include within
602+the scope of its coverage, prohibits the exercise of, or is
603+conditioned on the non-exercise of one or more of the rights that are
604+specifically granted under this License. You may not convey a covered
605+work if you are a party to an arrangement with a third party that is
606+in the business of distributing software, under which you make payment
607+to the third party based on the extent of your activity of conveying
608+the work, and under which the third party grants, to any of the
609+parties who would receive the covered work from you, a discriminatory
610+patent license (a) in connection with copies of the covered work
611+conveyed by you (or copies made from those copies), or (b) primarily
612+for and in connection with specific products or compilations that
613+contain the covered work, unless you entered into that arrangement,
614+or that patent license was granted, prior to 28 March 2007.
615+
616+ Nothing in this License shall be construed as excluding or limiting
617+any implied license or other defenses to infringement that may
618+otherwise be available to you under applicable patent law.
619+
620+ 12. No Surrender of Others' Freedom.
621+
622+ If conditions are imposed on you (whether by court order, agreement or
623+otherwise) that contradict the conditions of this License, they do not
624+excuse you from the conditions of this License. If you cannot convey a
625+covered work so as to satisfy simultaneously your obligations under this
626+License and any other pertinent obligations, then as a consequence you may
627+not convey it at all. For example, if you agree to terms that obligate you
628+to collect a royalty for further conveying from those to whom you convey
629+the Program, the only way you could satisfy both those terms and this
630+License would be to refrain entirely from conveying the Program.
631+
632+ 13. Use with the GNU Affero General Public License.
633+
634+ Notwithstanding any other provision of this License, you have
635+permission to link or combine any covered work with a work licensed
636+under version 3 of the GNU Affero General Public License into a single
637+combined work, and to convey the resulting work. The terms of this
638+License will continue to apply to the part which is the covered work,
639+but the special requirements of the GNU Affero General Public License,
640+section 13, concerning interaction through a network will apply to the
641+combination as such.
642+
643+ 14. Revised Versions of this License.
644+
645+ The Free Software Foundation may publish revised and/or new versions of
646+the GNU General Public License from time to time. Such new versions will
647+be similar in spirit to the present version, but may differ in detail to
648+address new problems or concerns.
649+
650+ Each version is given a distinguishing version number. If the
651+Program specifies that a certain numbered version of the GNU General
652+Public License "or any later version" applies to it, you have the
653+option of following the terms and conditions either of that numbered
654+version or of any later version published by the Free Software
655+Foundation. If the Program does not specify a version number of the
656+GNU General Public License, you may choose any version ever published
657+by the Free Software Foundation.
658+
659+ If the Program specifies that a proxy can decide which future
660+versions of the GNU General Public License can be used, that proxy's
661+public statement of acceptance of a version permanently authorizes you
662+to choose that version for the Program.
663+
664+ Later license versions may give you additional or different
665+permissions. However, no additional obligations are imposed on any
666+author or copyright holder as a result of your choosing to follow a
667+later version.
668+
669+ 15. Disclaimer of Warranty.
670+
671+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
672+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
673+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
674+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
675+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
676+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
677+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
678+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
679+
680+ 16. Limitation of Liability.
681+
682+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
683+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
684+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
685+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
686+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
687+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
688+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
689+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
690+SUCH DAMAGES.
691+
692+ 17. Interpretation of Sections 15 and 16.
693+
694+ If the disclaimer of warranty and limitation of liability provided
695+above cannot be given local legal effect according to their terms,
696+reviewing courts shall apply local law that most closely approximates
697+an absolute waiver of all civil liability in connection with the
698+Program, unless a warranty or assumption of liability accompanies a
699+copy of the Program in return for a fee.
700+
701+ END OF TERMS AND CONDITIONS
702+
703+ How to Apply These Terms to Your New Programs
704+
705+ If you develop a new program, and you want it to be of the greatest
706+possible use to the public, the best way to achieve this is to make it
707+free software which everyone can redistribute and change under these terms.
708+
709+ To do so, attach the following notices to the program. It is safest
710+to attach them to the start of each source file to most effectively
711+state the exclusion of warranty; and each file should have at least
712+the "copyright" line and a pointer to where the full notice is found.
713+
714+ <one line to give the program's name and a brief idea of what it does.>
715+ Copyright (C) <year> <name of author>
716+
717+ This program is free software: you can redistribute it and/or modify
718+ it under the terms of the GNU General Public License as published by
719+ the Free Software Foundation, either version 3 of the License, or
720+ (at your option) any later version.
721+
722+ This program is distributed in the hope that it will be useful,
723+ but WITHOUT ANY WARRANTY; without even the implied warranty of
724+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
725+ GNU General Public License for more details.
726+
727+ You should have received a copy of the GNU General Public License
728+ along with this program. If not, see <http://www.gnu.org/licenses/>.
729+
730+Also add information on how to contact you by electronic and paper mail.
731+
732+ If the program does terminal interaction, make it output a short
733+notice like this when it starts in an interactive mode:
734+
735+ <program> Copyright (C) <year> <name of author>
736+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
737+ This is free software, and you are welcome to redistribute it
738+ under certain conditions; type `show c' for details.
739+
740+The hypothetical commands `show w' and `show c' should show the appropriate
741+parts of the General Public License. Of course, your program's commands
742+might be different; for a GUI interface, you would use an "about box".
743+
744+ You should also get your employer (if you work as a programmer) or school,
745+if any, to sign a "copyright disclaimer" for the program, if necessary.
746+For more information on this, and how to apply and follow the GNU GPL, see
747+<http://www.gnu.org/licenses/>.
748+
749+ The GNU General Public License does not permit incorporating your program
750+into proprietary programs. If your program is a subroutine library, you
751+may consider it more useful to permit linking proprietary applications with
752+the library. If this is what you want to do, use the GNU Lesser General
753+Public License instead of this License. But first, please read
754+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
755
756=== removed file 'ChangeLog'
757=== removed file 'Makefile.am'
758--- Makefile.am 2012-03-27 22:12:02 +0000
759+++ Makefile.am 1970-01-01 00:00:00 +0000
760@@ -1,6 +0,0 @@
761-
762-SUBDIRS = src data test po
763-
764-DISTCHECK_CONFIGURE_FLAGS = --enable-localinstall
765-
766-include $(top_srcdir)/Makefile.am.coverage
767
768=== removed file 'Makefile.am.coverage'
769--- Makefile.am.coverage 2012-03-27 22:12:02 +0000
770+++ Makefile.am.coverage 1970-01-01 00:00:00 +0000
771@@ -1,48 +0,0 @@
772-
773-# Coverage targets
774-
775-.PHONY: clean-gcno clean-gcda \
776- coverage-html generate-coverage-html clean-coverage-html \
777- coverage-gcovr generate-coverage-gcovr clean-coverage-gcovr
778-
779-clean-local: clean-gcno clean-coverage-html clean-coverage-gcovr
780-
781-if HAVE_GCOV
782-
783-clean-gcno:
784- @echo Removing old coverage instrumentation
785- -find -name '*.gcno' -print | xargs -r rm
786-
787-clean-gcda:
788- @echo Removing old coverage results
789- -find -name '*.gcda' -print | xargs -r rm
790-
791-coverage-html: clean-gcda
792- -$(MAKE) $(AM_MAKEFLAGS) -k check
793- $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html
794-
795-generate-coverage-html:
796- @echo Collecting coverage data
797- $(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool
798- LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
799-
800-clean-coverage-html: clean-gcda
801- -$(LCOV) --directory $(top_builddir) -z
802- -rm -rf coverage.info coveragereport
803-
804-if HAVE_GCOVR
805-
806-coverage-gcovr: clean-gcda
807- -$(MAKE) $(AM_MAKEFLAGS) -k check
808- $(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr
809-
810-generate-coverage-gcovr:
811- @echo Generating coverage GCOVR report
812- $(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.xml
813-
814-clean-coverage-gcovr: clean-gcda
815- -rm -rf $(top_builddir)/coverage.xml
816-
817-endif # HAVE_GCOVR
818-
819-endif # HAVE_GCOV
820
821=== removed file 'NEWS'
822=== removed file 'autogen.sh'
823--- autogen.sh 2012-01-11 14:29:38 +0000
824+++ autogen.sh 1970-01-01 00:00:00 +0000
825@@ -1,9 +0,0 @@
826-#!/bin/sh
827-
828-which gnome-autogen.sh || {
829- echo "Could not find 'gnome-autgen.sh'. Is gnome-common installed?"
830- exit 1
831-}
832-
833-. gnome-autogen.sh
834-
835
836=== added directory 'cmake'
837=== added file 'cmake/GdbusCodegen.cmake'
838--- cmake/GdbusCodegen.cmake 1970-01-01 00:00:00 +0000
839+++ cmake/GdbusCodegen.cmake 2017-01-10 21:54:44 +0000
840@@ -0,0 +1,36 @@
841+cmake_minimum_required(VERSION 2.6)
842+if(POLICY CMP0011)
843+ cmake_policy(SET CMP0011 NEW)
844+endif(POLICY CMP0011)
845+
846+find_program(GDBUS_CODEGEN NAMES gdbus-codegen DOC "gdbus-codegen executable")
847+if(NOT GDBUS_CODEGEN)
848+ message(FATAL_ERROR "Excutable gdbus-codegen not found")
849+endif()
850+
851+macro(add_gdbus_codegen outfiles name prefix service_xml)
852+ add_custom_command(
853+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" "${CMAKE_CURRENT_BINARY_DIR}/${name}.c"
854+ COMMAND "${GDBUS_CODEGEN}"
855+ --interface-prefix "${prefix}"
856+ --generate-c-code "${name}"
857+ "${service_xml}"
858+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
859+ DEPENDS ${ARGN} "${service_xml}"
860+ )
861+ list(APPEND ${outfiles} "${CMAKE_CURRENT_BINARY_DIR}/${name}.c")
862+endmacro(add_gdbus_codegen)
863+
864+macro(add_gdbus_codegen_with_namespace outfiles name prefix namespace service_xml)
865+ add_custom_command(
866+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" "${CMAKE_CURRENT_BINARY_DIR}/${name}.c"
867+ COMMAND "${GDBUS_CODEGEN}"
868+ --interface-prefix "${prefix}"
869+ --generate-c-code "${name}"
870+ --c-namespace "${namespace}"
871+ "${service_xml}"
872+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
873+ DEPENDS ${ARGN} "${service_xml}"
874+ )
875+ list(APPEND ${outfiles} "${CMAKE_CURRENT_BINARY_DIR}/${name}.c")
876+endmacro(add_gdbus_codegen_with_namespace)
877
878=== removed file 'configure.ac'
879--- configure.ac 2016-07-19 15:43:40 +0000
880+++ configure.ac 1970-01-01 00:00:00 +0000
881@@ -1,105 +0,0 @@
882-
883-AC_INIT(indicator-printers, 0.1.6)
884-
885-AC_PREREQ(2.53)
886-AM_INIT_AUTOMAKE([])
887-
888-AC_PROG_CC
889-AC_PROG_INSTALL
890-AC_PROG_LIBTOOL
891-AM_PROG_CC_C_O
892-AM_SILENT_RULES([yes])
893-AC_CONFIG_MACRO_DIR([m4])
894-
895-AC_DEFUN([AC_DEFINE_PATH], [
896- test "x$prefix" = xNONE && prefix="$ac_default_prefix"
897- test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
898- ac_define_path=`eval echo [$]$2`
899- ac_define_path=`eval echo [$]ac_define_path`
900- $1="$ac_define_path"
901- AC_SUBST($1)
902- ifelse($3, ,
903- AC_DEFINE_UNQUOTED($1, "$ac_define_path"),
904- AC_DEFINE_UNQUOTED($1, "$ac_define_path", $3))
905-])
906-
907-IT_PROG_INTLTOOL([0.35.0])
908-GETTEXT_PACKAGE=indicator-printers
909-AC_SUBST(GETTEXT_PACKAGE)
910-AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [gettext package])
911-AC_DEFINE_PATH(GNOMELOCALEDIR, "${datadir}/locale", [locale directory])
912-AM_GLIB_GNU_GETTEXT
913-
914-AC_CONFIG_HEADER(config.h)
915-AC_CONFIG_FILES([
916- Makefile
917- src/Makefile
918- data/Makefile
919- data/upstart/Makefile
920- test/Makefile
921- po/Makefile.in
922-])
923-
924-PKG_CHECK_MODULES(APPLET, gtk+-3.0 >= 3.0
925- indicator3-0.4 >= 0.2
926- dbusmenu-gtk3-0.4 >= 0.2)
927-PKG_CHECK_MODULES(SERVICE, gtk+-3.0 >= 3.0
928- indicator3-0.4 >= 0.2
929- dbusmenu-glib-0.4 >= 0.2)
930-
931-AC_PATH_PROG(CUPS_CONFIG, cups-config, no)
932-if test "x$CUPS_CONFIG" = "xno"; then
933- AC_MSG_ERROR([could not find cups-config])
934-fi
935-AC_CHECK_HEADER(cups/cups.h,,AC_MSG_ERROR([could not find cups.h]))
936-CUPS_CFLAGS+=`$CUPS_CONFIG --cflags`
937-CUPS_LIBS+=`$CUPS_CONFIG --libs`
938-SERVICE_CFLAGS="$SERVICE_CFLAGS $CUPS_CFLAGS"
939-SERVICE_LIBS="$SERVICE_LIBS $CUPS_LIBS"
940-
941-SYSTEMD_USERDIR=`$PKG_CONFIG --variable=systemduserunitdir systemd`
942-AC_SUBST(SYSTEMD_USERDIR)
943-
944-with_localinstall="no"
945-AC_ARG_ENABLE(localinstall, AS_HELP_STRING([--enable-localinstall],
946- [install all files locally (for distcheck)]),
947- with_localinstall=$enableval,
948- with_localinstall=no)
949-
950-if test "x$with_localinstall" = "xyes"; then
951- INDICATORDIR="${libdir}/indicators/2/"
952- INDICATORICONSDIR="${datadir}/libindicate/icons/"
953-else
954- INDICATORDIR=`$PKG_CONFIG --variable=indicatordir indicator3-0.4`
955- INDICATORICONSDIR=`$PKG_CONFIG --variable=iconsdir indicator3-0.4`
956-fi
957-AC_SUBST(INDICATORDIR)
958-AC_SUBST(INDICATORICONSDIR)
959-
960-###########################
961-# DBus Service Info
962-###########################
963-
964-if test "x$with_localinstall" = "xyes"; then
965- DBUSSERVICEDIR="${datadir}/dbus-1/services/"
966-else
967- DBUSSERVICEDIR=`$PKG_CONFIG --variable=session_bus_services_dir dbus-1`
968-fi
969-AC_SUBST(DBUSSERVICEDIR)
970-
971-###########################
972-# gcov coverage reporting
973-###########################
974-
975-m4_include([m4/gcov.m4])
976-AC_TDD_GCOV
977-AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
978-AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
979-AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
980-AC_SUBST(COVERAGE_CFLAGS)
981-AC_SUBST(COVERAGE_LDFLAGS)
982-
983-AC_SUBST(AM_CFLAGS, "-Wall")
984-
985-AC_OUTPUT
986-
987
988=== added file 'data/CMakeLists.txt'
989--- data/CMakeLists.txt 1970-01-01 00:00:00 +0000
990+++ data/CMakeLists.txt 2017-01-10 21:54:44 +0000
991@@ -0,0 +1,64 @@
992+##
993+## Systemd Unit File
994+##
995+
996+# where to install
997+# Uncomment when we drop Vivid
998+# pkg_get_variable(SYSTEMD_USER_DIR systemd systemduserunitdir)
999+set (SYSTEMD_USER_DIR "/usr/lib/systemd/user")
1000+message (STATUS "${SYSTEMD_USER_DIR} is the systemd user unit file install dir")
1001+
1002+set (SYSTEMD_USER_NAME "${CMAKE_PROJECT_NAME}.service")
1003+set (SYSTEMD_USER_FILE "${CMAKE_CURRENT_BINARY_DIR}/${SYSTEMD_USER_NAME}")
1004+set (SYSTEMD_USER_FILE_IN "${CMAKE_CURRENT_SOURCE_DIR}/${SYSTEMD_USER_NAME}.in")
1005+
1006+# build it
1007+set (pkglibexecdir "${CMAKE_INSTALL_FULL_PKGLIBEXECDIR}")
1008+configure_file ("${SYSTEMD_USER_FILE_IN}" "${SYSTEMD_USER_FILE}")
1009+
1010+# install it
1011+install (FILES "${SYSTEMD_USER_FILE}"
1012+ DESTINATION "${SYSTEMD_USER_DIR}")
1013+
1014+##
1015+## Upstart systemd override Job File
1016+##
1017+
1018+set (UPSTART_SYSTEMD_OVERRIDE_DIR "${CMAKE_INSTALL_FULL_DATADIR}/upstart/systemd-session/upstart")
1019+message (STATUS "${UPSTART_SYSTEMD_OVERRIDE_DIR} is the Upstart override Job File for systemd dir")
1020+
1021+install (FILES "${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_PROJECT_NAME}.override"
1022+ DESTINATION "${UPSTART_SYSTEMD_OVERRIDE_DIR}")
1023+
1024+##
1025+## Upstart Job File
1026+##
1027+
1028+# where to install
1029+set (UPSTART_JOB_DIR "${CMAKE_INSTALL_FULL_DATADIR}/upstart/sessions")
1030+message (STATUS "${UPSTART_JOB_DIR} is the Upstart Job File install dir")
1031+
1032+set (UPSTART_JOB_NAME "${CMAKE_PROJECT_NAME}.conf")
1033+set (UPSTART_JOB_FILE "${CMAKE_CURRENT_BINARY_DIR}/${UPSTART_JOB_NAME}")
1034+set (UPSTART_JOB_FILE_IN "${CMAKE_CURRENT_SOURCE_DIR}/${UPSTART_JOB_NAME}.in")
1035+
1036+# build it
1037+configure_file ("${UPSTART_JOB_FILE_IN}" "${UPSTART_JOB_FILE}")
1038+
1039+# install it
1040+install (FILES "${UPSTART_JOB_FILE}"
1041+ DESTINATION "${UPSTART_JOB_DIR}")
1042+
1043+##
1044+## Unity Indicator File
1045+##
1046+
1047+# where to install
1048+set (UNITY_INDICATOR_DIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/unity/indicators")
1049+message (STATUS "${UNITY_INDICATOR_DIR} is the Unity Indicator install dir")
1050+
1051+set (UNITY_INDICATOR_NAME "com.canonical.indicator.printers")
1052+set (UNITY_INDICATOR_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${UNITY_INDICATOR_NAME}")
1053+
1054+install (FILES "${UNITY_INDICATOR_FILE}"
1055+ DESTINATION "${UNITY_INDICATOR_DIR}")
1056
1057=== removed file 'data/Makefile.am'
1058--- data/Makefile.am 2016-07-19 15:43:40 +0000
1059+++ data/Makefile.am 1970-01-01 00:00:00 +0000
1060@@ -1,55 +0,0 @@
1061-
1062-BUILT_SOURCES=
1063-CLEANFILES=
1064-EXTRA_DIST=
1065-
1066-SUBDIRS = upstart
1067-
1068-#
1069-# the systemd unit file
1070-#
1071-
1072-systemddir = $(SYSTEMD_USERDIR)
1073-systemd_DATA = indicator-printers.service
1074-systemd_in = $(systemd_DATA:.service=.service.in)
1075-$(systemd_DATA): $(systemd_in)
1076- $(AM_V_GEN) $(SED) -e "s|\@pkglibexecdir\@|$(pkglibexecdir)|" $< > $@
1077-BUILT_SOURCES += $(systemd_DATA)
1078-EXTRA_DIST += $(systemd_in)
1079-CLEANFILES += $(systemd_DATA)
1080-
1081-#
1082-# the systemd upstart override
1083-#
1084-
1085-upstart_overridedir = $(datadir)/upstart/systemd-session/upstart
1086-upstart_override_DATA = indicator-printers.override
1087-EXTRA_DIST += $(upstart_override_DATA)
1088-
1089-#
1090-# the upstart job file
1091-#
1092-
1093-upstart_jobsdir = $(datadir)/upstart/sessions
1094-upstart_jobs_DATA = indicator-printers.conf
1095-upstart_jobs_in = $(upstart_jobs_DATA:.conf=.conf.in)
1096-$(upstart_jobs_DATA): $(upstart_jobs_in)
1097- $(AM_V_GEN) $(SED) -e "s|\@pkglibexecdir\@|$(pkglibexecdir)|" $< > $@
1098-BUILT_SOURCES += $(upstart_jobs_DATA)
1099-CLEANFILES += $(upstart_jobs_DATA)
1100-EXTRA_DIST += $(upstart_jobs_in)
1101-
1102-#
1103-# the xdg autostart job file
1104-#
1105-
1106-xdg_autostartdir = /etc/xdg/autostart
1107-xdg_autostart_DATA = indicator-printers.desktop
1108-xdg_autostart_in = $(xdg_autostart_DATA:.desktop=.desktop.in)
1109-$(xdg_autostart_DATA): $(xdg_autostart_in)
1110- $(AM_V_GEN) $(SED) -e "s|\@pkglibexecdir\@|$(pkglibexecdir)|" $< > $@
1111-BUILT_SOURCES += $(xdg_autostart_DATA)
1112-CLEANFILES += $(xdg_autostart_DATA)
1113-EXTRA_DIST += $(xdg_autostart_in)
1114-
1115-
1116
1117=== added file 'data/com.canonical.indicator.printers'
1118--- data/com.canonical.indicator.printers 1970-01-01 00:00:00 +0000
1119+++ data/com.canonical.indicator.printers 2017-01-10 21:54:44 +0000
1120@@ -0,0 +1,20 @@
1121+[Indicator Service]
1122+Name=indicator-printers
1123+ObjectPath=/com/canonical/indicator/printers
1124+Position=90
1125+
1126+[desktop]
1127+ObjectPath=/com/canonical/indicator/printers/menu
1128+
1129+[desktop_greeter]
1130+ObjectPath=/com/canonical/indicator/printers/menu
1131+
1132+[desktop_lockscreen]
1133+ObjectPath=/com/canonical/indicator/printers/menu
1134+
1135+[phone]
1136+ObjectPath=/com/canonical/indicator/printers/menu
1137+
1138+[phone_greeter]
1139+ObjectPath=/com/canonical/indicator/printers/menu
1140+
1141
1142=== removed file 'data/indicator-printers.desktop.in'
1143--- data/indicator-printers.desktop.in 2014-02-20 16:08:19 +0000
1144+++ data/indicator-printers.desktop.in 1970-01-01 00:00:00 +0000
1145@@ -1,8 +0,0 @@
1146-[Desktop Entry]
1147-Type=Application
1148-Name=Indicator Printers
1149-Exec=@pkglibexecdir@/indicator-printers-service
1150-OnlyShowIn=Unity;
1151-NoDisplay=true
1152-StartupNotify=false
1153-Terminal=false
1154
1155=== removed directory 'data/upstart'
1156=== removed file 'data/upstart/Makefile.am'
1157--- data/upstart/Makefile.am 2014-02-20 16:06:20 +0000
1158+++ data/upstart/Makefile.am 1970-01-01 00:00:00 +0000
1159@@ -1,17 +0,0 @@
1160-BUILT_SOURCES=
1161-CLEANFILES=
1162-EXTRA_DIST=
1163-
1164-#
1165-# the upstart xdg autostart override
1166-#
1167-
1168-xdg_autostartdir = $(datadir)/upstart/xdg/autostart
1169-xdg_autostart_DATA = indicator-printers.desktop
1170-xdg_autostart_in = $(xdg_autostart_DATA:.desktop=.desktop.in)
1171-$(xdg_autostart_DATA): $(xdg_autostart_in)
1172- $(AM_V_GEN) $(SED) -e "s|\@pkglibexecdir\@|$(pkglibexecdir)|" $< > $@
1173-BUILT_SOURCES += $(xdg_autostart_DATA)
1174-CLEANFILES += $(xdg_autostart_DATA)
1175-EXTRA_DIST += $(xdg_autostart_in)
1176-
1177
1178=== removed file 'data/upstart/indicator-printers.desktop.in'
1179--- data/upstart/indicator-printers.desktop.in 2014-02-20 16:08:19 +0000
1180+++ data/upstart/indicator-printers.desktop.in 1970-01-01 00:00:00 +0000
1181@@ -1,9 +0,0 @@
1182-[Desktop Entry]
1183-Type=Application
1184-Name=Indicator Printers
1185-Exec=@pkglibexecdir@/indicator-printers-service
1186-OnlyShowIn=Unity;
1187-NoDisplay=true
1188-StartupNotify=false
1189-Terminal=false
1190-Hidden=true
1191
1192=== modified file 'debian/control'
1193--- debian/control 2016-11-24 23:20:47 +0000
1194+++ debian/control 2017-01-10 21:54:44 +0000
1195@@ -2,26 +2,24 @@
1196 Section: gnome
1197 Priority: extra
1198 Maintainer: Ubuntu Desktop Team <ubuntu-desktop@lists.ubuntu.com>
1199-XSBC-Original-Maintainer: Lars Uebernickel <lars.uebernickel@canonical.com>
1200-Build-Depends: debhelper (>= 9),
1201- autotools-dev,
1202- dh-autoreconf,
1203- gnome-common,
1204- python,
1205- libglib2.0-dev (>= 2.43.2),
1206- libgtk-3-dev,
1207- libdbusmenu-glib-dev (>= 0.5.90),
1208- libdbusmenu-gtk3-dev (>= 0.5.90),
1209- libindicator3-dev (>= 0.3.91),
1210- libcups2-dev,
1211- systemd,
1212-Standards-Version: 3.9.2
1213+Build-Depends:
1214+ cmake,
1215+ cmake-extras (>= 0.10),
1216+ debhelper (>= 9),
1217+ dbus,
1218+ dh-translations,
1219+ gcovr,
1220+ googletest | google-mock,
1221+ intltool,
1222+ lcov,
1223+ libcups2-dev,
1224+ libglib2.0-dev (>= 2.35.4),
1225+ libproperties-cpp-dev,
1226+ systemd,
1227+Standards-Version: 3.9.6
1228 Homepage: https://launchpad.net/indicator-printers
1229-# If you aren't a member of ~indicator-applet-developers but need to upload
1230-# packaging changes, just go ahead. ~indicator-applet-developers will notice
1231-# and sync up the code again.
1232-Vcs-Bzr: https://code.launchpad.net/~indicator-applet-developers/indicator-printers/trunk.13.04
1233-Vcs-Browser: https://bazaar.launchpad.net/~indicator-applet-developers/indicator-printers/trunk.13.04/files
1234+Vcs-Bzr: lp:indicator-printers
1235+X-Ubuntu-Use-Langpack: yes
1236
1237 Package: indicator-printers
1238 Architecture: any
1239@@ -30,7 +28,6 @@
1240 cups (>= 1.5),
1241 indicator-common,
1242 Recommends: indicator-applet (>= 0.2) | indicator-renderer,
1243- system-config-printer,
1244 Description: indicator showing active print jobs
1245 This indicator is designed to let you view and control active print jobs.
1246 .
1247
1248=== modified file 'debian/copyright'
1249--- debian/copyright 2012-02-16 16:23:19 +0000
1250+++ debian/copyright 2017-01-10 21:54:44 +0000
1251@@ -1,10 +1,9 @@
1252 Format: http://dep.debian.net/deps/dep5/
1253 Upstream-Name: indicator-printers
1254-Upstream-Contact: Lars Uebernickel <lars.uebernickel@canonical.com>
1255 Source: https://launchpad.net/indicator-printers
1256
1257 Files: *
1258-Copyright: 2012 Canonical Ltd
1259+Copyright: 2012, 2016-2017 Canonical Ltd
1260 License: GPL-3
1261 This program is free software: you can redistribute it and/or modify
1262 it under the terms of the GNU General Public License as published by
1263
1264=== modified file 'debian/rules'
1265--- debian/rules 2012-11-20 15:32:37 +0000
1266+++ debian/rules 2017-01-10 21:54:44 +0000
1267@@ -1,22 +1,7 @@
1268 #!/usr/bin/make -f
1269-
1270-
1271-CFLAGS += -Wno-error=deprecated-declarations
1272 LDFLAGS += -Wl,-z,defs -Wl,--as-needed
1273
1274 export DPKG_GENSYMBOLS_CHECK_LEVEL = 4
1275
1276 %:
1277- dh $@ --with autoreconf
1278-
1279-override_dh_autoreconf:
1280- NOCONFIGURE=1 dh_autoreconf ./autogen.sh
1281-
1282-override_dh_auto_configure:
1283- dh_auto_configure -- \
1284- --disable-static
1285-
1286-override_dh_install:
1287- find debian/indicator-printers -name \*.la -delete
1288- find debian/indicator-printers -name \*.a -delete
1289- dh_install --fail-missing
1290+ dh $@ --parallel --buildsystem cmake --fail-missing
1291
1292=== removed file 'debian/watch'
1293--- debian/watch 2012-02-16 16:23:19 +0000
1294+++ debian/watch 1970-01-01 00:00:00 +0000
1295@@ -1,2 +0,0 @@
1296-version=3
1297-https://launchpad.net/indicator-printers/+download .*/indicator-printers-([0-9.]+)\.tar\.gz
1298
1299=== removed directory 'm4'
1300=== removed file 'm4/gcov.m4'
1301--- m4/gcov.m4 2012-03-27 22:12:02 +0000
1302+++ m4/gcov.m4 1970-01-01 00:00:00 +0000
1303@@ -1,86 +0,0 @@
1304-# Checks for existence of coverage tools:
1305-# * gcov
1306-# * lcov
1307-# * genhtml
1308-# * gcovr
1309-#
1310-# Sets ac_cv_check_gcov to yes if tooling is present
1311-# and reports the executables to the variables LCOV, GCOVR and GENHTML.
1312-AC_DEFUN([AC_TDD_GCOV],
1313-[
1314- AC_ARG_ENABLE(gcov,
1315- AS_HELP_STRING([--enable-gcov],
1316- [enable coverage testing with gcov]),
1317- [use_gcov=$enableval], [use_gcov=no])
1318-
1319- if test "x$use_gcov" = "xyes"; then
1320- # we need gcc:
1321- if test "$GCC" != "yes"; then
1322- AC_MSG_ERROR([GCC is required for --enable-gcov])
1323- fi
1324-
1325- # Check if ccache is being used
1326- AC_CHECK_PROG(SHTOOL, shtool, shtool)
1327- case `$SHTOOL path $CC` in
1328- *ccache*[)] gcc_ccache=yes;;
1329- *[)] gcc_ccache=no;;
1330- esac
1331-
1332- if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
1333- AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
1334- fi
1335-
1336- lcov_version_list="1.6 1.7 1.8 1.9"
1337- AC_CHECK_PROG(LCOV, lcov, lcov)
1338- AC_CHECK_PROG(GENHTML, genhtml, genhtml)
1339-
1340- if test "$LCOV"; then
1341- AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
1342- glib_cv_lcov_version=invalid
1343- lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
1344- for lcov_check_version in $lcov_version_list; do
1345- if test "$lcov_version" = "$lcov_check_version"; then
1346- glib_cv_lcov_version="$lcov_check_version (ok)"
1347- fi
1348- done
1349- ])
1350- else
1351- lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
1352- AC_MSG_ERROR([$lcov_msg])
1353- fi
1354-
1355- case $glib_cv_lcov_version in
1356- ""|invalid[)]
1357- lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
1358- AC_MSG_ERROR([$lcov_msg])
1359- LCOV="exit 0;"
1360- ;;
1361- esac
1362-
1363- if test -z "$GENHTML"; then
1364- AC_MSG_ERROR([Could not find genhtml from the lcov package])
1365- fi
1366-
1367- ac_cv_check_gcov=yes
1368- ac_cv_check_lcov=yes
1369-
1370- # Remove all optimization flags from CFLAGS
1371- changequote({,})
1372- CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
1373- changequote([,])
1374-
1375- # Add the special gcc flags
1376- COVERAGE_CFLAGS="-O0 -fprofile-arcs -ftest-coverage"
1377- COVERAGE_CXXFLAGS="-O0 -fprofile-arcs -ftest-coverage"
1378- COVERAGE_LDFLAGS="-lgcov"
1379-
1380- # Check availability of gcovr
1381- AC_CHECK_PROG(GCOVR, gcovr, gcovr)
1382- if test -z "$GCOVR"; then
1383- ac_cv_check_gcovr=no
1384- else
1385- ac_cv_check_gcovr=yes
1386- fi
1387-
1388-fi
1389-]) # AC_TDD_GCOV
1390
1391=== added file 'po/CMakeLists.txt'
1392--- po/CMakeLists.txt 1970-01-01 00:00:00 +0000
1393+++ po/CMakeLists.txt 2017-01-10 21:54:44 +0000
1394@@ -0,0 +1,12 @@
1395+find_package(Intltool REQUIRED)
1396+
1397+intltool_update_potfile(
1398+ KEYWORDS "_" "_:1,2" "N_" "N_:1,2"
1399+ GETTEXT_PACKAGE ${GETTEXT_PACKAGE}
1400+ COPYRIGHT_HOLDER "Canonical Ltd."
1401+)
1402+
1403+intltool_install_translations(
1404+ ALL
1405+ GETTEXT_PACKAGE ${GETTEXT_PACKAGE}
1406+)
1407
1408=== removed file 'po/POTFILES.in'
1409--- po/POTFILES.in 2012-02-16 16:25:33 +0000
1410+++ po/POTFILES.in 1970-01-01 00:00:00 +0000
1411@@ -1,6 +0,0 @@
1412-[encoding: UTF-8]
1413-src/indicator-menu-item.c
1414-src/indicator-printers.c
1415-src/indicator-printers-menu.c
1416-src/indicator-printers-service.c
1417-src/indicator-printer-state-notifier.c
1418
1419=== added file 'src/CMakeLists.txt'
1420--- src/CMakeLists.txt 1970-01-01 00:00:00 +0000
1421+++ src/CMakeLists.txt 2017-01-10 21:54:44 +0000
1422@@ -0,0 +1,62 @@
1423+add_definitions(
1424+ -DGETTEXT_PACKAGE=\"${PROJECT_NAME}\"
1425+ -DGETTEXT_LOCALEDIR=\"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}\"
1426+ -DG_LOG_DOMAIN=\"${CMAKE_PROJECT_NAME}\"
1427+)
1428+
1429+include_directories(
1430+ ${CMAKE_CURRENT_SOURCE_DIR}
1431+ ${CMAKE_CURRENT_BINARY_DIR}
1432+ ${SERVICE_DEPS_INCLUDE_DIRS}
1433+)
1434+link_directories(
1435+ ${SERVICE_DEPS_LIBRARY_DIRS}
1436+)
1437+
1438+include (GdbusCodegen)
1439+add_gdbus_codegen(SERVICE_GENERATED_SOURCES cups-cupsd-notifier
1440+ org.cups.cupsd
1441+ ${CMAKE_CURRENT_SOURCE_DIR}/org.cups.cupsd.Notifier.xml)
1442+
1443+add_library(${SERVICE_LIB_NAME} STATIC
1444+ actions-live.cpp
1445+ actions-live.h
1446+ actions.cpp
1447+ actions.h
1448+ client.h
1449+ cups-client.cpp
1450+ cups-client.h
1451+ exporter.cpp
1452+ exporter.h
1453+ menu.cpp
1454+ menu.h
1455+ job.h
1456+ printer.h
1457+ utils.cpp
1458+ utils.h
1459+ ${SERVICE_GENERATED_SOURCES}
1460+)
1461+
1462+target_link_libraries(${SERVICE_LIB_NAME}
1463+ ${SERVICE_DEPS_LIBRARIES}
1464+ ${CUPS_LIBS}
1465+)
1466+
1467+
1468+add_executable(${SERVICE_EXEC_NAME}
1469+ main.cpp
1470+)
1471+
1472+target_link_libraries(${SERVICE_EXEC_NAME}
1473+ ${SERVICE_LIB_NAME}
1474+ ${SERVICE_DEPS_LIBRARIES}
1475+ ${CUPS_LIBS}
1476+
1477+ ${CMAKE_THREAD_LIBS_INIT}
1478+)
1479+
1480+install(
1481+ TARGETS ${SERVICE_EXEC_NAME}
1482+ RUNTIME
1483+ DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/${PROJECT_NAME}
1484+)
1485
1486=== added file 'src/actions-live.cpp'
1487--- src/actions-live.cpp 1970-01-01 00:00:00 +0000
1488+++ src/actions-live.cpp 2017-01-10 21:54:44 +0000
1489@@ -0,0 +1,104 @@
1490+/*
1491+ * Copyright 2016-2017 Canonical Ltd.
1492+ *
1493+ * This program is free software: you can redistribute it and/or modify it
1494+ * under the terms of the GNU General Public License version 3, as published
1495+ * by the Free Software Foundation.
1496+ *
1497+ * This program is distributed in the hope that it will be useful, but
1498+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1499+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1500+ * PURPOSE. See the GNU General Public License for more details.
1501+ *
1502+ * You should have received a copy of the GNU General Public License along
1503+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1504+ */
1505+
1506+#include "actions-live.h"
1507+
1508+//#include <url-dispatcher.h>
1509+
1510+#include <glib.h>
1511+
1512+#include <sstream>
1513+
1514+namespace unity {
1515+namespace indicator {
1516+namespace printers {
1517+
1518+/***
1519+****
1520+***/
1521+
1522+LiveActions::LiveActions():
1523+ Actions()
1524+{
1525+}
1526+
1527+void LiveActions::execute_command(const std::string& cmdstr)
1528+{
1529+ const auto cmd = cmdstr.c_str();
1530+ g_debug("Issuing command '%s'", cmd);
1531+
1532+ GError* error = nullptr;
1533+ if (!g_spawn_command_line_async(cmd, &error))
1534+ {
1535+ g_warning("Unable to start \"%s\": %s", cmd, error->message);
1536+ g_error_free(error);
1537+ }
1538+}
1539+
1540+void LiveActions::dispatch_url(const std::string& url)
1541+{
1542+ g_debug("Dispatching url '%s'", url.c_str());
1543+ //url_dispatch_send(url.c_str(), nullptr, nullptr);
1544+}
1545+
1546+/***
1547+****
1548+***/
1549+
1550+LiveActions::Desktop LiveActions::get_desktop()
1551+{
1552+ static bool cached = false;
1553+ static LiveActions::Desktop result = LiveActions::OTHER;
1554+
1555+ if (cached) {
1556+ return result;
1557+ }
1558+
1559+ // check for unity8
1560+ if (g_getenv ("MIR_SOCKET") != nullptr) {
1561+ result = LiveActions::UNITY8;
1562+ } else {
1563+ const gchar *xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
1564+ if (xdg_current_desktop != NULL) {
1565+ gchar **desktop_names = g_strsplit (xdg_current_desktop, ":", 0);
1566+ for (size_t i = 0; desktop_names[i]; ++i) {
1567+ if (!g_strcmp0 (desktop_names[i], "Unity")) {
1568+ result = LiveActions::UNITY7;
1569+ break;
1570+ }
1571+ }
1572+ g_strfreev (desktop_names);
1573+ }
1574+ }
1575+ cached = true;
1576+ return result;
1577+}
1578+
1579+void LiveActions::open_settings_app()
1580+{
1581+ switch(get_desktop()) {
1582+ case LiveActions::UNITY8:
1583+ dispatch_url("settings:///system/printers");
1584+ break;
1585+ default:
1586+ execute_command("system-config-printer");
1587+ }
1588+}
1589+
1590+
1591+} // namespace printers
1592+} // namespace indicator
1593+} // namespace unity
1594
1595=== added file 'src/actions-live.h'
1596--- src/actions-live.h 1970-01-01 00:00:00 +0000
1597+++ src/actions-live.h 2017-01-10 21:54:44 +0000
1598@@ -0,0 +1,54 @@
1599+/*
1600+ * Copyright 2016-2017 Canonical Ltd.
1601+ *
1602+ * This program is free software: you can redistribute it and/or modify it
1603+ * under the terms of the GNU General Public License version 3, as published
1604+ * by the Free Software Foundation.
1605+ *
1606+ * This program is distributed in the hope that it will be useful, but
1607+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1608+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1609+ * PURPOSE. See the GNU General Public License for more details.
1610+ *
1611+ * You should have received a copy of the GNU General Public License along
1612+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1613+ */
1614+
1615+#pragma once
1616+
1617+#include "actions.h"
1618+
1619+namespace unity {
1620+namespace indicator {
1621+namespace printers {
1622+
1623+/**
1624+ * \brief Production implementation of the Actions interface.
1625+ *
1626+ * Open a URL or launch a command for an action.
1627+ *
1628+ * @see MockActions
1629+ */
1630+class LiveActions: public Actions
1631+{
1632+public:
1633+ enum Desktop {
1634+ OTHER = 0,
1635+ UNITY7,
1636+ UNITY8,
1637+ };
1638+
1639+ explicit LiveActions();
1640+ virtual ~LiveActions() =default;
1641+
1642+ void open_settings_app() override;
1643+
1644+protected:
1645+ virtual Desktop get_desktop();
1646+ virtual void execute_command(const std::string& command);
1647+ virtual void dispatch_url(const std::string& url);
1648+};
1649+
1650+} // namespace printers
1651+} // namespace indicator
1652+} // namespace unity
1653
1654=== added file 'src/actions.cpp'
1655--- src/actions.cpp 1970-01-01 00:00:00 +0000
1656+++ src/actions.cpp 2017-01-10 21:54:44 +0000
1657@@ -0,0 +1,73 @@
1658+/*
1659+ * Copyright 2016-2017 Canonical Ltd.
1660+ *
1661+ * This program is free software: you can redistribute it and/or modify it
1662+ * under the terms of the GNU General Public License version 3, as published
1663+ * by the Free Software Foundation.
1664+ *
1665+ * This program is distributed in the hope that it will be useful, but
1666+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1667+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1668+ * PURPOSE. See the GNU General Public License for more details.
1669+ *
1670+ * You should have received a copy of the GNU General Public License along
1671+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1672+ */
1673+
1674+#include "actions.h"
1675+
1676+#include <glib.h>
1677+#include <gio/gio.h>
1678+
1679+namespace unity {
1680+namespace indicator {
1681+namespace printers {
1682+
1683+/***
1684+****
1685+***/
1686+
1687+namespace
1688+{
1689+
1690+GVariant* create_default_header_state()
1691+{
1692+ GVariantBuilder b;
1693+ g_variant_builder_init(&b, G_VARIANT_TYPE_VARDICT);
1694+ g_variant_builder_add(&b, "{sv}", "accessible-desc", g_variant_new_string("accessible-desc"));
1695+ g_variant_builder_add(&b, "{sv}", "label", g_variant_new_string("label"));
1696+ g_variant_builder_add(&b, "{sv}", "title", g_variant_new_string("title"));
1697+ g_variant_builder_add(&b, "{sv}", "visible", g_variant_new_boolean(true));
1698+ return g_variant_builder_end(&b);
1699+}
1700+
1701+} // unnamed namespace
1702+
1703+/***
1704+****
1705+***/
1706+
1707+Actions::Actions():
1708+ m_actions(g_simple_action_group_new())
1709+{
1710+ // add the header actions
1711+ auto v = create_default_header_state();
1712+ auto a = g_simple_action_new_stateful("printers", nullptr, v);
1713+ g_action_map_add_action(G_ACTION_MAP(m_actions), G_ACTION(a));
1714+ g_object_unref(a);
1715+}
1716+
1717+Actions::~Actions()
1718+{
1719+ g_clear_object(&m_actions);
1720+}
1721+
1722+GActionGroup* Actions::action_group()
1723+{
1724+ return G_ACTION_GROUP(m_actions);
1725+}
1726+
1727+
1728+} // namespace printers
1729+} // namespace indicator
1730+} // namespace unity
1731
1732=== added file 'src/actions.h'
1733--- src/actions.h 1970-01-01 00:00:00 +0000
1734+++ src/actions.h 2017-01-10 21:54:44 +0000
1735@@ -0,0 +1,57 @@
1736+/*
1737+ * Copyright 2016-2017 Canonical Ltd.
1738+ *
1739+ * This program is free software: you can redistribute it and/or modify it
1740+ * under the terms of the GNU General Public License version 3, as published
1741+ * by the Free Software Foundation.
1742+ *
1743+ * This program is distributed in the hope that it will be useful, but
1744+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1745+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1746+ * PURPOSE. See the GNU General Public License for more details.
1747+ *
1748+ * You should have received a copy of the GNU General Public License along
1749+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1750+ */
1751+
1752+#pragma once
1753+
1754+#include <memory> // shared_ptr
1755+#include <string>
1756+
1757+#include <gio/gio.h> // GSimpleActionGroup
1758+
1759+namespace unity {
1760+namespace indicator {
1761+namespace printers {
1762+
1763+/**
1764+ * \brief Interface for all the actions that can be activated by users.
1765+ *
1766+ * This is a simple C++ wrapper around our GActionGroup that gets exported
1767+ * onto the bus. Subclasses implement the actual code that should be run
1768+ * when a particular action is triggered.
1769+ */
1770+class Actions
1771+{
1772+public:
1773+
1774+ virtual void open_settings_app() = 0;
1775+
1776+ GActionGroup* action_group();
1777+
1778+protected:
1779+ explicit Actions();
1780+ virtual ~Actions();
1781+
1782+private:
1783+ GSimpleActionGroup* m_actions = nullptr;
1784+
1785+ // we've got raw pointers in here, so disable copying
1786+ Actions(const Actions&) = delete;
1787+ Actions& operator=(const Actions&) = delete;
1788+};
1789+
1790+} // namespace printers
1791+} // namespace indicator
1792+} // namespace unity
1793
1794=== added file 'src/client.h'
1795--- src/client.h 1970-01-01 00:00:00 +0000
1796+++ src/client.h 2017-01-10 21:54:44 +0000
1797@@ -0,0 +1,56 @@
1798+/*
1799+ * Copyright 2016-2017 Canonical Ltd.
1800+ *
1801+ * This program is free software: you can redistribute it and/or modify it
1802+ * under the terms of the GNU General Public License version 3, as published
1803+ * by the Free Software Foundation.
1804+ *
1805+ * This program is distributed in the hope that it will be useful, but
1806+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1807+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1808+ * PURPOSE. See the GNU General Public License for more details.
1809+ *
1810+ * You should have received a copy of the GNU General Public License along
1811+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1812+ */
1813+
1814+#pragma once
1815+
1816+#include "job.h"
1817+#include "printer.h"
1818+
1819+#include <core/signal.h>
1820+
1821+
1822+namespace unity {
1823+namespace indicator {
1824+namespace printers {
1825+
1826+ class Client {
1827+ public:
1828+ explicit Client() = default;
1829+ virtual ~Client() = default;
1830+
1831+ // Signals corresponding to printers
1832+ virtual core::Signal<const Printer&>& printer_state_changed() = 0;
1833+
1834+ // Signals corresponding to jobs
1835+ virtual core::Signal<const Job&>& job_state_changed() = 0;
1836+
1837+ // Methods to manage notification monitoring
1838+ virtual void create_subscription() = 0;
1839+ virtual void renew_subscription() = 0;
1840+ virtual void cancel_subscription() = 0;
1841+
1842+ // To iniitalize the indicator with current jobs
1843+ virtual void refresh() = 0;
1844+
1845+ private:
1846+ // disable copying
1847+ Client(const Client&) = delete;
1848+ Client& operator=(const Client&) = delete;
1849+ };
1850+
1851+} // printers
1852+} // indicators
1853+} // unity
1854
1855=== added file 'src/cups-client.cpp'
1856--- src/cups-client.cpp 1970-01-01 00:00:00 +0000
1857+++ src/cups-client.cpp 2017-01-10 21:54:44 +0000
1858@@ -0,0 +1,328 @@
1859+/*
1860+ * Copyright 2016-2017 Canonical Ltd.
1861+ *
1862+ * This program is free software: you can redistribute it and/or modify it
1863+ * under the terms of the GNU General Public License version 3, as published
1864+ * by the Free Software Foundation.
1865+ *
1866+ * This program is distributed in the hope that it will be useful, but
1867+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1868+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1869+ * PURPOSE. See the GNU General Public License for more details.
1870+ *
1871+ * You should have received a copy of the GNU General Public License along
1872+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1873+ */
1874+
1875+#include "cups-client.h"
1876+#include "cups-cupsd-notifier.h"
1877+
1878+#include <cups/cups.h>
1879+
1880+#include <stdexcept>
1881+
1882+namespace unity {
1883+namespace indicator {
1884+namespace printers {
1885+
1886+#define NOTIFY_LEASE_DURATION (24 * 60 * 60)
1887+
1888+
1889+class CupsClient::Impl {
1890+public:
1891+ Impl()
1892+ {
1893+ GError *error = nullptr;
1894+
1895+ m_notifier_proxy = notifier_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
1896+ G_DBUS_PROXY_FLAGS_NONE,
1897+ nullptr,
1898+ CUPS_DBUS_PATH,
1899+ nullptr,
1900+ &error);
1901+
1902+ if (error != nullptr) {
1903+ std::string msg{"Error creating cups notifier proxy: "};
1904+ throw std::runtime_error(msg + error->message);
1905+ g_clear_error(&error);
1906+ }
1907+
1908+ g_object_connect(m_notifier_proxy,
1909+ "signal::job-created", on_job_changed, this,
1910+ "signal::job-state", on_job_changed, this,
1911+ "signal::job-completed", on_job_changed, this,
1912+ "signal::printer-state-changed", on_printer_state_changed, this,
1913+ nullptr);
1914+ }
1915+
1916+ ~Impl()
1917+ {
1918+ if (m_notifier_proxy != nullptr) {
1919+ g_signal_handlers_disconnect_by_data(m_notifier_proxy, this);
1920+ g_clear_object(&m_notifier_proxy);
1921+ }
1922+
1923+ // Cancel the subscription from cups, so its notifier can exit.
1924+ cancel_subscription();
1925+ }
1926+
1927+ // Signals to propagate
1928+ core::Signal<const Printer&>& printer_state_changed()
1929+ {
1930+ return m_printer_state_changed;
1931+ }
1932+
1933+ core::Signal<const Job&>& job_state_changed()
1934+ {
1935+ return m_job_state_changed;
1936+ }
1937+
1938+ void create_subscription()
1939+ {
1940+ ipp_t *req;
1941+ ipp_t *resp;
1942+ ipp_attribute_t *attr;
1943+
1944+ req = ippNewRequest (IPP_CREATE_PRINTER_SUBSCRIPTION);
1945+ ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI,
1946+ "printer-uri", NULL, "/");
1947+ ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD,
1948+ "notify-events", NULL, "all");
1949+ ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
1950+ "notify-recipient-uri", NULL, "dbus://");
1951+ ippAddInteger (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
1952+ "notify-lease-duration", NOTIFY_LEASE_DURATION);
1953+
1954+ resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
1955+ if (!resp || cupsLastError() != IPP_OK) {
1956+ g_warning ("Error subscribing to CUPS notifications: %s\n",
1957+ cupsLastErrorString ());
1958+ return;
1959+ }
1960+
1961+ attr = ippFindAttribute (resp, "notify-subscription-id", IPP_TAG_INTEGER);
1962+ if (attr) {
1963+ m_subscription_id = ippGetInteger (attr, 0);
1964+ } else {
1965+ g_warning ("ipp-create-printer-subscription response doesn't contain "
1966+ "subscription id.\n");
1967+ }
1968+ ippDelete (resp);
1969+
1970+ // Set up to renew the subscription a minute before it expires
1971+ g_timeout_add_seconds(NOTIFY_LEASE_DURATION - 60,
1972+ on_subscription_timeout,
1973+ this);
1974+ }
1975+
1976+ void renew_subscription()
1977+ {
1978+ ipp_t *req;
1979+ ipp_t *resp;
1980+
1981+ req = ippNewRequest (IPP_RENEW_SUBSCRIPTION);
1982+ ippAddInteger (req, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
1983+ "notify-subscription-id", m_subscription_id);
1984+ ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI,
1985+ "printer-uri", NULL, "/");
1986+ ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
1987+ "notify-recipient-uri", NULL, "dbus://");
1988+ ippAddInteger (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
1989+ "notify-lease-duration", NOTIFY_LEASE_DURATION);
1990+
1991+ resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
1992+ if (!resp || cupsLastError() != IPP_OK) {
1993+ g_warning ("Error renewing CUPS subscription %d: %s\n",
1994+ m_subscription_id, cupsLastErrorString ());
1995+ create_subscription();
1996+ }
1997+
1998+ ippDelete (resp);
1999+ }
2000+
2001+ void cancel_subscription()
2002+ {
2003+ ipp_t *req;
2004+ ipp_t *resp;
2005+
2006+ if (m_subscription_id <= 0) {
2007+ return;
2008+ }
2009+
2010+ req = ippNewRequest (IPP_CANCEL_SUBSCRIPTION);
2011+ ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI,
2012+ "printer-uri", NULL, "/");
2013+ ippAddInteger (req, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
2014+ "notify-subscription-id", m_subscription_id);
2015+
2016+ resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
2017+ if (!resp || cupsLastError() != IPP_OK) {
2018+ g_warning ("Error unsubscribing to CUPS notifications: %s\n",
2019+ cupsLastErrorString ());
2020+ return;
2021+ }
2022+
2023+ ippDelete (resp);
2024+ }
2025+
2026+ void refresh()
2027+ {
2028+ int num_dests;
2029+ cups_dest_t* dests;
2030+
2031+ num_dests = cupsGetDests(&dests);
2032+ for (int i = 0; i < num_dests; i++) {
2033+ auto printer = get_printer_info(dests[i].name);
2034+
2035+ cups_job_t* jobs;
2036+ const auto num_jobs = cupsGetJobs(&jobs, dests[i].name,
2037+ true, CUPS_WHICHJOBS_ACTIVE);
2038+ for (int j = 0; j < num_jobs; j++) {
2039+ Job job;
2040+ job.id = jobs[j].id;
2041+ job.state = static_cast<Job::State>(jobs[j].state);
2042+ job.name = jobs[j].title;
2043+
2044+ job.printer = printer;
2045+
2046+ m_job_state_changed(job);
2047+ }
2048+ cupsFreeJobs(num_jobs, jobs);
2049+ }
2050+ cupsFreeDests(num_dests, dests);
2051+ }
2052+
2053+private:
2054+ // Method to get Printer object from the name
2055+ Printer get_printer_info(const std::string& name)
2056+ {
2057+ int num_dests;
2058+ cups_dest_t* dests;
2059+ cups_dest_t* our_dest;
2060+ Printer printer;
2061+ printer.name = name;
2062+
2063+ num_dests = cupsGetDests(&dests);
2064+ our_dest = cupsGetDest(name.c_str(), nullptr,
2065+ num_dests, dests);
2066+
2067+ // Get the printer's description
2068+ auto description = cupsGetOption("printer-info",
2069+ our_dest->num_options,
2070+ our_dest->options);
2071+ if (description != nullptr) {
2072+ printer.description = description;
2073+ }
2074+
2075+ cupsFreeDests(num_dests, dests);
2076+ return printer;
2077+ }
2078+
2079+ static gboolean on_subscription_timeout(gpointer gthis)
2080+ {
2081+ static_cast<Impl*>(gthis)->renew_subscription();
2082+ return G_SOURCE_CONTINUE;
2083+ }
2084+
2085+ static void on_job_changed (Notifier*,
2086+ const char* printer_text,
2087+ const char* printer_uri,
2088+ const char *printer_name,
2089+ unsigned int printer_state,
2090+ const char *printer_state_reasons,
2091+ bool printer_is_accepting_jobs,
2092+ unsigned int job_id,
2093+ unsigned int job_state,
2094+ const char *job_state_reasons,
2095+ const char *job_name,
2096+ unsigned int job_impressions_completed,
2097+ gpointer gthis)
2098+ {
2099+ auto self = static_cast<Impl*>(gthis);
2100+
2101+ auto printer = self->get_printer_info(printer_name);
2102+ printer.state = static_cast<Printer::State>(printer_state);
2103+ printer.text = printer_text;
2104+ printer.uri = printer_uri;
2105+ printer.state_reasons = printer_state_reasons;
2106+ printer.accepting_jobs = printer_is_accepting_jobs;
2107+
2108+ Job job;
2109+ job.printer = printer;
2110+ job.state = static_cast<Job::State>(job_state);
2111+ job.id = job_id;
2112+ job.name = job_name;
2113+ job.state_reasons = job_state_reasons;
2114+ job.impressions_completed = job_impressions_completed;
2115+
2116+ self->m_job_state_changed(job);
2117+ }
2118+
2119+ static void on_printer_state_changed(Notifier*,
2120+ const char* text,
2121+ const char* uri,
2122+ const char* name,
2123+ unsigned int state,
2124+ const char* state_reasons,
2125+ bool is_accepting_jobs,
2126+ gpointer gthis)
2127+ {
2128+ auto self = static_cast<Impl*>(gthis);
2129+
2130+ auto printer = self->get_printer_info(name);
2131+ printer.state = static_cast<Printer::State>(state);
2132+ printer.text = text;
2133+ printer.uri = uri;
2134+ printer.state_reasons = state_reasons;
2135+ printer.accepting_jobs = is_accepting_jobs;
2136+ self->m_printer_state_changed(printer);
2137+ }
2138+
2139+ int m_subscription_id = 0;
2140+ Notifier* m_notifier_proxy = nullptr;
2141+ core::Signal<const Printer&> m_printer_state_changed;
2142+ core::Signal<const Job&> m_job_state_changed;
2143+};
2144+
2145+CupsClient::CupsClient() :
2146+ p(new Impl())
2147+{
2148+}
2149+
2150+CupsClient::~CupsClient()
2151+{
2152+}
2153+
2154+core::Signal<const Printer&>& CupsClient::printer_state_changed()
2155+{
2156+ return p->printer_state_changed();
2157+}
2158+
2159+core::Signal<const Job&>& CupsClient::job_state_changed()
2160+{
2161+ return p->job_state_changed();
2162+}
2163+
2164+void CupsClient::create_subscription()
2165+{
2166+ p->create_subscription();
2167+}
2168+
2169+void CupsClient::renew_subscription()
2170+{
2171+ p->renew_subscription();
2172+}
2173+
2174+void CupsClient::cancel_subscription()
2175+{
2176+ p->cancel_subscription();
2177+}
2178+
2179+void CupsClient::refresh()
2180+{
2181+ p->refresh();
2182+}
2183+
2184+} // printers
2185+} // indicators
2186+} // unity
2187
2188=== added file 'src/cups-client.h'
2189--- src/cups-client.h 1970-01-01 00:00:00 +0000
2190+++ src/cups-client.h 2017-01-10 21:54:44 +0000
2191@@ -0,0 +1,65 @@
2192+/*
2193+ * Copyright 2016-2017 Canonical Ltd.
2194+ *
2195+ * This program is free software: you can redistribute it and/or modify it
2196+ * under the terms of the GNU General Public License version 3, as published
2197+ * by the Free Software Foundation.
2198+ *
2199+ * This program is distributed in the hope that it will be useful, but
2200+ * WITHOUT ANY WARRANTY; without even the implied warranties of
2201+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
2202+ * PURPOSE. See the GNU General Public License for more details.
2203+ *
2204+ * You should have received a copy of the GNU General Public License along
2205+ * with this program. If not, see <http://www.gnu.org/licenses/>.
2206+ */
2207+
2208+#pragma once
2209+
2210+#include "client.h"
2211+#include "job.h"
2212+#include "printer.h"
2213+
2214+#include <core/signal.h>
2215+
2216+#include <memory>
2217+
2218+namespace unity {
2219+namespace indicator {
2220+namespace printers {
2221+
2222+#define CUPS_DBUS_NAME "org.cups.cupsd.Notifier"
2223+#define CUPS_DBUS_PATH "/org/cups/cupsd/Notifier"
2224+#define CUPS_DBUS_INTERFACE "org.cups.cupsd.Notifier"
2225+
2226+ class CupsClient : public Client {
2227+ public:
2228+ CupsClient();
2229+ virtual ~CupsClient();
2230+
2231+ // Signals corresponding to printers
2232+ core::Signal<const Printer&>& printer_state_changed() override;
2233+
2234+ // Signals corresponding to jobs
2235+ core::Signal<const Job&>& job_state_changed() override;
2236+
2237+ // Methods to manage notification monitoring
2238+ virtual void create_subscription() override;
2239+ virtual void renew_subscription() override;
2240+ virtual void cancel_subscription() override;
2241+
2242+ // To initialize the indicator with current jobs
2243+ virtual void refresh() override;
2244+
2245+ private:
2246+ class Impl;
2247+ std::unique_ptr<Impl> p;
2248+
2249+ // disable copying
2250+ CupsClient(const CupsClient&) = delete;
2251+ CupsClient& operator=(const CupsClient&) = delete;
2252+ };
2253+
2254+} // printers
2255+} // indicators
2256+} // unity
2257
2258=== added file 'src/exporter.cpp'
2259--- src/exporter.cpp 1970-01-01 00:00:00 +0000
2260+++ src/exporter.cpp 2017-01-10 21:54:44 +0000
2261@@ -0,0 +1,158 @@
2262+/*
2263+ * Copyright 2016-2017 Canonical Ltd.
2264+ *
2265+ * This program is free software: you can redistribute it and/or modify it
2266+ * under the terms of the GNU General Public License version 3, as published
2267+ * by the Free Software Foundation.
2268+ *
2269+ * This program is distributed in the hope that it will be useful, but
2270+ * WITHOUT ANY WARRANTY; without even the implied warranties of
2271+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
2272+ * PURPOSE. See the GNU General Public License for more details.
2273+ *
2274+ * You should have received a copy of the GNU General Public License along
2275+ * with this program. If not, see <http://www.gnu.org/licenses/>.
2276+ */
2277+
2278+#include "exporter.h"
2279+
2280+#include <core/signal.h>
2281+
2282+namespace unity {
2283+namespace indicator {
2284+namespace printers {
2285+
2286+class Exporter::Impl
2287+{
2288+public:
2289+
2290+ Impl()
2291+ {
2292+ }
2293+
2294+ ~Impl()
2295+ {
2296+ if (m_bus != nullptr) {
2297+ if (m_exported_menu_id) {
2298+ g_dbus_connection_unexport_menu_model(m_bus, m_exported_menu_id);
2299+ }
2300+
2301+ if (m_exported_actions_id) {
2302+ g_dbus_connection_unexport_action_group(m_bus,
2303+ m_exported_actions_id);
2304+ }
2305+ }
2306+
2307+ if (m_own_id) {
2308+ g_bus_unown_name(m_own_id);
2309+ }
2310+
2311+ g_clear_object(&m_bus);
2312+ }
2313+
2314+ core::Signal<> name_lost;
2315+
2316+ void publish(const std::shared_ptr<Actions>& actions,
2317+ const std::shared_ptr<Client>& client)
2318+ {
2319+ m_actions = actions;
2320+ m_client = client;
2321+ m_menu.reset(new Menu(m_actions, m_client));
2322+ m_own_id = g_bus_own_name(G_BUS_TYPE_SESSION,
2323+ INDICATOR_BUS_NAME,
2324+ G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
2325+ on_bus_acquired,
2326+ nullptr,
2327+ on_name_lost,
2328+ this,
2329+ nullptr);
2330+ }
2331+
2332+private:
2333+ static void on_bus_acquired(GDBusConnection* connection,
2334+ const gchar* name,
2335+ gpointer gthis)
2336+ {
2337+ g_debug("bus acquired: %s", name);
2338+ static_cast<Impl*>(gthis)->on_bus_acquired(connection, name);
2339+ }
2340+
2341+ void on_bus_acquired(GDBusConnection* bus, const gchar* /*name*/)
2342+ {
2343+ m_bus = static_cast<GDBusConnection*>(g_object_ref(G_OBJECT(bus)));
2344+
2345+ // export the actions
2346+ GError * error = nullptr;
2347+ const auto id = g_dbus_connection_export_action_group(m_bus,
2348+ INDICATOR_BUS_PATH,
2349+ m_actions->action_group(),
2350+ &error);
2351+ if (id)
2352+ {
2353+ m_exported_actions_id = id;
2354+ }
2355+ else
2356+ {
2357+ g_warning("cannot export action group: %s", error->message);
2358+ g_clear_error(&error);
2359+ }
2360+
2361+ // export the menus
2362+ const auto path = std::string(INDICATOR_BUS_PATH) + "/menu";
2363+ m_exported_menu_id = g_dbus_connection_export_menu_model(m_bus,
2364+ path.c_str(),
2365+ m_menu->menu_model(),
2366+ &error);
2367+ if (error != nullptr) {
2368+ g_warning("cannot export menu: %s", error->message);
2369+ g_clear_error(&error);
2370+ }
2371+
2372+ m_client->create_subscription();
2373+ m_client->refresh();
2374+ }
2375+
2376+ static void on_name_lost(GDBusConnection*, const gchar* name,
2377+ gpointer gthis)
2378+ {
2379+ g_debug("name lost: %s", name);
2380+ static_cast<Impl*>(gthis)->name_lost();
2381+ }
2382+
2383+
2384+ guint m_exported_menu_id = 0;
2385+ guint m_own_id = 0;
2386+ guint m_exported_actions_id = 0;
2387+ GDBusConnection* m_bus = nullptr;
2388+ std::shared_ptr<Actions> m_actions;
2389+ std::shared_ptr<Client> m_client;
2390+ std::shared_ptr<Menu> m_menu;
2391+};
2392+
2393+
2394+
2395+Exporter::Exporter():
2396+ p(new Impl())
2397+{
2398+}
2399+
2400+
2401+Exporter::~Exporter()
2402+{
2403+}
2404+
2405+core::Signal<>& Exporter::name_lost()
2406+{
2407+ return p->name_lost;
2408+}
2409+
2410+void Exporter::publish(const std::shared_ptr<Actions>& actions,
2411+ const std::shared_ptr<Client>& client)
2412+{
2413+ p->publish(actions, client);
2414+}
2415+
2416+
2417+} // namespace printers
2418+} // namespace indicator
2419+} // namespace unity
2420
2421=== added file 'src/exporter.h'
2422--- src/exporter.h 1970-01-01 00:00:00 +0000
2423+++ src/exporter.h 2017-01-10 21:54:44 +0000
2424@@ -0,0 +1,60 @@
2425+/*
2426+ * Copyright 2016-2017 Canonical Ltd.
2427+ *
2428+ * This program is free software: you can redistribute it and/or modify it
2429+ * under the terms of the GNU General Public License version 3, as published
2430+ * by the Free Software Foundation.
2431+ *
2432+ * This program is distributed in the hope that it will be useful, but
2433+ * WITHOUT ANY WARRANTY; without even the implied warranties of
2434+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
2435+ * PURPOSE. See the GNU General Public License for more details.
2436+ *
2437+ * You should have received a copy of the GNU General Public License along
2438+ * with this program. If not, see <http://www.gnu.org/licenses/>.
2439+ */
2440+
2441+#pragma once
2442+
2443+#include "actions.h"
2444+#include "client.h"
2445+#include "menu.h"
2446+
2447+#include <core/signal.h>
2448+
2449+#include <memory> // std::shared_ptr
2450+#include <vector>
2451+
2452+namespace unity {
2453+namespace indicator {
2454+namespace printers {
2455+
2456+#define INDICATOR_BUS_NAME "com.canonical.indicator.printers"
2457+#define INDICATOR_BUS_PATH "/com/canonical/indicator/printers"
2458+
2459+/**
2460+ * \brief Exports actions and menu to DBus.
2461+ */
2462+class Exporter
2463+{
2464+public:
2465+ Exporter();
2466+ virtual ~Exporter();
2467+
2468+ core::Signal<>& name_lost();
2469+
2470+ void publish(const std::shared_ptr<Actions>& actions,
2471+ const std::shared_ptr<Client>& client);
2472+
2473+private:
2474+ class Impl;
2475+ std::unique_ptr<Impl> p;
2476+
2477+ // disable copying
2478+ Exporter(const Exporter&) = delete;
2479+ Exporter& operator=(const Exporter&) = delete;
2480+};
2481+
2482+} // namespace printers
2483+} // namespace indicator
2484+} // namespace unity
2485
2486=== removed file 'src/indicator-menu-item.c'
2487--- src/indicator-menu-item.c 2012-02-12 15:10:07 +0000
2488+++ src/indicator-menu-item.c 1970-01-01 00:00:00 +0000
2489@@ -1,404 +0,0 @@
2490-/*
2491- * Copyright 2012 Canonical Ltd.
2492- *
2493- * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
2494- *
2495- * This program is free software: you can redistribute it and/or modify it
2496- * under the terms of the GNU General Public License version 3, as published
2497- * by the Free Software Foundation.
2498- *
2499- * This program is distributed in the hope that it will be useful, but
2500- * WITHOUT ANY WARRANTY; without even the implied warranties of
2501- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
2502- * PURPOSE. See the GNU General Public License for more details.
2503- *
2504- * You should have received a copy of the GNU General Public License along
2505- * with this program. If not, see <http://www.gnu.org/licenses/>.
2506- */
2507-
2508-#include "indicator-menu-item.h"
2509-
2510-#include <math.h>
2511-
2512-
2513-G_DEFINE_TYPE (IndicatorMenuItem, indicator_menu_item, GTK_TYPE_MENU_ITEM)
2514-
2515-
2516-struct _IndicatorMenuItemPrivate
2517-{
2518- GtkImage *image;
2519- GtkWidget *label;
2520- GtkWidget *right_label;
2521- gboolean right_is_lozenge;
2522-};
2523-
2524-
2525-enum {
2526- PROP_0,
2527- PROP_ICON,
2528- PROP_ICON_NAME,
2529- PROP_LABEL,
2530- PROP_RIGHT,
2531- PROP_RIGHT_IS_LOZENGE,
2532- N_PROPERTIES
2533-};
2534-
2535-static GParamSpec *properties[N_PROPERTIES];
2536-
2537-
2538-static gint
2539-gtk_widget_get_font_size (GtkWidget *widget)
2540-{
2541- const PangoFontDescription *font;
2542-
2543- font = gtk_style_context_get_font (gtk_widget_get_style_context (widget),
2544- gtk_widget_get_state_flags (widget));
2545-
2546- return pango_font_description_get_size (font) / PANGO_SCALE;
2547-}
2548-
2549-static void
2550-cairo_lozenge (cairo_t *cr, double x, double y, double w, double h)
2551-{
2552- double radius = MIN (w / 2.0, h / 2.0);
2553- double x1 = x + w - radius;
2554- double x2 = x + radius;
2555- double y1 = y + radius;
2556- double y2 = y + h - radius;
2557-
2558- cairo_move_to (cr, x+radius, y);
2559- cairo_arc (cr, x1, y1, radius, M_PI * 1.5, M_PI * 2);
2560- cairo_arc (cr, x1, y2, radius, 0, M_PI * 0.5);
2561- cairo_arc (cr, x2, y2, radius, M_PI * 0.5, M_PI);
2562- cairo_arc (cr, x2, y1, radius, M_PI, M_PI * 1.5);
2563-}
2564-
2565-static gboolean
2566-detail_label_draw (GtkWidget *widget,
2567- cairo_t *cr,
2568- gpointer data)
2569-{
2570- GtkAllocation allocation;
2571- double x, y, w, h;
2572- GdkRGBA color;
2573- PangoLayout *layout;
2574- PangoRectangle layout_extents;
2575- gboolean is_lozenge = *(gboolean *)data;
2576- gint font_size = gtk_widget_get_font_size (widget);
2577-
2578- /* let the label handle the drawing if it's not a lozenge */
2579- if (!is_lozenge)
2580- return FALSE;
2581-
2582- layout = gtk_label_get_layout (GTK_LABEL(widget));
2583- pango_layout_get_extents (layout, NULL, &layout_extents);
2584- pango_extents_to_pixels (&layout_extents, NULL);
2585-
2586- gtk_widget_get_allocation (widget, &allocation);
2587- x = -font_size / 2.0;
2588- y = 1;
2589- w = allocation.width;
2590- h = MIN (allocation.height, layout_extents.height + 4);
2591-
2592- if (layout_extents.width == 0)
2593- return TRUE;
2594-
2595- gtk_style_context_get_color (gtk_widget_get_style_context (widget),
2596- gtk_widget_get_state_flags (widget),
2597- &color);
2598- gdk_cairo_set_source_rgba (cr, &color);
2599-
2600- cairo_set_line_width (cr, 1.0);
2601- cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
2602- cairo_lozenge (cr, x - font_size / 2.0, y, w + font_size, h);
2603-
2604- x += (w - layout_extents.width) / 2.0;
2605- y += (h - layout_extents.height) / 2.0;
2606- cairo_move_to (cr, floor (x), floor (y));
2607- pango_cairo_layout_path (cr, layout);
2608- cairo_fill (cr);
2609-
2610- return TRUE;
2611-}
2612-
2613-
2614-static void
2615-indicator_menu_item_get_property (GObject *object,
2616- guint property_id,
2617- GValue *value,
2618- GParamSpec *pspec)
2619-{
2620- IndicatorMenuItem *self = INDICATOR_MENU_ITEM (object);
2621-
2622- switch (property_id)
2623- {
2624- case PROP_ICON:
2625- g_value_set_object (value, indicator_menu_item_get_icon (self));
2626- break;
2627-
2628- case PROP_ICON_NAME:
2629- g_value_set_string (value, indicator_menu_item_get_icon_name (self));
2630- break;
2631-
2632- case PROP_LABEL:
2633- g_value_set_string (value, gtk_label_get_label (GTK_LABEL (self->priv->label)));
2634- break;
2635-
2636- case PROP_RIGHT:
2637- g_value_set_string (value, gtk_label_get_label (GTK_LABEL (self->priv->right_label)));
2638- break;
2639-
2640- case PROP_RIGHT_IS_LOZENGE:
2641- g_value_set_boolean (value, self->priv->right_is_lozenge);
2642- break;
2643-
2644- default:
2645- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2646- }
2647-}
2648-
2649-
2650-static void
2651-indicator_menu_item_set_property (GObject *object,
2652- guint property_id,
2653- const GValue *value,
2654- GParamSpec *pspec)
2655-{
2656- switch (property_id)
2657- {
2658- case PROP_ICON:
2659- indicator_menu_item_set_icon (INDICATOR_MENU_ITEM (object),
2660- g_value_get_object (value));
2661- break;
2662-
2663- case PROP_ICON_NAME:
2664- indicator_menu_item_set_icon_name (INDICATOR_MENU_ITEM (object),
2665- g_value_get_string (value));
2666- break;
2667-
2668- case PROP_LABEL:
2669- indicator_menu_item_set_label (INDICATOR_MENU_ITEM (object),
2670- g_value_get_string (value));
2671- break;
2672-
2673- case PROP_RIGHT:
2674- indicator_menu_item_set_right (INDICATOR_MENU_ITEM (object),
2675- g_value_get_string (value));
2676- break;
2677-
2678- case PROP_RIGHT_IS_LOZENGE:
2679- indicator_menu_item_set_right_is_lozenge (INDICATOR_MENU_ITEM (object),
2680- g_value_get_boolean (value));
2681- break;
2682-
2683-
2684- default:
2685- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2686- }
2687-}
2688-
2689-
2690-static void
2691-indicator_menu_item_dispose (GObject *object)
2692-{
2693- IndicatorMenuItem *self = INDICATOR_MENU_ITEM (object);
2694-
2695- g_clear_object (&self->priv->image);
2696- g_clear_object (&self->priv->label);
2697- g_clear_object (&self->priv->right_label);
2698-
2699- G_OBJECT_CLASS (indicator_menu_item_parent_class)->dispose (object);
2700-}
2701-
2702-
2703-static void
2704-indicator_menu_item_class_init (IndicatorMenuItemClass *klass)
2705-{
2706- GObjectClass *object_class = G_OBJECT_CLASS (klass);
2707-
2708- g_type_class_add_private (klass, sizeof (IndicatorMenuItemPrivate));
2709-
2710- object_class->get_property = indicator_menu_item_get_property;
2711- object_class->set_property = indicator_menu_item_set_property;
2712- object_class->dispose = indicator_menu_item_dispose;
2713-
2714- properties[PROP_ICON] = g_param_spec_object ("icon",
2715- "Icon",
2716- "Icon for this menu item",
2717- GDK_TYPE_PIXBUF,
2718- G_PARAM_READWRITE);
2719-
2720- properties[PROP_ICON_NAME] = g_param_spec_string ("icon-name",
2721- "Icon name",
2722- "Name of the themed icon",
2723- "",
2724- G_PARAM_READWRITE);
2725-
2726- properties[PROP_LABEL] = g_param_spec_string ("label",
2727- "Label",
2728- "The text for the main label",
2729- "",
2730- G_PARAM_READWRITE);
2731-
2732- properties[PROP_RIGHT] = g_param_spec_string ("right",
2733- "Right",
2734- "The text on the right side of the menu item",
2735- "",
2736- G_PARAM_READWRITE);
2737-
2738- properties[PROP_RIGHT_IS_LOZENGE] = g_param_spec_boolean ("right-is-lozenge",
2739- "Right is a lozenge",
2740- "Whether the right label is displayed as a lonzenge",
2741- FALSE,
2742- G_PARAM_READWRITE);
2743-
2744- g_object_class_install_properties (object_class, N_PROPERTIES, properties);
2745-}
2746-
2747-
2748-static void
2749-indicator_menu_item_init (IndicatorMenuItem *self)
2750-{
2751- IndicatorMenuItemPrivate *priv;
2752- gint spacing;
2753- GtkWidget *hbox;
2754-
2755- priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
2756- INDICATOR_TYPE_MENU_ITEM,
2757- IndicatorMenuItemPrivate);
2758- self->priv = priv;
2759-
2760- gtk_widget_style_get (GTK_WIDGET (self),
2761- "toggle-spacing", &spacing,
2762- NULL);
2763-
2764- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, spacing);
2765-
2766- priv->image = g_object_new (GTK_TYPE_IMAGE, NULL);
2767- g_object_ref_sink (priv->image);
2768- gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (priv->image), FALSE, FALSE, 0);
2769-
2770- priv->label = g_object_new (GTK_TYPE_LABEL,
2771- "xalign", 0.0,
2772- NULL);
2773- g_object_ref_sink (priv->label);
2774- gtk_box_pack_start (GTK_BOX (hbox), priv->label, TRUE, TRUE, 0);
2775-
2776- priv->right_label = g_object_new (GTK_TYPE_LABEL,
2777- "xalign", 1.0,
2778- "width-chars", 2,
2779- NULL);
2780- gtk_style_context_add_class (gtk_widget_get_style_context (priv->right_label),
2781- "accelerator");
2782- g_signal_connect (priv->right_label,
2783- "draw",
2784- G_CALLBACK (detail_label_draw),
2785- &priv->right_is_lozenge);
2786- g_object_ref_sink (priv->right_label);
2787- gtk_box_pack_start (GTK_BOX (hbox),
2788- priv->right_label,
2789- FALSE,
2790- FALSE,
2791- gtk_widget_get_font_size (priv->right_label) / 2.0 + 1);
2792-
2793- gtk_container_add (GTK_CONTAINER (self), hbox);
2794-
2795- priv->right_is_lozenge = FALSE;
2796-}
2797-
2798-
2799-IndicatorMenuItem *
2800-indicator_menu_item_new (void)
2801-{
2802- return g_object_new (INDICATOR_TYPE_MENU_ITEM, NULL);
2803-}
2804-
2805-
2806-const gchar *
2807-indicator_menu_item_get_label (IndicatorMenuItem *self)
2808-{
2809- return gtk_label_get_label (GTK_LABEL (self->priv->label));
2810-}
2811-
2812-
2813-void
2814-indicator_menu_item_set_label (IndicatorMenuItem *self,
2815- const gchar *text)
2816-{
2817- gtk_label_set_label (GTK_LABEL (self->priv->label), text);
2818- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LABEL]);
2819-}
2820-
2821-
2822-const gchar *
2823-indicator_menu_item_get_right (IndicatorMenuItem *self)
2824-{
2825- return gtk_label_get_label (GTK_LABEL (self->priv->right_label));
2826-}
2827-
2828-
2829-void
2830-indicator_menu_item_set_right (IndicatorMenuItem *self,
2831- const gchar *text)
2832-{
2833- gtk_label_set_label (GTK_LABEL (self->priv->right_label), text);
2834- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RIGHT]);
2835-}
2836-
2837-
2838-gboolean
2839-indicator_menu_item_get_right_is_lozenge (IndicatorMenuItem *self)
2840-{
2841- return self->priv->right_is_lozenge;
2842-}
2843-
2844-
2845-void
2846-indicator_menu_item_set_right_is_lozenge (IndicatorMenuItem *self,
2847- gboolean is_lozenge)
2848-{
2849- self->priv->right_is_lozenge = is_lozenge;
2850- gtk_widget_queue_draw (self->priv->right_label);
2851- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RIGHT_IS_LOZENGE]);
2852-}
2853-
2854-
2855-GdkPixbuf *
2856-indicator_menu_item_get_icon (IndicatorMenuItem *self)
2857-{
2858- if (gtk_image_get_storage_type (self->priv->image) == GTK_IMAGE_PIXBUF)
2859- return gtk_image_get_pixbuf (self->priv->image);
2860- else
2861- return NULL;
2862-}
2863-
2864-
2865-void
2866-indicator_menu_item_set_icon (IndicatorMenuItem *self,
2867- GdkPixbuf *icon)
2868-{
2869- gtk_image_set_from_pixbuf (self->priv->image, icon);
2870- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON]);
2871-}
2872-
2873-
2874-const gchar *
2875-indicator_menu_item_get_icon_name (IndicatorMenuItem *self)
2876-{
2877- const gchar *name = NULL;
2878-
2879- if (gtk_image_get_storage_type (self->priv->image) == GTK_IMAGE_ICON_NAME)
2880- gtk_image_get_icon_name (self->priv->image, &name, NULL);
2881-
2882- return name;
2883-}
2884-
2885-
2886-void
2887-indicator_menu_item_set_icon_name (IndicatorMenuItem *self,
2888- const gchar *name)
2889-{
2890- gtk_image_set_from_icon_name (self->priv->image, name, GTK_ICON_SIZE_MENU);
2891- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON_NAME]);
2892-}
2893-
2894
2895=== removed file 'src/indicator-menu-item.h'
2896--- src/indicator-menu-item.h 2012-02-12 13:20:44 +0000
2897+++ src/indicator-menu-item.h 1970-01-01 00:00:00 +0000
2898@@ -1,82 +0,0 @@
2899-/*
2900- * Copyright 2012 Canonical Ltd.
2901- *
2902- * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
2903- *
2904- * This program is free software: you can redistribute it and/or modify it
2905- * under the terms of the GNU General Public License version 3, as published
2906- * by the Free Software Foundation.
2907- *
2908- * This program is distributed in the hope that it will be useful, but
2909- * WITHOUT ANY WARRANTY; without even the implied warranties of
2910- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
2911- * PURPOSE. See the GNU General Public License for more details.
2912- *
2913- * You should have received a copy of the GNU General Public License along
2914- * with this program. If not, see <http://www.gnu.org/licenses/>.
2915- */
2916-
2917-#ifndef INDICATOR_MENU_ITEM_H
2918-#define INDICATOR_MENU_ITEM_H
2919-
2920-#include <gtk/gtk.h>
2921-
2922-G_BEGIN_DECLS
2923-
2924-#define INDICATOR_TYPE_MENU_ITEM indicator_menu_item_get_type()
2925-
2926-#define INDICATOR_MENU_ITEM(obj) \
2927- (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
2928- INDICATOR_TYPE_MENU_ITEM, IndicatorMenuItem))
2929-
2930-#define INDICATOR_MENU_ITEM_CLASS(klass) \
2931- (G_TYPE_CHECK_CLASS_CAST ((klass), \
2932- INDICATOR_TYPE_MENU_ITEM, IndicatorMenuItemClass))
2933-
2934-#define INDICATOR_IS_MENU_ITEM(obj) \
2935- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
2936- INDICATOR_TYPE_MENU_ITEM))
2937-
2938-#define INDICATOR_IS_MENU_ITEM_CLASS(klass) \
2939- (G_TYPE_CHECK_CLASS_TYPE ((klass), \
2940- INDICATOR_TYPE_MENU_ITEM))
2941-
2942-#define INDICATOR_MENU_ITEM_GET_CLASS(obj) \
2943- (G_TYPE_INSTANCE_GET_CLASS ((obj), \
2944- INDICATOR_TYPE_MENU_ITEM, IndicatorMenuItemClass))
2945-
2946-typedef struct _IndicatorMenuItem IndicatorMenuItem;
2947-typedef struct _IndicatorMenuItemClass IndicatorMenuItemClass;
2948-typedef struct _IndicatorMenuItemPrivate IndicatorMenuItemPrivate;
2949-
2950-struct _IndicatorMenuItem
2951-{
2952- GtkMenuItem parent;
2953- IndicatorMenuItemPrivate *priv;
2954-};
2955-
2956-struct _IndicatorMenuItemClass
2957-{
2958- GtkMenuItemClass parent_class;
2959-};
2960-
2961-GType indicator_menu_item_get_type (void) G_GNUC_CONST;
2962-
2963-IndicatorMenuItem *indicator_menu_item_new (void);
2964-
2965-const gchar * indicator_menu_item_get_label (IndicatorMenuItem *self);
2966-void indicator_menu_item_set_label (IndicatorMenuItem *self, const gchar *text);
2967-const gchar * indicator_menu_item_get_right (IndicatorMenuItem *self);
2968-void indicator_menu_item_set_right (IndicatorMenuItem *self, const gchar *text);
2969-
2970-gboolean indicator_menu_item_get_right_is_lozenge (IndicatorMenuItem *self);
2971-void indicator_menu_item_set_right_is_lozenge (IndicatorMenuItem *self, gboolean is_lozenge);
2972-const gchar * indicator_menu_item_get_icon_name (IndicatorMenuItem *self);
2973-void indicator_menu_item_set_icon (IndicatorMenuItem *self, GdkPixbuf *icon);
2974-GdkPixbuf * indicator_menu_item_get_icon (IndicatorMenuItem *self);
2975-void indicator_menu_item_set_icon_name (IndicatorMenuItem *self, const gchar *name);
2976-
2977-G_END_DECLS
2978-
2979-#endif
2980-
2981
2982=== removed file 'src/indicator-printers-menu.c'
2983--- src/indicator-printers-menu.c 2012-03-03 10:40:46 +0000
2984+++ src/indicator-printers-menu.c 1970-01-01 00:00:00 +0000
2985@@ -1,339 +0,0 @@
2986-/*
2987- * Copyright 2012 Canonical Ltd.
2988- *
2989- * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
2990- *
2991- * This program is free software: you can redistribute it and/or modify it
2992- * under the terms of the GNU General Public License version 3, as published
2993- * by the Free Software Foundation.
2994- *
2995- * This program is distributed in the hope that it will be useful, but
2996- * WITHOUT ANY WARRANTY; without even the implied warranties of
2997- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
2998- * PURPOSE. See the GNU General Public License for more details.
2999- *
3000- * You should have received a copy of the GNU General Public License along
3001- * with this program. If not, see <http://www.gnu.org/licenses/>.
3002- */
3003-
3004-#include "indicator-printers-menu.h"
3005-
3006-#include <glib/gi18n.h>
3007-
3008-#include <cups/cups.h>
3009-
3010-#include "spawn-printer-settings.h"
3011-
3012-
3013-G_DEFINE_TYPE (IndicatorPrintersMenu, indicator_printers_menu, G_TYPE_OBJECT)
3014-
3015-
3016-struct _IndicatorPrintersMenuPrivate
3017-{
3018- DbusmenuMenuitem *root;
3019- GHashTable *printers; /* printer name -> dbusmenuitem */
3020- CupsNotifier *cups_notifier;
3021-};
3022-
3023-
3024-enum {
3025- PROP_0,
3026- PROP_CUPS_NOTIFIER,
3027- NUM_PROPERTIES
3028-};
3029-
3030-GParamSpec *properties[NUM_PROPERTIES];
3031-
3032-
3033-static void
3034-dispose (GObject *object)
3035-{
3036- IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (object);
3037-
3038- if (self->priv->printers) {
3039- g_hash_table_unref (self->priv->printers);
3040- self->priv->printers = NULL;
3041- }
3042-
3043- g_clear_object (&self->priv->root);
3044- g_clear_object (&self->priv->cups_notifier);
3045-
3046- G_OBJECT_CLASS (indicator_printers_menu_parent_class)->dispose (object);
3047-}
3048-
3049-
3050-void
3051-set_property (GObject *object,
3052- guint property_id,
3053- const GValue *value,
3054- GParamSpec *pspec)
3055-{
3056- IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (object);
3057-
3058- switch (property_id) {
3059- case PROP_CUPS_NOTIFIER:
3060- indicator_printers_menu_set_cups_notifier (self,
3061- g_value_get_object (value));
3062- break;
3063-
3064- default:
3065- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
3066- }
3067-}
3068-
3069-
3070-void
3071-get_property (GObject *object,
3072- guint property_id,
3073- GValue *value,
3074- GParamSpec *pspec)
3075-{
3076- IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (object);
3077-
3078- switch (property_id) {
3079- case PROP_CUPS_NOTIFIER:
3080- g_value_set_object (value,
3081- indicator_printers_menu_get_cups_notifier (self));
3082- break;
3083-
3084- default:
3085- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
3086- }
3087-}
3088-
3089-
3090-static void
3091-indicator_printers_menu_class_init (IndicatorPrintersMenuClass *klass)
3092-{
3093- GObjectClass *object_class = G_OBJECT_CLASS (klass);
3094-
3095- g_type_class_add_private (klass, sizeof (IndicatorPrintersMenuPrivate));
3096-
3097- object_class->dispose = dispose;
3098- object_class->get_property = get_property;
3099- object_class->set_property = set_property;
3100-
3101- properties[PROP_CUPS_NOTIFIER] = g_param_spec_object ("cups-notifier",
3102- "Cups Notifier",
3103- "A cups notifier object",
3104- CUPS_TYPE_NOTIFIER,
3105- G_PARAM_READWRITE);
3106-
3107- g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
3108-}
3109-
3110-
3111-static void
3112-on_printer_item_activated (DbusmenuMenuitem *menuitem,
3113- guint timestamp,
3114- gpointer user_data)
3115-{
3116- const gchar *printer = user_data;
3117- spawn_printer_settings_with_args ("--show-jobs %s", printer);
3118-}
3119-
3120-
3121-static void
3122-update_indicator_visibility (IndicatorPrintersMenu *self)
3123-{
3124- GList *it;
3125- gboolean is_visible = FALSE;
3126-
3127- for (it = dbusmenu_menuitem_get_children (self->priv->root);
3128- it;
3129- it = g_list_next (it))
3130- {
3131- DbusmenuMenuitem *child = it->data;
3132- if ((is_visible = dbusmenu_menuitem_property_get_bool (child, "visible")))
3133- break;
3134- }
3135-
3136- dbusmenu_menuitem_property_set_bool (self->priv->root, "visible", is_visible);
3137-}
3138-
3139-
3140-static void
3141-update_printer_menuitem (IndicatorPrintersMenu *self,
3142- const char *printer,
3143- int state)
3144-{
3145- DbusmenuMenuitem *item;
3146- int njobs;
3147- cups_job_t *jobs;
3148-
3149- njobs = cupsGetJobs (&jobs, printer, 1, CUPS_WHICHJOBS_ACTIVE);
3150- cupsFreeJobs (njobs, jobs);
3151-
3152- if (njobs < 0) {
3153- g_warning ("printer '%s' does not exist\n", printer);
3154- return;
3155- }
3156-
3157- item = g_hash_table_lookup (self->priv->printers, printer);
3158-
3159- if (!item) {
3160- item = dbusmenu_menuitem_new ();
3161- dbusmenu_menuitem_property_set (item, "type", "indicator-item");
3162- dbusmenu_menuitem_property_set (item, "indicator-icon-name", "printer");
3163- dbusmenu_menuitem_property_set (item, "indicator-label", printer);
3164- g_signal_connect_data (item, "item-activated",
3165- G_CALLBACK (on_printer_item_activated),
3166- g_strdup (printer), (GClosureNotify) g_free, 0);
3167-
3168- dbusmenu_menuitem_child_append(self->priv->root, item);
3169- g_hash_table_insert (self->priv->printers, g_strdup (printer), item);
3170- }
3171-
3172- if (njobs == 0) {
3173- dbusmenu_menuitem_property_set_bool (item, "visible", FALSE);
3174- update_indicator_visibility (self);
3175- return;
3176- }
3177-
3178- /* there are jobs for this printer. Make sure the indicator and the menu
3179- * item for that printer are shown */
3180- dbusmenu_menuitem_property_set_bool (self->priv->root, "visible", TRUE);
3181- dbusmenu_menuitem_property_set_bool (item, "visible", TRUE);
3182-
3183- switch (state) {
3184- case IPP_PRINTER_STOPPED:
3185- dbusmenu_menuitem_property_set (item, "indicator-right", _("Paused"));
3186- dbusmenu_menuitem_property_set_bool (item, "indicator-right-is-lozenge", FALSE);
3187- break;
3188-
3189- case IPP_PRINTER_PROCESSING: {
3190- gchar *jobstr = g_strdup_printf ("%d", njobs);
3191- dbusmenu_menuitem_property_set (item, "indicator-right", jobstr);
3192- dbusmenu_menuitem_property_set_bool (item, "indicator-right-is-lozenge", TRUE);
3193- g_free (jobstr);
3194- break;
3195- }
3196- }
3197-}
3198-
3199-
3200-static void
3201-update_all_printer_menuitems (IndicatorPrintersMenu *self)
3202-{
3203- int ndests, i;
3204- cups_dest_t *dests;
3205-
3206- ndests = cupsGetDests (&dests);
3207- for (i = 0; i < ndests; i++) {
3208- int state = atoi (cupsGetOption ("printer-state",
3209- dests[i].num_options,
3210- dests[i].options));
3211- update_printer_menuitem (self, dests[i].name, state);
3212- }
3213- cupsFreeDests (ndests, dests);
3214-}
3215-
3216-
3217-static void
3218-update_job (CupsNotifier *cups_notifier,
3219- const gchar *text,
3220- const gchar *printer_uri,
3221- const gchar *printer_name,
3222- guint printer_state,
3223- const gchar *printer_state_reasons,
3224- gboolean printer_is_accepting_jobs,
3225- guint job_id,
3226- guint job_state,
3227- const gchar *job_state_reasons,
3228- const gchar *job_name,
3229- guint job_impressions_completed,
3230- gpointer user_data)
3231-{
3232- IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (user_data);
3233-
3234- /* CUPS doesn't send the printer's name for these events. Update all menu
3235- * items as a temporary workaround */
3236- if (job_state == IPP_JOB_CANCELLED ||
3237- job_state == IPP_JOB_ABORTED ||
3238- job_state == IPP_JOB_COMPLETED)
3239- update_all_printer_menuitems (self);
3240- else
3241- update_printer_menuitem (self, printer_name, printer_state);
3242-}
3243-
3244-
3245-static void
3246-on_printer_state_changed (CupsNotifier *object,
3247- const gchar *text,
3248- const gchar *printer_uri,
3249- const gchar *printer_name,
3250- guint printer_state,
3251- const gchar *printer_state_reasons,
3252- gboolean printer_is_accepting_jobs,
3253- gpointer user_data)
3254-{
3255- IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (user_data);
3256-
3257- update_printer_menuitem (self, printer_name, printer_state);
3258-}
3259-
3260-
3261-static void
3262-indicator_printers_menu_init (IndicatorPrintersMenu *self)
3263-{
3264- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
3265- INDICATOR_TYPE_PRINTERS_MENU,
3266- IndicatorPrintersMenuPrivate);
3267-
3268- self->priv->root = dbusmenu_menuitem_new ();
3269- dbusmenu_menuitem_property_set_bool (self->priv->root, "visible", FALSE);
3270-
3271- self->priv->printers = g_hash_table_new_full (g_str_hash,
3272- g_str_equal,
3273- g_free,
3274- g_object_unref);
3275-
3276- /* create initial menu items */
3277- update_all_printer_menuitems (self);
3278-}
3279-
3280-
3281-IndicatorPrintersMenu *
3282-indicator_printers_menu_new (void)
3283-{
3284- return g_object_new (INDICATOR_TYPE_PRINTERS_MENU, NULL);
3285-}
3286-
3287-
3288-DbusmenuMenuitem *
3289-indicator_printers_menu_get_root (IndicatorPrintersMenu *self)
3290-{
3291- return self->priv->root;
3292-}
3293-
3294-
3295-CupsNotifier *
3296-indicator_printers_menu_get_cups_notifier (IndicatorPrintersMenu *self)
3297-{
3298- return self->priv->cups_notifier;
3299-}
3300-
3301-
3302-void
3303-indicator_printers_menu_set_cups_notifier (IndicatorPrintersMenu *self,
3304- CupsNotifier *cups_notifier)
3305-{
3306- if (self->priv->cups_notifier) {
3307- g_object_disconnect (self->priv->cups_notifier,
3308- "any-signal", update_job, self,
3309- "any-signal", on_printer_state_changed, self,
3310- NULL);
3311- g_clear_object (&self->priv->cups_notifier);
3312- }
3313-
3314- if (cups_notifier) {
3315- self->priv->cups_notifier = g_object_ref (cups_notifier);
3316- g_object_connect (self->priv->cups_notifier,
3317- "signal::job-created", update_job, self,
3318- "signal::job-state", update_job, self,
3319- "signal::job-completed", update_job, self,
3320- "signal::printer-state-changed", on_printer_state_changed, self,
3321- NULL);
3322- }
3323-}
3324-
3325
3326=== removed file 'src/indicator-printers-menu.h'
3327--- src/indicator-printers-menu.h 2012-02-12 13:20:44 +0000
3328+++ src/indicator-printers-menu.h 1970-01-01 00:00:00 +0000
3329@@ -1,77 +0,0 @@
3330-/*
3331- * Copyright 2012 Canonical Ltd.
3332- *
3333- * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
3334- *
3335- * This program is free software: you can redistribute it and/or modify it
3336- * under the terms of the GNU General Public License version 3, as published
3337- * by the Free Software Foundation.
3338- *
3339- * This program is distributed in the hope that it will be useful, but
3340- * WITHOUT ANY WARRANTY; without even the implied warranties of
3341- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
3342- * PURPOSE. See the GNU General Public License for more details.
3343- *
3344- * You should have received a copy of the GNU General Public License along
3345- * with this program. If not, see <http://www.gnu.org/licenses/>.
3346- */
3347-
3348-#ifndef INDICATOR_PRINTERS_MENU_H
3349-#define INDICATOR_PRINTERS_MENU_H
3350-
3351-#include <glib-object.h>
3352-#include <libdbusmenu-glib/dbusmenu-glib.h>
3353-
3354-#include "cups-notifier.h"
3355-
3356-G_BEGIN_DECLS
3357-
3358-#define INDICATOR_TYPE_PRINTERS_MENU indicator_printers_menu_get_type()
3359-
3360-#define INDICATOR_PRINTERS_MENU(obj) \
3361- (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
3362- INDICATOR_TYPE_PRINTERS_MENU, IndicatorPrintersMenu))
3363-
3364-#define INDICATOR_PRINTERS_MENU_CLASS(klass) \
3365- (G_TYPE_CHECK_CLASS_CAST ((klass), \
3366- INDICATOR_TYPE_PRINTERS_MENU, IndicatorPrintersMenuClass))
3367-
3368-#define INDICATOR_IS_PRINTERS_MENU(obj) \
3369- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
3370- INDICATOR_TYPE_PRINTERS_MENU))
3371-
3372-#define INDICATOR_IS_PRINTERS_MENU_CLASS(klass) \
3373- (G_TYPE_CHECK_CLASS_TYPE ((klass), \
3374- INDICATOR_TYPE_PRINTERS_MENU))
3375-
3376-#define INDICATOR_PRINTERS_MENU_GET_CLASS(obj) \
3377- (G_TYPE_INSTANCE_GET_CLASS ((obj), \
3378- INDICATOR_TYPE_PRINTERS_MENU, IndicatorPrintersMenuClass))
3379-
3380-typedef struct _IndicatorPrintersMenu IndicatorPrintersMenu;
3381-typedef struct _IndicatorPrintersMenuClass IndicatorPrintersMenuClass;
3382-typedef struct _IndicatorPrintersMenuPrivate IndicatorPrintersMenuPrivate;
3383-
3384-struct _IndicatorPrintersMenu
3385-{
3386- GObject parent;
3387- IndicatorPrintersMenuPrivate *priv;
3388-};
3389-
3390-struct _IndicatorPrintersMenuClass
3391-{
3392- GObjectClass parent_class;
3393-};
3394-
3395-GType indicator_printers_menu_get_type (void) G_GNUC_CONST;
3396-
3397-IndicatorPrintersMenu *indicator_printers_menu_new (void);
3398-DbusmenuMenuitem * indicator_printers_menu_get_root (IndicatorPrintersMenu *menu);
3399-CupsNotifier * indicator_printers_menu_get_cups_notifier (IndicatorPrintersMenu *self);
3400-void indicator_printers_menu_set_cups_notifier (IndicatorPrintersMenu *self,
3401- CupsNotifier *cups_notifier);
3402-
3403-G_END_DECLS
3404-
3405-#endif
3406-
3407
3408=== removed file 'src/indicator-printers-service.c'
3409--- src/indicator-printers-service.c 2014-05-15 11:13:15 +0000
3410+++ src/indicator-printers-service.c 1970-01-01 00:00:00 +0000
3411@@ -1,206 +0,0 @@
3412-/*
3413- * Copyright 2012 Canonical Ltd.
3414- *
3415- * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
3416- *
3417- * This program is free software: you can redistribute it and/or modify it
3418- * under the terms of the GNU General Public License version 3, as published
3419- * by the Free Software Foundation.
3420- *
3421- * This program is distributed in the hope that it will be useful, but
3422- * WITHOUT ANY WARRANTY; without even the implied warranties of
3423- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
3424- * PURPOSE. See the GNU General Public License for more details.
3425- *
3426- * You should have received a copy of the GNU General Public License along
3427- * with this program. If not, see <http://www.gnu.org/licenses/>.
3428- */
3429-
3430-#include <libindicator/indicator-service.h>
3431-#include <libdbusmenu-glib/dbusmenu-glib.h>
3432-#include <gtk/gtk.h>
3433-#include <cups/cups.h>
3434-#include "dbus-names.h"
3435-#include "config.h"
3436-
3437-#include "cups-notifier.h"
3438-#include "indicator-printers-menu.h"
3439-#include "indicator-printer-state-notifier.h"
3440-
3441-#define NOTIFY_LEASE_DURATION (24 * 60 * 60)
3442-
3443-
3444-static int
3445-create_subscription ()
3446-{
3447- ipp_t *req;
3448- ipp_t *resp;
3449- ipp_attribute_t *attr;
3450- int id = 0;
3451-
3452- req = ippNewRequest (IPP_CREATE_PRINTER_SUBSCRIPTION);
3453- ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI,
3454- "printer-uri", NULL, "/");
3455- ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD,
3456- "notify-events", NULL, "all");
3457- ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
3458- "notify-recipient-uri", NULL, "dbus://");
3459- ippAddInteger (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
3460- "notify-lease-duration", NOTIFY_LEASE_DURATION);
3461-
3462- resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
3463- if (!resp || cupsLastError() != IPP_OK) {
3464- g_warning ("Error subscribing to CUPS notifications: %s\n",
3465- cupsLastErrorString ());
3466- return 0;
3467- }
3468-
3469- attr = ippFindAttribute (resp, "notify-subscription-id", IPP_TAG_INTEGER);
3470- if (attr)
3471- id = ippGetInteger (attr, 0);
3472- else
3473- g_warning ("ipp-create-printer-subscription response doesn't contain "
3474- "subscription id.\n");
3475-
3476- ippDelete (resp);
3477- return id;
3478-}
3479-
3480-
3481-static gboolean
3482-renew_subscription (int id)
3483-{
3484- ipp_t *req;
3485- ipp_t *resp;
3486-
3487- req = ippNewRequest (IPP_RENEW_SUBSCRIPTION);
3488- ippAddInteger (req, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
3489- "notify-subscription-id", id);
3490- ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI,
3491- "printer-uri", NULL, "/");
3492- ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
3493- "notify-recipient-uri", NULL, "dbus://");
3494- ippAddInteger (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
3495- "notify-lease-duration", NOTIFY_LEASE_DURATION);
3496-
3497- resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
3498- if (!resp || cupsLastError() != IPP_OK) {
3499- g_warning ("Error renewing CUPS subscription %d: %s\n",
3500- id, cupsLastErrorString ());
3501- return FALSE;
3502- }
3503-
3504- ippDelete (resp);
3505- return TRUE;
3506-}
3507-
3508-
3509-static gboolean
3510-renew_subscription_timeout (gpointer userdata)
3511-{
3512- int *subscription_id = userdata;
3513-
3514- if (*subscription_id <= 0 || !renew_subscription (*subscription_id))
3515- *subscription_id = create_subscription ();
3516-
3517- return TRUE;
3518-}
3519-
3520-
3521-void
3522-cancel_subscription (int id)
3523-{
3524- ipp_t *req;
3525- ipp_t *resp;
3526-
3527- if (id <= 0)
3528- return;
3529-
3530- req = ippNewRequest (IPP_CANCEL_SUBSCRIPTION);
3531- ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI,
3532- "printer-uri", NULL, "/");
3533- ippAddInteger (req, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
3534- "notify-subscription-id", id);
3535-
3536- resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
3537- if (!resp || cupsLastError() != IPP_OK) {
3538- g_warning ("Error subscribing to CUPS notifications: %s\n",
3539- cupsLastErrorString ());
3540- return;
3541- }
3542-
3543- ippDelete (resp);
3544-}
3545-
3546-static void
3547-name_lost (GDBusConnection *connection,
3548- const gchar *name,
3549- gpointer user_data)
3550-{
3551- int subscription_id = GPOINTER_TO_INT (user_data);
3552-
3553- cancel_subscription (subscription_id);
3554- gtk_main_quit ();
3555-}
3556-
3557-int main (int argc, char *argv[])
3558-{
3559- /* Init i18n */
3560- setlocale (LC_ALL, "");
3561- bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
3562- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
3563- textdomain (GETTEXT_PACKAGE);
3564-
3565- DbusmenuServer *menuserver;
3566- CupsNotifier *cups_notifier;
3567- IndicatorPrintersMenu *menu;
3568- IndicatorPrinterStateNotifier *state_notifier;
3569- GError *error = NULL;
3570- int subscription_id;
3571-
3572- gtk_init (&argc, &argv);
3573-
3574- subscription_id = create_subscription ();
3575- g_timeout_add_seconds (NOTIFY_LEASE_DURATION - 60,
3576- renew_subscription_timeout,
3577- &subscription_id);
3578-
3579- g_bus_own_name (G_BUS_TYPE_SESSION,
3580- INDICATOR_PRINTERS_DBUS_NAME,
3581- G_BUS_NAME_OWNER_FLAGS_NONE,
3582- NULL, NULL, name_lost,
3583- GINT_TO_POINTER (subscription_id), NULL);
3584-
3585- cups_notifier = cups_notifier_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
3586- 0,
3587- NULL,
3588- CUPS_DBUS_PATH,
3589- NULL,
3590- &error);
3591- if (error) {
3592- g_warning ("Error creating cups notify handler: %s", error->message);
3593- g_error_free (error);
3594- return 1;
3595- }
3596-
3597- menu = g_object_new (INDICATOR_TYPE_PRINTERS_MENU,
3598- "cups-notifier", cups_notifier,
3599- NULL);
3600-
3601- menuserver = dbusmenu_server_new (INDICATOR_PRINTERS_DBUS_OBJECT_PATH);
3602- dbusmenu_server_set_root (menuserver,
3603- indicator_printers_menu_get_root (menu));
3604-
3605- state_notifier = g_object_new (INDICATOR_TYPE_PRINTER_STATE_NOTIFIER,
3606- "cups-notifier", cups_notifier,
3607- NULL);
3608-
3609- gtk_main ();
3610-
3611- g_object_unref (menu);
3612- g_object_unref (menuserver);
3613- g_object_unref (state_notifier);
3614- g_object_unref (cups_notifier);
3615- return 0;
3616-}
3617-
3618
3619=== removed file 'src/indicator-printers.c'
3620--- src/indicator-printers.c 2014-02-20 22:16:42 +0000
3621+++ src/indicator-printers.c 1970-01-01 00:00:00 +0000
3622@@ -1,311 +0,0 @@
3623-/*
3624- * Copyright 2012 Canonical Ltd.
3625- *
3626- * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
3627- *
3628- * This program is free software: you can redistribute it and/or modify it
3629- * under the terms of the GNU General Public License version 3, as published
3630- * by the Free Software Foundation.
3631- *
3632- * This program is distributed in the hope that it will be useful, but
3633- * WITHOUT ANY WARRANTY; without even the implied warranties of
3634- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
3635- * PURPOSE. See the GNU General Public License for more details.
3636- *
3637- * You should have received a copy of the GNU General Public License along
3638- * with this program. If not, see <http://www.gnu.org/licenses/>.
3639- */
3640-
3641-#include "config.h"
3642-
3643-#include "indicator-printers.h"
3644-#include "indicator-menu-item.h"
3645-#include "dbus-names.h"
3646-
3647-#include <glib/gi18n-lib.h>
3648-#include <gtk/gtk.h>
3649-#include <gio/gio.h>
3650-
3651-#include <libindicator/indicator.h>
3652-#include <libindicator/indicator-image-helper.h>
3653-
3654-#include <libdbusmenu-gtk/menu.h>
3655-#include <libdbusmenu-gtk/menuitem.h>
3656-
3657-
3658-INDICATOR_SET_VERSION
3659-INDICATOR_SET_TYPE(INDICATOR_PRINTERS_TYPE)
3660-
3661-
3662-G_DEFINE_TYPE (IndicatorPrinters, indicator_printers, INDICATOR_OBJECT_TYPE)
3663-
3664-
3665-struct _IndicatorPrintersPrivate
3666-{
3667- IndicatorObjectEntry entry;
3668- guint name_watch;
3669-};
3670-
3671-
3672-static void
3673-dispose (GObject *object)
3674-{
3675- IndicatorPrinters *self = INDICATOR_PRINTERS (object);
3676- if (self->priv->name_watch != 0) {
3677- g_bus_unwatch_name(self->priv->name_watch);
3678- self->priv->name_watch = 0;
3679- }
3680- g_clear_object (&self->priv->entry.menu);
3681- g_clear_object (&self->priv->entry.image);
3682- G_OBJECT_CLASS (indicator_printers_parent_class)->dispose (object);
3683-}
3684-
3685-
3686-static GList *
3687-get_entries (IndicatorObject *io)
3688-{
3689- IndicatorPrinters *self = INDICATOR_PRINTERS (io);
3690- return g_list_append (NULL, &self->priv->entry);
3691-}
3692-
3693-
3694-static void
3695-indicator_printers_class_init (IndicatorPrintersClass *klass)
3696-{
3697- GObjectClass *object_class = G_OBJECT_CLASS (klass);
3698- IndicatorObjectClass *io_class = INDICATOR_OBJECT_CLASS (klass);
3699-
3700- g_type_class_add_private (klass, sizeof (IndicatorPrintersPrivate));
3701-
3702- object_class->dispose = dispose;
3703-
3704- io_class->get_entries = get_entries;
3705-}
3706-
3707-
3708-static void
3709-name_vanished (GDBusConnection * con,
3710- const gchar * name,
3711- gpointer user_data)
3712-{
3713- IndicatorPrinters *self = INDICATOR_PRINTERS (user_data);
3714-
3715- indicator_object_set_visible (INDICATOR_OBJECT (self), FALSE);
3716-}
3717-
3718-
3719-static GdkPixbuf *
3720-gdk_pixbuf_new_from_encoded_data (guchar *data,
3721- gsize length)
3722-{
3723- GInputStream * input;
3724- GError *err = NULL;
3725- GdkPixbuf *img;
3726-
3727- input = g_memory_input_stream_new_from_data(data, length, NULL);
3728- if (input == NULL)
3729- return NULL;
3730-
3731- img = gdk_pixbuf_new_from_stream(input, NULL, &err);
3732- if (err) {
3733- g_warning("%s", err->message);
3734- g_error_free(err);
3735- }
3736-
3737- g_object_unref(input);
3738- return img;
3739-}
3740-
3741-
3742-static GdkPixbuf *
3743-g_variant_get_image (GVariant *value)
3744-{
3745- const gchar *strvalue = NULL;
3746- gsize length = 0;
3747- guchar *icondata;
3748- GdkPixbuf *img;
3749-
3750- if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
3751- strvalue = g_variant_get_string(value, NULL);
3752-
3753- if (!strvalue || !*strvalue) {
3754- g_warning ("%s: value does not contain a base64 encoded image",
3755- __func__);
3756- return NULL;
3757- }
3758-
3759- icondata = g_base64_decode(strvalue, &length);
3760- img = gdk_pixbuf_new_from_encoded_data (icondata, length);
3761-
3762- g_free(icondata);
3763- return img;
3764-}
3765-
3766-
3767-static gboolean
3768-properties_match (const gchar *name,
3769- const gchar *prop,
3770- GVariant *value,
3771- const GVariantType *type)
3772-{
3773- return !g_strcmp0 (name, prop) && g_variant_is_of_type (value, type);
3774-}
3775-
3776-
3777-static void
3778-indicator_prop_change_cb (DbusmenuMenuitem *mi,
3779- gchar *prop,
3780- GVariant *value,
3781- gpointer user_data)
3782-{
3783- IndicatorMenuItem *menuitem = user_data;
3784-
3785- if (properties_match (prop, "indicator-label", value, G_VARIANT_TYPE_STRING))
3786- indicator_menu_item_set_label (menuitem, g_variant_get_string (value, NULL));
3787-
3788- else if (properties_match (prop, "indicator-right", value, G_VARIANT_TYPE_STRING))
3789- indicator_menu_item_set_right (menuitem, g_variant_get_string (value, NULL));
3790-
3791- else if (properties_match (prop, "indicator-icon-name", value, G_VARIANT_TYPE_STRING))
3792- indicator_menu_item_set_icon_name (menuitem, g_variant_get_string (value, NULL));
3793-
3794- else if (properties_match (prop, "indicator-icon", value, G_VARIANT_TYPE_STRING)) {
3795- GdkPixbuf *pb = g_variant_get_image (value);
3796- indicator_menu_item_set_icon (menuitem, pb);
3797- g_object_unref (pb);
3798- }
3799-
3800- else if (properties_match (prop, "visible", value, G_VARIANT_TYPE_BOOLEAN))
3801- gtk_widget_set_visible (GTK_WIDGET (menuitem), g_variant_get_boolean (value));
3802-
3803- else if (properties_match (prop, "indicator-right-is-lozenge", value, G_VARIANT_TYPE_BOOLEAN))
3804- indicator_menu_item_set_right_is_lozenge (menuitem, g_variant_get_boolean (value));
3805-}
3806-
3807-
3808-static void
3809-root_property_changed (DbusmenuMenuitem *mi,
3810- gchar *prop,
3811- GVariant *value,
3812- gpointer user_data)
3813-{
3814- IndicatorObject *io = user_data;
3815-
3816- if (properties_match (prop, "visible", value, G_VARIANT_TYPE_BOOLEAN))
3817- indicator_object_set_visible (io, g_variant_get_boolean (value));
3818-}
3819-
3820-
3821-static gboolean
3822-new_indicator_item (DbusmenuMenuitem *newitem,
3823- DbusmenuMenuitem *parent,
3824- DbusmenuClient *client,
3825- gpointer user_data)
3826-{
3827- GtkWidget *menuitem;
3828- const gchar *icon_name, *text, *right_text;
3829- GVariant *icon;
3830- gboolean is_lozenge, visible;
3831-
3832- icon_name = dbusmenu_menuitem_property_get (newitem, "indicator-icon-name");
3833- icon = dbusmenu_menuitem_property_get_variant (newitem, "indicator-icon");
3834- text = dbusmenu_menuitem_property_get (newitem, "indicator-label");
3835- right_text = dbusmenu_menuitem_property_get (newitem, "indicator-right");
3836- is_lozenge = dbusmenu_menuitem_property_get_bool (newitem, "indicator-right-is-lozenge");
3837- visible = dbusmenu_menuitem_property_get_bool (newitem, "visible");
3838-
3839- menuitem = g_object_new (INDICATOR_TYPE_MENU_ITEM,
3840- "icon-name", icon_name,
3841- "label", text,
3842- "right", right_text,
3843- "right-is-lozenge", is_lozenge,
3844- "visible", visible,
3845- NULL);
3846- if (icon) {
3847- GdkPixbuf *pb = g_variant_get_image (icon);
3848- indicator_menu_item_set_icon (INDICATOR_MENU_ITEM (menuitem), pb);
3849- g_object_unref (pb);
3850- }
3851- gtk_widget_show_all (menuitem);
3852-
3853- dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client),
3854- newitem,
3855- GTK_MENU_ITEM (menuitem),
3856- parent);
3857-
3858- g_signal_connect(G_OBJECT(newitem),
3859- "property-changed",
3860- G_CALLBACK(indicator_prop_change_cb),
3861- menuitem);
3862-
3863- return TRUE;
3864-}
3865-
3866-
3867-static void
3868-root_changed (DbusmenuClient *client,
3869- DbusmenuMenuitem *newroot,
3870- gpointer user_data)
3871-{
3872- IndicatorPrinters *indicator = user_data;
3873- gboolean is_visible;
3874-
3875- if (newroot) {
3876- is_visible = dbusmenu_menuitem_property_get_bool (newroot, "visible");
3877- g_signal_connect (newroot, "property-changed",
3878- G_CALLBACK (root_property_changed), indicator);
3879- }
3880- else
3881- is_visible = FALSE;
3882-
3883- indicator_object_set_visible (INDICATOR_OBJECT (indicator), is_visible);
3884-}
3885-
3886-
3887-static void
3888-indicator_printers_init (IndicatorPrinters *self)
3889-{
3890- IndicatorPrintersPrivate *priv;
3891- DbusmenuGtkMenu *menu;
3892- DbusmenuClient *client;
3893- GtkImage *image;
3894-
3895- priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
3896- INDICATOR_PRINTERS_TYPE,
3897- IndicatorPrintersPrivate);
3898- self->priv = priv;
3899-
3900- priv->name_watch = g_bus_watch_name(G_BUS_TYPE_SESSION,
3901- INDICATOR_PRINTERS_DBUS_NAME,
3902- G_BUS_NAME_WATCHER_FLAGS_NONE,
3903- NULL, /* appeared */
3904- name_vanished,
3905- self, NULL);
3906-
3907- menu = dbusmenu_gtkmenu_new(INDICATOR_PRINTERS_DBUS_NAME,
3908- INDICATOR_PRINTERS_DBUS_OBJECT_PATH);
3909-
3910- client = DBUSMENU_CLIENT (dbusmenu_gtkmenu_get_client (menu));
3911- dbusmenu_client_add_type_handler(client,
3912- "indicator-item",
3913- new_indicator_item);
3914- g_signal_connect (client, "root-changed", G_CALLBACK (root_changed), self);
3915-
3916- image = indicator_image_helper ("printer-symbolic");
3917- gtk_widget_show (GTK_WIDGET (image));
3918-
3919- priv->entry.name_hint = PACKAGE_NAME;
3920- priv->entry.accessible_desc = _("Printers");
3921- priv->entry.menu = GTK_MENU (g_object_ref_sink (menu));
3922- priv->entry.image = g_object_ref_sink (image);
3923-
3924- indicator_object_set_visible (INDICATOR_OBJECT (self), FALSE);
3925-}
3926-
3927-
3928-IndicatorPrinters *
3929-indicator_printers_new (void)
3930-{
3931- return g_object_new (INDICATOR_PRINTERS_TYPE, NULL);
3932-}
3933-
3934
3935=== removed file 'src/indicator-printers.h'
3936--- src/indicator-printers.h 2012-02-03 13:39:34 +0000
3937+++ src/indicator-printers.h 1970-01-01 00:00:00 +0000
3938@@ -1,70 +0,0 @@
3939-/*
3940- * Copyright 2012 Canonical Ltd.
3941- *
3942- * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
3943- *
3944- * This program is free software: you can redistribute it and/or modify it
3945- * under the terms of the GNU General Public License version 3, as published
3946- * by the Free Software Foundation.
3947- *
3948- * This program is distributed in the hope that it will be useful, but
3949- * WITHOUT ANY WARRANTY; without even the implied warranties of
3950- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
3951- * PURPOSE. See the GNU General Public License for more details.
3952- *
3953- * You should have received a copy of the GNU General Public License along
3954- * with this program. If not, see <http://www.gnu.org/licenses/>.
3955- */
3956-
3957-#ifndef INDICATOR_PRINTERS_H
3958-#define INDICATOR_PRINTERS_H
3959-
3960-#include <libindicator/indicator-object.h>
3961-
3962-G_BEGIN_DECLS
3963-
3964-#define INDICATOR_PRINTERS_TYPE indicator_printers_get_type()
3965-
3966-#define INDICATOR_PRINTERS(obj) \
3967- (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
3968- INDICATOR_PRINTERS_TYPE, IndicatorPrinters))
3969-
3970-#define INDICATOR_PRINTERS_CLASS(klass) \
3971- (G_TYPE_CHECK_CLASS_CAST ((klass), \
3972- INDICATOR_PRINTERS_TYPE, IndicatorPrintersClass))
3973-
3974-#define INDICATOR_IS_PRINTERS(obj) \
3975- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
3976- INDICATOR_PRINTERS_TYPE))
3977-
3978-#define INDICATOR_IS_PRINTERS_CLASS(klass) \
3979- (G_TYPE_CHECK_CLASS_TYPE ((klass), \
3980- INDICATOR_PRINTERS_TYPE))
3981-
3982-#define INDICATOR_PRINTERS_GET_CLASS(obj) \
3983- (G_TYPE_INSTANCE_GET_CLASS ((obj), \
3984- INDICATOR_PRINTERS_TYPE, IndicatorPrintersClass))
3985-
3986-typedef struct _IndicatorPrinters IndicatorPrinters;
3987-typedef struct _IndicatorPrintersClass IndicatorPrintersClass;
3988-typedef struct _IndicatorPrintersPrivate IndicatorPrintersPrivate;
3989-
3990-struct _IndicatorPrinters
3991-{
3992- IndicatorObject parent;
3993- IndicatorPrintersPrivate *priv;
3994-};
3995-
3996-struct _IndicatorPrintersClass
3997-{
3998- IndicatorObjectClass parent_class;
3999-};
4000-
4001-GType indicator_printers_get_type (void) G_GNUC_CONST;
4002-
4003-IndicatorPrinters *indicator_printers_new (void);
4004-
4005-G_END_DECLS
4006-
4007-#endif
4008-
4009
4010=== added file 'src/job.h'
4011--- src/job.h 1970-01-01 00:00:00 +0000
4012+++ src/job.h 2017-01-10 21:54:44 +0000
4013@@ -0,0 +1,50 @@
4014+/*
4015+ * Copyright 2016-2017 Canonical Ltd.
4016+ *
4017+ * This program is free software: you can redistribute it and/or modify it
4018+ * under the terms of the GNU General Public License version 3, as published
4019+ * by the Free Software Foundation.
4020+ *
4021+ * This program is distributed in the hope that it will be useful, but
4022+ * WITHOUT ANY WARRANTY; without even the implied warranties of
4023+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
4024+ * PURPOSE. See the GNU General Public License for more details.
4025+ *
4026+ * You should have received a copy of the GNU General Public License along
4027+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4028+ */
4029+
4030+#pragma once
4031+
4032+#include "printer.h"
4033+
4034+#include <string>
4035+
4036+namespace unity {
4037+namespace indicator {
4038+namespace printers {
4039+
4040+ struct Job {
4041+ // State to match ipp_jstate_t from cups.h
4042+ typedef enum {
4043+ PENDING = 3,
4044+ HELD,
4045+ PROCESSING,
4046+ STOPPED,
4047+ CANCELED,
4048+ ABORTED,
4049+ COMPLETED
4050+ } State;
4051+ State state = PENDING;
4052+
4053+ uint32_t id = 0;
4054+ std::string name;
4055+ std::string state_reasons;
4056+ uint32_t impressions_completed = 0;
4057+
4058+ Printer printer;
4059+ };
4060+
4061+} // printers
4062+} // indicators
4063+} // unity
4064
4065=== added file 'src/main.cpp'
4066--- src/main.cpp 1970-01-01 00:00:00 +0000
4067+++ src/main.cpp 2017-01-10 21:54:44 +0000
4068@@ -0,0 +1,60 @@
4069+/*
4070+ * Copyright 2016-2017 Canonical Ltd.
4071+ *
4072+ * This program is free software: you can redistribute it and/or modify it
4073+ * under the terms of the GNU General Public License version 3, as published
4074+ * by the Free Software Foundation.
4075+ *
4076+ * This program is distributed in the hope that it will be useful, but
4077+ * WITHOUT ANY WARRANTY; without even the implied warranties of
4078+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
4079+ * PURPOSE. See the GNU General Public License for more details.
4080+ *
4081+ * You should have received a copy of the GNU General Public License along
4082+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4083+ */
4084+
4085+#include "actions-live.h"
4086+#include "cups-client.h"
4087+#include "exporter.h"
4088+#include "utils.h"
4089+
4090+#include <glib/gi18n.h>
4091+#include <gio/gio.h>
4092+
4093+using namespace unity::indicator::printers;
4094+
4095+int main() {
4096+ // Work around a deadlock in glib's type initialization.
4097+ // It can be removed when https://bugzilla.gnome.org/show_bug.cgi?id=674885 is fixed.
4098+ g_type_ensure(G_TYPE_DBUS_CONNECTION);
4099+
4100+ // boilerplate i18n
4101+ setlocale(LC_ALL, "");
4102+
4103+ // Need to prepend $SNAP to properly load translations
4104+ auto localedir = Utilities::prepend_snap_path(GETTEXT_LOCALEDIR);
4105+ bindtextdomain(GETTEXT_PACKAGE, localedir.c_str());
4106+ textdomain(GETTEXT_PACKAGE);
4107+
4108+ // set up us the machine
4109+ auto loop = g_main_loop_new(nullptr, false);
4110+
4111+ // create the menus
4112+ auto actions = std::make_shared<LiveActions>();
4113+ auto client = std::make_shared<CupsClient>();
4114+
4115+ // export them & run until we lose the busname
4116+ Exporter exporter;
4117+ exporter.name_lost().connect([loop](){
4118+ g_message("%s exiting; failed/lost bus ownership", GETTEXT_PACKAGE);
4119+ g_main_loop_quit(loop);
4120+ });
4121+ exporter.publish(actions, client);
4122+
4123+ g_main_loop_run(loop);
4124+
4125+ // cleanup
4126+ g_main_loop_unref(loop);
4127+ return 0;
4128+}
4129
4130=== added file 'src/menu.cpp'
4131--- src/menu.cpp 1970-01-01 00:00:00 +0000
4132+++ src/menu.cpp 2017-01-10 21:54:44 +0000
4133@@ -0,0 +1,291 @@
4134+/*
4135+ * Copyright 2016-2017 Canonical Ltd.
4136+ *
4137+ * This program is free software: you can redistribute it and/or modify it
4138+ * under the terms of the GNU General Public License version 3, as published
4139+ * by the Free Software Foundation.
4140+ *
4141+ * This program is distributed in the hope that it will be useful, but
4142+ * WITHOUT ANY WARRANTY; without even the implied warranties of
4143+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
4144+ * PURPOSE. See the GNU General Public License for more details.
4145+ *
4146+ * You should have received a copy of the GNU General Public License along
4147+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4148+ */
4149+
4150+#include "menu.h"
4151+
4152+#include <glib/gi18n.h>
4153+#include <gio/gio.h>
4154+
4155+#include <algorithm>
4156+#include <iterator>
4157+#include <map>
4158+
4159+namespace unity {
4160+namespace indicator {
4161+namespace printers {
4162+
4163+
4164+class Menu::Impl
4165+{
4166+public:
4167+
4168+ static constexpr char const * ATTRIBUTE_JOB_ID {"x-canonical-job-id"};
4169+ static constexpr char const * ATTRIBUTE_TYPE {"x-canonical-type"};
4170+ static constexpr char const * TYPE_SECTION {"section"};
4171+
4172+ enum Section {
4173+ CURRENT,
4174+ QUEUED,
4175+ PAUSED,
4176+ NUM_SECTIONS
4177+ };
4178+
4179+ Impl(const std::shared_ptr<Actions>& actions,
4180+ const std::shared_ptr<Client>& client):
4181+ m_actions(actions),
4182+ m_client(client)
4183+ {
4184+ // initialize the menu
4185+ create_gmenu();
4186+ update_header();
4187+
4188+ m_client->job_state_changed().connect([this](const Job& job) {
4189+ const auto printer = job.printer;
4190+ g_debug("State changed for job %u '%s` on printer '%s'",
4191+ job.id,
4192+ job.name.c_str(),
4193+ printer.description.empty() ? printer.name.c_str() : printer.description.c_str());
4194+
4195+ // Remove any existing menu item for the job.
4196+ remove(job);
4197+
4198+ Section section = NUM_SECTIONS;
4199+ switch (job.state) {
4200+ case Job::State::PENDING:
4201+ section = QUEUED;
4202+ break;
4203+ case Job::State::HELD:
4204+ section = PAUSED;
4205+ break;
4206+ case Job::State::PROCESSING:
4207+ section = CURRENT;
4208+ break;
4209+ case Job::State::STOPPED:
4210+ case Job::State::CANCELED:
4211+ case Job::State::ABORTED:
4212+ case Job::State::COMPLETED:
4213+ update_header();
4214+ return;
4215+ }
4216+
4217+ auto model = menu_model_for_section(section);
4218+ if (model != nullptr) {
4219+ auto item = create_job_menu_item(job);
4220+ g_menu_append_item(G_MENU(model), item);
4221+ g_object_unref(item);
4222+ m_current_jobs[job.id] = section;
4223+ }
4224+
4225+ update_header();
4226+ });
4227+ }
4228+
4229+ virtual ~Impl()
4230+ {
4231+ g_clear_object(&m_menu);
4232+ }
4233+
4234+ void update_header()
4235+ {
4236+ auto action_group = m_actions->action_group();
4237+ std::string action_name{"printers"};
4238+ auto state = create_header_state();
4239+ g_action_group_change_action_state(action_group,
4240+ action_name.c_str(),
4241+ state);
4242+ }
4243+
4244+ GVariant* get_serialized_icon(const std::string& icon_name)
4245+ {
4246+ auto icon = g_themed_icon_new_with_default_fallbacks(icon_name.c_str());
4247+ auto ret = g_icon_serialize(icon);
4248+ g_object_unref(icon);
4249+
4250+ return ret;
4251+ }
4252+
4253+ GVariant* create_header_state()
4254+ {
4255+ auto title_v = g_variant_new_string(_("Printing"));
4256+ const bool visible = !m_current_jobs.empty();
4257+ GVariantBuilder b;
4258+ g_variant_builder_init(&b, G_VARIANT_TYPE_VARDICT);
4259+ g_variant_builder_add(&b, "{sv}", "title", title_v);
4260+ g_variant_builder_add(&b, "{sv}", "accessible-desc", title_v);
4261+ g_variant_builder_add(&b, "{sv}", "icon", get_serialized_icon("printer-symbolic"));
4262+ g_variant_builder_add(&b, "{sv}", "visible", g_variant_new_boolean(visible));
4263+ return g_variant_builder_end(&b);
4264+ }
4265+
4266+ GMenuModel* menu_model()
4267+ {
4268+ return G_MENU_MODEL(m_menu);
4269+ }
4270+
4271+ GMenuModel* menu_model_for_section(Section section)
4272+ {
4273+ return g_menu_model_get_item_link(G_MENU_MODEL(m_submenu),
4274+ section,
4275+ G_MENU_LINK_SECTION);
4276+ }
4277+
4278+ void remove(const Job& job)
4279+ {
4280+ Section section = NUM_SECTIONS;
4281+ if(get_current_section_for_job(job, section)) {
4282+ auto model = menu_model_for_section(section);
4283+ auto value = g_variant_new_uint32(job.id);
4284+ auto pos = find_matching_menu_item(model, ATTRIBUTE_JOB_ID, value);
4285+
4286+ if (pos >= 0) {
4287+ g_menu_remove(G_MENU(model), pos);
4288+ m_current_jobs.erase(job.id);
4289+ }
4290+ }
4291+ }
4292+
4293+private:
4294+ std::shared_ptr<Actions> m_actions;
4295+ std::shared_ptr<Client> m_client;
4296+ std::map<uint32_t, Section> m_current_jobs;
4297+
4298+ GMenu* m_submenu = nullptr;
4299+ GMenu* m_menu = nullptr;
4300+
4301+ static GMenuItem* create_section_menu_item(const Section& section)
4302+ {
4303+ const char* label;
4304+ switch (section) {
4305+ case CURRENT:
4306+ label = _("Current jobs");
4307+ break;
4308+ case QUEUED:
4309+ label = _("Queued jobs");
4310+ break;
4311+ case PAUSED:
4312+ label = _("Paused jobs");
4313+ break;
4314+ default:
4315+ g_warning("Request for section title of unknown section: %u",
4316+ static_cast<uint32_t>(section));
4317+ return nullptr;
4318+ }
4319+
4320+ // create a new item
4321+ auto item = g_menu_item_new(label, "indicator.section");
4322+ g_menu_item_set_attribute(item, ATTRIBUTE_TYPE, "s", TYPE_SECTION);
4323+
4324+ return item;
4325+ }
4326+
4327+ // Create the GMenuItem for the job.
4328+ static GMenuItem* create_job_menu_item(const Job& job)
4329+ {
4330+ auto menu_item = g_menu_item_new(job.name.c_str(), nullptr);
4331+ g_menu_item_set_attribute(menu_item, ATTRIBUTE_JOB_ID, "u", job.id);
4332+
4333+ return menu_item;
4334+ }
4335+
4336+ // find the position of the menumodel's item with the specified attribute
4337+ static int find_matching_menu_item(GMenuModel* mm, const char* attr,
4338+ GVariant* value)
4339+ {
4340+ g_return_val_if_fail(value != nullptr, -1);
4341+
4342+ for (int i = 0, n = g_menu_model_get_n_items(mm); i < n; ++i) {
4343+ auto test = g_menu_model_get_item_attribute_value(mm,
4344+ i,
4345+ attr,
4346+ nullptr);
4347+ const bool equal = g_variant_equal(value, test);
4348+ g_clear_pointer(&test, g_variant_unref);
4349+ if (equal) {
4350+ return i;
4351+ }
4352+ }
4353+
4354+ return -1;
4355+ }
4356+
4357+ bool get_current_section_for_job(const Job& job, Section& section) const
4358+ {
4359+ const auto it = m_current_jobs.find(job.id);
4360+ if (it == m_current_jobs.end()) {
4361+ return false;
4362+ }
4363+
4364+ section = it->second;
4365+ return true;
4366+ }
4367+
4368+ void create_gmenu()
4369+ {
4370+ g_assert(m_submenu == nullptr);
4371+
4372+ // build the submenu
4373+ m_submenu = g_menu_new();
4374+ for(int i = 0; i < NUM_SECTIONS; i++) {
4375+ // Create the section menu
4376+ auto section = g_menu_new();
4377+ g_menu_append_section(m_submenu, nullptr, G_MENU_MODEL(section));
4378+
4379+ // Add the label menuitem for the section
4380+ auto item = create_section_menu_item(static_cast<Section>(i));
4381+ if (item != nullptr) {
4382+ g_menu_insert_item(section, 0, item);
4383+ g_clear_object(&item);
4384+ }
4385+
4386+ g_object_unref(section);
4387+ }
4388+
4389+ // add submenu to the header
4390+ const std::string detailed_action{"indicator.printers"};
4391+ auto header = g_menu_item_new(nullptr, detailed_action.c_str());
4392+ g_menu_item_set_attribute(header, "x-canonical-type", "s",
4393+ "com.canonical.indicator.root");
4394+ g_menu_item_set_submenu(header, G_MENU_MODEL(m_submenu));
4395+ g_object_unref(m_submenu);
4396+
4397+ // add header to the menu
4398+ m_menu = g_menu_new();
4399+ g_menu_append_item(m_menu, header);
4400+ g_object_unref(header);
4401+ }
4402+
4403+
4404+}; // class MenuImpl
4405+
4406+
4407+Menu::Menu(const std::shared_ptr<Actions>& actions,
4408+ const std::shared_ptr<Client>& client):
4409+ p(new Impl(actions, client))
4410+{
4411+}
4412+
4413+Menu::~Menu()
4414+{
4415+}
4416+
4417+GMenuModel* Menu::menu_model()
4418+{
4419+ return p->menu_model();
4420+}
4421+
4422+} // namespace printers
4423+} // namespace indicator
4424+} // namespace unity
4425
4426=== added file 'src/menu.h'
4427--- src/menu.h 1970-01-01 00:00:00 +0000
4428+++ src/menu.h 2017-01-10 21:54:44 +0000
4429@@ -0,0 +1,57 @@
4430+/*
4431+ * Copyright 2016-2017 Canonical Ltd.
4432+ *
4433+ * This program is free software: you can redistribute it and/or modify it
4434+ * under the terms of the GNU General Public License version 3, as published
4435+ * by the Free Software Foundation.
4436+ *
4437+ * This program is distributed in the hope that it will be useful, but
4438+ * WITHOUT ANY WARRANTY; without even the implied warranties of
4439+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
4440+ * PURPOSE. See the GNU General Public License for more details.
4441+ *
4442+ * You should have received a copy of the GNU General Public License along
4443+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4444+ */
4445+
4446+#pragma once
4447+
4448+#include "actions.h"
4449+#include "client.h"
4450+
4451+#include <memory> // std::shared_ptr
4452+#include <vector>
4453+
4454+#include <gio/gio.h> // GMenuModel
4455+
4456+namespace unity {
4457+namespace indicator {
4458+namespace printers {
4459+
4460+/**
4461+ * \brief A menu for a specific profile; eg, Desktop or Phone.
4462+ *
4463+ * @see MenuFactory
4464+ * @see Exporter
4465+ */
4466+class Menu
4467+{
4468+public:
4469+ Menu(const std::shared_ptr<Actions>& actions,
4470+ const std::shared_ptr<Client>& client);
4471+ virtual ~Menu();
4472+
4473+ GMenuModel* menu_model();
4474+
4475+private:
4476+ class Impl;
4477+ std::unique_ptr<Impl> p;
4478+
4479+ // disable copying
4480+ Menu(const Menu&) = delete;
4481+ Menu& operator=(const Menu&) = delete;
4482+};
4483+
4484+} // namespace printers
4485+} // namespace indicator
4486+} // namespace unity
4487
4488=== added file 'src/printer.h'
4489--- src/printer.h 1970-01-01 00:00:00 +0000
4490+++ src/printer.h 2017-01-10 21:54:44 +0000
4491@@ -0,0 +1,44 @@
4492+/*
4493+ * Copyright 2016-2017 Canonical Ltd.
4494+ *
4495+ * This program is free software: you can redistribute it and/or modify it
4496+ * under the terms of the GNU General Public License version 3, as published
4497+ * by the Free Software Foundation.
4498+ *
4499+ * This program is distributed in the hope that it will be useful, but
4500+ * WITHOUT ANY WARRANTY; without even the implied warranties of
4501+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
4502+ * PURPOSE. See the GNU General Public License for more details.
4503+ *
4504+ * You should have received a copy of the GNU General Public License along
4505+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4506+ */
4507+
4508+#pragma once
4509+
4510+#include <string>
4511+
4512+namespace unity {
4513+namespace indicator {
4514+namespace printers {
4515+
4516+ struct Printer {
4517+ // State to match ipp_jstate_t from cups.h
4518+ typedef enum {
4519+ IDLE = 3,
4520+ PROCESSING,
4521+ STOPPED
4522+ } State;
4523+ State state = IDLE;
4524+
4525+ std::string name;
4526+ std::string description;
4527+ std::string text;
4528+ std::string uri;
4529+ std::string state_reasons;
4530+ bool accepting_jobs = false;
4531+ };
4532+
4533+} // printers
4534+} // indicators
4535+} // unity
4536
4537=== removed file 'src/spawn-printer-settings.c'
4538--- src/spawn-printer-settings.c 2012-02-15 10:40:19 +0000
4539+++ src/spawn-printer-settings.c 1970-01-01 00:00:00 +0000
4540@@ -1,35 +0,0 @@
4541-
4542-#include "spawn-printer-settings.h"
4543-
4544-void
4545-spawn_printer_settings ()
4546-{
4547- spawn_printer_settings_with_args (NULL);
4548-}
4549-
4550-
4551-void
4552-spawn_printer_settings_with_args (const gchar *fmt,
4553- ...)
4554-{
4555- GString *cmdline;
4556- GError *err = NULL;
4557-
4558- cmdline = g_string_new ("system-config-printer ");
4559-
4560- if (fmt) {
4561- va_list args;
4562- va_start (args, fmt);
4563- g_string_append_vprintf (cmdline, fmt, args);
4564- va_end (args);
4565- }
4566-
4567- g_spawn_command_line_async (cmdline->str, &err);
4568- if (err) {
4569- g_warning ("Could not spawn printer settings: %s", err->message);
4570- g_error_free (err);
4571- }
4572-
4573- g_string_free (cmdline, TRUE);
4574-}
4575-
4576
4577=== removed file 'src/spawn-printer-settings.h'
4578--- src/spawn-printer-settings.h 2012-02-12 13:58:57 +0000
4579+++ src/spawn-printer-settings.h 1970-01-01 00:00:00 +0000
4580@@ -1,11 +0,0 @@
4581-
4582-#ifndef SPAWN_PRINTER_SETTINGS_H
4583-#define SPAWN_PRINTER_SETTINGS_H
4584-
4585-#include <glib.h>
4586-
4587-void spawn_printer_settings ();
4588-void spawn_printer_settings_with_args (const gchar *args, ...);
4589-
4590-#endif
4591-
4592
4593=== added file 'src/utils.cpp'
4594--- src/utils.cpp 1970-01-01 00:00:00 +0000
4595+++ src/utils.cpp 2017-01-10 21:54:44 +0000
4596@@ -0,0 +1,37 @@
4597+/*
4598+ * Copyright 2016-2017 Canonical Ltd.
4599+ *
4600+ * This program is free software: you can redistribute it and/or modify it
4601+ * under the terms of the GNU General Public License version 3, as published
4602+ * by the Free Software Foundation.
4603+ *
4604+ * This program is distributed in the hope that it will be useful, but
4605+ * WITHOUT ANY WARRANTY; without even the implied warranties of
4606+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
4607+ * PURPOSE. See the GNU General Public License for more details.
4608+ *
4609+ * You should have received a copy of the GNU General Public License along
4610+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4611+ */
4612+
4613+#include "utils.h"
4614+
4615+namespace unity {
4616+namespace indicator {
4617+namespace printers {
4618+
4619+std::string Utilities::prepend_snap_path(const std::string& path)
4620+{
4621+ auto get_snap_path = []() {
4622+ const char* env_snap = getenv("SNAP");
4623+ if (env_snap == nullptr) {
4624+ return "";
4625+ }
4626+ return env_snap;
4627+ };
4628+ return get_snap_path() + path;
4629+}
4630+
4631+} // printers
4632+} // indicators
4633+} // unity
4634
4635=== added file 'src/utils.h'
4636--- src/utils.h 1970-01-01 00:00:00 +0000
4637+++ src/utils.h 2017-01-10 21:54:44 +0000
4638@@ -0,0 +1,32 @@
4639+/*
4640+ * Copyright 2016-2017 Canonical Ltd.
4641+ *
4642+ * This program is free software: you can redistribute it and/or modify it
4643+ * under the terms of the GNU General Public License version 3, as published
4644+ * by the Free Software Foundation.
4645+ *
4646+ * This program is distributed in the hope that it will be useful, but
4647+ * WITHOUT ANY WARRANTY; without even the implied warranties of
4648+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
4649+ * PURPOSE. See the GNU General Public License for more details.
4650+ *
4651+ * You should have received a copy of the GNU General Public License along
4652+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4653+ */
4654+
4655+#pragma once
4656+
4657+#include <string>
4658+
4659+namespace unity {
4660+namespace indicator {
4661+namespace printers {
4662+
4663+ class Utilities {
4664+ public:
4665+ static std::string prepend_snap_path(const std::string& path);
4666+ };
4667+
4668+} // printers
4669+} // indicators
4670+} // unity
4671
4672=== removed directory 'test'
4673=== removed file 'test/Makefile.am'
4674--- test/Makefile.am 2012-02-16 18:45:24 +0000
4675+++ test/Makefile.am 1970-01-01 00:00:00 +0000
4676@@ -1,29 +0,0 @@
4677-
4678-noinst_PROGRAMS = mock-cups-notifier
4679-DISTCLEANFILES = mock-cups-notifier
4680-
4681-cups_notifier_sources = \
4682- cups-notifier.c \
4683- cups-notifier.h
4684-
4685-$(cups_notifier_sources): $(top_srcdir)/src/org.cups.cupsd.Notifier.xml
4686- gdbus-codegen \
4687- --interface-prefix org.cups.cupsd \
4688- --c-namespace Cups \
4689- --generate-c-code cups-notifier \
4690- $^
4691-
4692-mock_cups_notifier_SOURCES = \
4693- mock-cups-notifier.c
4694-
4695-nodist_mock_cups_notifier_SOURCES = $(cups_notifier_sources)
4696-
4697-mock_cups_notifier_CPPFLAGS = \
4698- $(SERVICE_CFLAGS) \
4699- -I$(top_builddir)/src
4700-
4701-mock_cups_notifier_LDADD = $(SERVICE_LIBS)
4702-
4703-BUILT_SOURCES = $(cups_notifier_sources)
4704-CLEANFILES = $(BUILT_SOURCES)
4705-
4706
4707=== removed file 'test/mock-cups-notifier.c'
4708--- test/mock-cups-notifier.c 2012-02-09 17:19:57 +0000
4709+++ test/mock-cups-notifier.c 1970-01-01 00:00:00 +0000
4710@@ -1,52 +0,0 @@
4711-
4712-#include <glib.h>
4713-#include <cups-notifier.h>
4714-
4715-
4716-int main (int argc, char **argv)
4717-{
4718- GMainLoop *loop;
4719- CupsNotifier *notifier;
4720- GDBusConnection *con;
4721- GError *error = NULL;
4722-
4723- g_type_init ();
4724-
4725- loop = g_main_loop_new (NULL, FALSE);
4726-
4727- con = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
4728- if (error) {
4729- g_printerr ("Error getting system bus: %s\n", error->message);
4730- g_error_free (error);
4731- goto out;
4732- }
4733-
4734- notifier = cups_notifier_skeleton_new ();
4735-
4736- g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (notifier),
4737- con,
4738- "/org/cups/cupsd/Notifier",
4739- &error);
4740- if (error) {
4741- g_printerr ("Error exporting cups Notifier object: %s\n", error->message);
4742- g_error_free (error);
4743- goto out;
4744- }
4745-
4746- cups_notifier_emit_printer_state_changed (notifier,
4747- "Printer state changed!",
4748- "file:///tmp/print",
4749- "hp-LaserJet-1012",
4750- 5,
4751- "toner-low",
4752- FALSE);
4753-
4754- g_main_context_iteration (NULL, FALSE);
4755-
4756-out:
4757- g_clear_object (&notifier);
4758- g_clear_object (&con);
4759- g_main_loop_unref (loop);
4760- return 0;
4761-}
4762-
4763
4764=== added directory 'tests'
4765=== added file 'tests/CMakeLists.txt'
4766--- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
4767+++ tests/CMakeLists.txt 2017-01-10 21:54:44 +0000
4768@@ -0,0 +1,26 @@
4769+find_package(GMock REQUIRED)
4770+
4771+include_directories(
4772+ ${CMAKE_SOURCE_DIR}/src
4773+ ${SERVICE_DEPS_INCLUDE_DIRS}
4774+)
4775+link_directories(
4776+ ${SERVICE_DEPS_LIBRARY_DIRS}
4777+)
4778+
4779+add_executable(test-libindicator-printers
4780+ test_exporter.cpp
4781+ test_menu.cpp
4782+ test_utils.cpp
4783+)
4784+target_link_libraries(test-libindicator-printers
4785+ ${SERVICE_LIB_NAME}
4786+ ${SERVICE_DEPS_LIBRARIES}
4787+ ${CUPS_LIBS}
4788+
4789+ ${GTEST_LIBRARIES}
4790+ ${GMOCK_LIBRARIES}
4791+
4792+ ${CMAKE_THREAD_LIBS_INIT}
4793+)
4794+add_test(test-libindicator-printers test-libindicator-printers)
4795
4796=== added file 'tests/actions-mock.h'
4797--- tests/actions-mock.h 1970-01-01 00:00:00 +0000
4798+++ tests/actions-mock.h 2017-01-10 21:54:44 +0000
4799@@ -0,0 +1,36 @@
4800+/*
4801+ * Copyright 2016-2017 Canonical Ltd.
4802+ *
4803+ * This program is free software: you can redistribute it and/or modify it
4804+ * under the terms of the GNU General Public License version 3, as published
4805+ * by the Free Software Foundation.
4806+ *
4807+ * This program is distributed in the hope that it will be useful, but
4808+ * WITHOUT ANY WARRANTY; without even the implied warranties of
4809+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
4810+ * PURPOSE. See the GNU General Public License for more details.
4811+ *
4812+ * You should have received a copy of the GNU General Public License along
4813+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4814+ */
4815+
4816+#pragma once
4817+
4818+#include "actions.h"
4819+
4820+namespace unity {
4821+namespace indicator {
4822+namespace printers {
4823+
4824+ class MockActions: public Actions
4825+ {
4826+ public:
4827+ explicit MockActions(): Actions() {}
4828+ ~MockActions() = default;
4829+
4830+ void open_settings_app() {}
4831+ };
4832+
4833+} // printers
4834+} // indicator
4835+} // unity
4836
4837=== added file 'tests/client-mock.h'
4838--- tests/client-mock.h 1970-01-01 00:00:00 +0000
4839+++ tests/client-mock.h 2017-01-10 21:54:44 +0000
4840@@ -0,0 +1,54 @@
4841+/*
4842+ * Copyright 2016-2017 Canonical Ltd.
4843+ *
4844+ * This program is free software: you can redistribute it and/or modify it
4845+ * under the terms of the GNU General Public License version 3, as published
4846+ * by the Free Software Foundation.
4847+ *
4848+ * This program is distributed in the hope that it will be useful, but
4849+ * WITHOUT ANY WARRANTY; without even the implied warranties of
4850+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
4851+ * PURPOSE. See the GNU General Public License for more details.
4852+ *
4853+ * You should have received a copy of the GNU General Public License along
4854+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4855+ */
4856+
4857+#pragma once
4858+
4859+#include "client.h"
4860+
4861+#include <core/signal.h>
4862+#include <gmock/gmock.h>
4863+
4864+namespace unity {
4865+namespace indicator {
4866+namespace printers {
4867+
4868+ class MockClient: public Client
4869+ {
4870+ public:
4871+ explicit MockClient(): Client() {}
4872+ ~MockClient() = default;
4873+
4874+ core::Signal<const Printer&>& printer_state_changed()
4875+ {
4876+ return m_printer_state_changed;
4877+ }
4878+ core::Signal<const Job&>& job_state_changed()
4879+ {
4880+ return m_job_state_changed;
4881+ }
4882+
4883+ MOCK_METHOD0(create_subscription, void());
4884+ MOCK_METHOD0(renew_subscription, void());
4885+ MOCK_METHOD0(cancel_subscription, void());
4886+ MOCK_METHOD0(refresh, void());
4887+
4888+ core::Signal<const Printer&> m_printer_state_changed;
4889+ core::Signal<const Job&> m_job_state_changed;
4890+ };
4891+
4892+} // printers
4893+} // indicator
4894+} // unity
4895
4896=== added file 'tests/glib-fixture.h'
4897--- tests/glib-fixture.h 1970-01-01 00:00:00 +0000
4898+++ tests/glib-fixture.h 2017-01-10 21:54:44 +0000
4899@@ -0,0 +1,220 @@
4900+/*
4901+ * Copyright 2013-2016-2017 Canonical Ltd.
4902+ *
4903+ * This program is free software: you can redistribute it and/or modify it
4904+ * under the terms of the GNU General Public License version 3, as published
4905+ * by the Free Software Foundation.
4906+ *
4907+ * This program is distributed in the hope that it will be useful, but
4908+ * WITHOUT ANY WARRANTY; without even the implied warranties of
4909+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
4910+ * PURPOSE. See the GNU General Public License for more details.
4911+ *
4912+ * You should have received a copy of the GNU General Public License along
4913+ * with this program. If not, see <http://www.gnu.org/licenses/>.
4914+ */
4915+
4916+#pragma once
4917+
4918+#include <chrono>
4919+#include <functional> // std::function
4920+#include <map>
4921+#include <memory> // std::shared_ptr
4922+
4923+#include <glib.h>
4924+#include <glib/gstdio.h>
4925+#include <gio/gio.h>
4926+
4927+#include <gtest/gtest.h>
4928+
4929+#include <locale.h> // setlocale()
4930+
4931+class GlibFixture : public ::testing::Test
4932+{
4933+ public:
4934+
4935+ virtual ~GlibFixture() =default;
4936+
4937+ protected:
4938+
4939+ virtual void SetUp() override
4940+ {
4941+ setlocale(LC_ALL, "C.UTF-8");
4942+
4943+ loop = g_main_loop_new(nullptr, false);
4944+
4945+ // fail on unexpected messages from this domain
4946+ g_log_set_fatal_mask(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING);
4947+
4948+ g_unsetenv("DISPLAY");
4949+
4950+ }
4951+
4952+ virtual void TearDown() override
4953+ {
4954+ g_test_assert_expected_messages ();
4955+
4956+ g_clear_pointer(&loop, g_main_loop_unref);
4957+ }
4958+
4959+ void expectLogMessage (const gchar *domain, GLogLevelFlags level, const gchar *pattern)
4960+ {
4961+ g_test_expect_message (domain, level, pattern);
4962+ }
4963+
4964+ private:
4965+
4966+ static gboolean
4967+ wait_for_signal__timeout(gpointer name)
4968+ {
4969+ g_error("%s: timed out waiting for signal '%s'", G_STRLOC, (char*)name);
4970+ return G_SOURCE_REMOVE;
4971+ }
4972+
4973+ static gboolean
4974+ wait_msec__timeout(gpointer loop)
4975+ {
4976+ g_main_loop_quit(static_cast<GMainLoop*>(loop));
4977+ return G_SOURCE_CONTINUE;
4978+ }
4979+
4980+ protected:
4981+
4982+ /* convenience func to loop while waiting for a GObject's signal */
4983+ void wait_for_signal(gpointer o, const gchar * signal, const int timeout_seconds=5)
4984+ {
4985+ // wait for the signal or for timeout, whichever comes first
4986+ const auto handler_id = g_signal_connect_swapped(o, signal,
4987+ G_CALLBACK(g_main_loop_quit),
4988+ loop);
4989+ const auto timeout_id = g_timeout_add_seconds(timeout_seconds,
4990+ wait_for_signal__timeout,
4991+ loop);
4992+ g_main_loop_run(loop);
4993+ g_source_remove(timeout_id);
4994+ g_signal_handler_disconnect(o, handler_id);
4995+ }
4996+
4997+ /* convenience func to loop for N msec */
4998+ void wait_msec(int msec=50)
4999+ {
5000+ const auto id = g_timeout_add(msec, wait_msec__timeout, loop);
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches