Site configuration updating implemented
[biaweb_qt.git] / main_window.py
index 5902fbc..f917e76 100644 (file)
@@ -14,12 +14,68 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow):
                self.setupUi (self)
                self.current_db = None
 
+       # refresh the category list
+       def repopulate_categories (self):
+               recs = biaweb_db.get_categories (self.current_db)
+               if recs == False:
+                       PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in getting the categories")
+                       return
+
+               self.categories.clear ()
+               for (id, name, desc, stub) in recs:
+                       qrow = PyQt4.QtGui.QTreeWidgetItem ([str(id), str(name)])
+                       self.categories.addTopLevelItem (qrow)
+
+       # refresh the articles list
+       def repopulate_articles (self, catid=None):
+               recs = biaweb_db.get_articles (self.current_db, catid)
+               if recs == False:
+                       PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in getting the articles")
+                       return
+
+               self.articles.clear ()
+               for item in recs:
+                       qrow = PyQt4.QtGui.QTreeWidgetItem ([str(item[0]), str(item[1])])
+                       self.articles.addTopLevelItem (qrow)
+
+       # configuration dialog
+       def onConfiguration (self):
+               if self.current_db == None:
+                       PyQt4.QtGui.QMessageBox.critical (self, "Error",
+                                                       "Cannot edit configuration. You need to create or open a website first")
+               else:
+                       dlg = scd.SiteConfigDialog (self)
+                       configs = biaweb_db.get_configuration (self.current_db)
+
+                       dlg.site_url.setText (configs[0])
+                       dlg.site_title.setText (configs[1])
+                       dlg.keywords.setText (configs[2])
+                       dlg.description.setPlainText (configs[3])
+                       dlg.num_rss_items.setValue (configs[4])
+                       dlg.destination.setText (configs[5])
+                       dlg.copyright.setText (configs[6])
+
+                       if (dlg.exec_ () == PyQt4.QtGui.QDialog.Accepted):
+                               site_title = str (dlg.site_title.text ()).strip ()
+                               site_url = str (dlg.site_url.text ()).strip ()
+                               keywords = str (dlg.keywords.text ()).strip ()
+                               destination = str (dlg.destination.text ()).strip ()
+                               description = str (dlg.description.toPlainText ()).strip ()
+                               num_rss = dlg.num_rss_items.value ()
+                               copyright = str (dlg.copyright.text ()).strip ()
+                               flag = biaweb_db.set_configuration (self.current_db, site_title, site_url, keywords, description,
+                                                                                       copyright, num_rss, destination)
+                               if flag == False:
+                                       PyQt4.QtGui.QMessageBox.critical (self, "Error",
+                                                                                       "SQLite 3 error in updating configuration")
+
+
        # category add action
        def onCategoryAdd (self):
                # if there is no database
                if self.current_db == None:
                        PyQt4.QtGui.QMessageBox.critical (self, "Error",
-                                                       "Cannot add category. You need to create or open a website first.")
+                                                       "Cannot add category. You need to create or open a website first")
                else:
                        # show the category add dialog
                        dlg = catd.CategoryDialog (self)
@@ -31,9 +87,20 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow):
                                ret = biaweb_db.create_category (self.current_db, cat_name, cat_desc, cat_stub)
                                if ret == True:
                                        PyQt4.QtGui.QMessageBox.information (self, "Success", "Category successfully created")
+                                       self.repopulate_categories ()
+                                       self.repopulate_articles ()
                                else:
                                        PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in creating category")
 
+       # file open menu is clicked
+       def onFileOpen (self):
+               filename = PyQt4.QtGui.QFileDialog.getOpenFileName (self, "Open Site Database")
+               if filename:
+                       self.current_db = str (filename)
+                       self.setWindowTitle ("BiaWeb - " + self.current_db)
+                       self.repopulate_categories ()
+                       self.repopulate_articles ()
+
        # file new menu is clicked
        def onFileNew (self):
                # show the site configuration dialog to get the new site details
@@ -58,6 +125,8 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow):
                                if flag == True:
                                        PyQt4.QtGui.QMessageBox.information (self, "Success",
                                                                                                                        "New site db successfully created")
+                                       self.articles.clear ()
+                                       self.categories.clear ()
                                else:
                                        PyQt4.QtGui.QMessageBox.critical (self, "Error", "System or SQLite 3 error in creating database")