Commit 22f007d7 authored by John Stowers's avatar John Stowers

Autostart nautilus if configured to show desktop icons

parent eea70cc0
3.0.3
*
* Autostart nautilus at login if it is configured to show
desktop icons (bug 648087)
3.0.2
* Really tweak window theme - both the fallback and the
......
......@@ -15,6 +15,7 @@
import os.path
import optparse
import logging
import gi
gi.require_version("Gtk", "3.0")
......@@ -78,5 +79,7 @@ if __name__ == '__main__':
gtweak.PKG_DATA_DIR = PKG_DATA_DIR
gtweak.ENABLE_TEST = options.test
logging.basicConfig()
MainWindow()
......@@ -17,11 +17,29 @@
from gi.repository import Gtk
import gtweak
from gtweak.utils import AutostartManager
from gtweak.tweakmodel import TweakGroup
from gtweak.widgets import GSettingsSwitchTweak
class DesktopIconTweak(GSettingsSwitchTweak):
def __init__(self, **options):
GSettingsSwitchTweak.__init__(self,
"org.gnome.desktop.background",
"show-desktop-icons",
**options)
#when the user enables nautilus to draw the desktop icons, set nautilus
#to autostart
self.nautilus = AutostartManager(gtweak.DATA_DIR, "nautilus.desktop", "nautilus -n")
self.settings.connect('changed::'+self.key_name, self._on_setting_changed)
def _on_setting_changed(self, setting, key):
self.nautilus.update_start_at_login(
self.settings.get_boolean(key))
TWEAK_GROUPS = (
TweakGroup(
"File Manager",
GSettingsSwitchTweak("org.gnome.desktop.background", "show-desktop-icons")),
DesktopIconTweak()),
)
......@@ -16,14 +16,16 @@
# along with gnome-tweak-tool. If not, see <http://www.gnu.org/licenses/>.
import os.path
import logging
from gi.repository import GLib
class AutostartManager:
def __init__(self, DATA_DIR, desktop_filename, extra_exec_args=""):
self._desktop_file = os.path.join(DATA_DIR, desktop_filename)
def __init__(self, DATA_DIR, desktop_filename, exec_cmd="", extra_exec_args=""):
self._desktop_file = os.path.join(DATA_DIR, "applications", desktop_filename)
self._autostart_file = os.path.join(
GLib.get_user_config_dir(), "autostart", desktop_filename)
self._exec_cmd = exec_cmd
self._extra_exec_args = " %s\n" % extra_exec_args
def is_start_at_login_enabled(self):
......@@ -36,25 +38,29 @@ class AutostartManager:
return False
def update_start_at_login(self, update):
logging.debug("updating autostart desktop file: %s" % update)
if os.path.exists(self._autostart_file):
log.info("Removing autostart desktop file")
logging.info("Removing autostart desktop file")
os.remove(self._autostart_file)
if update:
if not os.path.exists(self._desktop_file):
log.critical("Could not find desktop file: %s" % self._desktop_file)
logging.critical("Could not find desktop file: %s" % self._desktop_file)
return
log.info("Adding autostart desktop file")
logging.info("Adding autostart desktop file")
#copy the original file to the new file, but add the extra exec args
old = open(self._desktop_file, "r")
new = open(self._autostart_file, "w")
for l in old.readlines():
if l.startswith("Exec="):
new.write(l[0:-1])
new.write(self._extra_exec_args)
if self._exec_cmd:
new.write("Exec=%s\n" % self._exec_cmd)
else:
new.write(l[0:-1])
new.write(self._extra_exec_args)
else:
new.write(l)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment