Refactoring...
This commit is contained in:
		
							parent
							
								
									96711c6f41
								
							
						
					
					
						commit
						b91e79cb4a
					
				
					 7 changed files with 54 additions and 26 deletions
				
			
		|  | @ -1954,16 +1954,27 @@ bool DatabaseQueries::editStandardFeed(const QSqlDatabase& db, int parent_id, in | |||
| } | ||||
| 
 | ||||
| bool DatabaseQueries::editBaseFeed(const QSqlDatabase& db, int feed_id, Feed::AutoUpdateType auto_update_type, | ||||
|                                    int auto_update_interval) { | ||||
|                                    int auto_update_interval, bool is_protected, const QString& username, | ||||
|                                    const QString& password) { | ||||
|   QSqlQuery q(db); | ||||
| 
 | ||||
|   q.setForwardOnly(true); | ||||
|   q.prepare("UPDATE Feeds " | ||||
|             "SET update_type = :update_type, update_interval = :update_interval " | ||||
|             "SET update_type = :update_type, update_interval = :update_interval, protected = :protected, username = :username, password = :password " | ||||
|             "WHERE id = :id;"); | ||||
|   q.bindValue(QSL(":update_type"), (int) auto_update_type); | ||||
|   q.bindValue(QSL(":update_interval"), auto_update_interval); | ||||
|   q.bindValue(QSL(":id"), feed_id); | ||||
|   q.bindValue(QSL(":protected"), is_protected ? 1 : 0); | ||||
|   q.bindValue(QSL(":username"), username); | ||||
| 
 | ||||
|   if (password.isEmpty()) { | ||||
|     q.bindValue(QSL(":password"), password); | ||||
|   } | ||||
|   else { | ||||
|     q.bindValue(QSL(":password"), TextFactory::encrypt(password)); | ||||
|   } | ||||
| 
 | ||||
|   return q.exec(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -96,7 +96,9 @@ class DatabaseQueries { | |||
|     static bool cleanFeeds(const QSqlDatabase& db, const QStringList& ids, bool clean_read_only, int account_id); | ||||
|     static bool storeAccountTree(const QSqlDatabase& db, RootItem* tree_root, int account_id); | ||||
|     static bool editBaseFeed(const QSqlDatabase& db, int feed_id, | ||||
|                              Feed::AutoUpdateType auto_update_type, int auto_update_interval); | ||||
|                              Feed::AutoUpdateType auto_update_type, int auto_update_interval, | ||||
|                              bool is_protected, const QString& username, | ||||
|                              const QString& password); | ||||
| 
 | ||||
|     template<typename T> | ||||
|     static Assignment getCategories(const QSqlDatabase& db, int account_id, bool* ok = nullptr); | ||||
|  | @ -200,18 +202,8 @@ void DatabaseQueries::fillFeedData(T* feed, const QSqlRecord& sql_record) { | |||
| 
 | ||||
| template<> | ||||
| inline void DatabaseQueries::fillFeedData(StandardFeed* feed, const QSqlRecord& sql_record) { | ||||
|   StandardFeed::Type type = static_cast<StandardFeed::Type>(sql_record.value(FDS_DB_TYPE_INDEX).toInt()); | ||||
| 
 | ||||
|   switch (type) { | ||||
|     case StandardFeed::Type::Atom10: | ||||
|     case StandardFeed::Type::Rdf: | ||||
|     case StandardFeed::Type::Rss0X: | ||||
|     case StandardFeed::Type::Rss2X: | ||||
|     case StandardFeed::Type::Json: { | ||||
|       feed->setType(type); | ||||
|       break; | ||||
|     } | ||||
|   } | ||||
|   Q_UNUSED(feed) | ||||
|   Q_UNUSED(sql_record) | ||||
| } | ||||
| 
 | ||||
| template<typename T> | ||||
|  |  | |||
|  | @ -46,6 +46,16 @@ Feed::Feed(const QSqlRecord& record) : Feed(nullptr) { | |||
|   setAutoUpdateType(static_cast<Feed::AutoUpdateType>(record.value(FDS_DB_UPDATE_TYPE_INDEX).toInt())); | ||||
|   setAutoUpdateInitialInterval(record.value(FDS_DB_UPDATE_INTERVAL_INDEX).toInt()); | ||||
| 
 | ||||
|   setPasswordProtected(record.value(FDS_DB_PROTECTED_INDEX).toBool()); | ||||
|   setUsername(record.value(FDS_DB_USERNAME_INDEX).toString()); | ||||
| 
 | ||||
|   if (record.value(FDS_DB_PASSWORD_INDEX).toString().isEmpty()) { | ||||
|     setPassword(record.value(FDS_DB_PASSWORD_INDEX).toString()); | ||||
|   } | ||||
|   else { | ||||
|     setPassword(TextFactory::decrypt(record.value(FDS_DB_PASSWORD_INDEX).toString())); | ||||
|   } | ||||
| 
 | ||||
|   qDebugNN << LOGSEC_CORE | ||||
|            << "Custom ID of feed when loading from DB is" | ||||
|            << QUOTE_W_SPACE_DOT(customId()); | ||||
|  | @ -160,9 +170,14 @@ bool Feed::editViaGui() { | |||
| bool Feed::editItself(Feed* new_feed_data) { | ||||
|   QSqlDatabase database = qApp->database()->connection(metaObject()->className()); | ||||
| 
 | ||||
|   // TODO: aby editbasefeed editoval i http/basic autentizační data.
 | ||||
|   if (DatabaseQueries::editBaseFeed(database, id(), new_feed_data->autoUpdateType(), | ||||
|                                     new_feed_data->autoUpdateInitialInterval())) { | ||||
|                                     new_feed_data->autoUpdateInitialInterval(), | ||||
|                                     new_feed_data->passwordProtected(), | ||||
|                                     new_feed_data->username(), | ||||
|                                     new_feed_data->password())) { | ||||
|     setPasswordProtected(new_feed_data->passwordProtected()); | ||||
|     setUsername(new_feed_data->username()); | ||||
|     setPassword(new_feed_data->password()); | ||||
|     setAutoUpdateType(new_feed_data->autoUpdateType()); | ||||
|     setAutoUpdateInitialInterval(new_feed_data->autoUpdateInitialInterval()); | ||||
|     return true; | ||||
|  | @ -234,6 +249,8 @@ bool Feed::cleanMessages(bool clean_read_only) { | |||
| } | ||||
| 
 | ||||
| QList<Message> Feed::obtainNewMessages(bool* error_during_obtaining) { | ||||
|   Q_UNUSED(error_during_obtaining) | ||||
| 
 | ||||
|   return {}; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -40,6 +40,10 @@ int FormFeedDetails::editBaseFeed(Feed* input_feed) { | |||
|   return QDialog::exec(); | ||||
| } | ||||
| 
 | ||||
| void FormFeedDetails::activateTab(int index) { | ||||
|   m_ui->m_tabWidget->setCurrentIndex(index); | ||||
| } | ||||
| 
 | ||||
| void FormFeedDetails::insertCustomTab(QWidget* custom_tab, const QString& title, int index) { | ||||
|   m_ui->m_tabWidget->insertTab(index, custom_tab, title); | ||||
| } | ||||
|  |  | |||
|  | @ -27,6 +27,7 @@ class FormFeedDetails : public QDialog { | |||
|     int editBaseFeed(Feed* input_feed); | ||||
| 
 | ||||
|   protected slots: | ||||
|     void activateTab(int index); | ||||
|     void insertCustomTab(QWidget* custom_tab, const QString& title, int index); | ||||
| 
 | ||||
|     // Applies changes.
 | ||||
|  |  | |||
|  | @ -18,6 +18,7 @@ | |||
| FormStandardFeedDetails::FormStandardFeedDetails(ServiceRoot* service_root, QWidget* parent) | ||||
|   : FormFeedDetails(service_root, parent), m_standardFeedDetails(new StandardFeedDetails(this)) { | ||||
|   insertCustomTab(m_standardFeedDetails, tr("General"), 0); | ||||
|   activateTab(0); | ||||
| 
 | ||||
|   m_standardFeedDetails->ui->m_txtTitle->lineEdit()->setPlaceholderText(tr("Feed title")); | ||||
|   m_standardFeedDetails->ui->m_txtTitle->lineEdit()->setToolTip(tr("Set title for your feed.")); | ||||
|  |  | |||
|  | @ -474,17 +474,19 @@ QNetworkReply::NetworkError StandardFeed::networkError() const { | |||
| 
 | ||||
| StandardFeed::StandardFeed(const QSqlRecord& record) : Feed(record) { | ||||
|   setEncoding(record.value(FDS_DB_ENCODING_INDEX).toString()); | ||||
|   setPasswordProtected(record.value(FDS_DB_PROTECTED_INDEX).toBool()); | ||||
|   setUsername(record.value(FDS_DB_USERNAME_INDEX).toString()); | ||||
| 
 | ||||
|   if (record.value(FDS_DB_PASSWORD_INDEX).toString().isEmpty()) { | ||||
|     setPassword(record.value(FDS_DB_PASSWORD_INDEX).toString()); | ||||
|   } | ||||
|   else { | ||||
|     setPassword(TextFactory::decrypt(record.value(FDS_DB_PASSWORD_INDEX).toString())); | ||||
|   StandardFeed::Type type = static_cast<StandardFeed::Type>(record.value(FDS_DB_TYPE_INDEX).toInt()); | ||||
| 
 | ||||
|   switch (type) { | ||||
|     case StandardFeed::Type::Atom10: | ||||
|     case StandardFeed::Type::Rdf: | ||||
|     case StandardFeed::Type::Rss0X: | ||||
|     case StandardFeed::Type::Rss2X: | ||||
|     case StandardFeed::Type::Json: { | ||||
|       setType(type); | ||||
|       break; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   setAutoUpdateType(static_cast<Feed::AutoUpdateType>(record.value(FDS_DB_UPDATE_TYPE_INDEX).toInt())); | ||||
|   setAutoUpdateInitialInterval(record.value(FDS_DB_UPDATE_INTERVAL_INDEX).toInt()); | ||||
|   m_networkError = QNetworkReply::NoError; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue