2013-01-23 15:55:14 +01:00
|
|
|
#!/usr/bin/python2
|
2011-05-25 02:26:41 +02:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2011 Marek Marczykowski <marmarek@mimuw.edu.pl>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
from PyQt4.QtCore import *
|
|
|
|
from PyQt4.QtGui import *
|
|
|
|
|
|
|
|
from qubes.qubes import QubesVmCollection
|
|
|
|
from qubes.qubes import QubesException
|
|
|
|
from qubes.qubes import QubesDaemonPidfile
|
|
|
|
from qubes.qubes import QubesHost
|
|
|
|
|
2012-01-24 16:49:14 +01:00
|
|
|
import qubesmanager.resources_rc
|
2011-05-25 02:26:41 +02:00
|
|
|
|
|
|
|
from pyinotify import WatchManager, Notifier, ThreadedNotifier, EventsCodes, ProcessEvent
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import time
|
2012-02-20 07:56:38 +01:00
|
|
|
|
2011-05-25 02:26:41 +02:00
|
|
|
from operator import itemgetter
|
|
|
|
|
2012-02-20 07:56:38 +01:00
|
|
|
from thread_monitor import *
|
2012-01-24 15:04:28 +01:00
|
|
|
from multiselectwidget import *
|
|
|
|
|
2011-05-25 02:26:41 +02:00
|
|
|
whitelisted_filename = 'whitelisted-appmenus.list'
|
|
|
|
|
2012-01-24 15:04:28 +01:00
|
|
|
class AppListWidgetItem(QListWidgetItem):
|
|
|
|
def __init__(self, name, filename, parent = None):
|
|
|
|
super(AppListWidgetItem, self).__init__(name, parent)
|
2011-05-25 02:26:41 +02:00
|
|
|
self.filename = filename
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-09 19:47:21 +01:00
|
|
|
class AppmenuSelectManager:
|
|
|
|
def __init__(self, vm, apps_multiselect, parent=None):
|
2012-01-24 15:04:28 +01:00
|
|
|
|
2012-02-09 19:47:21 +01:00
|
|
|
self.app_list = apps_multiselect # this is a multiselect wiget
|
2012-01-24 15:04:28 +01:00
|
|
|
|
2011-05-25 02:26:41 +02:00
|
|
|
self.vm = vm
|
2012-03-12 12:53:07 +01:00
|
|
|
if self.vm.template:
|
|
|
|
self.source_vm = self.vm.template
|
2011-05-25 02:26:41 +02:00
|
|
|
else:
|
|
|
|
self.source_vm = self.vm
|
|
|
|
|
2012-01-24 15:04:28 +01:00
|
|
|
self.fill_apps_list()
|
2011-05-25 02:26:41 +02:00
|
|
|
|
2012-01-24 15:04:28 +01:00
|
|
|
def fill_apps_list(self):
|
2011-05-25 02:26:41 +02:00
|
|
|
|
|
|
|
template_dir = self.source_vm.appmenus_templates_dir
|
|
|
|
|
|
|
|
template_file_list = os.listdir(template_dir)
|
|
|
|
|
2012-01-24 15:04:28 +01:00
|
|
|
whitelisted = []
|
|
|
|
if os.path.exists(self.vm.dir_path + '/' + whitelisted_filename):
|
|
|
|
f = open(self.vm.dir_path + '/' + whitelisted_filename, 'r')
|
|
|
|
whitelisted = [item.strip() for item in f]
|
|
|
|
f.close()
|
|
|
|
|
2012-11-27 02:35:39 +01:00
|
|
|
# Check if appmenu entry is really installed
|
|
|
|
whitelisted = [a for a in whitelisted if os.path.exists('%s/apps/%s-%s' % (self.vm.dir_path, self.vm.name, a))]
|
2011-05-25 02:26:41 +02:00
|
|
|
|
2012-11-27 02:35:39 +01:00
|
|
|
self.app_list.clear()
|
2012-01-24 15:04:28 +01:00
|
|
|
|
|
|
|
available_appmenus = []
|
2011-05-25 02:26:41 +02:00
|
|
|
for template_file in template_file_list:
|
|
|
|
desktop_template = open(template_dir + '/' + template_file, 'r')
|
|
|
|
for line in desktop_template:
|
|
|
|
if line.startswith("Name=%VMNAME%: "):
|
|
|
|
desktop_name = line.partition('Name=%VMNAME%: ')[2].strip()
|
2012-01-24 15:04:28 +01:00
|
|
|
available_appmenus.append( (template_file, desktop_name) )
|
2011-05-25 02:26:41 +02:00
|
|
|
break
|
|
|
|
desktop_template.close()
|
|
|
|
|
2012-03-12 15:54:16 +01:00
|
|
|
self.whitelisted_appmenus = [a for a in available_appmenus if a[0] in whitelisted]
|
2012-01-24 15:04:28 +01:00
|
|
|
available_appmenus = [a for a in available_appmenus if a[0] not in whitelisted]
|
|
|
|
|
|
|
|
for a in available_appmenus:
|
|
|
|
self.app_list.available_list.addItem( AppListWidgetItem(a[1], a[0]))
|
|
|
|
|
2012-03-12 15:54:16 +01:00
|
|
|
for a in self.whitelisted_appmenus:
|
2012-01-24 15:04:28 +01:00
|
|
|
self.app_list.selected_list.addItem( AppListWidgetItem(a[1], a[0]))
|
|
|
|
|
|
|
|
self.app_list.available_list.sortItems()
|
|
|
|
self.app_list.selected_list.sortItems()
|
2011-05-25 02:26:41 +02:00
|
|
|
|
|
|
|
def save_list_of_selected(self):
|
2012-03-12 15:54:16 +01:00
|
|
|
sth_changed = False
|
|
|
|
added = []
|
|
|
|
|
2012-01-24 15:04:28 +01:00
|
|
|
for i in range(self.app_list.selected_list.count()):
|
|
|
|
item = self.app_list.selected_list.item(i)
|
2012-03-12 15:54:16 +01:00
|
|
|
if item.filename not in [ w[0] for w in self.whitelisted_appmenus]:
|
|
|
|
added.append(item)
|
|
|
|
|
|
|
|
if self.app_list.selected_list.count() - len(added) < len(self.whitelisted_appmenus): #sth removed
|
|
|
|
sth_changed = True;
|
|
|
|
elif len(added) > 0:
|
|
|
|
sth_changed = True;
|
|
|
|
|
|
|
|
if sth_changed == True:
|
|
|
|
whitelisted = open(self.vm.dir_path + '/' + whitelisted_filename, 'w')
|
|
|
|
for i in range(self.app_list.selected_list.count()):
|
|
|
|
item = self.app_list.selected_list.item(i)
|
|
|
|
whitelisted.write(item.filename + '\n')
|
|
|
|
whitelisted.close()
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2012-01-24 15:04:28 +01:00
|
|
|
|
2012-02-09 19:47:21 +01:00
|
|
|
def save_appmenu_select_changes(self):
|
2012-03-12 15:54:16 +01:00
|
|
|
if self.save_list_of_selected():
|
2013-04-12 01:31:33 +02:00
|
|
|
self.vm.appmenus_remove()
|
|
|
|
self.vm.appmenus_create(verbose=False)
|
2011-05-25 02:26:41 +02:00
|
|
|
|