Working on #265.
This commit is contained in:
		
							parent
							
								
									45304b9e81
								
							
						
					
					
						commit
						e86882ccc1
					
				
					 3 changed files with 62 additions and 37 deletions
				
			
		|  | @ -81,6 +81,7 @@ | ||||||
| #define RELOAD_MODEL_BORDER_NUM               10 | #define RELOAD_MODEL_BORDER_NUM               10 | ||||||
| #define EXTERNAL_TOOL_SEPARATOR               "###" | #define EXTERNAL_TOOL_SEPARATOR               "###" | ||||||
| #define EXTERNAL_TOOL_PARAM_SEPARATOR         "|||" | #define EXTERNAL_TOOL_PARAM_SEPARATOR         "|||" | ||||||
|  | #define EXECUTION_LINE_USER_DATA_PLACEHOLDER  "%data%" | ||||||
| 
 | 
 | ||||||
| #define CLI_LOG_SHORT     "l" | #define CLI_LOG_SHORT     "l" | ||||||
| #define CLI_LOG_LONG      "log" | #define CLI_LOG_LONG      "log" | ||||||
|  |  | ||||||
|  | @ -26,6 +26,7 @@ | ||||||
| #include <QJsonDocument> | #include <QJsonDocument> | ||||||
| #include <QJsonObject> | #include <QJsonObject> | ||||||
| #include <QPointer> | #include <QPointer> | ||||||
|  | #include <QProcess> | ||||||
| #include <QTextCodec> | #include <QTextCodec> | ||||||
| #include <QVariant> | #include <QVariant> | ||||||
| #include <QXmlStreamReader> | #include <QXmlStreamReader> | ||||||
|  | @ -468,47 +469,54 @@ void StandardFeed::setEncoding(const QString& encoding) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QList<Message> StandardFeed::obtainNewMessages(bool* error_during_obtaining) { | QList<Message> StandardFeed::obtainNewMessages(bool* error_during_obtaining) { | ||||||
|   QByteArray feed_contents; |  | ||||||
|   int download_timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt(); |  | ||||||
|   QList<QPair<QByteArray, QByteArray>> headers; |  | ||||||
| 
 |  | ||||||
|   headers << NetworkFactory::generateBasicAuthHeader(username(), password()); |  | ||||||
|   m_networkError = NetworkFactory::performNetworkOperation(url(), |  | ||||||
|                                                            download_timeout, |  | ||||||
|                                                            QByteArray(), |  | ||||||
|                                                            feed_contents, |  | ||||||
|                                                            QNetworkAccessManager::Operation::GetOperation, |  | ||||||
|                                                            headers, |  | ||||||
|                                                            false, |  | ||||||
|                                                            {}, |  | ||||||
|                                                            {}, |  | ||||||
|                                                            getParentServiceRoot()->networkProxy()).first; |  | ||||||
| 
 |  | ||||||
|   if (m_networkError != QNetworkReply::NetworkError::NoError) { |  | ||||||
|     qWarningNN << LOGSEC_CORE |  | ||||||
|                << "Error" |  | ||||||
|                << QUOTE_W_SPACE(m_networkError) |  | ||||||
|                << "during fetching of new messages for feed" |  | ||||||
|                << QUOTE_W_SPACE_DOT(url()); |  | ||||||
|     setStatus(Status::NetworkError); |  | ||||||
|     *error_during_obtaining = true; |  | ||||||
|     return QList<Message>(); |  | ||||||
|   } |  | ||||||
|   else { |  | ||||||
|     *error_during_obtaining = false; |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   // Encode downloaded data for further parsing.
 |  | ||||||
|   QTextCodec* codec = QTextCodec::codecForName(encoding().toLocal8Bit()); |  | ||||||
|   QString formatted_feed_contents; |   QString formatted_feed_contents; | ||||||
|  |   int download_timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt(); | ||||||
| 
 | 
 | ||||||
|   if (codec == nullptr) { |   if (sourceType() == SourceType::Url) { | ||||||
|     // No suitable codec for this encoding was found.
 |     QByteArray feed_contents; | ||||||
|     // Use non-converted data.
 |     QList<QPair<QByteArray, QByteArray>> headers; | ||||||
|     formatted_feed_contents = feed_contents; | 
 | ||||||
|  |     headers << NetworkFactory::generateBasicAuthHeader(username(), password()); | ||||||
|  |     m_networkError = NetworkFactory::performNetworkOperation(url(), | ||||||
|  |                                                              download_timeout, | ||||||
|  |                                                              QByteArray(), | ||||||
|  |                                                              feed_contents, | ||||||
|  |                                                              QNetworkAccessManager::Operation::GetOperation, | ||||||
|  |                                                              headers, | ||||||
|  |                                                              false, | ||||||
|  |                                                              {}, | ||||||
|  |                                                              {}, | ||||||
|  |                                                              getParentServiceRoot()->networkProxy()).first; | ||||||
|  | 
 | ||||||
|  |     if (m_networkError != QNetworkReply::NetworkError::NoError) { | ||||||
|  |       qWarningNN << LOGSEC_CORE | ||||||
|  |                  << "Error" | ||||||
|  |                  << QUOTE_W_SPACE(m_networkError) | ||||||
|  |                  << "during fetching of new messages for feed" | ||||||
|  |                  << QUOTE_W_SPACE_DOT(url()); | ||||||
|  |       setStatus(Status::NetworkError); | ||||||
|  |       *error_during_obtaining = true; | ||||||
|  |       return QList<Message>(); | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |       *error_during_obtaining = false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // Encode downloaded data for further parsing.
 | ||||||
|  |     QTextCodec* codec = QTextCodec::codecForName(encoding().toLocal8Bit()); | ||||||
|  | 
 | ||||||
|  |     if (codec == nullptr) { | ||||||
|  |       // No suitable codec for this encoding was found.
 | ||||||
|  |       // Use non-converted data.
 | ||||||
|  |       formatted_feed_contents = feed_contents; | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |       formatted_feed_contents = codec->toUnicode(feed_contents); | ||||||
|  |     } | ||||||
|   } |   } | ||||||
|   else { |   else { | ||||||
|     formatted_feed_contents = codec->toUnicode(feed_contents); |     // Use script to generate feed file.
 | ||||||
|  |     formatted_feed_contents = generateFeedFileWithScript(url(), download_timeout); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // Feed data are downloaded and encoded.
 |   // Feed data are downloaded and encoded.
 | ||||||
|  | @ -540,6 +548,19 @@ QList<Message> StandardFeed::obtainNewMessages(bool* error_during_obtaining) { | ||||||
|   return messages; |   return messages; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | QPair<QString, QString> StandardFeed::prepareExecutionLine(const QString& execution_line) { | ||||||
|  |   auto split_exec = execution_line.split('#', Qt::SplitBehaviorFlags::KeepEmptyParts); | ||||||
|  |   auto user_data_folder = qApp->userDataFolder(); | ||||||
|  | 
 | ||||||
|  |   return { split_exec[0].replace(EXECUTION_LINE_USER_DATA_PLACEHOLDER, user_data_folder), | ||||||
|  |            split_exec[1].replace(EXECUTION_LINE_USER_DATA_PLACEHOLDER, user_data_folder) }; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | QString StandardFeed::generateFeedFileWithScript(const QString& execution_line, int run_timeout) { | ||||||
|  |   auto prepared_query = prepareExecutionLine(execution_line); | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
| QNetworkReply::NetworkError StandardFeed::networkError() const { | QNetworkReply::NetworkError StandardFeed::networkError() const { | ||||||
|   return m_networkError; |   return m_networkError; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -78,6 +78,9 @@ class StandardFeed : public Feed { | ||||||
| 
 | 
 | ||||||
|     QList<Message> obtainNewMessages(bool* error_during_obtaining); |     QList<Message> obtainNewMessages(bool* error_during_obtaining); | ||||||
| 
 | 
 | ||||||
|  |     static QPair<QString, QString> prepareExecutionLine(const QString& execution_line); | ||||||
|  |     static QString generateFeedFileWithScript(const QString& execution_line, int run_timeout); | ||||||
|  | 
 | ||||||
|     // Tries to guess feed hidden under given URL
 |     // Tries to guess feed hidden under given URL
 | ||||||
|     // and uses given credentials.
 |     // and uses given credentials.
 | ||||||
|     // Returns pointer to guessed feed (if at least partially
 |     // Returns pointer to guessed feed (if at least partially
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue