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
=== modified file '.bzrignore'
--- .bzrignore 2012-02-02 14:49:11 +0000
+++ .bzrignore 2017-01-10 21:54:44 +0000
@@ -27,3 +27,5 @@
27src/*.lo27src/*.lo
28src/cups-notifier.[ch]28src/cups-notifier.[ch]
2929
30build/
31
3032
=== removed file 'AUTHORS'
--- AUTHORS 2012-01-11 14:29:38 +0000
+++ AUTHORS 1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
1Lars Uebernickel <lars.uebernickel@canonical.com>
2
30
=== added file 'CMakeLists.txt'
--- CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ CMakeLists.txt 2017-01-10 21:54:44 +0000
@@ -0,0 +1,54 @@
1project(indicator-printers C CXX)
2cmake_minimum_required(VERSION 2.8.9)
3
4### Need to have own copy of gdbuscodegen module
5list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
6
7### Install path variables
8include (GNUInstallDirs)
9if (EXISTS "/etc/debian_version") # Workaround for libexecdir on debian
10 set (CMAKE_INSTALL_LIBEXECDIR "${CMAKE_INSTALL_LIBDIR}")
11 set (CMAKE_INSTALL_FULL_LIBEXECDIR "${CMAKE_INSTALL_FULL_LIBDIR}")
12endif ()
13set (CMAKE_INSTALL_PKGLIBEXECDIR "${CMAKE_INSTALL_LIBEXECDIR}/${CMAKE_PROJECT_NAME}")
14set (CMAKE_INSTALL_FULL_PKGLIBEXECDIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}/${CMAKE_PROJECT_NAME}")
15
16### Always Be Testing
17enable_testing()
18
19### Set variables for our binary build targets
20set(SERVICE_LIB_NAME "indicator-printers")
21set(SERVICE_EXEC_NAME "indicator-printers-service")
22
23### Some default compile flags
24set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g -fPIC")
25set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -g -Wextra -Wall -Werror -Werror=conversion-null -Wno-ignored-qualifiers -fPIC")
26
27### Find deps
28find_package(PkgConfig REQUIRED)
29find_package(Intltool REQUIRED)
30find_package(Threads)
31
32pkg_check_modules(SERVICE_DEPS REQUIRED
33 gio-unix-2.0>=2.36
34 glib-2.0>=2.36
35 properties-cpp
36)
37
38### Find libcups
39find_program(CUPS_CONFIG cups-config)
40execute_process(COMMAND ${CUPS_CONFIG} --cflags OUTPUT_VARIABLE CUPS_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
41execute_process(COMMAND ${CUPS_CONFIG} --libs OUTPUT_VARIABLE CUPS_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
42
43### Add sub-directories
44add_subdirectory(data)
45add_subdirectory(src)
46add_subdirectory(tests)
47
48### Enable coverage reporting
49find_package(CoverageReport)
50ENABLE_COVERAGE_REPORT(
51 TARGETS ${SERVICE_LIB_NAME} ${SERVICE_EXEC_NAME}
52 TESTS test-libindicator-printers
53 FILTER /usr/include ${CMAKE_BINARY_DIR}/*
54)
055
=== added file 'COPYING'
--- COPYING 1970-01-01 00:00:00 +0000
+++ COPYING 2017-01-10 21:54:44 +0000
@@ -0,0 +1,674 @@
1 GNU GENERAL PUBLIC LICENSE
2 Version 3, 29 June 2007
3
4 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5 Everyone is permitted to copy and distribute verbatim copies
6 of this license document, but changing it is not allowed.
7
8 Preamble
9
10 The GNU General Public License is a free, copyleft license for
11software and other kinds of works.
12
13 The licenses for most software and other practical works are designed
14to take away your freedom to share and change the works. By contrast,
15the GNU General Public License is intended to guarantee your freedom to
16share and change all versions of a program--to make sure it remains free
17software for all its users. We, the Free Software Foundation, use the
18GNU General Public License for most of our software; it applies also to
19any other work released this way by its authors. You can apply it to
20your programs, too.
21
22 When we speak of free software, we are referring to freedom, not
23price. Our General Public Licenses are designed to make sure that you
24have the freedom to distribute copies of free software (and charge for
25them if you wish), that you receive source code or can get it if you
26want it, that you can change the software or use pieces of it in new
27free programs, and that you know you can do these things.
28
29 To protect your rights, we need to prevent others from denying you
30these rights or asking you to surrender the rights. Therefore, you have
31certain responsibilities if you distribute copies of the software, or if
32you modify it: responsibilities to respect the freedom of others.
33
34 For example, if you distribute copies of such a program, whether
35gratis or for a fee, you must pass on to the recipients the same
36freedoms that you received. You must make sure that they, too, receive
37or can get the source code. And you must show them these terms so they
38know their rights.
39
40 Developers that use the GNU GPL protect your rights with two steps:
41(1) assert copyright on the software, and (2) offer you this License
42giving you legal permission to copy, distribute and/or modify it.
43
44 For the developers' and authors' protection, the GPL clearly explains
45that there is no warranty for this free software. For both users' and
46authors' sake, the GPL requires that modified versions be marked as
47changed, so that their problems will not be attributed erroneously to
48authors of previous versions.
49
50 Some devices are designed to deny users access to install or run
51modified versions of the software inside them, although the manufacturer
52can do so. This is fundamentally incompatible with the aim of
53protecting users' freedom to change the software. The systematic
54pattern of such abuse occurs in the area of products for individuals to
55use, which is precisely where it is most unacceptable. Therefore, we
56have designed this version of the GPL to prohibit the practice for those
57products. If such problems arise substantially in other domains, we
58stand ready to extend this provision to those domains in future versions
59of the GPL, as needed to protect the freedom of users.
60
61 Finally, every program is threatened constantly by software patents.
62States should not allow patents to restrict development and use of
63software on general-purpose computers, but in those that do, we wish to
64avoid the special danger that patents applied to a free program could
65make it effectively proprietary. To prevent this, the GPL assures that
66patents cannot be used to render the program non-free.
67
68 The precise terms and conditions for copying, distribution and
69modification follow.
70
71 TERMS AND CONDITIONS
72
73 0. Definitions.
74
75 "This License" refers to version 3 of the GNU General Public License.
76
77 "Copyright" also means copyright-like laws that apply to other kinds of
78works, such as semiconductor masks.
79
80 "The Program" refers to any copyrightable work licensed under this
81License. Each licensee is addressed as "you". "Licensees" and
82"recipients" may be individuals or organizations.
83
84 To "modify" a work means to copy from or adapt all or part of the work
85in a fashion requiring copyright permission, other than the making of an
86exact copy. The resulting work is called a "modified version" of the
87earlier work or a work "based on" the earlier work.
88
89 A "covered work" means either the unmodified Program or a work based
90on the Program.
91
92 To "propagate" a work means to do anything with it that, without
93permission, would make you directly or secondarily liable for
94infringement under applicable copyright law, except executing it on a
95computer or modifying a private copy. Propagation includes copying,
96distribution (with or without modification), making available to the
97public, and in some countries other activities as well.
98
99 To "convey" a work means any kind of propagation that enables other
100parties to make or receive copies. Mere interaction with a user through
101a computer network, with no transfer of a copy, is not conveying.
102
103 An interactive user interface displays "Appropriate Legal Notices"
104to the extent that it includes a convenient and prominently visible
105feature that (1) displays an appropriate copyright notice, and (2)
106tells the user that there is no warranty for the work (except to the
107extent that warranties are provided), that licensees may convey the
108work under this License, and how to view a copy of this License. If
109the interface presents a list of user commands or options, such as a
110menu, a prominent item in the list meets this criterion.
111
112 1. Source Code.
113
114 The "source code" for a work means the preferred form of the work
115for making modifications to it. "Object code" means any non-source
116form of a work.
117
118 A "Standard Interface" means an interface that either is an official
119standard defined by a recognized standards body, or, in the case of
120interfaces specified for a particular programming language, one that
121is widely used among developers working in that language.
122
123 The "System Libraries" of an executable work include anything, other
124than the work as a whole, that (a) is included in the normal form of
125packaging a Major Component, but which is not part of that Major
126Component, and (b) serves only to enable use of the work with that
127Major Component, or to implement a Standard Interface for which an
128implementation is available to the public in source code form. A
129"Major Component", in this context, means a major essential component
130(kernel, window system, and so on) of the specific operating system
131(if any) on which the executable work runs, or a compiler used to
132produce the work, or an object code interpreter used to run it.
133
134 The "Corresponding Source" for a work in object code form means all
135the source code needed to generate, install, and (for an executable
136work) run the object code and to modify the work, including scripts to
137control those activities. However, it does not include the work's
138System Libraries, or general-purpose tools or generally available free
139programs which are used unmodified in performing those activities but
140which are not part of the work. For example, Corresponding Source
141includes interface definition files associated with source files for
142the work, and the source code for shared libraries and dynamically
143linked subprograms that the work is specifically designed to require,
144such as by intimate data communication or control flow between those
145subprograms and other parts of the work.
146
147 The Corresponding Source need not include anything that users
148can regenerate automatically from other parts of the Corresponding
149Source.
150
151 The Corresponding Source for a work in source code form is that
152same work.
153
154 2. Basic Permissions.
155
156 All rights granted under this License are granted for the term of
157copyright on the Program, and are irrevocable provided the stated
158conditions are met. This License explicitly affirms your unlimited
159permission to run the unmodified Program. The output from running a
160covered work is covered by this License only if the output, given its
161content, constitutes a covered work. This License acknowledges your
162rights of fair use or other equivalent, as provided by copyright law.
163
164 You may make, run and propagate covered works that you do not
165convey, without conditions so long as your license otherwise remains
166in force. You may convey covered works to others for the sole purpose
167of having them make modifications exclusively for you, or provide you
168with facilities for running those works, provided that you comply with
169the terms of this License in conveying all material for which you do
170not control copyright. Those thus making or running the covered works
171for you must do so exclusively on your behalf, under your direction
172and control, on terms that prohibit them from making any copies of
173your copyrighted material outside their relationship with you.
174
175 Conveying under any other circumstances is permitted solely under
176the conditions stated below. Sublicensing is not allowed; section 10
177makes it unnecessary.
178
179 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
181 No covered work shall be deemed part of an effective technological
182measure under any applicable law fulfilling obligations under article
18311 of the WIPO copyright treaty adopted on 20 December 1996, or
184similar laws prohibiting or restricting circumvention of such
185measures.
186
187 When you convey a covered work, you waive any legal power to forbid
188circumvention of technological measures to the extent such circumvention
189is effected by exercising rights under this License with respect to
190the covered work, and you disclaim any intention to limit operation or
191modification of the work as a means of enforcing, against the work's
192users, your or third parties' legal rights to forbid circumvention of
193technological measures.
194
195 4. Conveying Verbatim Copies.
196
197 You may convey verbatim copies of the Program's source code as you
198receive it, in any medium, provided that you conspicuously and
199appropriately publish on each copy an appropriate copyright notice;
200keep intact all notices stating that this License and any
201non-permissive terms added in accord with section 7 apply to the code;
202keep intact all notices of the absence of any warranty; and give all
203recipients a copy of this License along with the Program.
204
205 You may charge any price or no price for each copy that you convey,
206and you may offer support or warranty protection for a fee.
207
208 5. Conveying Modified Source Versions.
209
210 You may convey a work based on the Program, or the modifications to
211produce it from the Program, in the form of source code under the
212terms of section 4, provided that you also meet all of these conditions:
213
214 a) The work must carry prominent notices stating that you modified
215 it, and giving a relevant date.
216
217 b) The work must carry prominent notices stating that it is
218 released under this License and any conditions added under section
219 7. This requirement modifies the requirement in section 4 to
220 "keep intact all notices".
221
222 c) You must license the entire work, as a whole, under this
223 License to anyone who comes into possession of a copy. This
224 License will therefore apply, along with any applicable section 7
225 additional terms, to the whole of the work, and all its parts,
226 regardless of how they are packaged. This License gives no
227 permission to license the work in any other way, but it does not
228 invalidate such permission if you have separately received it.
229
230 d) If the work has interactive user interfaces, each must display
231 Appropriate Legal Notices; however, if the Program has interactive
232 interfaces that do not display Appropriate Legal Notices, your
233 work need not make them do so.
234
235 A compilation of a covered work with other separate and independent
236works, which are not by their nature extensions of the covered work,
237and which are not combined with it such as to form a larger program,
238in or on a volume of a storage or distribution medium, is called an
239"aggregate" if the compilation and its resulting copyright are not
240used to limit the access or legal rights of the compilation's users
241beyond what the individual works permit. Inclusion of a covered work
242in an aggregate does not cause this License to apply to the other
243parts of the aggregate.
244
245 6. Conveying Non-Source Forms.
246
247 You may convey a covered work in object code form under the terms
248of sections 4 and 5, provided that you also convey the
249machine-readable Corresponding Source under the terms of this License,
250in one of these ways:
251
252 a) Convey the object code in, or embodied in, a physical product
253 (including a physical distribution medium), accompanied by the
254 Corresponding Source fixed on a durable physical medium
255 customarily used for software interchange.
256
257 b) Convey the object code in, or embodied in, a physical product
258 (including a physical distribution medium), accompanied by a
259 written offer, valid for at least three years and valid for as
260 long as you offer spare parts or customer support for that product
261 model, to give anyone who possesses the object code either (1) a
262 copy of the Corresponding Source for all the software in the
263 product that is covered by this License, on a durable physical
264 medium customarily used for software interchange, for a price no
265 more than your reasonable cost of physically performing this
266 conveying of source, or (2) access to copy the
267 Corresponding Source from a network server at no charge.
268
269 c) Convey individual copies of the object code with a copy of the
270 written offer to provide the Corresponding Source. This
271 alternative is allowed only occasionally and noncommercially, and
272 only if you received the object code with such an offer, in accord
273 with subsection 6b.
274
275 d) Convey the object code by offering access from a designated
276 place (gratis or for a charge), and offer equivalent access to the
277 Corresponding Source in the same way through the same place at no
278 further charge. You need not require recipients to copy the
279 Corresponding Source along with the object code. If the place to
280 copy the object code is a network server, the Corresponding Source
281 may be on a different server (operated by you or a third party)
282 that supports equivalent copying facilities, provided you maintain
283 clear directions next to the object code saying where to find the
284 Corresponding Source. Regardless of what server hosts the
285 Corresponding Source, you remain obligated to ensure that it is
286 available for as long as needed to satisfy these requirements.
287
288 e) Convey the object code using peer-to-peer transmission, provided
289 you inform other peers where the object code and Corresponding
290 Source of the work are being offered to the general public at no
291 charge under subsection 6d.
292
293 A separable portion of the object code, whose source code is excluded
294from the Corresponding Source as a System Library, need not be
295included in conveying the object code work.
296
297 A "User Product" is either (1) a "consumer product", which means any
298tangible personal property which is normally used for personal, family,
299or household purposes, or (2) anything designed or sold for incorporation
300into a dwelling. In determining whether a product is a consumer product,
301doubtful cases shall be resolved in favor of coverage. For a particular
302product received by a particular user, "normally used" refers to a
303typical or common use of that class of product, regardless of the status
304of the particular user or of the way in which the particular user
305actually uses, or expects or is expected to use, the product. A product
306is a consumer product regardless of whether the product has substantial
307commercial, industrial or non-consumer uses, unless such uses represent
308the only significant mode of use of the product.
309
310 "Installation Information" for a User Product means any methods,
311procedures, authorization keys, or other information required to install
312and execute modified versions of a covered work in that User Product from
313a modified version of its Corresponding Source. The information must
314suffice to ensure that the continued functioning of the modified object
315code is in no case prevented or interfered with solely because
316modification has been made.
317
318 If you convey an object code work under this section in, or with, or
319specifically for use in, a User Product, and the conveying occurs as
320part of a transaction in which the right of possession and use of the
321User Product is transferred to the recipient in perpetuity or for a
322fixed term (regardless of how the transaction is characterized), the
323Corresponding Source conveyed under this section must be accompanied
324by the Installation Information. But this requirement does not apply
325if neither you nor any third party retains the ability to install
326modified object code on the User Product (for example, the work has
327been installed in ROM).
328
329 The requirement to provide Installation Information does not include a
330requirement to continue to provide support service, warranty, or updates
331for a work that has been modified or installed by the recipient, or for
332the User Product in which it has been modified or installed. Access to a
333network may be denied when the modification itself materially and
334adversely affects the operation of the network or violates the rules and
335protocols for communication across the network.
336
337 Corresponding Source conveyed, and Installation Information provided,
338in accord with this section must be in a format that is publicly
339documented (and with an implementation available to the public in
340source code form), and must require no special password or key for
341unpacking, reading or copying.
342
343 7. Additional Terms.
344
345 "Additional permissions" are terms that supplement the terms of this
346License by making exceptions from one or more of its conditions.
347Additional permissions that are applicable to the entire Program shall
348be treated as though they were included in this License, to the extent
349that they are valid under applicable law. If additional permissions
350apply only to part of the Program, that part may be used separately
351under those permissions, but the entire Program remains governed by
352this License without regard to the additional permissions.
353
354 When you convey a copy of a covered work, you may at your option
355remove any additional permissions from that copy, or from any part of
356it. (Additional permissions may be written to require their own
357removal in certain cases when you modify the work.) You may place
358additional permissions on material, added by you to a covered work,
359for which you have or can give appropriate copyright permission.
360
361 Notwithstanding any other provision of this License, for material you
362add to a covered work, you may (if authorized by the copyright holders of
363that material) supplement the terms of this License with terms:
364
365 a) Disclaiming warranty or limiting liability differently from the
366 terms of sections 15 and 16 of this License; or
367
368 b) Requiring preservation of specified reasonable legal notices or
369 author attributions in that material or in the Appropriate Legal
370 Notices displayed by works containing it; or
371
372 c) Prohibiting misrepresentation of the origin of that material, or
373 requiring that modified versions of such material be marked in
374 reasonable ways as different from the original version; or
375
376 d) Limiting the use for publicity purposes of names of licensors or
377 authors of the material; or
378
379 e) Declining to grant rights under trademark law for use of some
380 trade names, trademarks, or service marks; or
381
382 f) Requiring indemnification of licensors and authors of that
383 material by anyone who conveys the material (or modified versions of
384 it) with contractual assumptions of liability to the recipient, for
385 any liability that these contractual assumptions directly impose on
386 those licensors and authors.
387
388 All other non-permissive additional terms are considered "further
389restrictions" within the meaning of section 10. If the Program as you
390received it, or any part of it, contains a notice stating that it is
391governed by this License along with a term that is a further
392restriction, you may remove that term. If a license document contains
393a further restriction but permits relicensing or conveying under this
394License, you may add to a covered work material governed by the terms
395of that license document, provided that the further restriction does
396not survive such relicensing or conveying.
397
398 If you add terms to a covered work in accord with this section, you
399must place, in the relevant source files, a statement of the
400additional terms that apply to those files, or a notice indicating
401where to find the applicable terms.
402
403 Additional terms, permissive or non-permissive, may be stated in the
404form of a separately written license, or stated as exceptions;
405the above requirements apply either way.
406
407 8. Termination.
408
409 You may not propagate or modify a covered work except as expressly
410provided under this License. Any attempt otherwise to propagate or
411modify it is void, and will automatically terminate your rights under
412this License (including any patent licenses granted under the third
413paragraph of section 11).
414
415 However, if you cease all violation of this License, then your
416license from a particular copyright holder is reinstated (a)
417provisionally, unless and until the copyright holder explicitly and
418finally terminates your license, and (b) permanently, if the copyright
419holder fails to notify you of the violation by some reasonable means
420prior to 60 days after the cessation.
421
422 Moreover, your license from a particular copyright holder is
423reinstated permanently if the copyright holder notifies you of the
424violation by some reasonable means, this is the first time you have
425received notice of violation of this License (for any work) from that
426copyright holder, and you cure the violation prior to 30 days after
427your receipt of the notice.
428
429 Termination of your rights under this section does not terminate the
430licenses of parties who have received copies or rights from you under
431this License. If your rights have been terminated and not permanently
432reinstated, you do not qualify to receive new licenses for the same
433material under section 10.
434
435 9. Acceptance Not Required for Having Copies.
436
437 You are not required to accept this License in order to receive or
438run a copy of the Program. Ancillary propagation of a covered work
439occurring solely as a consequence of using peer-to-peer transmission
440to receive a copy likewise does not require acceptance. However,
441nothing other than this License grants you permission to propagate or
442modify any covered work. These actions infringe copyright if you do
443not accept this License. Therefore, by modifying or propagating a
444covered work, you indicate your acceptance of this License to do so.
445
446 10. Automatic Licensing of Downstream Recipients.
447
448 Each time you convey a covered work, the recipient automatically
449receives a license from the original licensors, to run, modify and
450propagate that work, subject to this License. You are not responsible
451for enforcing compliance by third parties with this License.
452
453 An "entity transaction" is a transaction transferring control of an
454organization, or substantially all assets of one, or subdividing an
455organization, or merging organizations. If propagation of a covered
456work results from an entity transaction, each party to that
457transaction who receives a copy of the work also receives whatever
458licenses to the work the party's predecessor in interest had or could
459give under the previous paragraph, plus a right to possession of the
460Corresponding Source of the work from the predecessor in interest, if
461the predecessor has it or can get it with reasonable efforts.
462
463 You may not impose any further restrictions on the exercise of the
464rights granted or affirmed under this License. For example, you may
465not impose a license fee, royalty, or other charge for exercise of
466rights granted under this License, and you may not initiate litigation
467(including a cross-claim or counterclaim in a lawsuit) alleging that
468any patent claim is infringed by making, using, selling, offering for
469sale, or importing the Program or any portion of it.
470
471 11. Patents.
472
473 A "contributor" is a copyright holder who authorizes use under this
474License of the Program or a work on which the Program is based. The
475work thus licensed is called the contributor's "contributor version".
476
477 A contributor's "essential patent claims" are all patent claims
478owned or controlled by the contributor, whether already acquired or
479hereafter acquired, that would be infringed by some manner, permitted
480by this License, of making, using, or selling its contributor version,
481but do not include claims that would be infringed only as a
482consequence of further modification of the contributor version. For
483purposes of this definition, "control" includes the right to grant
484patent sublicenses in a manner consistent with the requirements of
485this License.
486
487 Each contributor grants you a non-exclusive, worldwide, royalty-free
488patent license under the contributor's essential patent claims, to
489make, use, sell, offer for sale, import and otherwise run, modify and
490propagate the contents of its contributor version.
491
492 In the following three paragraphs, a "patent license" is any express
493agreement or commitment, however denominated, not to enforce a patent
494(such as an express permission to practice a patent or covenant not to
495sue for patent infringement). To "grant" such a patent license to a
496party means to make such an agreement or commitment not to enforce a
497patent against the party.
498
499 If you convey a covered work, knowingly relying on a patent license,
500and the Corresponding Source of the work is not available for anyone
501to copy, free of charge and under the terms of this License, through a
502publicly available network server or other readily accessible means,
503then you must either (1) cause the Corresponding Source to be so
504available, or (2) arrange to deprive yourself of the benefit of the
505patent license for this particular work, or (3) arrange, in a manner
506consistent with the requirements of this License, to extend the patent
507license to downstream recipients. "Knowingly relying" means you have
508actual knowledge that, but for the patent license, your conveying the
509covered work in a country, or your recipient's use of the covered work
510in a country, would infringe one or more identifiable patents in that
511country that you have reason to believe are valid.
512
513 If, pursuant to or in connection with a single transaction or
514arrangement, you convey, or propagate by procuring conveyance of, a
515covered work, and grant a patent license to some of the parties
516receiving the covered work authorizing them to use, propagate, modify
517or convey a specific copy of the covered work, then the patent license
518you grant is automatically extended to all recipients of the covered
519work and works based on it.
520
521 A patent license is "discriminatory" if it does not include within
522the scope of its coverage, prohibits the exercise of, or is
523conditioned on the non-exercise of one or more of the rights that are
524specifically granted under this License. You may not convey a covered
525work if you are a party to an arrangement with a third party that is
526in the business of distributing software, under which you make payment
527to the third party based on the extent of your activity of conveying
528the work, and under which the third party grants, to any of the
529parties who would receive the covered work from you, a discriminatory
530patent license (a) in connection with copies of the covered work
531conveyed by you (or copies made from those copies), or (b) primarily
532for and in connection with specific products or compilations that
533contain the covered work, unless you entered into that arrangement,
534or that patent license was granted, prior to 28 March 2007.
535
536 Nothing in this License shall be construed as excluding or limiting
537any implied license or other defenses to infringement that may
538otherwise be available to you under applicable patent law.
539
540 12. No Surrender of Others' Freedom.
541
542 If conditions are imposed on you (whether by court order, agreement or
543otherwise) that contradict the conditions of this License, they do not
544excuse you from the conditions of this License. If you cannot convey a
545covered work so as to satisfy simultaneously your obligations under this
546License and any other pertinent obligations, then as a consequence you may
547not convey it at all. For example, if you agree to terms that obligate you
548to collect a royalty for further conveying from those to whom you convey
549the Program, the only way you could satisfy both those terms and this
550License would be to refrain entirely from conveying the Program.
551
552 13. Use with the GNU Affero General Public License.
553
554 Notwithstanding any other provision of this License, you have
555permission to link or combine any covered work with a work licensed
556under version 3 of the GNU Affero General Public License into a single
557combined work, and to convey the resulting work. The terms of this
558License will continue to apply to the part which is the covered work,
559but the special requirements of the GNU Affero General Public License,
560section 13, concerning interaction through a network will apply to the
561combination as such.
562
563 14. Revised Versions of this License.
564
565 The Free Software Foundation may publish revised and/or new versions of
566the GNU General Public License from time to time. Such new versions will
567be similar in spirit to the present version, but may differ in detail to
568address new problems or concerns.
569
570 Each version is given a distinguishing version number. If the
571Program specifies that a certain numbered version of the GNU General
572Public License "or any later version" applies to it, you have the
573option of following the terms and conditions either of that numbered
574version or of any later version published by the Free Software
575Foundation. If the Program does not specify a version number of the
576GNU General Public License, you may choose any version ever published
577by the Free Software Foundation.
578
579 If the Program specifies that a proxy can decide which future
580versions of the GNU General Public License can be used, that proxy's
581public statement of acceptance of a version permanently authorizes you
582to choose that version for the Program.
583
584 Later license versions may give you additional or different
585permissions. However, no additional obligations are imposed on any
586author or copyright holder as a result of your choosing to follow a
587later version.
588
589 15. Disclaimer of Warranty.
590
591 THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
600 16. Limitation of Liability.
601
602 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610SUCH DAMAGES.
611
612 17. Interpretation of Sections 15 and 16.
613
614 If the disclaimer of warranty and limitation of liability provided
615above cannot be given local legal effect according to their terms,
616reviewing courts shall apply local law that most closely approximates
617an absolute waiver of all civil liability in connection with the
618Program, unless a warranty or assumption of liability accompanies a
619copy of the Program in return for a fee.
620
621 END OF TERMS AND CONDITIONS
622
623 How to Apply These Terms to Your New Programs
624
625 If you develop a new program, and you want it to be of the greatest
626possible use to the public, the best way to achieve this is to make it
627free software which everyone can redistribute and change under these terms.
628
629 To do so, attach the following notices to the program. It is safest
630to attach them to the start of each source file to most effectively
631state the exclusion of warranty; and each file should have at least
632the "copyright" line and a pointer to where the full notice is found.
633
634 <one line to give the program's name and a brief idea of what it does.>
635 Copyright (C) <year> <name of author>
636
637 This program is free software: you can redistribute it and/or modify
638 it under the terms of the GNU General Public License as published by
639 the Free Software Foundation, either version 3 of the License, or
640 (at your option) any later version.
641
642 This program is distributed in the hope that it will be useful,
643 but WITHOUT ANY WARRANTY; without even the implied warranty of
644 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 GNU General Public License for more details.
646
647 You should have received a copy of the GNU General Public License
648 along with this program. If not, see <http://www.gnu.org/licenses/>.
649
650Also add information on how to contact you by electronic and paper mail.
651
652 If the program does terminal interaction, make it output a short
653notice like this when it starts in an interactive mode:
654
655 <program> Copyright (C) <year> <name of author>
656 This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 This is free software, and you are welcome to redistribute it
658 under certain conditions; type `show c' for details.
659
660The hypothetical commands `show w' and `show c' should show the appropriate
661parts of the General Public License. Of course, your program's commands
662might be different; for a GUI interface, you would use an "about box".
663
664 You should also get your employer (if you work as a programmer) or school,
665if any, to sign a "copyright disclaimer" for the program, if necessary.
666For more information on this, and how to apply and follow the GNU GPL, see
667<http://www.gnu.org/licenses/>.
668
669 The GNU General Public License does not permit incorporating your program
670into proprietary programs. If your program is a subroutine library, you
671may consider it more useful to permit linking proprietary applications with
672the library. If this is what you want to do, use the GNU Lesser General
673Public License instead of this License. But first, please read
674<http://www.gnu.org/philosophy/why-not-lgpl.html>.
0675
=== removed file 'ChangeLog'
=== removed file 'Makefile.am'
--- Makefile.am 2012-03-27 22:12:02 +0000
+++ Makefile.am 1970-01-01 00:00:00 +0000
@@ -1,6 +0,0 @@
1
2SUBDIRS = src data test po
3
4DISTCHECK_CONFIGURE_FLAGS = --enable-localinstall
5
6include $(top_srcdir)/Makefile.am.coverage
70
=== removed file 'Makefile.am.coverage'
--- Makefile.am.coverage 2012-03-27 22:12:02 +0000
+++ Makefile.am.coverage 1970-01-01 00:00:00 +0000
@@ -1,48 +0,0 @@
1
2# Coverage targets
3
4.PHONY: clean-gcno clean-gcda \
5 coverage-html generate-coverage-html clean-coverage-html \
6 coverage-gcovr generate-coverage-gcovr clean-coverage-gcovr
7
8clean-local: clean-gcno clean-coverage-html clean-coverage-gcovr
9
10if HAVE_GCOV
11
12clean-gcno:
13 @echo Removing old coverage instrumentation
14 -find -name '*.gcno' -print | xargs -r rm
15
16clean-gcda:
17 @echo Removing old coverage results
18 -find -name '*.gcda' -print | xargs -r rm
19
20coverage-html: clean-gcda
21 -$(MAKE) $(AM_MAKEFLAGS) -k check
22 $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html
23
24generate-coverage-html:
25 @echo Collecting coverage data
26 $(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool
27 LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
28
29clean-coverage-html: clean-gcda
30 -$(LCOV) --directory $(top_builddir) -z
31 -rm -rf coverage.info coveragereport
32
33if HAVE_GCOVR
34
35coverage-gcovr: clean-gcda
36 -$(MAKE) $(AM_MAKEFLAGS) -k check
37 $(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr
38
39generate-coverage-gcovr:
40 @echo Generating coverage GCOVR report
41 $(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.xml
42
43clean-coverage-gcovr: clean-gcda
44 -rm -rf $(top_builddir)/coverage.xml
45
46endif # HAVE_GCOVR
47
48endif # HAVE_GCOV
490
=== removed file 'NEWS'
=== removed file 'autogen.sh'
--- autogen.sh 2012-01-11 14:29:38 +0000
+++ autogen.sh 1970-01-01 00:00:00 +0000
@@ -1,9 +0,0 @@
1#!/bin/sh
2
3which gnome-autogen.sh || {
4 echo "Could not find 'gnome-autgen.sh'. Is gnome-common installed?"
5 exit 1
6}
7
8. gnome-autogen.sh
9
100
=== added directory 'cmake'
=== added file 'cmake/GdbusCodegen.cmake'
--- cmake/GdbusCodegen.cmake 1970-01-01 00:00:00 +0000
+++ cmake/GdbusCodegen.cmake 2017-01-10 21:54:44 +0000
@@ -0,0 +1,36 @@
1cmake_minimum_required(VERSION 2.6)
2if(POLICY CMP0011)
3 cmake_policy(SET CMP0011 NEW)
4endif(POLICY CMP0011)
5
6find_program(GDBUS_CODEGEN NAMES gdbus-codegen DOC "gdbus-codegen executable")
7if(NOT GDBUS_CODEGEN)
8 message(FATAL_ERROR "Excutable gdbus-codegen not found")
9endif()
10
11macro(add_gdbus_codegen outfiles name prefix service_xml)
12 add_custom_command(
13 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" "${CMAKE_CURRENT_BINARY_DIR}/${name}.c"
14 COMMAND "${GDBUS_CODEGEN}"
15 --interface-prefix "${prefix}"
16 --generate-c-code "${name}"
17 "${service_xml}"
18 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
19 DEPENDS ${ARGN} "${service_xml}"
20 )
21 list(APPEND ${outfiles} "${CMAKE_CURRENT_BINARY_DIR}/${name}.c")
22endmacro(add_gdbus_codegen)
23
24macro(add_gdbus_codegen_with_namespace outfiles name prefix namespace service_xml)
25 add_custom_command(
26 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" "${CMAKE_CURRENT_BINARY_DIR}/${name}.c"
27 COMMAND "${GDBUS_CODEGEN}"
28 --interface-prefix "${prefix}"
29 --generate-c-code "${name}"
30 --c-namespace "${namespace}"
31 "${service_xml}"
32 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
33 DEPENDS ${ARGN} "${service_xml}"
34 )
35 list(APPEND ${outfiles} "${CMAKE_CURRENT_BINARY_DIR}/${name}.c")
36endmacro(add_gdbus_codegen_with_namespace)
037
=== removed file 'configure.ac'
--- configure.ac 2016-07-19 15:43:40 +0000
+++ configure.ac 1970-01-01 00:00:00 +0000
@@ -1,105 +0,0 @@
1
2AC_INIT(indicator-printers, 0.1.6)
3
4AC_PREREQ(2.53)
5AM_INIT_AUTOMAKE([])
6
7AC_PROG_CC
8AC_PROG_INSTALL
9AC_PROG_LIBTOOL
10AM_PROG_CC_C_O
11AM_SILENT_RULES([yes])
12AC_CONFIG_MACRO_DIR([m4])
13
14AC_DEFUN([AC_DEFINE_PATH], [
15 test "x$prefix" = xNONE && prefix="$ac_default_prefix"
16 test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
17 ac_define_path=`eval echo [$]$2`
18 ac_define_path=`eval echo [$]ac_define_path`
19 $1="$ac_define_path"
20 AC_SUBST($1)
21 ifelse($3, ,
22 AC_DEFINE_UNQUOTED($1, "$ac_define_path"),
23 AC_DEFINE_UNQUOTED($1, "$ac_define_path", $3))
24])
25
26IT_PROG_INTLTOOL([0.35.0])
27GETTEXT_PACKAGE=indicator-printers
28AC_SUBST(GETTEXT_PACKAGE)
29AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [gettext package])
30AC_DEFINE_PATH(GNOMELOCALEDIR, "${datadir}/locale", [locale directory])
31AM_GLIB_GNU_GETTEXT
32
33AC_CONFIG_HEADER(config.h)
34AC_CONFIG_FILES([
35 Makefile
36 src/Makefile
37 data/Makefile
38 data/upstart/Makefile
39 test/Makefile
40 po/Makefile.in
41])
42
43PKG_CHECK_MODULES(APPLET, gtk+-3.0 >= 3.0
44 indicator3-0.4 >= 0.2
45 dbusmenu-gtk3-0.4 >= 0.2)
46PKG_CHECK_MODULES(SERVICE, gtk+-3.0 >= 3.0
47 indicator3-0.4 >= 0.2
48 dbusmenu-glib-0.4 >= 0.2)
49
50AC_PATH_PROG(CUPS_CONFIG, cups-config, no)
51if test "x$CUPS_CONFIG" = "xno"; then
52 AC_MSG_ERROR([could not find cups-config])
53fi
54AC_CHECK_HEADER(cups/cups.h,,AC_MSG_ERROR([could not find cups.h]))
55CUPS_CFLAGS+=`$CUPS_CONFIG --cflags`
56CUPS_LIBS+=`$CUPS_CONFIG --libs`
57SERVICE_CFLAGS="$SERVICE_CFLAGS $CUPS_CFLAGS"
58SERVICE_LIBS="$SERVICE_LIBS $CUPS_LIBS"
59
60SYSTEMD_USERDIR=`$PKG_CONFIG --variable=systemduserunitdir systemd`
61AC_SUBST(SYSTEMD_USERDIR)
62
63with_localinstall="no"
64AC_ARG_ENABLE(localinstall, AS_HELP_STRING([--enable-localinstall],
65 [install all files locally (for distcheck)]),
66 with_localinstall=$enableval,
67 with_localinstall=no)
68
69if test "x$with_localinstall" = "xyes"; then
70 INDICATORDIR="${libdir}/indicators/2/"
71 INDICATORICONSDIR="${datadir}/libindicate/icons/"
72else
73 INDICATORDIR=`$PKG_CONFIG --variable=indicatordir indicator3-0.4`
74 INDICATORICONSDIR=`$PKG_CONFIG --variable=iconsdir indicator3-0.4`
75fi
76AC_SUBST(INDICATORDIR)
77AC_SUBST(INDICATORICONSDIR)
78
79###########################
80# DBus Service Info
81###########################
82
83if test "x$with_localinstall" = "xyes"; then
84 DBUSSERVICEDIR="${datadir}/dbus-1/services/"
85else
86 DBUSSERVICEDIR=`$PKG_CONFIG --variable=session_bus_services_dir dbus-1`
87fi
88AC_SUBST(DBUSSERVICEDIR)
89
90###########################
91# gcov coverage reporting
92###########################
93
94m4_include([m4/gcov.m4])
95AC_TDD_GCOV
96AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
97AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
98AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
99AC_SUBST(COVERAGE_CFLAGS)
100AC_SUBST(COVERAGE_LDFLAGS)
101
102AC_SUBST(AM_CFLAGS, "-Wall")
103
104AC_OUTPUT
105
1060
=== added file 'data/CMakeLists.txt'
--- data/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ data/CMakeLists.txt 2017-01-10 21:54:44 +0000
@@ -0,0 +1,64 @@
1##
2## Systemd Unit File
3##
4
5# where to install
6# Uncomment when we drop Vivid
7# pkg_get_variable(SYSTEMD_USER_DIR systemd systemduserunitdir)
8set (SYSTEMD_USER_DIR "/usr/lib/systemd/user")
9message (STATUS "${SYSTEMD_USER_DIR} is the systemd user unit file install dir")
10
11set (SYSTEMD_USER_NAME "${CMAKE_PROJECT_NAME}.service")
12set (SYSTEMD_USER_FILE "${CMAKE_CURRENT_BINARY_DIR}/${SYSTEMD_USER_NAME}")
13set (SYSTEMD_USER_FILE_IN "${CMAKE_CURRENT_SOURCE_DIR}/${SYSTEMD_USER_NAME}.in")
14
15# build it
16set (pkglibexecdir "${CMAKE_INSTALL_FULL_PKGLIBEXECDIR}")
17configure_file ("${SYSTEMD_USER_FILE_IN}" "${SYSTEMD_USER_FILE}")
18
19# install it
20install (FILES "${SYSTEMD_USER_FILE}"
21 DESTINATION "${SYSTEMD_USER_DIR}")
22
23##
24## Upstart systemd override Job File
25##
26
27set (UPSTART_SYSTEMD_OVERRIDE_DIR "${CMAKE_INSTALL_FULL_DATADIR}/upstart/systemd-session/upstart")
28message (STATUS "${UPSTART_SYSTEMD_OVERRIDE_DIR} is the Upstart override Job File for systemd dir")
29
30install (FILES "${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_PROJECT_NAME}.override"
31 DESTINATION "${UPSTART_SYSTEMD_OVERRIDE_DIR}")
32
33##
34## Upstart Job File
35##
36
37# where to install
38set (UPSTART_JOB_DIR "${CMAKE_INSTALL_FULL_DATADIR}/upstart/sessions")
39message (STATUS "${UPSTART_JOB_DIR} is the Upstart Job File install dir")
40
41set (UPSTART_JOB_NAME "${CMAKE_PROJECT_NAME}.conf")
42set (UPSTART_JOB_FILE "${CMAKE_CURRENT_BINARY_DIR}/${UPSTART_JOB_NAME}")
43set (UPSTART_JOB_FILE_IN "${CMAKE_CURRENT_SOURCE_DIR}/${UPSTART_JOB_NAME}.in")
44
45# build it
46configure_file ("${UPSTART_JOB_FILE_IN}" "${UPSTART_JOB_FILE}")
47
48# install it
49install (FILES "${UPSTART_JOB_FILE}"
50 DESTINATION "${UPSTART_JOB_DIR}")
51
52##
53## Unity Indicator File
54##
55
56# where to install
57set (UNITY_INDICATOR_DIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/unity/indicators")
58message (STATUS "${UNITY_INDICATOR_DIR} is the Unity Indicator install dir")
59
60set (UNITY_INDICATOR_NAME "com.canonical.indicator.printers")
61set (UNITY_INDICATOR_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${UNITY_INDICATOR_NAME}")
62
63install (FILES "${UNITY_INDICATOR_FILE}"
64 DESTINATION "${UNITY_INDICATOR_DIR}")
065
=== removed file 'data/Makefile.am'
--- data/Makefile.am 2016-07-19 15:43:40 +0000
+++ data/Makefile.am 1970-01-01 00:00:00 +0000
@@ -1,55 +0,0 @@
1
2BUILT_SOURCES=
3CLEANFILES=
4EXTRA_DIST=
5
6SUBDIRS = upstart
7
8#
9# the systemd unit file
10#
11
12systemddir = $(SYSTEMD_USERDIR)
13systemd_DATA = indicator-printers.service
14systemd_in = $(systemd_DATA:.service=.service.in)
15$(systemd_DATA): $(systemd_in)
16 $(AM_V_GEN) $(SED) -e "s|\@pkglibexecdir\@|$(pkglibexecdir)|" $< > $@
17BUILT_SOURCES += $(systemd_DATA)
18EXTRA_DIST += $(systemd_in)
19CLEANFILES += $(systemd_DATA)
20
21#
22# the systemd upstart override
23#
24
25upstart_overridedir = $(datadir)/upstart/systemd-session/upstart
26upstart_override_DATA = indicator-printers.override
27EXTRA_DIST += $(upstart_override_DATA)
28
29#
30# the upstart job file
31#
32
33upstart_jobsdir = $(datadir)/upstart/sessions
34upstart_jobs_DATA = indicator-printers.conf
35upstart_jobs_in = $(upstart_jobs_DATA:.conf=.conf.in)
36$(upstart_jobs_DATA): $(upstart_jobs_in)
37 $(AM_V_GEN) $(SED) -e "s|\@pkglibexecdir\@|$(pkglibexecdir)|" $< > $@
38BUILT_SOURCES += $(upstart_jobs_DATA)
39CLEANFILES += $(upstart_jobs_DATA)
40EXTRA_DIST += $(upstart_jobs_in)
41
42#
43# the xdg autostart job file
44#
45
46xdg_autostartdir = /etc/xdg/autostart
47xdg_autostart_DATA = indicator-printers.desktop
48xdg_autostart_in = $(xdg_autostart_DATA:.desktop=.desktop.in)
49$(xdg_autostart_DATA): $(xdg_autostart_in)
50 $(AM_V_GEN) $(SED) -e "s|\@pkglibexecdir\@|$(pkglibexecdir)|" $< > $@
51BUILT_SOURCES += $(xdg_autostart_DATA)
52CLEANFILES += $(xdg_autostart_DATA)
53EXTRA_DIST += $(xdg_autostart_in)
54
55
560
=== added file 'data/com.canonical.indicator.printers'
--- data/com.canonical.indicator.printers 1970-01-01 00:00:00 +0000
+++ data/com.canonical.indicator.printers 2017-01-10 21:54:44 +0000
@@ -0,0 +1,20 @@
1[Indicator Service]
2Name=indicator-printers
3ObjectPath=/com/canonical/indicator/printers
4Position=90
5
6[desktop]
7ObjectPath=/com/canonical/indicator/printers/menu
8
9[desktop_greeter]
10ObjectPath=/com/canonical/indicator/printers/menu
11
12[desktop_lockscreen]
13ObjectPath=/com/canonical/indicator/printers/menu
14
15[phone]
16ObjectPath=/com/canonical/indicator/printers/menu
17
18[phone_greeter]
19ObjectPath=/com/canonical/indicator/printers/menu
20
021
=== removed file 'data/indicator-printers.desktop.in'
--- data/indicator-printers.desktop.in 2014-02-20 16:08:19 +0000
+++ data/indicator-printers.desktop.in 1970-01-01 00:00:00 +0000
@@ -1,8 +0,0 @@
1[Desktop Entry]
2Type=Application
3Name=Indicator Printers
4Exec=@pkglibexecdir@/indicator-printers-service
5OnlyShowIn=Unity;
6NoDisplay=true
7StartupNotify=false
8Terminal=false
90
=== removed directory 'data/upstart'
=== removed file 'data/upstart/Makefile.am'
--- data/upstart/Makefile.am 2014-02-20 16:06:20 +0000
+++ data/upstart/Makefile.am 1970-01-01 00:00:00 +0000
@@ -1,17 +0,0 @@
1BUILT_SOURCES=
2CLEANFILES=
3EXTRA_DIST=
4
5#
6# the upstart xdg autostart override
7#
8
9xdg_autostartdir = $(datadir)/upstart/xdg/autostart
10xdg_autostart_DATA = indicator-printers.desktop
11xdg_autostart_in = $(xdg_autostart_DATA:.desktop=.desktop.in)
12$(xdg_autostart_DATA): $(xdg_autostart_in)
13 $(AM_V_GEN) $(SED) -e "s|\@pkglibexecdir\@|$(pkglibexecdir)|" $< > $@
14BUILT_SOURCES += $(xdg_autostart_DATA)
15CLEANFILES += $(xdg_autostart_DATA)
16EXTRA_DIST += $(xdg_autostart_in)
17
180
=== removed file 'data/upstart/indicator-printers.desktop.in'
--- data/upstart/indicator-printers.desktop.in 2014-02-20 16:08:19 +0000
+++ data/upstart/indicator-printers.desktop.in 1970-01-01 00:00:00 +0000
@@ -1,9 +0,0 @@
1[Desktop Entry]
2Type=Application
3Name=Indicator Printers
4Exec=@pkglibexecdir@/indicator-printers-service
5OnlyShowIn=Unity;
6NoDisplay=true
7StartupNotify=false
8Terminal=false
9Hidden=true
100
=== modified file 'debian/control'
--- debian/control 2016-11-24 23:20:47 +0000
+++ debian/control 2017-01-10 21:54:44 +0000
@@ -2,26 +2,24 @@
2Section: gnome2Section: gnome
3Priority: extra3Priority: extra
4Maintainer: Ubuntu Desktop Team <ubuntu-desktop@lists.ubuntu.com>4Maintainer: Ubuntu Desktop Team <ubuntu-desktop@lists.ubuntu.com>
5XSBC-Original-Maintainer: Lars Uebernickel <lars.uebernickel@canonical.com>5Build-Depends:
6Build-Depends: debhelper (>= 9),6 cmake,
7 autotools-dev,7 cmake-extras (>= 0.10),
8 dh-autoreconf,8 debhelper (>= 9),
9 gnome-common,9 dbus,
10 python,10 dh-translations,
11 libglib2.0-dev (>= 2.43.2),11 gcovr,
12 libgtk-3-dev,12 googletest | google-mock,
13 libdbusmenu-glib-dev (>= 0.5.90),13 intltool,
14 libdbusmenu-gtk3-dev (>= 0.5.90),14 lcov,
15 libindicator3-dev (>= 0.3.91),15 libcups2-dev,
16 libcups2-dev,16 libglib2.0-dev (>= 2.35.4),
17 systemd,17 libproperties-cpp-dev,
18Standards-Version: 3.9.218 systemd,
19Standards-Version: 3.9.6
19Homepage: https://launchpad.net/indicator-printers20Homepage: https://launchpad.net/indicator-printers
20# If you aren't a member of ~indicator-applet-developers but need to upload21Vcs-Bzr: lp:indicator-printers
21# packaging changes, just go ahead. ~indicator-applet-developers will notice22X-Ubuntu-Use-Langpack: yes
22# and sync up the code again.
23Vcs-Bzr: https://code.launchpad.net/~indicator-applet-developers/indicator-printers/trunk.13.04
24Vcs-Browser: https://bazaar.launchpad.net/~indicator-applet-developers/indicator-printers/trunk.13.04/files
2523
26Package: indicator-printers24Package: indicator-printers
27Architecture: any25Architecture: any
@@ -30,7 +28,6 @@
30 cups (>= 1.5),28 cups (>= 1.5),
31 indicator-common,29 indicator-common,
32Recommends: indicator-applet (>= 0.2) | indicator-renderer,30Recommends: indicator-applet (>= 0.2) | indicator-renderer,
33 system-config-printer,
34Description: indicator showing active print jobs31Description: indicator showing active print jobs
35 This indicator is designed to let you view and control active print jobs.32 This indicator is designed to let you view and control active print jobs.
36 .33 .
3734
=== modified file 'debian/copyright'
--- debian/copyright 2012-02-16 16:23:19 +0000
+++ debian/copyright 2017-01-10 21:54:44 +0000
@@ -1,10 +1,9 @@
1Format: http://dep.debian.net/deps/dep5/1Format: http://dep.debian.net/deps/dep5/
2Upstream-Name: indicator-printers2Upstream-Name: indicator-printers
3Upstream-Contact: Lars Uebernickel <lars.uebernickel@canonical.com>
4Source: https://launchpad.net/indicator-printers3Source: https://launchpad.net/indicator-printers
54
6Files: *5Files: *
7Copyright: 2012 Canonical Ltd6Copyright: 2012, 2016-2017 Canonical Ltd
8License: GPL-37License: GPL-3
9 This program is free software: you can redistribute it and/or modify8 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by9 it under the terms of the GNU General Public License as published by
1110
=== modified file 'debian/rules'
--- debian/rules 2012-11-20 15:32:37 +0000
+++ debian/rules 2017-01-10 21:54:44 +0000
@@ -1,22 +1,7 @@
1#!/usr/bin/make -f1#!/usr/bin/make -f
2
3
4CFLAGS += -Wno-error=deprecated-declarations
5LDFLAGS += -Wl,-z,defs -Wl,--as-needed2LDFLAGS += -Wl,-z,defs -Wl,--as-needed
63
7export DPKG_GENSYMBOLS_CHECK_LEVEL = 44export DPKG_GENSYMBOLS_CHECK_LEVEL = 4
85
9%:6%:
10 dh $@ --with autoreconf7 dh $@ --parallel --buildsystem cmake --fail-missing
11
12override_dh_autoreconf:
13 NOCONFIGURE=1 dh_autoreconf ./autogen.sh
14
15override_dh_auto_configure:
16 dh_auto_configure -- \
17 --disable-static
18
19override_dh_install:
20 find debian/indicator-printers -name \*.la -delete
21 find debian/indicator-printers -name \*.a -delete
22 dh_install --fail-missing
238
=== removed file 'debian/watch'
--- debian/watch 2012-02-16 16:23:19 +0000
+++ debian/watch 1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
1version=3
2https://launchpad.net/indicator-printers/+download .*/indicator-printers-([0-9.]+)\.tar\.gz
30
=== removed directory 'm4'
=== removed file 'm4/gcov.m4'
--- m4/gcov.m4 2012-03-27 22:12:02 +0000
+++ m4/gcov.m4 1970-01-01 00:00:00 +0000
@@ -1,86 +0,0 @@
1# Checks for existence of coverage tools:
2# * gcov
3# * lcov
4# * genhtml
5# * gcovr
6#
7# Sets ac_cv_check_gcov to yes if tooling is present
8# and reports the executables to the variables LCOV, GCOVR and GENHTML.
9AC_DEFUN([AC_TDD_GCOV],
10[
11 AC_ARG_ENABLE(gcov,
12 AS_HELP_STRING([--enable-gcov],
13 [enable coverage testing with gcov]),
14 [use_gcov=$enableval], [use_gcov=no])
15
16 if test "x$use_gcov" = "xyes"; then
17 # we need gcc:
18 if test "$GCC" != "yes"; then
19 AC_MSG_ERROR([GCC is required for --enable-gcov])
20 fi
21
22 # Check if ccache is being used
23 AC_CHECK_PROG(SHTOOL, shtool, shtool)
24 case `$SHTOOL path $CC` in
25 *ccache*[)] gcc_ccache=yes;;
26 *[)] gcc_ccache=no;;
27 esac
28
29 if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
30 AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
31 fi
32
33 lcov_version_list="1.6 1.7 1.8 1.9"
34 AC_CHECK_PROG(LCOV, lcov, lcov)
35 AC_CHECK_PROG(GENHTML, genhtml, genhtml)
36
37 if test "$LCOV"; then
38 AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
39 glib_cv_lcov_version=invalid
40 lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
41 for lcov_check_version in $lcov_version_list; do
42 if test "$lcov_version" = "$lcov_check_version"; then
43 glib_cv_lcov_version="$lcov_check_version (ok)"
44 fi
45 done
46 ])
47 else
48 lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
49 AC_MSG_ERROR([$lcov_msg])
50 fi
51
52 case $glib_cv_lcov_version in
53 ""|invalid[)]
54 lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
55 AC_MSG_ERROR([$lcov_msg])
56 LCOV="exit 0;"
57 ;;
58 esac
59
60 if test -z "$GENHTML"; then
61 AC_MSG_ERROR([Could not find genhtml from the lcov package])
62 fi
63
64 ac_cv_check_gcov=yes
65 ac_cv_check_lcov=yes
66
67 # Remove all optimization flags from CFLAGS
68 changequote({,})
69 CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
70 changequote([,])
71
72 # Add the special gcc flags
73 COVERAGE_CFLAGS="-O0 -fprofile-arcs -ftest-coverage"
74 COVERAGE_CXXFLAGS="-O0 -fprofile-arcs -ftest-coverage"
75 COVERAGE_LDFLAGS="-lgcov"
76
77 # Check availability of gcovr
78 AC_CHECK_PROG(GCOVR, gcovr, gcovr)
79 if test -z "$GCOVR"; then
80 ac_cv_check_gcovr=no
81 else
82 ac_cv_check_gcovr=yes
83 fi
84
85fi
86]) # AC_TDD_GCOV
870
=== added file 'po/CMakeLists.txt'
--- po/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ po/CMakeLists.txt 2017-01-10 21:54:44 +0000
@@ -0,0 +1,12 @@
1find_package(Intltool REQUIRED)
2
3intltool_update_potfile(
4 KEYWORDS "_" "_:1,2" "N_" "N_:1,2"
5 GETTEXT_PACKAGE ${GETTEXT_PACKAGE}
6 COPYRIGHT_HOLDER "Canonical Ltd."
7)
8
9intltool_install_translations(
10 ALL
11 GETTEXT_PACKAGE ${GETTEXT_PACKAGE}
12)
013
=== removed file 'po/POTFILES.in'
--- po/POTFILES.in 2012-02-16 16:25:33 +0000
+++ po/POTFILES.in 1970-01-01 00:00:00 +0000
@@ -1,6 +0,0 @@
1[encoding: UTF-8]
2src/indicator-menu-item.c
3src/indicator-printers.c
4src/indicator-printers-menu.c
5src/indicator-printers-service.c
6src/indicator-printer-state-notifier.c
70
=== added file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ src/CMakeLists.txt 2017-01-10 21:54:44 +0000
@@ -0,0 +1,62 @@
1add_definitions(
2 -DGETTEXT_PACKAGE=\"${PROJECT_NAME}\"
3 -DGETTEXT_LOCALEDIR=\"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}\"
4 -DG_LOG_DOMAIN=\"${CMAKE_PROJECT_NAME}\"
5)
6
7include_directories(
8 ${CMAKE_CURRENT_SOURCE_DIR}
9 ${CMAKE_CURRENT_BINARY_DIR}
10 ${SERVICE_DEPS_INCLUDE_DIRS}
11)
12link_directories(
13 ${SERVICE_DEPS_LIBRARY_DIRS}
14)
15
16include (GdbusCodegen)
17add_gdbus_codegen(SERVICE_GENERATED_SOURCES cups-cupsd-notifier
18 org.cups.cupsd
19 ${CMAKE_CURRENT_SOURCE_DIR}/org.cups.cupsd.Notifier.xml)
20
21add_library(${SERVICE_LIB_NAME} STATIC
22 actions-live.cpp
23 actions-live.h
24 actions.cpp
25 actions.h
26 client.h
27 cups-client.cpp
28 cups-client.h
29 exporter.cpp
30 exporter.h
31 menu.cpp
32 menu.h
33 job.h
34 printer.h
35 utils.cpp
36 utils.h
37 ${SERVICE_GENERATED_SOURCES}
38)
39
40target_link_libraries(${SERVICE_LIB_NAME}
41 ${SERVICE_DEPS_LIBRARIES}
42 ${CUPS_LIBS}
43)
44
45
46add_executable(${SERVICE_EXEC_NAME}
47 main.cpp
48)
49
50target_link_libraries(${SERVICE_EXEC_NAME}
51 ${SERVICE_LIB_NAME}
52 ${SERVICE_DEPS_LIBRARIES}
53 ${CUPS_LIBS}
54
55 ${CMAKE_THREAD_LIBS_INIT}
56)
57
58install(
59 TARGETS ${SERVICE_EXEC_NAME}
60 RUNTIME
61 DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/${PROJECT_NAME}
62)
063
=== added file 'src/actions-live.cpp'
--- src/actions-live.cpp 1970-01-01 00:00:00 +0000
+++ src/actions-live.cpp 2017-01-10 21:54:44 +0000
@@ -0,0 +1,104 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "actions-live.h"
18
19//#include <url-dispatcher.h>
20
21#include <glib.h>
22
23#include <sstream>
24
25namespace unity {
26namespace indicator {
27namespace printers {
28
29/***
30****
31***/
32
33LiveActions::LiveActions():
34 Actions()
35{
36}
37
38void LiveActions::execute_command(const std::string& cmdstr)
39{
40 const auto cmd = cmdstr.c_str();
41 g_debug("Issuing command '%s'", cmd);
42
43 GError* error = nullptr;
44 if (!g_spawn_command_line_async(cmd, &error))
45 {
46 g_warning("Unable to start \"%s\": %s", cmd, error->message);
47 g_error_free(error);
48 }
49}
50
51void LiveActions::dispatch_url(const std::string& url)
52{
53 g_debug("Dispatching url '%s'", url.c_str());
54 //url_dispatch_send(url.c_str(), nullptr, nullptr);
55}
56
57/***
58****
59***/
60
61LiveActions::Desktop LiveActions::get_desktop()
62{
63 static bool cached = false;
64 static LiveActions::Desktop result = LiveActions::OTHER;
65
66 if (cached) {
67 return result;
68 }
69
70 // check for unity8
71 if (g_getenv ("MIR_SOCKET") != nullptr) {
72 result = LiveActions::UNITY8;
73 } else {
74 const gchar *xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
75 if (xdg_current_desktop != NULL) {
76 gchar **desktop_names = g_strsplit (xdg_current_desktop, ":", 0);
77 for (size_t i = 0; desktop_names[i]; ++i) {
78 if (!g_strcmp0 (desktop_names[i], "Unity")) {
79 result = LiveActions::UNITY7;
80 break;
81 }
82 }
83 g_strfreev (desktop_names);
84 }
85 }
86 cached = true;
87 return result;
88}
89
90void LiveActions::open_settings_app()
91{
92 switch(get_desktop()) {
93 case LiveActions::UNITY8:
94 dispatch_url("settings:///system/printers");
95 break;
96 default:
97 execute_command("system-config-printer");
98 }
99}
100
101
102} // namespace printers
103} // namespace indicator
104} // namespace unity
0105
=== added file 'src/actions-live.h'
--- src/actions-live.h 1970-01-01 00:00:00 +0000
+++ src/actions-live.h 2017-01-10 21:54:44 +0000
@@ -0,0 +1,54 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include "actions.h"
20
21namespace unity {
22namespace indicator {
23namespace printers {
24
25/**
26 * \brief Production implementation of the Actions interface.
27 *
28 * Open a URL or launch a command for an action.
29 *
30 * @see MockActions
31 */
32class LiveActions: public Actions
33{
34public:
35 enum Desktop {
36 OTHER = 0,
37 UNITY7,
38 UNITY8,
39 };
40
41 explicit LiveActions();
42 virtual ~LiveActions() =default;
43
44 void open_settings_app() override;
45
46protected:
47 virtual Desktop get_desktop();
48 virtual void execute_command(const std::string& command);
49 virtual void dispatch_url(const std::string& url);
50};
51
52} // namespace printers
53} // namespace indicator
54} // namespace unity
055
=== added file 'src/actions.cpp'
--- src/actions.cpp 1970-01-01 00:00:00 +0000
+++ src/actions.cpp 2017-01-10 21:54:44 +0000
@@ -0,0 +1,73 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "actions.h"
18
19#include <glib.h>
20#include <gio/gio.h>
21
22namespace unity {
23namespace indicator {
24namespace printers {
25
26/***
27****
28***/
29
30namespace
31{
32
33GVariant* create_default_header_state()
34{
35 GVariantBuilder b;
36 g_variant_builder_init(&b, G_VARIANT_TYPE_VARDICT);
37 g_variant_builder_add(&b, "{sv}", "accessible-desc", g_variant_new_string("accessible-desc"));
38 g_variant_builder_add(&b, "{sv}", "label", g_variant_new_string("label"));
39 g_variant_builder_add(&b, "{sv}", "title", g_variant_new_string("title"));
40 g_variant_builder_add(&b, "{sv}", "visible", g_variant_new_boolean(true));
41 return g_variant_builder_end(&b);
42}
43
44} // unnamed namespace
45
46/***
47****
48***/
49
50Actions::Actions():
51 m_actions(g_simple_action_group_new())
52{
53 // add the header actions
54 auto v = create_default_header_state();
55 auto a = g_simple_action_new_stateful("printers", nullptr, v);
56 g_action_map_add_action(G_ACTION_MAP(m_actions), G_ACTION(a));
57 g_object_unref(a);
58}
59
60Actions::~Actions()
61{
62 g_clear_object(&m_actions);
63}
64
65GActionGroup* Actions::action_group()
66{
67 return G_ACTION_GROUP(m_actions);
68}
69
70
71} // namespace printers
72} // namespace indicator
73} // namespace unity
074
=== added file 'src/actions.h'
--- src/actions.h 1970-01-01 00:00:00 +0000
+++ src/actions.h 2017-01-10 21:54:44 +0000
@@ -0,0 +1,57 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include <memory> // shared_ptr
20#include <string>
21
22#include <gio/gio.h> // GSimpleActionGroup
23
24namespace unity {
25namespace indicator {
26namespace printers {
27
28/**
29 * \brief Interface for all the actions that can be activated by users.
30 *
31 * This is a simple C++ wrapper around our GActionGroup that gets exported
32 * onto the bus. Subclasses implement the actual code that should be run
33 * when a particular action is triggered.
34 */
35class Actions
36{
37public:
38
39 virtual void open_settings_app() = 0;
40
41 GActionGroup* action_group();
42
43protected:
44 explicit Actions();
45 virtual ~Actions();
46
47private:
48 GSimpleActionGroup* m_actions = nullptr;
49
50 // we've got raw pointers in here, so disable copying
51 Actions(const Actions&) = delete;
52 Actions& operator=(const Actions&) = delete;
53};
54
55} // namespace printers
56} // namespace indicator
57} // namespace unity
058
=== added file 'src/client.h'
--- src/client.h 1970-01-01 00:00:00 +0000
+++ src/client.h 2017-01-10 21:54:44 +0000
@@ -0,0 +1,56 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include "job.h"
20#include "printer.h"
21
22#include <core/signal.h>
23
24
25namespace unity {
26namespace indicator {
27namespace printers {
28
29 class Client {
30 public:
31 explicit Client() = default;
32 virtual ~Client() = default;
33
34 // Signals corresponding to printers
35 virtual core::Signal<const Printer&>& printer_state_changed() = 0;
36
37 // Signals corresponding to jobs
38 virtual core::Signal<const Job&>& job_state_changed() = 0;
39
40 // Methods to manage notification monitoring
41 virtual void create_subscription() = 0;
42 virtual void renew_subscription() = 0;
43 virtual void cancel_subscription() = 0;
44
45 // To iniitalize the indicator with current jobs
46 virtual void refresh() = 0;
47
48 private:
49 // disable copying
50 Client(const Client&) = delete;
51 Client& operator=(const Client&) = delete;
52 };
53
54} // printers
55} // indicators
56} // unity
057
=== added file 'src/cups-client.cpp'
--- src/cups-client.cpp 1970-01-01 00:00:00 +0000
+++ src/cups-client.cpp 2017-01-10 21:54:44 +0000
@@ -0,0 +1,328 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "cups-client.h"
18#include "cups-cupsd-notifier.h"
19
20#include <cups/cups.h>
21
22#include <stdexcept>
23
24namespace unity {
25namespace indicator {
26namespace printers {
27
28#define NOTIFY_LEASE_DURATION (24 * 60 * 60)
29
30
31class CupsClient::Impl {
32public:
33 Impl()
34 {
35 GError *error = nullptr;
36
37 m_notifier_proxy = notifier_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
38 G_DBUS_PROXY_FLAGS_NONE,
39 nullptr,
40 CUPS_DBUS_PATH,
41 nullptr,
42 &error);
43
44 if (error != nullptr) {
45 std::string msg{"Error creating cups notifier proxy: "};
46 throw std::runtime_error(msg + error->message);
47 g_clear_error(&error);
48 }
49
50 g_object_connect(m_notifier_proxy,
51 "signal::job-created", on_job_changed, this,
52 "signal::job-state", on_job_changed, this,
53 "signal::job-completed", on_job_changed, this,
54 "signal::printer-state-changed", on_printer_state_changed, this,
55 nullptr);
56 }
57
58 ~Impl()
59 {
60 if (m_notifier_proxy != nullptr) {
61 g_signal_handlers_disconnect_by_data(m_notifier_proxy, this);
62 g_clear_object(&m_notifier_proxy);
63 }
64
65 // Cancel the subscription from cups, so its notifier can exit.
66 cancel_subscription();
67 }
68
69 // Signals to propagate
70 core::Signal<const Printer&>& printer_state_changed()
71 {
72 return m_printer_state_changed;
73 }
74
75 core::Signal<const Job&>& job_state_changed()
76 {
77 return m_job_state_changed;
78 }
79
80 void create_subscription()
81 {
82 ipp_t *req;
83 ipp_t *resp;
84 ipp_attribute_t *attr;
85
86 req = ippNewRequest (IPP_CREATE_PRINTER_SUBSCRIPTION);
87 ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI,
88 "printer-uri", NULL, "/");
89 ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD,
90 "notify-events", NULL, "all");
91 ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
92 "notify-recipient-uri", NULL, "dbus://");
93 ippAddInteger (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
94 "notify-lease-duration", NOTIFY_LEASE_DURATION);
95
96 resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
97 if (!resp || cupsLastError() != IPP_OK) {
98 g_warning ("Error subscribing to CUPS notifications: %s\n",
99 cupsLastErrorString ());
100 return;
101 }
102
103 attr = ippFindAttribute (resp, "notify-subscription-id", IPP_TAG_INTEGER);
104 if (attr) {
105 m_subscription_id = ippGetInteger (attr, 0);
106 } else {
107 g_warning ("ipp-create-printer-subscription response doesn't contain "
108 "subscription id.\n");
109 }
110 ippDelete (resp);
111
112 // Set up to renew the subscription a minute before it expires
113 g_timeout_add_seconds(NOTIFY_LEASE_DURATION - 60,
114 on_subscription_timeout,
115 this);
116 }
117
118 void renew_subscription()
119 {
120 ipp_t *req;
121 ipp_t *resp;
122
123 req = ippNewRequest (IPP_RENEW_SUBSCRIPTION);
124 ippAddInteger (req, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
125 "notify-subscription-id", m_subscription_id);
126 ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI,
127 "printer-uri", NULL, "/");
128 ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
129 "notify-recipient-uri", NULL, "dbus://");
130 ippAddInteger (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
131 "notify-lease-duration", NOTIFY_LEASE_DURATION);
132
133 resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
134 if (!resp || cupsLastError() != IPP_OK) {
135 g_warning ("Error renewing CUPS subscription %d: %s\n",
136 m_subscription_id, cupsLastErrorString ());
137 create_subscription();
138 }
139
140 ippDelete (resp);
141 }
142
143 void cancel_subscription()
144 {
145 ipp_t *req;
146 ipp_t *resp;
147
148 if (m_subscription_id <= 0) {
149 return;
150 }
151
152 req = ippNewRequest (IPP_CANCEL_SUBSCRIPTION);
153 ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI,
154 "printer-uri", NULL, "/");
155 ippAddInteger (req, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
156 "notify-subscription-id", m_subscription_id);
157
158 resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
159 if (!resp || cupsLastError() != IPP_OK) {
160 g_warning ("Error unsubscribing to CUPS notifications: %s\n",
161 cupsLastErrorString ());
162 return;
163 }
164
165 ippDelete (resp);
166 }
167
168 void refresh()
169 {
170 int num_dests;
171 cups_dest_t* dests;
172
173 num_dests = cupsGetDests(&dests);
174 for (int i = 0; i < num_dests; i++) {
175 auto printer = get_printer_info(dests[i].name);
176
177 cups_job_t* jobs;
178 const auto num_jobs = cupsGetJobs(&jobs, dests[i].name,
179 true, CUPS_WHICHJOBS_ACTIVE);
180 for (int j = 0; j < num_jobs; j++) {
181 Job job;
182 job.id = jobs[j].id;
183 job.state = static_cast<Job::State>(jobs[j].state);
184 job.name = jobs[j].title;
185
186 job.printer = printer;
187
188 m_job_state_changed(job);
189 }
190 cupsFreeJobs(num_jobs, jobs);
191 }
192 cupsFreeDests(num_dests, dests);
193 }
194
195private:
196 // Method to get Printer object from the name
197 Printer get_printer_info(const std::string& name)
198 {
199 int num_dests;
200 cups_dest_t* dests;
201 cups_dest_t* our_dest;
202 Printer printer;
203 printer.name = name;
204
205 num_dests = cupsGetDests(&dests);
206 our_dest = cupsGetDest(name.c_str(), nullptr,
207 num_dests, dests);
208
209 // Get the printer's description
210 auto description = cupsGetOption("printer-info",
211 our_dest->num_options,
212 our_dest->options);
213 if (description != nullptr) {
214 printer.description = description;
215 }
216
217 cupsFreeDests(num_dests, dests);
218 return printer;
219 }
220
221 static gboolean on_subscription_timeout(gpointer gthis)
222 {
223 static_cast<Impl*>(gthis)->renew_subscription();
224 return G_SOURCE_CONTINUE;
225 }
226
227 static void on_job_changed (Notifier*,
228 const char* printer_text,
229 const char* printer_uri,
230 const char *printer_name,
231 unsigned int printer_state,
232 const char *printer_state_reasons,
233 bool printer_is_accepting_jobs,
234 unsigned int job_id,
235 unsigned int job_state,
236 const char *job_state_reasons,
237 const char *job_name,
238 unsigned int job_impressions_completed,
239 gpointer gthis)
240 {
241 auto self = static_cast<Impl*>(gthis);
242
243 auto printer = self->get_printer_info(printer_name);
244 printer.state = static_cast<Printer::State>(printer_state);
245 printer.text = printer_text;
246 printer.uri = printer_uri;
247 printer.state_reasons = printer_state_reasons;
248 printer.accepting_jobs = printer_is_accepting_jobs;
249
250 Job job;
251 job.printer = printer;
252 job.state = static_cast<Job::State>(job_state);
253 job.id = job_id;
254 job.name = job_name;
255 job.state_reasons = job_state_reasons;
256 job.impressions_completed = job_impressions_completed;
257
258 self->m_job_state_changed(job);
259 }
260
261 static void on_printer_state_changed(Notifier*,
262 const char* text,
263 const char* uri,
264 const char* name,
265 unsigned int state,
266 const char* state_reasons,
267 bool is_accepting_jobs,
268 gpointer gthis)
269 {
270 auto self = static_cast<Impl*>(gthis);
271
272 auto printer = self->get_printer_info(name);
273 printer.state = static_cast<Printer::State>(state);
274 printer.text = text;
275 printer.uri = uri;
276 printer.state_reasons = state_reasons;
277 printer.accepting_jobs = is_accepting_jobs;
278 self->m_printer_state_changed(printer);
279 }
280
281 int m_subscription_id = 0;
282 Notifier* m_notifier_proxy = nullptr;
283 core::Signal<const Printer&> m_printer_state_changed;
284 core::Signal<const Job&> m_job_state_changed;
285};
286
287CupsClient::CupsClient() :
288 p(new Impl())
289{
290}
291
292CupsClient::~CupsClient()
293{
294}
295
296core::Signal<const Printer&>& CupsClient::printer_state_changed()
297{
298 return p->printer_state_changed();
299}
300
301core::Signal<const Job&>& CupsClient::job_state_changed()
302{
303 return p->job_state_changed();
304}
305
306void CupsClient::create_subscription()
307{
308 p->create_subscription();
309}
310
311void CupsClient::renew_subscription()
312{
313 p->renew_subscription();
314}
315
316void CupsClient::cancel_subscription()
317{
318 p->cancel_subscription();
319}
320
321void CupsClient::refresh()
322{
323 p->refresh();
324}
325
326} // printers
327} // indicators
328} // unity
0329
=== added file 'src/cups-client.h'
--- src/cups-client.h 1970-01-01 00:00:00 +0000
+++ src/cups-client.h 2017-01-10 21:54:44 +0000
@@ -0,0 +1,65 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include "client.h"
20#include "job.h"
21#include "printer.h"
22
23#include <core/signal.h>
24
25#include <memory>
26
27namespace unity {
28namespace indicator {
29namespace printers {
30
31#define CUPS_DBUS_NAME "org.cups.cupsd.Notifier"
32#define CUPS_DBUS_PATH "/org/cups/cupsd/Notifier"
33#define CUPS_DBUS_INTERFACE "org.cups.cupsd.Notifier"
34
35 class CupsClient : public Client {
36 public:
37 CupsClient();
38 virtual ~CupsClient();
39
40 // Signals corresponding to printers
41 core::Signal<const Printer&>& printer_state_changed() override;
42
43 // Signals corresponding to jobs
44 core::Signal<const Job&>& job_state_changed() override;
45
46 // Methods to manage notification monitoring
47 virtual void create_subscription() override;
48 virtual void renew_subscription() override;
49 virtual void cancel_subscription() override;
50
51 // To initialize the indicator with current jobs
52 virtual void refresh() override;
53
54 private:
55 class Impl;
56 std::unique_ptr<Impl> p;
57
58 // disable copying
59 CupsClient(const CupsClient&) = delete;
60 CupsClient& operator=(const CupsClient&) = delete;
61 };
62
63} // printers
64} // indicators
65} // unity
066
=== added file 'src/exporter.cpp'
--- src/exporter.cpp 1970-01-01 00:00:00 +0000
+++ src/exporter.cpp 2017-01-10 21:54:44 +0000
@@ -0,0 +1,158 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "exporter.h"
18
19#include <core/signal.h>
20
21namespace unity {
22namespace indicator {
23namespace printers {
24
25class Exporter::Impl
26{
27public:
28
29 Impl()
30 {
31 }
32
33 ~Impl()
34 {
35 if (m_bus != nullptr) {
36 if (m_exported_menu_id) {
37 g_dbus_connection_unexport_menu_model(m_bus, m_exported_menu_id);
38 }
39
40 if (m_exported_actions_id) {
41 g_dbus_connection_unexport_action_group(m_bus,
42 m_exported_actions_id);
43 }
44 }
45
46 if (m_own_id) {
47 g_bus_unown_name(m_own_id);
48 }
49
50 g_clear_object(&m_bus);
51 }
52
53 core::Signal<> name_lost;
54
55 void publish(const std::shared_ptr<Actions>& actions,
56 const std::shared_ptr<Client>& client)
57 {
58 m_actions = actions;
59 m_client = client;
60 m_menu.reset(new Menu(m_actions, m_client));
61 m_own_id = g_bus_own_name(G_BUS_TYPE_SESSION,
62 INDICATOR_BUS_NAME,
63 G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
64 on_bus_acquired,
65 nullptr,
66 on_name_lost,
67 this,
68 nullptr);
69 }
70
71private:
72 static void on_bus_acquired(GDBusConnection* connection,
73 const gchar* name,
74 gpointer gthis)
75 {
76 g_debug("bus acquired: %s", name);
77 static_cast<Impl*>(gthis)->on_bus_acquired(connection, name);
78 }
79
80 void on_bus_acquired(GDBusConnection* bus, const gchar* /*name*/)
81 {
82 m_bus = static_cast<GDBusConnection*>(g_object_ref(G_OBJECT(bus)));
83
84 // export the actions
85 GError * error = nullptr;
86 const auto id = g_dbus_connection_export_action_group(m_bus,
87 INDICATOR_BUS_PATH,
88 m_actions->action_group(),
89 &error);
90 if (id)
91 {
92 m_exported_actions_id = id;
93 }
94 else
95 {
96 g_warning("cannot export action group: %s", error->message);
97 g_clear_error(&error);
98 }
99
100 // export the menus
101 const auto path = std::string(INDICATOR_BUS_PATH) + "/menu";
102 m_exported_menu_id = g_dbus_connection_export_menu_model(m_bus,
103 path.c_str(),
104 m_menu->menu_model(),
105 &error);
106 if (error != nullptr) {
107 g_warning("cannot export menu: %s", error->message);
108 g_clear_error(&error);
109 }
110
111 m_client->create_subscription();
112 m_client->refresh();
113 }
114
115 static void on_name_lost(GDBusConnection*, const gchar* name,
116 gpointer gthis)
117 {
118 g_debug("name lost: %s", name);
119 static_cast<Impl*>(gthis)->name_lost();
120 }
121
122
123 guint m_exported_menu_id = 0;
124 guint m_own_id = 0;
125 guint m_exported_actions_id = 0;
126 GDBusConnection* m_bus = nullptr;
127 std::shared_ptr<Actions> m_actions;
128 std::shared_ptr<Client> m_client;
129 std::shared_ptr<Menu> m_menu;
130};
131
132
133
134Exporter::Exporter():
135 p(new Impl())
136{
137}
138
139
140Exporter::~Exporter()
141{
142}
143
144core::Signal<>& Exporter::name_lost()
145{
146 return p->name_lost;
147}
148
149void Exporter::publish(const std::shared_ptr<Actions>& actions,
150 const std::shared_ptr<Client>& client)
151{
152 p->publish(actions, client);
153}
154
155
156} // namespace printers
157} // namespace indicator
158} // namespace unity
0159
=== added file 'src/exporter.h'
--- src/exporter.h 1970-01-01 00:00:00 +0000
+++ src/exporter.h 2017-01-10 21:54:44 +0000
@@ -0,0 +1,60 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include "actions.h"
20#include "client.h"
21#include "menu.h"
22
23#include <core/signal.h>
24
25#include <memory> // std::shared_ptr
26#include <vector>
27
28namespace unity {
29namespace indicator {
30namespace printers {
31
32#define INDICATOR_BUS_NAME "com.canonical.indicator.printers"
33#define INDICATOR_BUS_PATH "/com/canonical/indicator/printers"
34
35/**
36 * \brief Exports actions and menu to DBus.
37 */
38class Exporter
39{
40public:
41 Exporter();
42 virtual ~Exporter();
43
44 core::Signal<>& name_lost();
45
46 void publish(const std::shared_ptr<Actions>& actions,
47 const std::shared_ptr<Client>& client);
48
49private:
50 class Impl;
51 std::unique_ptr<Impl> p;
52
53 // disable copying
54 Exporter(const Exporter&) = delete;
55 Exporter& operator=(const Exporter&) = delete;
56};
57
58} // namespace printers
59} // namespace indicator
60} // namespace unity
061
=== removed file 'src/indicator-menu-item.c'
--- src/indicator-menu-item.c 2012-02-12 15:10:07 +0000
+++ src/indicator-menu-item.c 1970-01-01 00:00:00 +0000
@@ -1,404 +0,0 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "indicator-menu-item.h"
20
21#include <math.h>
22
23
24G_DEFINE_TYPE (IndicatorMenuItem, indicator_menu_item, GTK_TYPE_MENU_ITEM)
25
26
27struct _IndicatorMenuItemPrivate
28{
29 GtkImage *image;
30 GtkWidget *label;
31 GtkWidget *right_label;
32 gboolean right_is_lozenge;
33};
34
35
36enum {
37 PROP_0,
38 PROP_ICON,
39 PROP_ICON_NAME,
40 PROP_LABEL,
41 PROP_RIGHT,
42 PROP_RIGHT_IS_LOZENGE,
43 N_PROPERTIES
44};
45
46static GParamSpec *properties[N_PROPERTIES];
47
48
49static gint
50gtk_widget_get_font_size (GtkWidget *widget)
51{
52 const PangoFontDescription *font;
53
54 font = gtk_style_context_get_font (gtk_widget_get_style_context (widget),
55 gtk_widget_get_state_flags (widget));
56
57 return pango_font_description_get_size (font) / PANGO_SCALE;
58}
59
60static void
61cairo_lozenge (cairo_t *cr, double x, double y, double w, double h)
62{
63 double radius = MIN (w / 2.0, h / 2.0);
64 double x1 = x + w - radius;
65 double x2 = x + radius;
66 double y1 = y + radius;
67 double y2 = y + h - radius;
68
69 cairo_move_to (cr, x+radius, y);
70 cairo_arc (cr, x1, y1, radius, M_PI * 1.5, M_PI * 2);
71 cairo_arc (cr, x1, y2, radius, 0, M_PI * 0.5);
72 cairo_arc (cr, x2, y2, radius, M_PI * 0.5, M_PI);
73 cairo_arc (cr, x2, y1, radius, M_PI, M_PI * 1.5);
74}
75
76static gboolean
77detail_label_draw (GtkWidget *widget,
78 cairo_t *cr,
79 gpointer data)
80{
81 GtkAllocation allocation;
82 double x, y, w, h;
83 GdkRGBA color;
84 PangoLayout *layout;
85 PangoRectangle layout_extents;
86 gboolean is_lozenge = *(gboolean *)data;
87 gint font_size = gtk_widget_get_font_size (widget);
88
89 /* let the label handle the drawing if it's not a lozenge */
90 if (!is_lozenge)
91 return FALSE;
92
93 layout = gtk_label_get_layout (GTK_LABEL(widget));
94 pango_layout_get_extents (layout, NULL, &layout_extents);
95 pango_extents_to_pixels (&layout_extents, NULL);
96
97 gtk_widget_get_allocation (widget, &allocation);
98 x = -font_size / 2.0;
99 y = 1;
100 w = allocation.width;
101 h = MIN (allocation.height, layout_extents.height + 4);
102
103 if (layout_extents.width == 0)
104 return TRUE;
105
106 gtk_style_context_get_color (gtk_widget_get_style_context (widget),
107 gtk_widget_get_state_flags (widget),
108 &color);
109 gdk_cairo_set_source_rgba (cr, &color);
110
111 cairo_set_line_width (cr, 1.0);
112 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
113 cairo_lozenge (cr, x - font_size / 2.0, y, w + font_size, h);
114
115 x += (w - layout_extents.width) / 2.0;
116 y += (h - layout_extents.height) / 2.0;
117 cairo_move_to (cr, floor (x), floor (y));
118 pango_cairo_layout_path (cr, layout);
119 cairo_fill (cr);
120
121 return TRUE;
122}
123
124
125static void
126indicator_menu_item_get_property (GObject *object,
127 guint property_id,
128 GValue *value,
129 GParamSpec *pspec)
130{
131 IndicatorMenuItem *self = INDICATOR_MENU_ITEM (object);
132
133 switch (property_id)
134 {
135 case PROP_ICON:
136 g_value_set_object (value, indicator_menu_item_get_icon (self));
137 break;
138
139 case PROP_ICON_NAME:
140 g_value_set_string (value, indicator_menu_item_get_icon_name (self));
141 break;
142
143 case PROP_LABEL:
144 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (self->priv->label)));
145 break;
146
147 case PROP_RIGHT:
148 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (self->priv->right_label)));
149 break;
150
151 case PROP_RIGHT_IS_LOZENGE:
152 g_value_set_boolean (value, self->priv->right_is_lozenge);
153 break;
154
155 default:
156 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
157 }
158}
159
160
161static void
162indicator_menu_item_set_property (GObject *object,
163 guint property_id,
164 const GValue *value,
165 GParamSpec *pspec)
166{
167 switch (property_id)
168 {
169 case PROP_ICON:
170 indicator_menu_item_set_icon (INDICATOR_MENU_ITEM (object),
171 g_value_get_object (value));
172 break;
173
174 case PROP_ICON_NAME:
175 indicator_menu_item_set_icon_name (INDICATOR_MENU_ITEM (object),
176 g_value_get_string (value));
177 break;
178
179 case PROP_LABEL:
180 indicator_menu_item_set_label (INDICATOR_MENU_ITEM (object),
181 g_value_get_string (value));
182 break;
183
184 case PROP_RIGHT:
185 indicator_menu_item_set_right (INDICATOR_MENU_ITEM (object),
186 g_value_get_string (value));
187 break;
188
189 case PROP_RIGHT_IS_LOZENGE:
190 indicator_menu_item_set_right_is_lozenge (INDICATOR_MENU_ITEM (object),
191 g_value_get_boolean (value));
192 break;
193
194
195 default:
196 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
197 }
198}
199
200
201static void
202indicator_menu_item_dispose (GObject *object)
203{
204 IndicatorMenuItem *self = INDICATOR_MENU_ITEM (object);
205
206 g_clear_object (&self->priv->image);
207 g_clear_object (&self->priv->label);
208 g_clear_object (&self->priv->right_label);
209
210 G_OBJECT_CLASS (indicator_menu_item_parent_class)->dispose (object);
211}
212
213
214static void
215indicator_menu_item_class_init (IndicatorMenuItemClass *klass)
216{
217 GObjectClass *object_class = G_OBJECT_CLASS (klass);
218
219 g_type_class_add_private (klass, sizeof (IndicatorMenuItemPrivate));
220
221 object_class->get_property = indicator_menu_item_get_property;
222 object_class->set_property = indicator_menu_item_set_property;
223 object_class->dispose = indicator_menu_item_dispose;
224
225 properties[PROP_ICON] = g_param_spec_object ("icon",
226 "Icon",
227 "Icon for this menu item",
228 GDK_TYPE_PIXBUF,
229 G_PARAM_READWRITE);
230
231 properties[PROP_ICON_NAME] = g_param_spec_string ("icon-name",
232 "Icon name",
233 "Name of the themed icon",
234 "",
235 G_PARAM_READWRITE);
236
237 properties[PROP_LABEL] = g_param_spec_string ("label",
238 "Label",
239 "The text for the main label",
240 "",
241 G_PARAM_READWRITE);
242
243 properties[PROP_RIGHT] = g_param_spec_string ("right",
244 "Right",
245 "The text on the right side of the menu item",
246 "",
247 G_PARAM_READWRITE);
248
249 properties[PROP_RIGHT_IS_LOZENGE] = g_param_spec_boolean ("right-is-lozenge",
250 "Right is a lozenge",
251 "Whether the right label is displayed as a lonzenge",
252 FALSE,
253 G_PARAM_READWRITE);
254
255 g_object_class_install_properties (object_class, N_PROPERTIES, properties);
256}
257
258
259static void
260indicator_menu_item_init (IndicatorMenuItem *self)
261{
262 IndicatorMenuItemPrivate *priv;
263 gint spacing;
264 GtkWidget *hbox;
265
266 priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
267 INDICATOR_TYPE_MENU_ITEM,
268 IndicatorMenuItemPrivate);
269 self->priv = priv;
270
271 gtk_widget_style_get (GTK_WIDGET (self),
272 "toggle-spacing", &spacing,
273 NULL);
274
275 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, spacing);
276
277 priv->image = g_object_new (GTK_TYPE_IMAGE, NULL);
278 g_object_ref_sink (priv->image);
279 gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (priv->image), FALSE, FALSE, 0);
280
281 priv->label = g_object_new (GTK_TYPE_LABEL,
282 "xalign", 0.0,
283 NULL);
284 g_object_ref_sink (priv->label);
285 gtk_box_pack_start (GTK_BOX (hbox), priv->label, TRUE, TRUE, 0);
286
287 priv->right_label = g_object_new (GTK_TYPE_LABEL,
288 "xalign", 1.0,
289 "width-chars", 2,
290 NULL);
291 gtk_style_context_add_class (gtk_widget_get_style_context (priv->right_label),
292 "accelerator");
293 g_signal_connect (priv->right_label,
294 "draw",
295 G_CALLBACK (detail_label_draw),
296 &priv->right_is_lozenge);
297 g_object_ref_sink (priv->right_label);
298 gtk_box_pack_start (GTK_BOX (hbox),
299 priv->right_label,
300 FALSE,
301 FALSE,
302 gtk_widget_get_font_size (priv->right_label) / 2.0 + 1);
303
304 gtk_container_add (GTK_CONTAINER (self), hbox);
305
306 priv->right_is_lozenge = FALSE;
307}
308
309
310IndicatorMenuItem *
311indicator_menu_item_new (void)
312{
313 return g_object_new (INDICATOR_TYPE_MENU_ITEM, NULL);
314}
315
316
317const gchar *
318indicator_menu_item_get_label (IndicatorMenuItem *self)
319{
320 return gtk_label_get_label (GTK_LABEL (self->priv->label));
321}
322
323
324void
325indicator_menu_item_set_label (IndicatorMenuItem *self,
326 const gchar *text)
327{
328 gtk_label_set_label (GTK_LABEL (self->priv->label), text);
329 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LABEL]);
330}
331
332
333const gchar *
334indicator_menu_item_get_right (IndicatorMenuItem *self)
335{
336 return gtk_label_get_label (GTK_LABEL (self->priv->right_label));
337}
338
339
340void
341indicator_menu_item_set_right (IndicatorMenuItem *self,
342 const gchar *text)
343{
344 gtk_label_set_label (GTK_LABEL (self->priv->right_label), text);
345 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RIGHT]);
346}
347
348
349gboolean
350indicator_menu_item_get_right_is_lozenge (IndicatorMenuItem *self)
351{
352 return self->priv->right_is_lozenge;
353}
354
355
356void
357indicator_menu_item_set_right_is_lozenge (IndicatorMenuItem *self,
358 gboolean is_lozenge)
359{
360 self->priv->right_is_lozenge = is_lozenge;
361 gtk_widget_queue_draw (self->priv->right_label);
362 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RIGHT_IS_LOZENGE]);
363}
364
365
366GdkPixbuf *
367indicator_menu_item_get_icon (IndicatorMenuItem *self)
368{
369 if (gtk_image_get_storage_type (self->priv->image) == GTK_IMAGE_PIXBUF)
370 return gtk_image_get_pixbuf (self->priv->image);
371 else
372 return NULL;
373}
374
375
376void
377indicator_menu_item_set_icon (IndicatorMenuItem *self,
378 GdkPixbuf *icon)
379{
380 gtk_image_set_from_pixbuf (self->priv->image, icon);
381 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON]);
382}
383
384
385const gchar *
386indicator_menu_item_get_icon_name (IndicatorMenuItem *self)
387{
388 const gchar *name = NULL;
389
390 if (gtk_image_get_storage_type (self->priv->image) == GTK_IMAGE_ICON_NAME)
391 gtk_image_get_icon_name (self->priv->image, &name, NULL);
392
393 return name;
394}
395
396
397void
398indicator_menu_item_set_icon_name (IndicatorMenuItem *self,
399 const gchar *name)
400{
401 gtk_image_set_from_icon_name (self->priv->image, name, GTK_ICON_SIZE_MENU);
402 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON_NAME]);
403}
404
4050
=== removed file 'src/indicator-menu-item.h'
--- src/indicator-menu-item.h 2012-02-12 13:20:44 +0000
+++ src/indicator-menu-item.h 1970-01-01 00:00:00 +0000
@@ -1,82 +0,0 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef INDICATOR_MENU_ITEM_H
20#define INDICATOR_MENU_ITEM_H
21
22#include <gtk/gtk.h>
23
24G_BEGIN_DECLS
25
26#define INDICATOR_TYPE_MENU_ITEM indicator_menu_item_get_type()
27
28#define INDICATOR_MENU_ITEM(obj) \
29 (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
30 INDICATOR_TYPE_MENU_ITEM, IndicatorMenuItem))
31
32#define INDICATOR_MENU_ITEM_CLASS(klass) \
33 (G_TYPE_CHECK_CLASS_CAST ((klass), \
34 INDICATOR_TYPE_MENU_ITEM, IndicatorMenuItemClass))
35
36#define INDICATOR_IS_MENU_ITEM(obj) \
37 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
38 INDICATOR_TYPE_MENU_ITEM))
39
40#define INDICATOR_IS_MENU_ITEM_CLASS(klass) \
41 (G_TYPE_CHECK_CLASS_TYPE ((klass), \
42 INDICATOR_TYPE_MENU_ITEM))
43
44#define INDICATOR_MENU_ITEM_GET_CLASS(obj) \
45 (G_TYPE_INSTANCE_GET_CLASS ((obj), \
46 INDICATOR_TYPE_MENU_ITEM, IndicatorMenuItemClass))
47
48typedef struct _IndicatorMenuItem IndicatorMenuItem;
49typedef struct _IndicatorMenuItemClass IndicatorMenuItemClass;
50typedef struct _IndicatorMenuItemPrivate IndicatorMenuItemPrivate;
51
52struct _IndicatorMenuItem
53{
54 GtkMenuItem parent;
55 IndicatorMenuItemPrivate *priv;
56};
57
58struct _IndicatorMenuItemClass
59{
60 GtkMenuItemClass parent_class;
61};
62
63GType indicator_menu_item_get_type (void) G_GNUC_CONST;
64
65IndicatorMenuItem *indicator_menu_item_new (void);
66
67const gchar * indicator_menu_item_get_label (IndicatorMenuItem *self);
68void indicator_menu_item_set_label (IndicatorMenuItem *self, const gchar *text);
69const gchar * indicator_menu_item_get_right (IndicatorMenuItem *self);
70void indicator_menu_item_set_right (IndicatorMenuItem *self, const gchar *text);
71
72gboolean indicator_menu_item_get_right_is_lozenge (IndicatorMenuItem *self);
73void indicator_menu_item_set_right_is_lozenge (IndicatorMenuItem *self, gboolean is_lozenge);
74const gchar * indicator_menu_item_get_icon_name (IndicatorMenuItem *self);
75void indicator_menu_item_set_icon (IndicatorMenuItem *self, GdkPixbuf *icon);
76GdkPixbuf * indicator_menu_item_get_icon (IndicatorMenuItem *self);
77void indicator_menu_item_set_icon_name (IndicatorMenuItem *self, const gchar *name);
78
79G_END_DECLS
80
81#endif
82
830
=== removed file 'src/indicator-printers-menu.c'
--- src/indicator-printers-menu.c 2012-03-03 10:40:46 +0000
+++ src/indicator-printers-menu.c 1970-01-01 00:00:00 +0000
@@ -1,339 +0,0 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "indicator-printers-menu.h"
20
21#include <glib/gi18n.h>
22
23#include <cups/cups.h>
24
25#include "spawn-printer-settings.h"
26
27
28G_DEFINE_TYPE (IndicatorPrintersMenu, indicator_printers_menu, G_TYPE_OBJECT)
29
30
31struct _IndicatorPrintersMenuPrivate
32{
33 DbusmenuMenuitem *root;
34 GHashTable *printers; /* printer name -> dbusmenuitem */
35 CupsNotifier *cups_notifier;
36};
37
38
39enum {
40 PROP_0,
41 PROP_CUPS_NOTIFIER,
42 NUM_PROPERTIES
43};
44
45GParamSpec *properties[NUM_PROPERTIES];
46
47
48static void
49dispose (GObject *object)
50{
51 IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (object);
52
53 if (self->priv->printers) {
54 g_hash_table_unref (self->priv->printers);
55 self->priv->printers = NULL;
56 }
57
58 g_clear_object (&self->priv->root);
59 g_clear_object (&self->priv->cups_notifier);
60
61 G_OBJECT_CLASS (indicator_printers_menu_parent_class)->dispose (object);
62}
63
64
65void
66set_property (GObject *object,
67 guint property_id,
68 const GValue *value,
69 GParamSpec *pspec)
70{
71 IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (object);
72
73 switch (property_id) {
74 case PROP_CUPS_NOTIFIER:
75 indicator_printers_menu_set_cups_notifier (self,
76 g_value_get_object (value));
77 break;
78
79 default:
80 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
81 }
82}
83
84
85void
86get_property (GObject *object,
87 guint property_id,
88 GValue *value,
89 GParamSpec *pspec)
90{
91 IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (object);
92
93 switch (property_id) {
94 case PROP_CUPS_NOTIFIER:
95 g_value_set_object (value,
96 indicator_printers_menu_get_cups_notifier (self));
97 break;
98
99 default:
100 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
101 }
102}
103
104
105static void
106indicator_printers_menu_class_init (IndicatorPrintersMenuClass *klass)
107{
108 GObjectClass *object_class = G_OBJECT_CLASS (klass);
109
110 g_type_class_add_private (klass, sizeof (IndicatorPrintersMenuPrivate));
111
112 object_class->dispose = dispose;
113 object_class->get_property = get_property;
114 object_class->set_property = set_property;
115
116 properties[PROP_CUPS_NOTIFIER] = g_param_spec_object ("cups-notifier",
117 "Cups Notifier",
118 "A cups notifier object",
119 CUPS_TYPE_NOTIFIER,
120 G_PARAM_READWRITE);
121
122 g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
123}
124
125
126static void
127on_printer_item_activated (DbusmenuMenuitem *menuitem,
128 guint timestamp,
129 gpointer user_data)
130{
131 const gchar *printer = user_data;
132 spawn_printer_settings_with_args ("--show-jobs %s", printer);
133}
134
135
136static void
137update_indicator_visibility (IndicatorPrintersMenu *self)
138{
139 GList *it;
140 gboolean is_visible = FALSE;
141
142 for (it = dbusmenu_menuitem_get_children (self->priv->root);
143 it;
144 it = g_list_next (it))
145 {
146 DbusmenuMenuitem *child = it->data;
147 if ((is_visible = dbusmenu_menuitem_property_get_bool (child, "visible")))
148 break;
149 }
150
151 dbusmenu_menuitem_property_set_bool (self->priv->root, "visible", is_visible);
152}
153
154
155static void
156update_printer_menuitem (IndicatorPrintersMenu *self,
157 const char *printer,
158 int state)
159{
160 DbusmenuMenuitem *item;
161 int njobs;
162 cups_job_t *jobs;
163
164 njobs = cupsGetJobs (&jobs, printer, 1, CUPS_WHICHJOBS_ACTIVE);
165 cupsFreeJobs (njobs, jobs);
166
167 if (njobs < 0) {
168 g_warning ("printer '%s' does not exist\n", printer);
169 return;
170 }
171
172 item = g_hash_table_lookup (self->priv->printers, printer);
173
174 if (!item) {
175 item = dbusmenu_menuitem_new ();
176 dbusmenu_menuitem_property_set (item, "type", "indicator-item");
177 dbusmenu_menuitem_property_set (item, "indicator-icon-name", "printer");
178 dbusmenu_menuitem_property_set (item, "indicator-label", printer);
179 g_signal_connect_data (item, "item-activated",
180 G_CALLBACK (on_printer_item_activated),
181 g_strdup (printer), (GClosureNotify) g_free, 0);
182
183 dbusmenu_menuitem_child_append(self->priv->root, item);
184 g_hash_table_insert (self->priv->printers, g_strdup (printer), item);
185 }
186
187 if (njobs == 0) {
188 dbusmenu_menuitem_property_set_bool (item, "visible", FALSE);
189 update_indicator_visibility (self);
190 return;
191 }
192
193 /* there are jobs for this printer. Make sure the indicator and the menu
194 * item for that printer are shown */
195 dbusmenu_menuitem_property_set_bool (self->priv->root, "visible", TRUE);
196 dbusmenu_menuitem_property_set_bool (item, "visible", TRUE);
197
198 switch (state) {
199 case IPP_PRINTER_STOPPED:
200 dbusmenu_menuitem_property_set (item, "indicator-right", _("Paused"));
201 dbusmenu_menuitem_property_set_bool (item, "indicator-right-is-lozenge", FALSE);
202 break;
203
204 case IPP_PRINTER_PROCESSING: {
205 gchar *jobstr = g_strdup_printf ("%d", njobs);
206 dbusmenu_menuitem_property_set (item, "indicator-right", jobstr);
207 dbusmenu_menuitem_property_set_bool (item, "indicator-right-is-lozenge", TRUE);
208 g_free (jobstr);
209 break;
210 }
211 }
212}
213
214
215static void
216update_all_printer_menuitems (IndicatorPrintersMenu *self)
217{
218 int ndests, i;
219 cups_dest_t *dests;
220
221 ndests = cupsGetDests (&dests);
222 for (i = 0; i < ndests; i++) {
223 int state = atoi (cupsGetOption ("printer-state",
224 dests[i].num_options,
225 dests[i].options));
226 update_printer_menuitem (self, dests[i].name, state);
227 }
228 cupsFreeDests (ndests, dests);
229}
230
231
232static void
233update_job (CupsNotifier *cups_notifier,
234 const gchar *text,
235 const gchar *printer_uri,
236 const gchar *printer_name,
237 guint printer_state,
238 const gchar *printer_state_reasons,
239 gboolean printer_is_accepting_jobs,
240 guint job_id,
241 guint job_state,
242 const gchar *job_state_reasons,
243 const gchar *job_name,
244 guint job_impressions_completed,
245 gpointer user_data)
246{
247 IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (user_data);
248
249 /* CUPS doesn't send the printer's name for these events. Update all menu
250 * items as a temporary workaround */
251 if (job_state == IPP_JOB_CANCELLED ||
252 job_state == IPP_JOB_ABORTED ||
253 job_state == IPP_JOB_COMPLETED)
254 update_all_printer_menuitems (self);
255 else
256 update_printer_menuitem (self, printer_name, printer_state);
257}
258
259
260static void
261on_printer_state_changed (CupsNotifier *object,
262 const gchar *text,
263 const gchar *printer_uri,
264 const gchar *printer_name,
265 guint printer_state,
266 const gchar *printer_state_reasons,
267 gboolean printer_is_accepting_jobs,
268 gpointer user_data)
269{
270 IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (user_data);
271
272 update_printer_menuitem (self, printer_name, printer_state);
273}
274
275
276static void
277indicator_printers_menu_init (IndicatorPrintersMenu *self)
278{
279 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
280 INDICATOR_TYPE_PRINTERS_MENU,
281 IndicatorPrintersMenuPrivate);
282
283 self->priv->root = dbusmenu_menuitem_new ();
284 dbusmenu_menuitem_property_set_bool (self->priv->root, "visible", FALSE);
285
286 self->priv->printers = g_hash_table_new_full (g_str_hash,
287 g_str_equal,
288 g_free,
289 g_object_unref);
290
291 /* create initial menu items */
292 update_all_printer_menuitems (self);
293}
294
295
296IndicatorPrintersMenu *
297indicator_printers_menu_new (void)
298{
299 return g_object_new (INDICATOR_TYPE_PRINTERS_MENU, NULL);
300}
301
302
303DbusmenuMenuitem *
304indicator_printers_menu_get_root (IndicatorPrintersMenu *self)
305{
306 return self->priv->root;
307}
308
309
310CupsNotifier *
311indicator_printers_menu_get_cups_notifier (IndicatorPrintersMenu *self)
312{
313 return self->priv->cups_notifier;
314}
315
316
317void
318indicator_printers_menu_set_cups_notifier (IndicatorPrintersMenu *self,
319 CupsNotifier *cups_notifier)
320{
321 if (self->priv->cups_notifier) {
322 g_object_disconnect (self->priv->cups_notifier,
323 "any-signal", update_job, self,
324 "any-signal", on_printer_state_changed, self,
325 NULL);
326 g_clear_object (&self->priv->cups_notifier);
327 }
328
329 if (cups_notifier) {
330 self->priv->cups_notifier = g_object_ref (cups_notifier);
331 g_object_connect (self->priv->cups_notifier,
332 "signal::job-created", update_job, self,
333 "signal::job-state", update_job, self,
334 "signal::job-completed", update_job, self,
335 "signal::printer-state-changed", on_printer_state_changed, self,
336 NULL);
337 }
338}
339
3400
=== removed file 'src/indicator-printers-menu.h'
--- src/indicator-printers-menu.h 2012-02-12 13:20:44 +0000
+++ src/indicator-printers-menu.h 1970-01-01 00:00:00 +0000
@@ -1,77 +0,0 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef INDICATOR_PRINTERS_MENU_H
20#define INDICATOR_PRINTERS_MENU_H
21
22#include <glib-object.h>
23#include <libdbusmenu-glib/dbusmenu-glib.h>
24
25#include "cups-notifier.h"
26
27G_BEGIN_DECLS
28
29#define INDICATOR_TYPE_PRINTERS_MENU indicator_printers_menu_get_type()
30
31#define INDICATOR_PRINTERS_MENU(obj) \
32 (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
33 INDICATOR_TYPE_PRINTERS_MENU, IndicatorPrintersMenu))
34
35#define INDICATOR_PRINTERS_MENU_CLASS(klass) \
36 (G_TYPE_CHECK_CLASS_CAST ((klass), \
37 INDICATOR_TYPE_PRINTERS_MENU, IndicatorPrintersMenuClass))
38
39#define INDICATOR_IS_PRINTERS_MENU(obj) \
40 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
41 INDICATOR_TYPE_PRINTERS_MENU))
42
43#define INDICATOR_IS_PRINTERS_MENU_CLASS(klass) \
44 (G_TYPE_CHECK_CLASS_TYPE ((klass), \
45 INDICATOR_TYPE_PRINTERS_MENU))
46
47#define INDICATOR_PRINTERS_MENU_GET_CLASS(obj) \
48 (G_TYPE_INSTANCE_GET_CLASS ((obj), \
49 INDICATOR_TYPE_PRINTERS_MENU, IndicatorPrintersMenuClass))
50
51typedef struct _IndicatorPrintersMenu IndicatorPrintersMenu;
52typedef struct _IndicatorPrintersMenuClass IndicatorPrintersMenuClass;
53typedef struct _IndicatorPrintersMenuPrivate IndicatorPrintersMenuPrivate;
54
55struct _IndicatorPrintersMenu
56{
57 GObject parent;
58 IndicatorPrintersMenuPrivate *priv;
59};
60
61struct _IndicatorPrintersMenuClass
62{
63 GObjectClass parent_class;
64};
65
66GType indicator_printers_menu_get_type (void) G_GNUC_CONST;
67
68IndicatorPrintersMenu *indicator_printers_menu_new (void);
69DbusmenuMenuitem * indicator_printers_menu_get_root (IndicatorPrintersMenu *menu);
70CupsNotifier * indicator_printers_menu_get_cups_notifier (IndicatorPrintersMenu *self);
71void indicator_printers_menu_set_cups_notifier (IndicatorPrintersMenu *self,
72 CupsNotifier *cups_notifier);
73
74G_END_DECLS
75
76#endif
77
780
=== removed file 'src/indicator-printers-service.c'
--- src/indicator-printers-service.c 2014-05-15 11:13:15 +0000
+++ src/indicator-printers-service.c 1970-01-01 00:00:00 +0000
@@ -1,206 +0,0 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <libindicator/indicator-service.h>
20#include <libdbusmenu-glib/dbusmenu-glib.h>
21#include <gtk/gtk.h>
22#include <cups/cups.h>
23#include "dbus-names.h"
24#include "config.h"
25
26#include "cups-notifier.h"
27#include "indicator-printers-menu.h"
28#include "indicator-printer-state-notifier.h"
29
30#define NOTIFY_LEASE_DURATION (24 * 60 * 60)
31
32
33static int
34create_subscription ()
35{
36 ipp_t *req;
37 ipp_t *resp;
38 ipp_attribute_t *attr;
39 int id = 0;
40
41 req = ippNewRequest (IPP_CREATE_PRINTER_SUBSCRIPTION);
42 ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI,
43 "printer-uri", NULL, "/");
44 ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD,
45 "notify-events", NULL, "all");
46 ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
47 "notify-recipient-uri", NULL, "dbus://");
48 ippAddInteger (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
49 "notify-lease-duration", NOTIFY_LEASE_DURATION);
50
51 resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
52 if (!resp || cupsLastError() != IPP_OK) {
53 g_warning ("Error subscribing to CUPS notifications: %s\n",
54 cupsLastErrorString ());
55 return 0;
56 }
57
58 attr = ippFindAttribute (resp, "notify-subscription-id", IPP_TAG_INTEGER);
59 if (attr)
60 id = ippGetInteger (attr, 0);
61 else
62 g_warning ("ipp-create-printer-subscription response doesn't contain "
63 "subscription id.\n");
64
65 ippDelete (resp);
66 return id;
67}
68
69
70static gboolean
71renew_subscription (int id)
72{
73 ipp_t *req;
74 ipp_t *resp;
75
76 req = ippNewRequest (IPP_RENEW_SUBSCRIPTION);
77 ippAddInteger (req, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
78 "notify-subscription-id", id);
79 ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI,
80 "printer-uri", NULL, "/");
81 ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
82 "notify-recipient-uri", NULL, "dbus://");
83 ippAddInteger (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
84 "notify-lease-duration", NOTIFY_LEASE_DURATION);
85
86 resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
87 if (!resp || cupsLastError() != IPP_OK) {
88 g_warning ("Error renewing CUPS subscription %d: %s\n",
89 id, cupsLastErrorString ());
90 return FALSE;
91 }
92
93 ippDelete (resp);
94 return TRUE;
95}
96
97
98static gboolean
99renew_subscription_timeout (gpointer userdata)
100{
101 int *subscription_id = userdata;
102
103 if (*subscription_id <= 0 || !renew_subscription (*subscription_id))
104 *subscription_id = create_subscription ();
105
106 return TRUE;
107}
108
109
110void
111cancel_subscription (int id)
112{
113 ipp_t *req;
114 ipp_t *resp;
115
116 if (id <= 0)
117 return;
118
119 req = ippNewRequest (IPP_CANCEL_SUBSCRIPTION);
120 ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI,
121 "printer-uri", NULL, "/");
122 ippAddInteger (req, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
123 "notify-subscription-id", id);
124
125 resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
126 if (!resp || cupsLastError() != IPP_OK) {
127 g_warning ("Error subscribing to CUPS notifications: %s\n",
128 cupsLastErrorString ());
129 return;
130 }
131
132 ippDelete (resp);
133}
134
135static void
136name_lost (GDBusConnection *connection,
137 const gchar *name,
138 gpointer user_data)
139{
140 int subscription_id = GPOINTER_TO_INT (user_data);
141
142 cancel_subscription (subscription_id);
143 gtk_main_quit ();
144}
145
146int main (int argc, char *argv[])
147{
148 /* Init i18n */
149 setlocale (LC_ALL, "");
150 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
151 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
152 textdomain (GETTEXT_PACKAGE);
153
154 DbusmenuServer *menuserver;
155 CupsNotifier *cups_notifier;
156 IndicatorPrintersMenu *menu;
157 IndicatorPrinterStateNotifier *state_notifier;
158 GError *error = NULL;
159 int subscription_id;
160
161 gtk_init (&argc, &argv);
162
163 subscription_id = create_subscription ();
164 g_timeout_add_seconds (NOTIFY_LEASE_DURATION - 60,
165 renew_subscription_timeout,
166 &subscription_id);
167
168 g_bus_own_name (G_BUS_TYPE_SESSION,
169 INDICATOR_PRINTERS_DBUS_NAME,
170 G_BUS_NAME_OWNER_FLAGS_NONE,
171 NULL, NULL, name_lost,
172 GINT_TO_POINTER (subscription_id), NULL);
173
174 cups_notifier = cups_notifier_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
175 0,
176 NULL,
177 CUPS_DBUS_PATH,
178 NULL,
179 &error);
180 if (error) {
181 g_warning ("Error creating cups notify handler: %s", error->message);
182 g_error_free (error);
183 return 1;
184 }
185
186 menu = g_object_new (INDICATOR_TYPE_PRINTERS_MENU,
187 "cups-notifier", cups_notifier,
188 NULL);
189
190 menuserver = dbusmenu_server_new (INDICATOR_PRINTERS_DBUS_OBJECT_PATH);
191 dbusmenu_server_set_root (menuserver,
192 indicator_printers_menu_get_root (menu));
193
194 state_notifier = g_object_new (INDICATOR_TYPE_PRINTER_STATE_NOTIFIER,
195 "cups-notifier", cups_notifier,
196 NULL);
197
198 gtk_main ();
199
200 g_object_unref (menu);
201 g_object_unref (menuserver);
202 g_object_unref (state_notifier);
203 g_object_unref (cups_notifier);
204 return 0;
205}
206
2070
=== removed file 'src/indicator-printers.c'
--- src/indicator-printers.c 2014-02-20 22:16:42 +0000
+++ src/indicator-printers.c 1970-01-01 00:00:00 +0000
@@ -1,311 +0,0 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "config.h"
20
21#include "indicator-printers.h"
22#include "indicator-menu-item.h"
23#include "dbus-names.h"
24
25#include <glib/gi18n-lib.h>
26#include <gtk/gtk.h>
27#include <gio/gio.h>
28
29#include <libindicator/indicator.h>
30#include <libindicator/indicator-image-helper.h>
31
32#include <libdbusmenu-gtk/menu.h>
33#include <libdbusmenu-gtk/menuitem.h>
34
35
36INDICATOR_SET_VERSION
37INDICATOR_SET_TYPE(INDICATOR_PRINTERS_TYPE)
38
39
40G_DEFINE_TYPE (IndicatorPrinters, indicator_printers, INDICATOR_OBJECT_TYPE)
41
42
43struct _IndicatorPrintersPrivate
44{
45 IndicatorObjectEntry entry;
46 guint name_watch;
47};
48
49
50static void
51dispose (GObject *object)
52{
53 IndicatorPrinters *self = INDICATOR_PRINTERS (object);
54 if (self->priv->name_watch != 0) {
55 g_bus_unwatch_name(self->priv->name_watch);
56 self->priv->name_watch = 0;
57 }
58 g_clear_object (&self->priv->entry.menu);
59 g_clear_object (&self->priv->entry.image);
60 G_OBJECT_CLASS (indicator_printers_parent_class)->dispose (object);
61}
62
63
64static GList *
65get_entries (IndicatorObject *io)
66{
67 IndicatorPrinters *self = INDICATOR_PRINTERS (io);
68 return g_list_append (NULL, &self->priv->entry);
69}
70
71
72static void
73indicator_printers_class_init (IndicatorPrintersClass *klass)
74{
75 GObjectClass *object_class = G_OBJECT_CLASS (klass);
76 IndicatorObjectClass *io_class = INDICATOR_OBJECT_CLASS (klass);
77
78 g_type_class_add_private (klass, sizeof (IndicatorPrintersPrivate));
79
80 object_class->dispose = dispose;
81
82 io_class->get_entries = get_entries;
83}
84
85
86static void
87name_vanished (GDBusConnection * con,
88 const gchar * name,
89 gpointer user_data)
90{
91 IndicatorPrinters *self = INDICATOR_PRINTERS (user_data);
92
93 indicator_object_set_visible (INDICATOR_OBJECT (self), FALSE);
94}
95
96
97static GdkPixbuf *
98gdk_pixbuf_new_from_encoded_data (guchar *data,
99 gsize length)
100{
101 GInputStream * input;
102 GError *err = NULL;
103 GdkPixbuf *img;
104
105 input = g_memory_input_stream_new_from_data(data, length, NULL);
106 if (input == NULL)
107 return NULL;
108
109 img = gdk_pixbuf_new_from_stream(input, NULL, &err);
110 if (err) {
111 g_warning("%s", err->message);
112 g_error_free(err);
113 }
114
115 g_object_unref(input);
116 return img;
117}
118
119
120static GdkPixbuf *
121g_variant_get_image (GVariant *value)
122{
123 const gchar *strvalue = NULL;
124 gsize length = 0;
125 guchar *icondata;
126 GdkPixbuf *img;
127
128 if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
129 strvalue = g_variant_get_string(value, NULL);
130
131 if (!strvalue || !*strvalue) {
132 g_warning ("%s: value does not contain a base64 encoded image",
133 __func__);
134 return NULL;
135 }
136
137 icondata = g_base64_decode(strvalue, &length);
138 img = gdk_pixbuf_new_from_encoded_data (icondata, length);
139
140 g_free(icondata);
141 return img;
142}
143
144
145static gboolean
146properties_match (const gchar *name,
147 const gchar *prop,
148 GVariant *value,
149 const GVariantType *type)
150{
151 return !g_strcmp0 (name, prop) && g_variant_is_of_type (value, type);
152}
153
154
155static void
156indicator_prop_change_cb (DbusmenuMenuitem *mi,
157 gchar *prop,
158 GVariant *value,
159 gpointer user_data)
160{
161 IndicatorMenuItem *menuitem = user_data;
162
163 if (properties_match (prop, "indicator-label", value, G_VARIANT_TYPE_STRING))
164 indicator_menu_item_set_label (menuitem, g_variant_get_string (value, NULL));
165
166 else if (properties_match (prop, "indicator-right", value, G_VARIANT_TYPE_STRING))
167 indicator_menu_item_set_right (menuitem, g_variant_get_string (value, NULL));
168
169 else if (properties_match (prop, "indicator-icon-name", value, G_VARIANT_TYPE_STRING))
170 indicator_menu_item_set_icon_name (menuitem, g_variant_get_string (value, NULL));
171
172 else if (properties_match (prop, "indicator-icon", value, G_VARIANT_TYPE_STRING)) {
173 GdkPixbuf *pb = g_variant_get_image (value);
174 indicator_menu_item_set_icon (menuitem, pb);
175 g_object_unref (pb);
176 }
177
178 else if (properties_match (prop, "visible", value, G_VARIANT_TYPE_BOOLEAN))
179 gtk_widget_set_visible (GTK_WIDGET (menuitem), g_variant_get_boolean (value));
180
181 else if (properties_match (prop, "indicator-right-is-lozenge", value, G_VARIANT_TYPE_BOOLEAN))
182 indicator_menu_item_set_right_is_lozenge (menuitem, g_variant_get_boolean (value));
183}
184
185
186static void
187root_property_changed (DbusmenuMenuitem *mi,
188 gchar *prop,
189 GVariant *value,
190 gpointer user_data)
191{
192 IndicatorObject *io = user_data;
193
194 if (properties_match (prop, "visible", value, G_VARIANT_TYPE_BOOLEAN))
195 indicator_object_set_visible (io, g_variant_get_boolean (value));
196}
197
198
199static gboolean
200new_indicator_item (DbusmenuMenuitem *newitem,
201 DbusmenuMenuitem *parent,
202 DbusmenuClient *client,
203 gpointer user_data)
204{
205 GtkWidget *menuitem;
206 const gchar *icon_name, *text, *right_text;
207 GVariant *icon;
208 gboolean is_lozenge, visible;
209
210 icon_name = dbusmenu_menuitem_property_get (newitem, "indicator-icon-name");
211 icon = dbusmenu_menuitem_property_get_variant (newitem, "indicator-icon");
212 text = dbusmenu_menuitem_property_get (newitem, "indicator-label");
213 right_text = dbusmenu_menuitem_property_get (newitem, "indicator-right");
214 is_lozenge = dbusmenu_menuitem_property_get_bool (newitem, "indicator-right-is-lozenge");
215 visible = dbusmenu_menuitem_property_get_bool (newitem, "visible");
216
217 menuitem = g_object_new (INDICATOR_TYPE_MENU_ITEM,
218 "icon-name", icon_name,
219 "label", text,
220 "right", right_text,
221 "right-is-lozenge", is_lozenge,
222 "visible", visible,
223 NULL);
224 if (icon) {
225 GdkPixbuf *pb = g_variant_get_image (icon);
226 indicator_menu_item_set_icon (INDICATOR_MENU_ITEM (menuitem), pb);
227 g_object_unref (pb);
228 }
229 gtk_widget_show_all (menuitem);
230
231 dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client),
232 newitem,
233 GTK_MENU_ITEM (menuitem),
234 parent);
235
236 g_signal_connect(G_OBJECT(newitem),
237 "property-changed",
238 G_CALLBACK(indicator_prop_change_cb),
239 menuitem);
240
241 return TRUE;
242}
243
244
245static void
246root_changed (DbusmenuClient *client,
247 DbusmenuMenuitem *newroot,
248 gpointer user_data)
249{
250 IndicatorPrinters *indicator = user_data;
251 gboolean is_visible;
252
253 if (newroot) {
254 is_visible = dbusmenu_menuitem_property_get_bool (newroot, "visible");
255 g_signal_connect (newroot, "property-changed",
256 G_CALLBACK (root_property_changed), indicator);
257 }
258 else
259 is_visible = FALSE;
260
261 indicator_object_set_visible (INDICATOR_OBJECT (indicator), is_visible);
262}
263
264
265static void
266indicator_printers_init (IndicatorPrinters *self)
267{
268 IndicatorPrintersPrivate *priv;
269 DbusmenuGtkMenu *menu;
270 DbusmenuClient *client;
271 GtkImage *image;
272
273 priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
274 INDICATOR_PRINTERS_TYPE,
275 IndicatorPrintersPrivate);
276 self->priv = priv;
277
278 priv->name_watch = g_bus_watch_name(G_BUS_TYPE_SESSION,
279 INDICATOR_PRINTERS_DBUS_NAME,
280 G_BUS_NAME_WATCHER_FLAGS_NONE,
281 NULL, /* appeared */
282 name_vanished,
283 self, NULL);
284
285 menu = dbusmenu_gtkmenu_new(INDICATOR_PRINTERS_DBUS_NAME,
286 INDICATOR_PRINTERS_DBUS_OBJECT_PATH);
287
288 client = DBUSMENU_CLIENT (dbusmenu_gtkmenu_get_client (menu));
289 dbusmenu_client_add_type_handler(client,
290 "indicator-item",
291 new_indicator_item);
292 g_signal_connect (client, "root-changed", G_CALLBACK (root_changed), self);
293
294 image = indicator_image_helper ("printer-symbolic");
295 gtk_widget_show (GTK_WIDGET (image));
296
297 priv->entry.name_hint = PACKAGE_NAME;
298 priv->entry.accessible_desc = _("Printers");
299 priv->entry.menu = GTK_MENU (g_object_ref_sink (menu));
300 priv->entry.image = g_object_ref_sink (image);
301
302 indicator_object_set_visible (INDICATOR_OBJECT (self), FALSE);
303}
304
305
306IndicatorPrinters *
307indicator_printers_new (void)
308{
309 return g_object_new (INDICATOR_PRINTERS_TYPE, NULL);
310}
311
3120
=== removed file 'src/indicator-printers.h'
--- src/indicator-printers.h 2012-02-03 13:39:34 +0000
+++ src/indicator-printers.h 1970-01-01 00:00:00 +0000
@@ -1,70 +0,0 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef INDICATOR_PRINTERS_H
20#define INDICATOR_PRINTERS_H
21
22#include <libindicator/indicator-object.h>
23
24G_BEGIN_DECLS
25
26#define INDICATOR_PRINTERS_TYPE indicator_printers_get_type()
27
28#define INDICATOR_PRINTERS(obj) \
29 (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
30 INDICATOR_PRINTERS_TYPE, IndicatorPrinters))
31
32#define INDICATOR_PRINTERS_CLASS(klass) \
33 (G_TYPE_CHECK_CLASS_CAST ((klass), \
34 INDICATOR_PRINTERS_TYPE, IndicatorPrintersClass))
35
36#define INDICATOR_IS_PRINTERS(obj) \
37 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
38 INDICATOR_PRINTERS_TYPE))
39
40#define INDICATOR_IS_PRINTERS_CLASS(klass) \
41 (G_TYPE_CHECK_CLASS_TYPE ((klass), \
42 INDICATOR_PRINTERS_TYPE))
43
44#define INDICATOR_PRINTERS_GET_CLASS(obj) \
45 (G_TYPE_INSTANCE_GET_CLASS ((obj), \
46 INDICATOR_PRINTERS_TYPE, IndicatorPrintersClass))
47
48typedef struct _IndicatorPrinters IndicatorPrinters;
49typedef struct _IndicatorPrintersClass IndicatorPrintersClass;
50typedef struct _IndicatorPrintersPrivate IndicatorPrintersPrivate;
51
52struct _IndicatorPrinters
53{
54 IndicatorObject parent;
55 IndicatorPrintersPrivate *priv;
56};
57
58struct _IndicatorPrintersClass
59{
60 IndicatorObjectClass parent_class;
61};
62
63GType indicator_printers_get_type (void) G_GNUC_CONST;
64
65IndicatorPrinters *indicator_printers_new (void);
66
67G_END_DECLS
68
69#endif
70
710
=== added file 'src/job.h'
--- src/job.h 1970-01-01 00:00:00 +0000
+++ src/job.h 2017-01-10 21:54:44 +0000
@@ -0,0 +1,50 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include "printer.h"
20
21#include <string>
22
23namespace unity {
24namespace indicator {
25namespace printers {
26
27 struct Job {
28 // State to match ipp_jstate_t from cups.h
29 typedef enum {
30 PENDING = 3,
31 HELD,
32 PROCESSING,
33 STOPPED,
34 CANCELED,
35 ABORTED,
36 COMPLETED
37 } State;
38 State state = PENDING;
39
40 uint32_t id = 0;
41 std::string name;
42 std::string state_reasons;
43 uint32_t impressions_completed = 0;
44
45 Printer printer;
46 };
47
48} // printers
49} // indicators
50} // unity
051
=== added file 'src/main.cpp'
--- src/main.cpp 1970-01-01 00:00:00 +0000
+++ src/main.cpp 2017-01-10 21:54:44 +0000
@@ -0,0 +1,60 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "actions-live.h"
18#include "cups-client.h"
19#include "exporter.h"
20#include "utils.h"
21
22#include <glib/gi18n.h>
23#include <gio/gio.h>
24
25using namespace unity::indicator::printers;
26
27int main() {
28 // Work around a deadlock in glib's type initialization.
29 // It can be removed when https://bugzilla.gnome.org/show_bug.cgi?id=674885 is fixed.
30 g_type_ensure(G_TYPE_DBUS_CONNECTION);
31
32 // boilerplate i18n
33 setlocale(LC_ALL, "");
34
35 // Need to prepend $SNAP to properly load translations
36 auto localedir = Utilities::prepend_snap_path(GETTEXT_LOCALEDIR);
37 bindtextdomain(GETTEXT_PACKAGE, localedir.c_str());
38 textdomain(GETTEXT_PACKAGE);
39
40 // set up us the machine
41 auto loop = g_main_loop_new(nullptr, false);
42
43 // create the menus
44 auto actions = std::make_shared<LiveActions>();
45 auto client = std::make_shared<CupsClient>();
46
47 // export them & run until we lose the busname
48 Exporter exporter;
49 exporter.name_lost().connect([loop](){
50 g_message("%s exiting; failed/lost bus ownership", GETTEXT_PACKAGE);
51 g_main_loop_quit(loop);
52 });
53 exporter.publish(actions, client);
54
55 g_main_loop_run(loop);
56
57 // cleanup
58 g_main_loop_unref(loop);
59 return 0;
60}
061
=== added file 'src/menu.cpp'
--- src/menu.cpp 1970-01-01 00:00:00 +0000
+++ src/menu.cpp 2017-01-10 21:54:44 +0000
@@ -0,0 +1,291 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "menu.h"
18
19#include <glib/gi18n.h>
20#include <gio/gio.h>
21
22#include <algorithm>
23#include <iterator>
24#include <map>
25
26namespace unity {
27namespace indicator {
28namespace printers {
29
30
31class Menu::Impl
32{
33public:
34
35 static constexpr char const * ATTRIBUTE_JOB_ID {"x-canonical-job-id"};
36 static constexpr char const * ATTRIBUTE_TYPE {"x-canonical-type"};
37 static constexpr char const * TYPE_SECTION {"section"};
38
39 enum Section {
40 CURRENT,
41 QUEUED,
42 PAUSED,
43 NUM_SECTIONS
44 };
45
46 Impl(const std::shared_ptr<Actions>& actions,
47 const std::shared_ptr<Client>& client):
48 m_actions(actions),
49 m_client(client)
50 {
51 // initialize the menu
52 create_gmenu();
53 update_header();
54
55 m_client->job_state_changed().connect([this](const Job& job) {
56 const auto printer = job.printer;
57 g_debug("State changed for job %u '%s` on printer '%s'",
58 job.id,
59 job.name.c_str(),
60 printer.description.empty() ? printer.name.c_str() : printer.description.c_str());
61
62 // Remove any existing menu item for the job.
63 remove(job);
64
65 Section section = NUM_SECTIONS;
66 switch (job.state) {
67 case Job::State::PENDING:
68 section = QUEUED;
69 break;
70 case Job::State::HELD:
71 section = PAUSED;
72 break;
73 case Job::State::PROCESSING:
74 section = CURRENT;
75 break;
76 case Job::State::STOPPED:
77 case Job::State::CANCELED:
78 case Job::State::ABORTED:
79 case Job::State::COMPLETED:
80 update_header();
81 return;
82 }
83
84 auto model = menu_model_for_section(section);
85 if (model != nullptr) {
86 auto item = create_job_menu_item(job);
87 g_menu_append_item(G_MENU(model), item);
88 g_object_unref(item);
89 m_current_jobs[job.id] = section;
90 }
91
92 update_header();
93 });
94 }
95
96 virtual ~Impl()
97 {
98 g_clear_object(&m_menu);
99 }
100
101 void update_header()
102 {
103 auto action_group = m_actions->action_group();
104 std::string action_name{"printers"};
105 auto state = create_header_state();
106 g_action_group_change_action_state(action_group,
107 action_name.c_str(),
108 state);
109 }
110
111 GVariant* get_serialized_icon(const std::string& icon_name)
112 {
113 auto icon = g_themed_icon_new_with_default_fallbacks(icon_name.c_str());
114 auto ret = g_icon_serialize(icon);
115 g_object_unref(icon);
116
117 return ret;
118 }
119
120 GVariant* create_header_state()
121 {
122 auto title_v = g_variant_new_string(_("Printing"));
123 const bool visible = !m_current_jobs.empty();
124 GVariantBuilder b;
125 g_variant_builder_init(&b, G_VARIANT_TYPE_VARDICT);
126 g_variant_builder_add(&b, "{sv}", "title", title_v);
127 g_variant_builder_add(&b, "{sv}", "accessible-desc", title_v);
128 g_variant_builder_add(&b, "{sv}", "icon", get_serialized_icon("printer-symbolic"));
129 g_variant_builder_add(&b, "{sv}", "visible", g_variant_new_boolean(visible));
130 return g_variant_builder_end(&b);
131 }
132
133 GMenuModel* menu_model()
134 {
135 return G_MENU_MODEL(m_menu);
136 }
137
138 GMenuModel* menu_model_for_section(Section section)
139 {
140 return g_menu_model_get_item_link(G_MENU_MODEL(m_submenu),
141 section,
142 G_MENU_LINK_SECTION);
143 }
144
145 void remove(const Job& job)
146 {
147 Section section = NUM_SECTIONS;
148 if(get_current_section_for_job(job, section)) {
149 auto model = menu_model_for_section(section);
150 auto value = g_variant_new_uint32(job.id);
151 auto pos = find_matching_menu_item(model, ATTRIBUTE_JOB_ID, value);
152
153 if (pos >= 0) {
154 g_menu_remove(G_MENU(model), pos);
155 m_current_jobs.erase(job.id);
156 }
157 }
158 }
159
160private:
161 std::shared_ptr<Actions> m_actions;
162 std::shared_ptr<Client> m_client;
163 std::map<uint32_t, Section> m_current_jobs;
164
165 GMenu* m_submenu = nullptr;
166 GMenu* m_menu = nullptr;
167
168 static GMenuItem* create_section_menu_item(const Section& section)
169 {
170 const char* label;
171 switch (section) {
172 case CURRENT:
173 label = _("Current jobs");
174 break;
175 case QUEUED:
176 label = _("Queued jobs");
177 break;
178 case PAUSED:
179 label = _("Paused jobs");
180 break;
181 default:
182 g_warning("Request for section title of unknown section: %u",
183 static_cast<uint32_t>(section));
184 return nullptr;
185 }
186
187 // create a new item
188 auto item = g_menu_item_new(label, "indicator.section");
189 g_menu_item_set_attribute(item, ATTRIBUTE_TYPE, "s", TYPE_SECTION);
190
191 return item;
192 }
193
194 // Create the GMenuItem for the job.
195 static GMenuItem* create_job_menu_item(const Job& job)
196 {
197 auto menu_item = g_menu_item_new(job.name.c_str(), nullptr);
198 g_menu_item_set_attribute(menu_item, ATTRIBUTE_JOB_ID, "u", job.id);
199
200 return menu_item;
201 }
202
203 // find the position of the menumodel's item with the specified attribute
204 static int find_matching_menu_item(GMenuModel* mm, const char* attr,
205 GVariant* value)
206 {
207 g_return_val_if_fail(value != nullptr, -1);
208
209 for (int i = 0, n = g_menu_model_get_n_items(mm); i < n; ++i) {
210 auto test = g_menu_model_get_item_attribute_value(mm,
211 i,
212 attr,
213 nullptr);
214 const bool equal = g_variant_equal(value, test);
215 g_clear_pointer(&test, g_variant_unref);
216 if (equal) {
217 return i;
218 }
219 }
220
221 return -1;
222 }
223
224 bool get_current_section_for_job(const Job& job, Section& section) const
225 {
226 const auto it = m_current_jobs.find(job.id);
227 if (it == m_current_jobs.end()) {
228 return false;
229 }
230
231 section = it->second;
232 return true;
233 }
234
235 void create_gmenu()
236 {
237 g_assert(m_submenu == nullptr);
238
239 // build the submenu
240 m_submenu = g_menu_new();
241 for(int i = 0; i < NUM_SECTIONS; i++) {
242 // Create the section menu
243 auto section = g_menu_new();
244 g_menu_append_section(m_submenu, nullptr, G_MENU_MODEL(section));
245
246 // Add the label menuitem for the section
247 auto item = create_section_menu_item(static_cast<Section>(i));
248 if (item != nullptr) {
249 g_menu_insert_item(section, 0, item);
250 g_clear_object(&item);
251 }
252
253 g_object_unref(section);
254 }
255
256 // add submenu to the header
257 const std::string detailed_action{"indicator.printers"};
258 auto header = g_menu_item_new(nullptr, detailed_action.c_str());
259 g_menu_item_set_attribute(header, "x-canonical-type", "s",
260 "com.canonical.indicator.root");
261 g_menu_item_set_submenu(header, G_MENU_MODEL(m_submenu));
262 g_object_unref(m_submenu);
263
264 // add header to the menu
265 m_menu = g_menu_new();
266 g_menu_append_item(m_menu, header);
267 g_object_unref(header);
268 }
269
270
271}; // class MenuImpl
272
273
274Menu::Menu(const std::shared_ptr<Actions>& actions,
275 const std::shared_ptr<Client>& client):
276 p(new Impl(actions, client))
277{
278}
279
280Menu::~Menu()
281{
282}
283
284GMenuModel* Menu::menu_model()
285{
286 return p->menu_model();
287}
288
289} // namespace printers
290} // namespace indicator
291} // namespace unity
0292
=== added file 'src/menu.h'
--- src/menu.h 1970-01-01 00:00:00 +0000
+++ src/menu.h 2017-01-10 21:54:44 +0000
@@ -0,0 +1,57 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include "actions.h"
20#include "client.h"
21
22#include <memory> // std::shared_ptr
23#include <vector>
24
25#include <gio/gio.h> // GMenuModel
26
27namespace unity {
28namespace indicator {
29namespace printers {
30
31/**
32 * \brief A menu for a specific profile; eg, Desktop or Phone.
33 *
34 * @see MenuFactory
35 * @see Exporter
36 */
37class Menu
38{
39public:
40 Menu(const std::shared_ptr<Actions>& actions,
41 const std::shared_ptr<Client>& client);
42 virtual ~Menu();
43
44 GMenuModel* menu_model();
45
46private:
47 class Impl;
48 std::unique_ptr<Impl> p;
49
50 // disable copying
51 Menu(const Menu&) = delete;
52 Menu& operator=(const Menu&) = delete;
53};
54
55} // namespace printers
56} // namespace indicator
57} // namespace unity
058
=== added file 'src/printer.h'
--- src/printer.h 1970-01-01 00:00:00 +0000
+++ src/printer.h 2017-01-10 21:54:44 +0000
@@ -0,0 +1,44 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include <string>
20
21namespace unity {
22namespace indicator {
23namespace printers {
24
25 struct Printer {
26 // State to match ipp_jstate_t from cups.h
27 typedef enum {
28 IDLE = 3,
29 PROCESSING,
30 STOPPED
31 } State;
32 State state = IDLE;
33
34 std::string name;
35 std::string description;
36 std::string text;
37 std::string uri;
38 std::string state_reasons;
39 bool accepting_jobs = false;
40 };
41
42} // printers
43} // indicators
44} // unity
045
=== removed file 'src/spawn-printer-settings.c'
--- src/spawn-printer-settings.c 2012-02-15 10:40:19 +0000
+++ src/spawn-printer-settings.c 1970-01-01 00:00:00 +0000
@@ -1,35 +0,0 @@
1
2#include "spawn-printer-settings.h"
3
4void
5spawn_printer_settings ()
6{
7 spawn_printer_settings_with_args (NULL);
8}
9
10
11void
12spawn_printer_settings_with_args (const gchar *fmt,
13 ...)
14{
15 GString *cmdline;
16 GError *err = NULL;
17
18 cmdline = g_string_new ("system-config-printer ");
19
20 if (fmt) {
21 va_list args;
22 va_start (args, fmt);
23 g_string_append_vprintf (cmdline, fmt, args);
24 va_end (args);
25 }
26
27 g_spawn_command_line_async (cmdline->str, &err);
28 if (err) {
29 g_warning ("Could not spawn printer settings: %s", err->message);
30 g_error_free (err);
31 }
32
33 g_string_free (cmdline, TRUE);
34}
35
360
=== removed file 'src/spawn-printer-settings.h'
--- src/spawn-printer-settings.h 2012-02-12 13:58:57 +0000
+++ src/spawn-printer-settings.h 1970-01-01 00:00:00 +0000
@@ -1,11 +0,0 @@
1
2#ifndef SPAWN_PRINTER_SETTINGS_H
3#define SPAWN_PRINTER_SETTINGS_H
4
5#include <glib.h>
6
7void spawn_printer_settings ();
8void spawn_printer_settings_with_args (const gchar *args, ...);
9
10#endif
11
120
=== added file 'src/utils.cpp'
--- src/utils.cpp 1970-01-01 00:00:00 +0000
+++ src/utils.cpp 2017-01-10 21:54:44 +0000
@@ -0,0 +1,37 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "utils.h"
18
19namespace unity {
20namespace indicator {
21namespace printers {
22
23std::string Utilities::prepend_snap_path(const std::string& path)
24{
25 auto get_snap_path = []() {
26 const char* env_snap = getenv("SNAP");
27 if (env_snap == nullptr) {
28 return "";
29 }
30 return env_snap;
31 };
32 return get_snap_path() + path;
33}
34
35} // printers
36} // indicators
37} // unity
038
=== added file 'src/utils.h'
--- src/utils.h 1970-01-01 00:00:00 +0000
+++ src/utils.h 2017-01-10 21:54:44 +0000
@@ -0,0 +1,32 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include <string>
20
21namespace unity {
22namespace indicator {
23namespace printers {
24
25 class Utilities {
26 public:
27 static std::string prepend_snap_path(const std::string& path);
28 };
29
30} // printers
31} // indicators
32} // unity
033
=== removed directory 'test'
=== removed file 'test/Makefile.am'
--- test/Makefile.am 2012-02-16 18:45:24 +0000
+++ test/Makefile.am 1970-01-01 00:00:00 +0000
@@ -1,29 +0,0 @@
1
2noinst_PROGRAMS = mock-cups-notifier
3DISTCLEANFILES = mock-cups-notifier
4
5cups_notifier_sources = \
6 cups-notifier.c \
7 cups-notifier.h
8
9$(cups_notifier_sources): $(top_srcdir)/src/org.cups.cupsd.Notifier.xml
10 gdbus-codegen \
11 --interface-prefix org.cups.cupsd \
12 --c-namespace Cups \
13 --generate-c-code cups-notifier \
14 $^
15
16mock_cups_notifier_SOURCES = \
17 mock-cups-notifier.c
18
19nodist_mock_cups_notifier_SOURCES = $(cups_notifier_sources)
20
21mock_cups_notifier_CPPFLAGS = \
22 $(SERVICE_CFLAGS) \
23 -I$(top_builddir)/src
24
25mock_cups_notifier_LDADD = $(SERVICE_LIBS)
26
27BUILT_SOURCES = $(cups_notifier_sources)
28CLEANFILES = $(BUILT_SOURCES)
29
300
=== removed file 'test/mock-cups-notifier.c'
--- test/mock-cups-notifier.c 2012-02-09 17:19:57 +0000
+++ test/mock-cups-notifier.c 1970-01-01 00:00:00 +0000
@@ -1,52 +0,0 @@
1
2#include <glib.h>
3#include <cups-notifier.h>
4
5
6int main (int argc, char **argv)
7{
8 GMainLoop *loop;
9 CupsNotifier *notifier;
10 GDBusConnection *con;
11 GError *error = NULL;
12
13 g_type_init ();
14
15 loop = g_main_loop_new (NULL, FALSE);
16
17 con = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
18 if (error) {
19 g_printerr ("Error getting system bus: %s\n", error->message);
20 g_error_free (error);
21 goto out;
22 }
23
24 notifier = cups_notifier_skeleton_new ();
25
26 g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (notifier),
27 con,
28 "/org/cups/cupsd/Notifier",
29 &error);
30 if (error) {
31 g_printerr ("Error exporting cups Notifier object: %s\n", error->message);
32 g_error_free (error);
33 goto out;
34 }
35
36 cups_notifier_emit_printer_state_changed (notifier,
37 "Printer state changed!",
38 "file:///tmp/print",
39 "hp-LaserJet-1012",
40 5,
41 "toner-low",
42 FALSE);
43
44 g_main_context_iteration (NULL, FALSE);
45
46out:
47 g_clear_object (&notifier);
48 g_clear_object (&con);
49 g_main_loop_unref (loop);
50 return 0;
51}
52
530
=== added directory 'tests'
=== added file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/CMakeLists.txt 2017-01-10 21:54:44 +0000
@@ -0,0 +1,26 @@
1find_package(GMock REQUIRED)
2
3include_directories(
4 ${CMAKE_SOURCE_DIR}/src
5 ${SERVICE_DEPS_INCLUDE_DIRS}
6)
7link_directories(
8 ${SERVICE_DEPS_LIBRARY_DIRS}
9)
10
11add_executable(test-libindicator-printers
12 test_exporter.cpp
13 test_menu.cpp
14 test_utils.cpp
15)
16target_link_libraries(test-libindicator-printers
17 ${SERVICE_LIB_NAME}
18 ${SERVICE_DEPS_LIBRARIES}
19 ${CUPS_LIBS}
20
21 ${GTEST_LIBRARIES}
22 ${GMOCK_LIBRARIES}
23
24 ${CMAKE_THREAD_LIBS_INIT}
25)
26add_test(test-libindicator-printers test-libindicator-printers)
027
=== added file 'tests/actions-mock.h'
--- tests/actions-mock.h 1970-01-01 00:00:00 +0000
+++ tests/actions-mock.h 2017-01-10 21:54:44 +0000
@@ -0,0 +1,36 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include "actions.h"
20
21namespace unity {
22namespace indicator {
23namespace printers {
24
25 class MockActions: public Actions
26 {
27 public:
28 explicit MockActions(): Actions() {}
29 ~MockActions() = default;
30
31 void open_settings_app() {}
32 };
33
34} // printers
35} // indicator
36} // unity
037
=== added file 'tests/client-mock.h'
--- tests/client-mock.h 1970-01-01 00:00:00 +0000
+++ tests/client-mock.h 2017-01-10 21:54:44 +0000
@@ -0,0 +1,54 @@
1/*
2 * Copyright 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include "client.h"
20
21#include <core/signal.h>
22#include <gmock/gmock.h>
23
24namespace unity {
25namespace indicator {
26namespace printers {
27
28 class MockClient: public Client
29 {
30 public:
31 explicit MockClient(): Client() {}
32 ~MockClient() = default;
33
34 core::Signal<const Printer&>& printer_state_changed()
35 {
36 return m_printer_state_changed;
37 }
38 core::Signal<const Job&>& job_state_changed()
39 {
40 return m_job_state_changed;
41 }
42
43 MOCK_METHOD0(create_subscription, void());
44 MOCK_METHOD0(renew_subscription, void());
45 MOCK_METHOD0(cancel_subscription, void());
46 MOCK_METHOD0(refresh, void());
47
48 core::Signal<const Printer&> m_printer_state_changed;
49 core::Signal<const Job&> m_job_state_changed;
50 };
51
52} // printers
53} // indicator
54} // unity
055
=== added file 'tests/glib-fixture.h'
--- tests/glib-fixture.h 1970-01-01 00:00:00 +0000
+++ tests/glib-fixture.h 2017-01-10 21:54:44 +0000
@@ -0,0 +1,220 @@
1/*
2 * Copyright 2013-2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include <chrono>
20#include <functional> // std::function
21#include <map>
22#include <memory> // std::shared_ptr
23
24#include <glib.h>
25#include <glib/gstdio.h>
26#include <gio/gio.h>
27
28#include <gtest/gtest.h>
29
30#include <locale.h> // setlocale()
31
32class GlibFixture : public ::testing::Test
33{
34 public:
35
36 virtual ~GlibFixture() =default;
37
38 protected:
39
40 virtual void SetUp() override
41 {
42 setlocale(LC_ALL, "C.UTF-8");
43
44 loop = g_main_loop_new(nullptr, false);
45
46 // fail on unexpected messages from this domain
47 g_log_set_fatal_mask(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING);
48
49 g_unsetenv("DISPLAY");
50
51 }
52
53 virtual void TearDown() override
54 {
55 g_test_assert_expected_messages ();
56
57 g_clear_pointer(&loop, g_main_loop_unref);
58 }
59
60 void expectLogMessage (const gchar *domain, GLogLevelFlags level, const gchar *pattern)
61 {
62 g_test_expect_message (domain, level, pattern);
63 }
64
65 private:
66
67 static gboolean
68 wait_for_signal__timeout(gpointer name)
69 {
70 g_error("%s: timed out waiting for signal '%s'", G_STRLOC, (char*)name);
71 return G_SOURCE_REMOVE;
72 }
73
74 static gboolean
75 wait_msec__timeout(gpointer loop)
76 {
77 g_main_loop_quit(static_cast<GMainLoop*>(loop));
78 return G_SOURCE_CONTINUE;
79 }
80
81 protected:
82
83 /* convenience func to loop while waiting for a GObject's signal */
84 void wait_for_signal(gpointer o, const gchar * signal, const int timeout_seconds=5)
85 {
86 // wait for the signal or for timeout, whichever comes first
87 const auto handler_id = g_signal_connect_swapped(o, signal,
88 G_CALLBACK(g_main_loop_quit),
89 loop);
90 const auto timeout_id = g_timeout_add_seconds(timeout_seconds,
91 wait_for_signal__timeout,
92 loop);
93 g_main_loop_run(loop);
94 g_source_remove(timeout_id);
95 g_signal_handler_disconnect(o, handler_id);
96 }
97
98 /* convenience func to loop for N msec */
99 void wait_msec(int msec=50)
100 {
101 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