Example #1
0
	def __init__(self, store, peer, rules, parent):
		super(SyncRuleWidget, self).__init__(parent)

		self.__store = store
		self.__peer = peer
		self.__rules = rules

		self.__descrEdit = QtGui.QLineEdit()
		self.__descrEdit.textEdited.connect(self.__setRule)
		self.__storeBtn = DocButton(store, store, True)
		self.__peerBtn = DocButton(peer, peer, True)
		self.__modeSel = QtGui.QComboBox()
		self.__modeSel.addItems([SyncRuleWidget.MAP[m] for m in SyncRuleWidget.MODES])
		self.__modeSel.currentIndexChanged.connect(self.__setRule)
		self.__reverseBtn = QtGui.QPushButton('Reverse')
		self.__reverseBtn.clicked.connect(self.__reverse)
		self.__removeBtn = QtGui.QPushButton('Remove')
		self.__removeBtn.clicked.connect(self.__remove)

		layout = QtGui.QHBoxLayout()
		layout.addWidget(self.__descrEdit)
		layout.addWidget(self.__storeBtn)
		layout.addWidget(self.__modeSel)
		layout.addWidget(self.__peerBtn)
		layout.addWidget(self.__reverseBtn)
		layout.addWidget(self.__removeBtn)
		self.setLayout(layout)

		mode = (rules.mode(store, peer), rules.mode(peer, store))
		self.__modeSel.setCurrentIndex(SyncRuleWidget.MODES.index(mode))
		self.__descrEdit.setText(rules.descr(store, peer))
Example #2
0
	def __init__(self, tag, typ, fromStore, toStore, item, trayIcon):
		super(ProgressWidget, self).__init__()
		self.tag = tag
		self.__type = typ
		self.__state = Connector().PROGRESS_RUNNING
		self.__fromStore = fromStore
		self.__toStore = toStore
		self.__trayIcon = trayIcon

		self.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Sunken)

		self.__progressInd = QtGui.QLabel()
		self.__progressInd.setMargin(4)
		if typ == Connector().PROGRESS_SYNC:
			self.fromBtn = DocButton(fromStore, fromStore, True)
			self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-sync.png"))
		elif typ == Connector().PROGRESS_REP_DOC:
			self.fromBtn = DocButton(fromStore, item, True)
			self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-replicate.png"))
		elif typ == Connector().PROGRESS_REP_REV:
			self.fromBtn = RevButton(fromStore, item, True)
			self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-replicate.png"))
		self.toBtn = DocButton(toStore, toStore, True)
		self.progressBar = QtGui.QProgressBar()
		self.progressBar.setMinimum(0)
		self.progressBar.setMaximum(0)
		self.__pauseBtn = QtGui.QToolButton()
		self.__pauseBtn.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
		self.__pauseBtn.setIcon(QtGui.QIcon("icons/progress-pause.png"))
		self.__pauseBtn.setToolTip("Pause")
		self.__pauseBtn.clicked.connect(self.__pause)
		self.__stopBtn = QtGui.QToolButton()
		self.__stopBtn.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
		self.__stopBtn.setIcon(QtGui.QIcon("icons/progress-stop.png"))
		self.__stopBtn.setToolTip("Abort")
		self.__stopBtn.clicked.connect(self.__stop)
		self.__skipBtn = QtGui.QToolButton()
		self.__skipBtn.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
		self.__skipBtn.setIcon(QtGui.QIcon("icons/progress-skip.png"))
		self.__skipBtn.setToolTip("Skip")
		self.__skipBtn.clicked.connect(self.__skip)
		self.__skipBtn.hide()
		self.__errorMsg = QtGui.QLabel()
		self.__errorMsg.setWordWrap(True)
		self.__errorMsg.hide()

		layout = QtGui.QHBoxLayout()
		layout.setMargin(0)
		layout.addWidget(self.__progressInd)
		layout.addWidget(self.fromBtn)
		layout.addWidget(self.progressBar)
		layout.addWidget(self.__errorMsg)
		layout.addWidget(self.toBtn)
		layout.addWidget(self.__pauseBtn)
		layout.addWidget(self.__skipBtn)
		if typ != Connector().PROGRESS_SYNC:
			layout.addWidget(self.__stopBtn)
		self.setLayout(layout)

		Connector().regProgressHandler(progress=self.progress)
