Implemented category delete and more
[biaweb_qt.git] / main_window.py
index 4d4afa3..0d6c91a 100644 (file)
@@ -38,7 +38,19 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow):
                        qrow = PyQt4.QtGui.QTreeWidgetItem ([str(item[0]), str(item[1])])
                        self.articles.addTopLevelItem (qrow)
 
-       # configuration dialog
+       # when the view is refreshed
+       def onViewRefresh (self):
+               if self.current_db is not None:
+                       self.repopulate_categories ()
+                       self.repopulate_articles ()
+
+       # when item selection is changed in categories tree widget
+       def onCategorySelectionChanged (self):
+               if self.current_db is not None:
+                       catid = self.get_selected_item_id (self.categories)
+                       self.repopulate_articles (catid)
+
+       # when configuration menu is activated
        def onConfiguration (self):
                if self.current_db == None:
                        PyQt4.QtGui.QMessageBox.critical (self, "Error",
@@ -126,6 +138,32 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow):
                                                PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in updating category")
 
 
+       # category delete action
+       def onCategoryDelete (self):
+               # if there is no database
+               if self.current_db == None:
+                       PyQt4.QtGui.QMessageBox.critical (self, "Error",
+                                                               "Cannot edit category. You need to create or open a website first")
+               else:
+                       # get the selected category
+                       catid = self.get_selected_item_id (self.categories)
+                       if catid is None:
+                               PyQt4.QtGui.QMessageBox.critical (self, "Error", "No category selected")
+                       # category is selected
+                       else:
+                               # get confirmation first
+                               flag = PyQt4.QtGui.QMessageBox.question (self, "Confirm",
+                       "This will delete the category and all associated articles. Are you sure you wish to continue?",
+                       PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
+                               # if confirmed
+                               if flag == PyQt4.QtGui.QMessageBox.Yes:
+                                       ret = biaweb_db.remove_category (self.current_db, catid)
+                                       if ret == False:
+                                               PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in deleting category")
+                                       else:
+                                               self.repopulate_categories ()
+                                               self.repopulate_articles ()
+
        # category add action
        def onCategoryAdd (self):
                # if there is no database