~mario-carrion/gwibber/gwibber-services

« back to all changes in this revision

Viewing changes to bin/nautilus-extension.py

  • Committer: Mario Carrion
  • Date: 2009-07-27 00:39:14 UTC
  • Revision ID: mario@carrion.ws-20090727003914-84373nqngcph5pmy
Services/Provider implementation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Permission is hereby granted, free of charge, to any person
 
3
# obtaining a copy of this software and associated documentation
 
4
# files (the "Software"), to deal in the Software without
 
5
# restriction, including without limitation the rights to use,
 
6
# copy, modify, merge, publish, distribute, sublicense, and/or sell
 
7
# copies of the Software, and to permit persons to whom the
 
8
# Software is furnished to do so, subject to the following
 
9
# conditions:
 
10
#
 
11
# The above copyright notice and this permission notice shall be
 
12
# included in all copies or substantial portions of the Software.
 
13
#
 
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
15
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 
16
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
17
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 
18
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 
19
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
20
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
21
# OTHER DEALINGS IN THE SOFTWARE.
 
22
#
 
23
# Copyright (c) 2009 Mario Carrion <http://www.mariocarrion.com>
 
24
#
 
25
# Authors:
 
26
#       Mario Carrion <mario@carrion.ws>
 
27
#
 
28
import nautilus
 
29
import os
 
30
import dbus
 
31
 
 
32
class NautilusExtension(nautilus.MenuProvider):
 
33
  def __init__(self):
 
34
    pass
 
35
 
 
36
  def on_gwibber_share(self, menu, file):
 
37
    file=file[7:] # HACK: Remove this
 
38
    print os.spawnv(os.P_NOWAIT,
 
39
              "/home/mario/bin/gwibber-share", # FIXME: Hardcoded path
 
40
              [ 
 
41
               "gwibber-share", 
 
42
               str("--filename=%s" % file), 
 
43
               "-e",
 
44
               "-w"
 
45
              ])
 
46
 
 
47
  def get_file_items(self, window, files):
 
48
    if len(files) == 1:
 
49
      if not files[0].is_directory():
 
50
        #Try to load gwibber using dbus
 
51
        try:
 
52
          bus = dbus.SessionBus()
 
53
          obj = bus.get_object("net.launchpad.Gwibber", "/net/launchpad/gwibber/Interface")
 
54
          gwibber = dbus.Interface(obj, "net.launchpad.Gwibber")
 
55
 
 
56
          item = nautilus.MenuItem(
 
57
            "NautilusPython::gwibber_share",
 
58
            "Share on Gwibber",
 
59
            "Share %s on Gwibber" % files[0].get_name(),
 
60
            "gnome-fs-share")
 
61
          item.connect("activate",self.on_gwibber_share, files[0].get_uri())
 
62
 
 
63
          return item,
 
64
        except:
 
65
          pass
 
66