Example #3
0
	def __init__(self, store, peer, rules, parent):
		super(SyncRuleWidget, self).__init__(parent)

		self.__store = store
		self.__peer = peer
		self.__rules = rules

		self.__descrEdit = QtGui.QLineEdit()
		self.__storeBtn = DocButton(store, store, True)
		self.__peerBtn = DocButton(peer, peer, True)
		self.__modeSel = QtGui.QComboBox()
		self.__modeSel.addItems([SyncRuleWidget.MAP[m] for m in SyncRuleWidget.MODES])
		self.__reverseBtn = QtGui.QPushButton('Reverse')
		self.__reverseBtn.clicked.connect(self.__reverse)
		self.__removeBtn = QtGui.QPushButton('Remove')
		self.__removeBtn.clicked.connect(self.__remove)

		layout = QtGui.QHBoxLayout()
		layout.addWidget(self.__descrEdit)
		layout.addWidget(self.__storeBtn)
		layout.addWidget(self.__modeSel)
		layout.addWidget(self.__peerBtn)
		layout.addWidget(self.__reverseBtn)
		layout.addWidget(self.__removeBtn)
		self.setLayout(layout)

		mode = (rules.mode(store, peer), rules.mode(peer, store))
		self.__modeSel.setCurrentIndex(SyncRuleWidget.MODES.index(mode))
		self.__descrEdit.setText(rules.descr(store, peer))

		# connect signals as last step, otherwise loading the rule already triggers
		self.__descrEdit.textEdited.connect(self.__setRule)
		self.__modeSel.currentIndexChanged.connect(self.__setRule)
Example #4
0
class SyncProgressWidget(QtGui.QFrame):
	def __init__(self, tag, fromStore, toStore, parent=None):
		super(SyncProgressWidget, self).__init__(parent)
		self.tag = tag

		self.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Sunken)

		self.fromBtn = DocButton(fromStore, fromStore, True)
		self.toBtn = DocButton(toStore, toStore, True)
		self.progressBar = QtGui.QProgressBar()
		self.progressBar.setMaximum(255)

		layout = QtGui.QHBoxLayout()
		layout.setMargin(0)
		layout.addWidget(self.fromBtn)
		layout.addWidget(self.progressBar)
		layout.addWidget(self.toBtn)
		self.setLayout(layout)

		Connector().regProgressHandler(progress=self.progress)

	def remove(self):
		Connector().unregProgressHandler(progress=self.progress)
		self.fromBtn.cleanup()
		self.toBtn.cleanup()
		self.deleteLater()

	def progress(self, tag, value):
		if self.tag == tag:
			self.progressBar.setValue(value)
Example #5
0
class StoreWidget(QtGui.QWidget):
	class StoreWatch(Watch):
		def __init__(self, doc, callback):
			self.__callback = callback
			super(StoreWidget.StoreWatch, self).__init__(Watch.TYPE_DOC, doc)

		def triggered(self, cause):
			if cause == Watch.EVENT_DISAPPEARED:
				self.__callback()

	def __init__(self, mountId, parent=None):
		super(StoreWidget, self).__init__(parent)
		self.mountId = mountId
		self.watch = None

		self.mountBtn = QtGui.QPushButton("")
		self.storeBtn = DocButton(withText=True)
		self.mountBtn.clicked.connect(self.mountUnmount)

		layout = QtGui.QHBoxLayout()
		layout.setMargin(0)
		layout.addWidget(self.storeBtn)
		layout.addStretch()
		layout.addWidget(self.mountBtn)
		self.setLayout(layout)

		self.update()

	def update(self):
		if self.watch:
			Connector().unwatch(self.watch)
			self.watch = None

		enum = Connector().enum()
		self.mountBtn.setEnabled(enum.isRemovable(self.mountId))
		if enum.isMounted(self.mountId):
			doc = enum.doc(self.mountId)
			self.mountBtn.setText("Unmount")
			self.storeBtn.setDocument(doc, doc)
			self.watch = StoreWidget.StoreWatch(doc, self.update)
			Connector().watch(self.watch)
			self.mounted = True
		else:
			self.mountBtn.setText("Mount")
			self.storeBtn.setText(enum.name(self.mountId))
			self.mounted = False

	def mountUnmount(self):
		try:
			if self.mounted:
				Connector().unmount(self.mountId)
			else:
				Connector().mount(self.mountId)
				self.update()
		except IOError as e:
			QtGui.QMessageBox.warning(self, 'Error', 'Mount opertaion failed: ' +
				str(e))
Example #6
0
    def __init__(self, tag, typ, fromStore, toStore, item, trayIcon):
        super(ProgressWidget, self).__init__()
        self.tag = tag
        self.__type = typ
        self.__state = Connector().PROGRESS_RUNNING
        self.__fromStore = fromStore
        self.__toStore = toStore
        self.__trayIcon = trayIcon

        self.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Sunken)

        self.__progressInd = QtGui.QLabel()
        self.__progressInd.setMargin(4)
        if typ == Connector().PROGRESS_SYNC:
            self.fromBtn = DocButton(fromStore, fromStore, True)
            self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-sync.png"))
        elif typ == Connector().PROGRESS_REP_DOC:
            self.fromBtn = DocButton(fromStore, item, True)
            self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-replicate.png"))
        elif typ == Connector().PROGRESS_REP_REV:
            self.fromBtn = RevButton(fromStore, item, True)
            self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-replicate.png"))
        self.toBtn = DocButton(toStore, toStore, True)
        self.progressBar = QtGui.QProgressBar()
        self.progressBar.setMinimum(0)
        self.progressBar.setMaximum(0)
        self.__pauseBtn = QtGui.QToolButton()
        self.__pauseBtn.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
        self.__pauseBtn.setIcon(QtGui.QIcon("icons/progress-pause.png"))
        self.__pauseBtn.setToolTip("Pause")
        self.__pauseBtn.clicked.connect(self.__pause)
        self.__stopBtn = QtGui.QToolButton()
        self.__stopBtn.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
        self.__stopBtn.setIcon(QtGui.QIcon("icons/progress-stop.png"))
        self.__stopBtn.setToolTip("Abort")
        self.__stopBtn.clicked.connect(self.__stop)
        self.__skipBtn = QtGui.QToolButton()
        self.__skipBtn.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
        self.__skipBtn.setIcon(QtGui.QIcon("icons/progress-skip.png"))
        self.__skipBtn.setToolTip("Skip")
        self.__skipBtn.clicked.connect(self.__skip)
        self.__skipBtn.hide()
        self.__errorMsg = QtGui.QLabel()
        self.__errorMsg.setWordWrap(True)
        self.__errorMsg.hide()

        layout = QtGui.QHBoxLayout()
        layout.setMargin(0)
        layout.addWidget(self.__progressInd)
        layout.addWidget(self.fromBtn)
        layout.addWidget(self.progressBar)
        layout.addWidget(self.__errorMsg)
        layout.addWidget(self.toBtn)
        layout.addWidget(self.__pauseBtn)
        layout.addWidget(self.__skipBtn)
        if typ != Connector().PROGRESS_SYNC:
            layout.addWidget(self.__stopBtn)
        self.setLayout(layout)

        Connector().regProgressHandler(progress=self.progress)
Example #7
0
	def __init__(self, tag, fromStore, toStore, parent=None):
		super(SyncProgressWidget, self).__init__(parent)
		self.tag = tag

		self.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Sunken)

		self.fromBtn = DocButton(fromStore, fromStore, True)
		self.toBtn = DocButton(toStore, toStore, True)
		self.progressBar = QtGui.QProgressBar()
		self.progressBar.setMaximum(255)

		layout = QtGui.QHBoxLayout()
		layout.setMargin(0)
		layout.addWidget(self.fromBtn)
		layout.addWidget(self.progressBar)
		layout.addWidget(self.toBtn)
		self.setLayout(layout)

		Connector().regProgressHandler(progress=self.progress)
	def __updateStoreButtons(self):
		view = self.__viewHandler.getView()
		curStore = view.store()
		if view.doc():
			allStores = Connector().lookupDoc(view.doc()).stores()
		else:
			allStores = Connector().lookupRev(view.rev())

		# update store buttons in status bar
		for store in set(self.__storeButtons) ^ set(allStores):
			if store in allStores:
				button = DocButton(store, store, checkable=True)
				button.clicked.connect(lambda x,store=store: self.__switchStore(store))
				self.statusBar().addPermanentWidget(button)
				self.__storeButtons[store] = button
			else:
				self.statusBar().removeWidget(self.__storeButtons[store])
				del self.__storeButtons[store]

		for (store,button) in self.__storeButtons.items():
			button.setChecked(store == curStore)
Example #9
0
    def __init__(self, store, stores, descr, parent=None):
        super(DocumentTab, self).__init__(parent)

        if store in stores:
            self.__store = store
        else:
            self.__store = stores[0]
        self.__buttons = {}

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addWidget(QtGui.QLabel("The " + descr + " exists on the following stores:"))
        subLayout = QtGui.QHBoxLayout()
        for store in stores:
            button = DocButton(store, store, True, True)
            button.setCheckable(True)
            button.setChecked(store == self.__store)
            button.clicked.connect(lambda x, store=store: self.__switchStore(store))
            subLayout.addWidget(button)
            self.__buttons[store] = button
        subLayout.addStretch()
        mainLayout.addLayout(subLayout)
        self.setLayout(mainLayout)
Example #10
0
    def __updateStoreButtons(self):
        view = self.__viewHandler.getView()
        curStore = view.store()
        if view.doc():
            allStores = Connector().lookupDoc(view.doc()).stores()
        else:
            allStores = Connector().lookupRev(view.rev())

        # update store buttons in status bar
        for store in set(self.__storeButtons) ^ set(allStores):
            if store in allStores:
                button = DocButton(store, store, checkable=True)
                button.clicked.connect(
                    lambda x, store=store: self.__switchStore(store))
                self.statusBar().addPermanentWidget(button)
                self.__storeButtons[store] = button
            else:
                self.statusBar().removeWidget(self.__storeButtons[store])
                del self.__storeButtons[store]

        for (store, button) in self.__storeButtons.items():
            button.setChecked(store == curStore)
Example #11
0
	def __init__(self, mountId, parent=None):
		super(StoreWidget, self).__init__(parent)
		self.mountId = mountId
		self.watch = None

		self.mountBtn = QtGui.QPushButton("")
		self.storeBtn = DocButton(withText=True)
		self.mountBtn.clicked.connect(self.mountUnmount)

		layout = QtGui.QHBoxLayout()
		layout.setMargin(0)
		layout.addWidget(self.storeBtn)
		layout.addStretch()
		layout.addWidget(self.mountBtn)
		self.setLayout(layout)

		self.update()
Example #12
0
    def __init__(self, store, stores, descr, parent=None):
        super(DocumentTab, self).__init__(parent)

        if store in stores:
            self.__store = store
        else:
            self.__store = stores[0]
        self.__buttons = {}

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addWidget(
            QtGui.QLabel("The " + descr + " exists on the following stores:"))
        subLayout = QtGui.QHBoxLayout()
        for store in stores:
            button = DocButton(store, store, True, True)
            button.setCheckable(True)
            button.setChecked(store == self.__store)
            button.clicked.connect(
                lambda x, store=store: self.__switchStore(store))
            subLayout.addWidget(button)
            self.__buttons[store] = button
        subLayout.addStretch()
        mainLayout.addLayout(subLayout)
        self.setLayout(mainLayout)
