remove sources from deck properties, as they can be configured online

This commit is contained in:
Damien Elmes 2010-10-19 19:55:31 +09:00
parent aaaf025062
commit cdab5318d1
2 changed files with 2 additions and 145 deletions

View file

@ -34,8 +34,6 @@ class DeckProperties(QDialog):
self.connect(self.dialog.modelsEdit, SIGNAL("clicked()"), self.onEdit)
self.connect(self.dialog.modelsDelete, SIGNAL("clicked()"), self.onDelete)
self.connect(self.dialog.buttonBox, SIGNAL("helpRequested()"), self.helpRequested)
self.connect(self.dialog.addSource, SIGNAL("clicked()"), self.onAddSource)
self.connect(self.dialog.deleteSource, SIGNAL("clicked()"), self.onDeleteSource)
self.show()
def readData(self):
@ -64,10 +62,6 @@ class DeckProperties(QDialog):
and Qt.Checked or Qt.Unchecked)
self.dialog.perDay.setCheckState(self.d.getBool("perDay")
and Qt.Checked or Qt.Unchecked)
# sources
self.sources = self.d.s.all("select id, name from sources")
self.sourcesToRemove = []
self.drawSourcesTable()
# models
self.updateModelsList()
# hour shift
@ -77,30 +71,6 @@ class DeckProperties(QDialog):
self.dialog.suspendLeeches.setChecked(self.d.getBool("suspendLeeches"))
self.dialog.leechFails.setValue(self.d.getInt("leechFails"))
def drawSourcesTable(self):
self.dialog.sourcesTable.clear()
self.dialog.sourcesTable.setRowCount(len(self.sources))
self.dialog.sourcesTable.setColumnCount(2)
self.dialog.sourcesTable.setHorizontalHeaderLabels(
QStringList([_("ID"),
_("Name")]))
self.dialog.sourcesTable.horizontalHeader().setResizeMode(
QHeaderView.Stretch)
self.dialog.sourcesTable.verticalHeader().hide()
self.dialog.sourcesTable.setSelectionBehavior(
QAbstractItemView.SelectRows)
self.dialog.sourcesTable.setSelectionMode(
QAbstractItemView.SingleSelection)
self.sourceItems = []
n = 0
for (id, name) in self.sources:
a = QTableWidgetItem(hexifyID(id))
b = QTableWidgetItem(name)
self.sourceItems.append([a, b])
self.dialog.sourcesTable.setItem(n, 0, a)
self.dialog.sourcesTable.setItem(n, 1, b)
n += 1
def updateModelsList(self):
idx = self.dialog.modelsList.currentRow()
self.dialog.modelsList.clear()
@ -185,29 +155,6 @@ class DeckProperties(QDialog):
"DeckProperties#" +
tabs[idx]))
def onAddSource(self):
(s, ret) = QInputDialog.getText(self, _("Anki"),
_("Source ID:"))
if not s:
return
rc = self.dialog.sourcesTable.rowCount()
self.dialog.sourcesTable.insertRow(rc)
a = QTableWidgetItem(s)
b = QTableWidgetItem("")
self.dialog.sourcesTable.setItem(rc, 0, a)
self.dialog.sourcesTable.setItem(rc, 1, b)
def onDeleteSource(self):
r = self.dialog.sourcesTable.currentRow()
if r == -1:
return
self.dialog.sourcesTable.removeRow(r)
try:
id = self.sources[r][0]
self.sourcesToRemove.append(id)
except IndexError:
pass
def reject(self):
n = _("Deck Properties")
self.d.startProgress()
@ -275,36 +222,6 @@ class DeckProperties(QDialog):
"lowPriority",
unicode(self.dialog.lowPriority.text()))
prioritiesChanged = was != self.d.modified
# sources
d = {}
d.update(self.sources)
for n in range(self.dialog.sourcesTable.rowCount()):
try:
id = dehexifyID(str(self.dialog.sourcesTable.item(n, 0).text()))
except (ValueError,OverflowError):
continue
name = unicode(self.dialog.sourcesTable.item(n, 1).text())
if id in d:
if d[id] == name:
del d[id]
continue
# name changed
self.d.s.statement(
"update sources set name = :n where id = :id",
id=id, n=name)
else:
self.d.s.statement("""
insert into sources values
(:id, :n, :t, 0, 0)""", id=id, n=name, t=time.time())
self.d.setModified()
try:
del d[id]
except KeyError:
pass
for id in self.sourcesToRemove + d.keys():
self.d.s.statement("delete from sources where id = :id",
id=id)
self.d.setModified()
# mark deck dirty and close
if self.origMod != self.d.modified:
if prioritiesChanged:

View file

@ -178,45 +178,8 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_28">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>&lt;h1&gt;Sources&lt;/h1&gt;</string>
</property>
</widget>
</item>
<item row="8" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="addSource">
<property name="text">
<string>&amp;Add Source</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteSource">
<property name="text">
<string>&amp;Delete Source</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0">
<widget class="QTableWidget" name="sourcesTable"/>
<item row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3"/>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer_4">
@ -252,26 +215,6 @@
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="5" column="0">
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
@ -619,9 +562,6 @@
<tabstop>lowPriority</tabstop>
<tabstop>doSync</tabstop>
<tabstop>syncName</tabstop>
<tabstop>sourcesTable</tabstop>
<tabstop>addSource</tabstop>
<tabstop>deleteSource</tabstop>
<tabstop>delay0</tabstop>
<tabstop>delay1</tabstop>
<tabstop>delay2</tabstop>