X-Git-Url: http://git.onelab.eu/?p=sface.git;a=blobdiff_plain;f=sface%2Fscreens%2Fuserscreen.py;h=db0d3e78219d0911966aa0976d1167e3b2c59d4d;hp=dd01804633ef459d139c4eb1523272a462591d8f;hb=57955fb30bcffb386779c0b75cc6f8d7db1795d3;hpb=c66463257c5957f79df0a0a02e3f285a41f8bbc1
diff --git a/sface/screens/userscreen.py b/sface/screens/userscreen.py
index dd01804..db0d3e7 100644
--- a/sface/screens/userscreen.py
+++ b/sface/screens/userscreen.py
@@ -15,11 +15,70 @@ NAME_COLUMN = 0
MEMBERSHIP_STATUS_COLUMN = 1
SERVER_MEMBERSHIP_STATUS_COLUMN = 2
+# maximum length of a name to display before clipping
+NAME_MAX_LEN = 48
+
user_status = { "in": "Already Selected",
"out": "Not Selected",
"add": "To be Added",
"remove": "To be Removed"}
+color_status = { "in": QColor.fromRgb(0, 250, 250),
+ "add": QColor.fromRgb(0, 250, 0),
+ "remove": QColor.fromRgb(250, 0, 0) }
+
+
+class UserNameDelegate(QStyledItemDelegate):
+ def __init__(self, parent):
+ QStyledItemDelegate.__init__(self, parent)
+
+ def displayText(self, value, locale):
+ data = str(QStyledItemDelegate.displayText(self, value, locale))
+ if (len(data)>NAME_MAX_LEN):
+ data = data[:(NAME_MAX_LEN-3)] + "..."
+ return QString(data)
+
+ def paint(self, painter, option, index):
+ model = index.model()
+ data = str(self.displayText(index.data(), QLocale()))
+ status_index = model.index(index.row(), MEMBERSHIP_STATUS_COLUMN, index.parent())
+ status_data = status_index.data().toString()
+
+ fm = QFontMetrics(option.font)
+ rect = QRect(option.rect)
+
+ rect.setHeight(rect.height() - 2)
+ rect.setWidth(fm.width(QString(data)) + 6)
+ rect.setX(rect.x() + 5)
+ rect.setY(rect.y() - 1)
+
+ textRect = QRect(option.rect)
+ textRect.setWidth(fm.width(QString(data)) + 6)
+ textRect.setX(rect.x())
+
+ x, y, h, w = rect.x(), rect.y(), rect.height(), rect.width()
+
+ path = QPainterPath()
+ path.addRoundedRect(x - 1, y + 1, w, h, 4, 4)
+
+ painter.save()
+ painter.setRenderHint(QPainter.Antialiasing)
+
+ if option.state & QStyle.State_Selected:
+ painter.fillRect(option.rect, option.palette.color(QPalette.Active, QPalette.Highlight))
+
+ color = None
+ for x in user_status.keys():
+ if (user_status[x] == status_data) and (x in color_status):
+ color = color_status[x]
+
+ if color != None:
+ painter.fillPath(path, color)
+ painter.setPen(QColor.fromRgb(0, 0, 0))
+ painter.drawText(textRect, Qt.AlignVCenter, QString(data))
+
+ painter.restore()
+
class UserView(QTableView):
def __init__(self, parent=None):
QTableView.__init__(self, parent)
@@ -31,6 +90,8 @@ class UserView(QTableView):
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.setToolTip("Double click on a row to change its status.")
+ self.setItemDelegateForColumn(0, UserNameDelegate(self))
+
def keyPressEvent(self, event):
if (event.key() == Qt.Key_Space):
self.toggleSelection()
@@ -66,7 +127,6 @@ class UserView(QTableView):
model = current.model()
node_index = model.index(current.row(), 0, current.parent())
node_data = node_index.data().toString()
- self.emit(SIGNAL('hostnameClicked(QString)'), node_data)
def hideUnusableColumns(self):
self.hideColumn(SERVER_MEMBERSHIP_STATUS_COLUMN)
@@ -98,10 +158,12 @@ class UserModel(QStandardItemModel):
while (os.path.exists(config.getAuthorityListFile(i))):
rec = self.readUserRecord(i)
if rec:
- name = str(rec.get_name())
- if not name in added_persons:
- slice_persons.append({"name": name, "role": "", "member": user_status["out"]})
- added_persons.append(name)
+ type = str(rec.get_type())
+ if (type == "user"):
+ name = str(rec.get_name())
+ if not name in added_persons:
+ slice_persons.append({"name": name, "role": "", "member": user_status["out"]})
+ added_persons.append(name)
i=i+1
rootItem = self.invisibleRootItem()
@@ -211,17 +273,35 @@ class UsersWidget(QWidget):
self.updateView()
def submitFinished(self):
- self.setStatus("Slice data submitted.")
- QTimer.singleShot(1000, self.refresh)
+ self.disconnect(self.process, SIGNAL('finished()'), self.submitFinished)
+
+ faultString = self.process.getFaultString()
+ if not faultString:
+ self.setStatus("Slice user data submitted.")
+ QTimer.singleShot(1000, self.refresh)
+ else:
+ self.setStatus("Slice user submit failed: %s" % (faultString))
def getSliceRecordFinished(self):
- self.setStatus("Authority data refreshed.", timeout=5000)
- self.refreshAuthority()
+ self.disconnect(self.process, SIGNAL('finished()'), self.getSliceRecordFinished)
+
+ faultString = self.process.getFaultString()
+ if not faultString:
+ self.setStatus("Slice record refreshed.")
+ self.refreshAuthority()
+ else:
+ self.setStatus("Slice rec refresh error: %s" % (faultString))
def getAuthorityRecordFinished(self):
- self.setStatus("Slice data refreshed.", timeout=5000)
- self.updateView()
- #self.parent().signalAll("usersUpdated")
+ self.disconnect(self.process, SIGNAL('finished()'), self.getAuthorityRecordFinished)
+
+ faultString = self.process.getFaultString()
+ if not faultString:
+ self.setStatus("User data refreshed.")
+ self.updateView()
+ #self.parent().signalAll("usersUpdated")
+ else:
+ self.setStatus("Authority rec refresh error: %s" % (faultString))
def readSliceRecord(self):
rec_file = config.getSliceRecordFile()
@@ -264,7 +344,6 @@ class UsersWidget(QWidget):
rec_file = config.getSliceRecordFile()
file(rec_file, "w").write(rec.save_to_string())
- self.disconnect(self.process, SIGNAL('finished()'), self.getAuthorityRecordFinished)
self.connect(self.process, SIGNAL('finished()'), self.submitFinished)
self.process.updateRecord(rec_file)
@@ -279,17 +358,15 @@ class UsersWidget(QWidget):
self.setStatus("There is already a process running. Please wait.")
return
- self.disconnect(self.process, SIGNAL('finished()'), self.submitFinished)
self.connect(self.process, SIGNAL('finished()'), self.getSliceRecordFinished)
self.process.getSliceRecord()
self.setStatus("Refreshing slice record. This will take some time...")
def refreshAuthority(self):
- self.disconnect(self.process, SIGNAL('finished()'), self.getSliceRecordFinished)
self.connect(self.process, SIGNAL('finished()'), self.getAuthorityRecordFinished)
- self.process.listRecords(config.getAuthority(), "user", config.getAuthorityListFile())
+ self.process.listRecords(config.getAuthority(), None, config.getAuthorityListFile())
self.setStatus("Refreshing user records. This will take some time...")
def updateView(self):