Example #13
0
class ProgressWidget(QtGui.QFrame):
	def __init__(self, tag, typ, fromStore, toStore, item, trayIcon):
		super(ProgressWidget, self).__init__()
		self.tag = tag
		self.__type = typ
		self.__state = Connector().PROGRESS_RUNNING
		self.__fromStore = fromStore
		self.__toStore = toStore
		self.__trayIcon = trayIcon

		self.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Sunken)

		self.__progressInd = QtGui.QLabel()
		self.__progressInd.setMargin(4)
		if typ == Connector().PROGRESS_SYNC:
			self.fromBtn = DocButton(fromStore, fromStore, True)
			self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-sync.png"))
		elif typ == Connector().PROGRESS_REP_DOC:
			self.fromBtn = DocButton(fromStore, item, True)
			self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-replicate.png"))
		elif typ == Connector().PROGRESS_REP_REV:
			self.fromBtn = RevButton(fromStore, item, True)
			self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-replicate.png"))
		self.toBtn = DocButton(toStore, toStore, True)
		self.progressBar = QtGui.QProgressBar()
		self.progressBar.setMinimum(0)
		self.progressBar.setMaximum(0)
		self.__pauseBtn = QtGui.QToolButton()
		self.__pauseBtn.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
		self.__pauseBtn.setIcon(QtGui.QIcon("icons/progress-pause.png"))
		self.__pauseBtn.setToolTip("Pause")
		self.__pauseBtn.clicked.connect(self.__pause)
		self.__stopBtn = QtGui.QToolButton()
		self.__stopBtn.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
		self.__stopBtn.setIcon(QtGui.QIcon("icons/progress-stop.png"))
		self.__stopBtn.setToolTip("Abort")
		self.__stopBtn.clicked.connect(self.__stop)
		self.__skipBtn = QtGui.QToolButton()
		self.__skipBtn.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
		self.__skipBtn.setIcon(QtGui.QIcon("icons/progress-skip.png"))
		self.__skipBtn.setToolTip("Skip")
		self.__skipBtn.clicked.connect(self.__skip)
		self.__skipBtn.hide()
		self.__errorMsg = QtGui.QLabel()
		self.__errorMsg.setWordWrap(True)
		self.__errorMsg.hide()

		layout = QtGui.QHBoxLayout()
		layout.setMargin(0)
		layout.addWidget(self.__progressInd)
		layout.addWidget(self.fromBtn)
		layout.addWidget(self.progressBar)
		layout.addWidget(self.__errorMsg)
		layout.addWidget(self.toBtn)
		layout.addWidget(self.__pauseBtn)
		layout.addWidget(self.__skipBtn)
		if typ != Connector().PROGRESS_SYNC:
			layout.addWidget(self.__stopBtn)
		self.setLayout(layout)

		Connector().regProgressHandler(progress=self.progress)

	def remove(self):
		Connector().unregProgressHandler(progress=self.progress)
		self.fromBtn.cleanup()
		self.toBtn.cleanup()
		self.deleteLater()

	def progress(self, tag, state, value, err_code=None, err_doc=None, err_rev=None):
		if self.tag != tag:
			return

		if value > 0:
			self.progressBar.setMaximum(255)
		self.progressBar.setValue(value)
		if self.__state == state:
			return

		self.__state = state
		self.progressBar.setVisible(state != Connector().PROGRESS_ERROR)
		self.__errorMsg.setVisible(state == Connector().PROGRESS_ERROR)
		self.__skipBtn.setVisible(state == Connector().PROGRESS_ERROR)
		if state == Connector().PROGRESS_RUNNING:
			self.__pauseBtn.setIcon(QtGui.QIcon("icons/progress-pause.png"))
			self.__pauseBtn.setToolTip("Pause")
			if self.__type == Connector().PROGRESS_SYNC:
				self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-sync.png"))
			else:
				self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-replicate.png"))
		elif state == Connector().PROGRESS_PAUSED:
			self.__pauseBtn.setIcon(QtGui.QIcon("icons/progress-start.png"))
			self.__pauseBtn.setToolTip("Resume")
			self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-pause.png"))
		elif state == Connector().PROGRESS_ERROR:
			self.__pauseBtn.setIcon(QtGui.QIcon("icons/progress-retry.png"))
			self.__pauseBtn.setToolTip("Retry")
			self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-error.png"))
			doc = struct.readTitle(RevLink(self.__fromStore, err_rev),
				'unknown document')
			self.__errorMsg.setText("Error '" + err_code[1] + "' while processing '"
				+ doc + "'!")
			if self.__type == Connector().PROGRESS_SYNC:
				title = "Synchronization error"
				message = "synchronizing"
			else:
				title = "Replication error"
				message = "replicating"
			message = "Error '" + err_code[1] + "' while " + message + " '" + doc + \
				"' \nfrom '" + struct.readTitle(DocLink(self.__fromStore, self.__fromStore), "unknown store") + \
				"' to '" + struct.readTitle(DocLink(self.__toStore, self.__toStore), "unknown store") + \
				"'!"
			self.__trayIcon.showMessage(title, message, QtGui.QSystemTrayIcon.Warning)

	def __pause(self):
		if self.__state == Connector().PROGRESS_RUNNING:
			Connector().progressPause(self.tag)
		else:
			Connector().progressResume(self.tag)

	def __stop(self):
		Connector().progressStop(self.tag)

	def __skip(self):
		Connector().progressResume(self.tag, True)
Example #14
0
class SyncRuleWidget(QtGui.QWidget):
	MODES = [("ff", None), ("merge", None), ("merge", "merge")]
	MAP = {
		("ff", None)       : "Forward",
		("merge", None)    : "One way sync",
		("merge", "merge") : "Full sync"
	}

	removed = QtCore.pyqtSignal(object)

	def __init__(self, store, peer, rules, parent):
		super(SyncRuleWidget, self).__init__(parent)

		self.__store = store
		self.__peer = peer
		self.__rules = rules

		self.__descrEdit = QtGui.QLineEdit()
		self.__storeBtn = DocButton(store, store, True)
		self.__peerBtn = DocButton(peer, peer, True)
		self.__modeSel = QtGui.QComboBox()
		self.__modeSel.addItems([SyncRuleWidget.MAP[m] for m in SyncRuleWidget.MODES])
		self.__reverseBtn = QtGui.QPushButton('Reverse')
		self.__reverseBtn.clicked.connect(self.__reverse)
		self.__removeBtn = QtGui.QPushButton('Remove')
		self.__removeBtn.clicked.connect(self.__remove)

		layout = QtGui.QHBoxLayout()
		layout.addWidget(self.__descrEdit)
		layout.addWidget(self.__storeBtn)
		layout.addWidget(self.__modeSel)
		layout.addWidget(self.__peerBtn)
		layout.addWidget(self.__reverseBtn)
		layout.addWidget(self.__removeBtn)
		self.setLayout(layout)

		mode = (rules.mode(store, peer), rules.mode(peer, store))
		self.__modeSel.setCurrentIndex(SyncRuleWidget.MODES.index(mode))
		self.__descrEdit.setText(rules.descr(store, peer))

		# connect signals as last step, otherwise loading the rule already triggers
		self.__descrEdit.textEdited.connect(self.__setRule)
		self.__modeSel.currentIndexChanged.connect(self.__setRule)

	def cleanup(self):
		self.__storeBtn.cleanup()
		self.__peerBtn.cleanup()

	def __setRule(self):
		descr = unicode(self.__descrEdit.text())
		(ltrMode, rtlMode) = SyncRuleWidget.MODES[self.__modeSel.currentIndex()]
		self.__rules.setMode(self.__store, self.__peer, ltrMode)
		self.__rules.setDescr(self.__store, self.__peer, descr)
		self.__rules.setMode(self.__peer, self.__store, rtlMode)
		if rtlMode:
			self.__rules.setDescr(self.__peer, self.__store, descr)

	def __reverse(self):
		store = self.__store
		self.__store = self.__peer
		self.__peer = store
		self.__storeBtn.setDocument(self.__store, self.__store)
		self.__peerBtn.setDocument(self.__peer, self.__peer)
		self.__setRule()

	def __remove(self):
		self.__rules.setMode(self.__store, self.__peer, None)
		self.__rules.setMode(self.__peer, self.__store, None)
		self.removed.emit(self)
		self.cleanup()
		self.deleteLater()
Example #15
0
class SyncRuleWidget(QtGui.QWidget):
	MODES = [("ff", None), ("merge", None), ("merge", "merge")]
	MAP = {
		("ff", None)       : "Forward",
		("merge", None)    : "One way sync",
		("merge", "merge") : "Full sync"
	}

	removed = QtCore.pyqtSignal(object)

	def __init__(self, store, peer, rules, parent):
		super(SyncRuleWidget, self).__init__(parent)

		self.__store = store
		self.__peer = peer
		self.__rules = rules

		self.__descrEdit = QtGui.QLineEdit()
		self.__descrEdit.textEdited.connect(self.__setRule)
		self.__storeBtn = DocButton(store, store, True)
		self.__peerBtn = DocButton(peer, peer, True)
		self.__modeSel = QtGui.QComboBox()
		self.__modeSel.addItems([SyncRuleWidget.MAP[m] for m in SyncRuleWidget.MODES])
		self.__modeSel.currentIndexChanged.connect(self.__setRule)
		self.__reverseBtn = QtGui.QPushButton('Reverse')
		self.__reverseBtn.clicked.connect(self.__reverse)
		self.__removeBtn = QtGui.QPushButton('Remove')
		self.__removeBtn.clicked.connect(self.__remove)

		layout = QtGui.QHBoxLayout()
		layout.addWidget(self.__descrEdit)
		layout.addWidget(self.__storeBtn)
		layout.addWidget(self.__modeSel)
		layout.addWidget(self.__peerBtn)
		layout.addWidget(self.__reverseBtn)
		layout.addWidget(self.__removeBtn)
		self.setLayout(layout)

		mode = (rules.mode(store, peer), rules.mode(peer, store))
		self.__modeSel.setCurrentIndex(SyncRuleWidget.MODES.index(mode))
		self.__descrEdit.setText(rules.descr(store, peer))

	def cleanup(self):
		self.__storeBtn.cleanup()
		self.__peerBtn.cleanup()

	def __setRule(self):
		descr = unicode(self.__descrEdit.text())
		(ltrMode, rtlMode) = SyncRuleWidget.MODES[self.__modeSel.currentIndex()]
		self.__rules.setMode(self.__store, self.__peer, ltrMode)
		self.__rules.setDescr(self.__store, self.__peer, descr)
		self.__rules.setMode(self.__peer, self.__store, rtlMode)
		if rtlMode:
			self.__rules.setDescr(self.__peer, self.__store, descr)

	def __reverse(self):
		store = self.__store
		self.__store = self.__peer
		self.__peer = store
		self.__storeBtn.setDocument(self.__store, self.__store)
		self.__peerBtn.setDocument(self.__peer, self.__peer)
		self.__setRule()

	def __remove(self):
		self.__rules.setMode(self.__store, self.__peer, None)
		self.__rules.setMode(self.__peer, self.__store, None)
		self.removed.emit(self)
		self.cleanup()
		self.deleteLater()
Example #16
0
class ProgressWidget(QtGui.QFrame):
    def __init__(self, tag, typ, fromStore, toStore, item, trayIcon):
        super(ProgressWidget, self).__init__()
        self.tag = tag
        self.__type = typ
        self.__state = Connector().PROGRESS_RUNNING
        self.__fromStore = fromStore
        self.__toStore = toStore
        self.__trayIcon = trayIcon

        self.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Sunken)

        self.__progressInd = QtGui.QLabel()
        self.__progressInd.setMargin(4)
        if typ == Connector().PROGRESS_SYNC:
            self.fromBtn = DocButton(fromStore, fromStore, True)
            self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-sync.png"))
        elif typ == Connector().PROGRESS_REP_DOC:
            self.fromBtn = DocButton(fromStore, item, True)
            self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-replicate.png"))
        elif typ == Connector().PROGRESS_REP_REV:
            self.fromBtn = RevButton(fromStore, item, True)
            self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-replicate.png"))
        self.toBtn = DocButton(toStore, toStore, True)
        self.progressBar = QtGui.QProgressBar()
        self.progressBar.setMinimum(0)
        self.progressBar.setMaximum(0)
        self.__pauseBtn = QtGui.QToolButton()
        self.__pauseBtn.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
        self.__pauseBtn.setIcon(QtGui.QIcon("icons/progress-pause.png"))
        self.__pauseBtn.setToolTip("Pause")
        self.__pauseBtn.clicked.connect(self.__pause)
        self.__stopBtn = QtGui.QToolButton()
        self.__stopBtn.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
        self.__stopBtn.setIcon(QtGui.QIcon("icons/progress-stop.png"))
        self.__stopBtn.setToolTip("Abort")
        self.__stopBtn.clicked.connect(self.__stop)
        self.__skipBtn = QtGui.QToolButton()
        self.__skipBtn.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
        self.__skipBtn.setIcon(QtGui.QIcon("icons/progress-skip.png"))
        self.__skipBtn.setToolTip("Skip")
        self.__skipBtn.clicked.connect(self.__skip)
        self.__skipBtn.hide()
        self.__errorMsg = QtGui.QLabel()
        self.__errorMsg.setWordWrap(True)
        self.__errorMsg.hide()

        layout = QtGui.QHBoxLayout()
        layout.setMargin(0)
        layout.addWidget(self.__progressInd)
        layout.addWidget(self.fromBtn)
        layout.addWidget(self.progressBar)
        layout.addWidget(self.__errorMsg)
        layout.addWidget(self.toBtn)
        layout.addWidget(self.__pauseBtn)
        layout.addWidget(self.__skipBtn)
        if typ != Connector().PROGRESS_SYNC:
            layout.addWidget(self.__stopBtn)
        self.setLayout(layout)

        Connector().regProgressHandler(progress=self.progress)

    def remove(self):
        Connector().unregProgressHandler(progress=self.progress)
        self.fromBtn.cleanup()
        self.toBtn.cleanup()
        self.deleteLater()

    def progress(self, tag, state, value, err_code=None, err_doc=None, err_rev=None):
        if self.tag != tag:
            return

        if value > 0:
            self.progressBar.setMaximum(255)
        self.progressBar.setValue(value)
        if self.__state == state:
            return

        self.__state = state
        self.progressBar.setVisible(state != Connector().PROGRESS_ERROR)
        self.__errorMsg.setVisible(state == Connector().PROGRESS_ERROR)
        self.__skipBtn.setVisible(state == Connector().PROGRESS_ERROR)
        if state == Connector().PROGRESS_RUNNING:
            self.__pauseBtn.setIcon(QtGui.QIcon("icons/progress-pause.png"))
            self.__pauseBtn.setToolTip("Pause")
            if self.__type == Connector().PROGRESS_SYNC:
                self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-sync.png"))
            else:
                self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-replicate.png"))
        elif state == Connector().PROGRESS_PAUSED:
            self.__pauseBtn.setIcon(QtGui.QIcon("icons/progress-start.png"))
            self.__pauseBtn.setToolTip("Resume")
            self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-pause.png"))
        elif state == Connector().PROGRESS_ERROR:
            self.__pauseBtn.setIcon(QtGui.QIcon("icons/progress-retry.png"))
            self.__pauseBtn.setToolTip("Retry")
            self.__progressInd.setPixmap(QtGui.QPixmap("icons/progress-error.png"))
            doc = struct.readTitle(RevLink(self.__fromStore, err_rev), "unknown document")
            self.__errorMsg.setText("Error '" + err_code[1] + "' while processing '" + doc + "'!")
            if self.__type == Connector().PROGRESS_SYNC:
                title = "Synchronization error"
                message = "synchronizing"
            else:
                title = "Replication error"
                message = "replicating"
            message = (
                "Error '"
                + err_code[1]
                + "' while "
                + message
                + " '"
                + doc
                + "' \nfrom '"
                + struct.readTitle(DocLink(self.__fromStore, self.__fromStore), "unknown store")
                + "' to '"
                + struct.readTitle(DocLink(self.__toStore, self.__toStore), "unknown store")
                + "'!"
            )
            self.__trayIcon.showMessage(title, message, QtGui.QSystemTrayIcon.Warning)

    def __pause(self):
        if self.__state == Connector().PROGRESS_RUNNING:
            Connector().progressPause(self.tag)
        else:
            Connector().progressResume(self.tag)

    def __stop(self):
        Connector().progressStop(self.tag)

    def __skip(self):
        Connector().progressResume(self.tag, True)