Work on filters dialog.
This commit is contained in:
		
							parent
							
								
									05025f7a04
								
							
						
					
					
						commit
						5d8fd25173
					
				
					 15 changed files with 424 additions and 178 deletions
				
			
		|  | @ -25,6 +25,7 @@ | |||
|     <file>./graphics/Faenza/actions/64/go-up.png</file> | ||||
|     <file>./graphics/Faenza/actions/64/gtk-edit.png</file> | ||||
|     <file>./graphics/Faenza/actions/64/help-about.png</file> | ||||
|     <file>./graphics/Faenza/actions/64/help-contents.png</file> | ||||
|     <file>./graphics/Faenza/actions/64/insert-object.png</file> | ||||
|     <file>./graphics/Faenza/actions/64/list-add.png</file> | ||||
|     <file>./graphics/Faenza/actions/64/list-remove.png</file> | ||||
|  | @ -37,6 +38,7 @@ | |||
|     <file>./graphics/Faenza/actions/64/mail-message-new.png</file> | ||||
|     <file>./graphics/Faenza/actions/64/mail-send.png</file> | ||||
|     <file>./graphics/Faenza/actions/64/mail-sent.png</file> | ||||
|     <file>./graphics/Faenza/actions/64/media-playback-start.png</file> | ||||
|     <file>./graphics/Faenza/actions/64/process-stop.png</file> | ||||
|     <file>./graphics/Faenza/actions/64/reload.png</file> | ||||
|     <file>./graphics/Faenza/actions/64/system-search.png</file> | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ class MessageFilter : public QObject { | |||
|   Q_OBJECT | ||||
| 
 | ||||
|   public: | ||||
|     explicit MessageFilter(int id, QObject* parent = nullptr); | ||||
|     explicit MessageFilter(int id = -1, QObject* parent = nullptr); | ||||
| 
 | ||||
|     FilteringAction filterMessage(QJSEngine* engine); | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,21 +2,83 @@ | |||
| 
 | ||||
| #include "gui/dialogs/formmessagefiltersmanager.h" | ||||
| 
 | ||||
| #include "core/messagefilter.h" | ||||
| #include "gui/guiutilities.h" | ||||
| #include "miscellaneous/application.h" | ||||
| #include "miscellaneous/feedreader.h" | ||||
| #include "miscellaneous/iconfactory.h" | ||||
| #include "network-web/webfactory.h" | ||||
| #include "services/abstract/accountcheckmodel.h" | ||||
| 
 | ||||
| FormMessageFiltersManager::FormMessageFiltersManager(QWidget* parent) : QDialog(parent) { | ||||
| FormMessageFiltersManager::FormMessageFiltersManager(FeedReader* reader, const QList<ServiceRoot*>& accounts, QWidget* parent) | ||||
|   : QDialog(parent), m_feedsModel(new AccountCheckModel(this)), m_rootItem(new RootItem()), | ||||
|   m_accounts(accounts), m_reader(reader) { | ||||
|   m_ui.setupUi(this); | ||||
| 
 | ||||
|   GuiUtilities::applyDialogProperties(*this, qApp->icons()->fromTheme(QSL("view-list-details"))); | ||||
| 
 | ||||
|   m_ui.m_btnAddNew->setIcon(qApp->icons()->fromTheme(QSL("list-add"))); | ||||
|   m_ui.m_btnRemoveSelected->setIcon(qApp->icons()->fromTheme(QSL("list-remove"))); | ||||
|   m_ui.m_btnTest->setIcon(qApp->icons()->fromTheme(QSL("media-playback-start"))); | ||||
|   m_ui.m_btnDetailedHelp->setIcon(qApp->icons()->fromTheme(QSL("help-contents"))); | ||||
|   m_ui.m_txtScript->setFont(QFontDatabase::systemFont(QFontDatabase::SystemFont::FixedFont)); | ||||
| 
 | ||||
|   connect(m_ui.m_btnDetailedHelp, &QPushButton::clicked, this, []() { | ||||
|     qApp->web()->openUrlInExternalBrowser(MSG_FILTERING_HELP); | ||||
|   }); | ||||
|   connect(m_ui.m_listFilters, &QListWidget::currentRowChanged, | ||||
|           this, &FormMessageFiltersManager::loadFilter); | ||||
|   connect(m_ui.m_btnAddNew, &QPushButton::clicked, | ||||
|           this, &FormMessageFiltersManager::addNewFilter); | ||||
| } | ||||
| 
 | ||||
| FormMessageFiltersManager::~FormMessageFiltersManager() { | ||||
|   delete m_rootItem; | ||||
| } | ||||
| 
 | ||||
| MessageFilter* FormMessageFiltersManager::selectedFilter() const { | ||||
|   if (m_ui.m_listFilters->selectedItems().isEmpty()) { | ||||
|     return nullptr; | ||||
|   } | ||||
|   else { | ||||
|     return m_ui.m_listFilters->selectedItems().at(0)->data(Qt::ItemDataRole::UserRole).value<MessageFilter*>(); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| ServiceRoot* FormMessageFiltersManager::selectedAccount() const { | ||||
|   return nullptr; | ||||
| } | ||||
| 
 | ||||
| void FormMessageFiltersManager::addNewFilter() { | ||||
|   auto* fltr = m_reader->addMessageFilter( | ||||
|     tr("New message filter"), | ||||
|     QSL("function filterMessage() { return 1; }")); | ||||
|   auto* it = new QListWidgetItem(fltr->name(), m_ui.m_listFilters); | ||||
| 
 | ||||
|   it->setData(Qt::ItemDataRole::UserRole, QVariant::fromValue<MessageFilter*>(fltr)); | ||||
| 
 | ||||
|   m_ui.m_listFilters->setCurrentRow(m_ui.m_listFilters->count() - 1); | ||||
| } | ||||
| 
 | ||||
| void FormMessageFiltersManager::loadFilter() { | ||||
|   auto* filter = selectedFilter(); | ||||
|   auto* acc = selectedAccount(); | ||||
| 
 | ||||
|   showFilter(filter); | ||||
|   updateFeedAssignments(filter, acc); | ||||
| } | ||||
| 
 | ||||
| void FormMessageFiltersManager::showFilter(MessageFilter* filter) { | ||||
|   if (filter == nullptr) { | ||||
|     m_ui.m_txtTitle->clear(); | ||||
|     m_ui.m_txtScript->clear(); | ||||
|     m_ui.m_gbDetails->setEnabled(false); | ||||
|   } | ||||
|   else { | ||||
|     m_ui.m_txtTitle->setText(filter->name()); | ||||
|     m_ui.m_txtScript->setPlainText(filter->script()); | ||||
|     m_ui.m_gbDetails->setEnabled(true); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void FormMessageFiltersManager::updateFeedAssignments(MessageFilter* filter, ServiceRoot* account) {} | ||||
|  |  | |||
|  | @ -5,16 +5,40 @@ | |||
| 
 | ||||
| #include <QDialog> | ||||
| 
 | ||||
| #include "services/abstract/serviceroot.h" | ||||
| 
 | ||||
| #include "ui_formmessagefiltersmanager.h" | ||||
| 
 | ||||
| class AccountCheckModel; | ||||
| class MessageFilter; | ||||
| class FeedReader; | ||||
| 
 | ||||
| class FormMessageFiltersManager : public QDialog { | ||||
|     Q_OBJECT | ||||
|   Q_OBJECT | ||||
| 
 | ||||
|   public: | ||||
|     explicit FormMessageFiltersManager(QWidget *parent = nullptr); | ||||
|     explicit FormMessageFiltersManager(FeedReader* reader, const QList<ServiceRoot*>& accounts, QWidget* parent = nullptr); | ||||
|     virtual ~FormMessageFiltersManager(); | ||||
| 
 | ||||
|     MessageFilter* selectedFilter() const; | ||||
|     ServiceRoot* selectedAccount() const; | ||||
| 
 | ||||
|   private slots: | ||||
|     void addNewFilter(); | ||||
|     void loadFilter(); | ||||
| 
 | ||||
|     // Display filter title/contents.
 | ||||
|     void showFilter(MessageFilter* filter); | ||||
| 
 | ||||
|     // Load feeds/categories of the account, place checkmarks where filter is used.
 | ||||
|     void updateFeedAssignments(MessageFilter* filter, ServiceRoot* account); | ||||
| 
 | ||||
|   private: | ||||
|     Ui::FormMessageFiltersManager m_ui; | ||||
|     AccountCheckModel* m_feedsModel; | ||||
|     RootItem* m_rootItem; | ||||
|     QList<ServiceRoot*> m_accounts; | ||||
|     FeedReader* m_reader; | ||||
| }; | ||||
| 
 | ||||
| #endif // FORMMESSAGEFILTERSMANAGER_H
 | ||||
|  |  | |||
|  | @ -6,144 +6,16 @@ | |||
|    <rect> | ||||
|     <x>0</x> | ||||
|     <y>0</y> | ||||
|     <width>737</width> | ||||
|     <height>592</height> | ||||
|     <width>900</width> | ||||
|     <height>625</height> | ||||
|    </rect> | ||||
|   </property> | ||||
|   <property name="windowTitle"> | ||||
|    <string>Message filters</string> | ||||
|   </property> | ||||
|   <layout class="QGridLayout" name="gridLayout_2"> | ||||
|    <item row="0" column="1"> | ||||
|     <widget class="QTreeView" name="m_treeFeeds"/> | ||||
|    </item> | ||||
|    <item row="1" column="0" colspan="2"> | ||||
|     <widget class="QGroupBox" name="groupBox"> | ||||
|      <property name="sizePolicy"> | ||||
|       <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> | ||||
|        <horstretch>0</horstretch> | ||||
|        <verstretch>1</verstretch> | ||||
|       </sizepolicy> | ||||
|      </property> | ||||
|      <property name="title"> | ||||
|       <string>Message filter details</string> | ||||
|      </property> | ||||
|      <layout class="QFormLayout" name="formLayout"> | ||||
|       <item row="0" column="0"> | ||||
|        <widget class="QLabel" name="label"> | ||||
|         <property name="text"> | ||||
|          <string>Title</string> | ||||
|         </property> | ||||
|         <property name="buddy"> | ||||
|          <cstring>m_txtTitle</cstring> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|       <item row="0" column="1"> | ||||
|        <layout class="QHBoxLayout" name="horizontalLayout"> | ||||
|         <item> | ||||
|          <widget class="QLineEdit" name="m_txtTitle"> | ||||
|           <property name="placeholderText"> | ||||
|            <string>Title of message filter</string> | ||||
|           </property> | ||||
|          </widget> | ||||
|         </item> | ||||
|         <item> | ||||
|          <spacer name="horizontalSpacer_2"> | ||||
|           <property name="orientation"> | ||||
|            <enum>Qt::Horizontal</enum> | ||||
|           </property> | ||||
|           <property name="sizeHint" stdset="0"> | ||||
|            <size> | ||||
|             <width>40</width> | ||||
|             <height>20</height> | ||||
|            </size> | ||||
|           </property> | ||||
|          </spacer> | ||||
|         </item> | ||||
|        </layout> | ||||
|       </item> | ||||
|       <item row="1" column="0"> | ||||
|        <widget class="QLabel" name="label_2"> | ||||
|         <property name="text"> | ||||
|          <string>JavaScript code</string> | ||||
|         </property> | ||||
|         <property name="buddy"> | ||||
|          <cstring>m_txtScript</cstring> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|       <item row="3" column="0"> | ||||
|        <widget class="QLabel" name="label_3"> | ||||
|         <property name="text"> | ||||
|          <string>Errors</string> | ||||
|         </property> | ||||
|         <property name="buddy"> | ||||
|          <cstring>m_txtErrors</cstring> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|       <item row="3" column="1"> | ||||
|        <widget class="QPlainTextEdit" name="m_txtErrors"> | ||||
|         <property name="enabled"> | ||||
|          <bool>false</bool> | ||||
|         </property> | ||||
|         <property name="sizePolicy"> | ||||
|          <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> | ||||
|           <horstretch>0</horstretch> | ||||
|           <verstretch>1</verstretch> | ||||
|          </sizepolicy> | ||||
|         </property> | ||||
|         <property name="readOnly"> | ||||
|          <bool>false</bool> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|       <item row="2" column="1"> | ||||
|        <layout class="QHBoxLayout" name="horizontalLayout_2"> | ||||
|         <item> | ||||
|          <widget class="QPushButton" name="m_btnDetailedHelp"> | ||||
|           <property name="text"> | ||||
|            <string>&Detailed help</string> | ||||
|           </property> | ||||
|          </widget> | ||||
|         </item> | ||||
|         <item> | ||||
|          <spacer name="horizontalSpacer_3"> | ||||
|           <property name="orientation"> | ||||
|            <enum>Qt::Horizontal</enum> | ||||
|           </property> | ||||
|           <property name="sizeHint" stdset="0"> | ||||
|            <size> | ||||
|             <width>40</width> | ||||
|             <height>20</height> | ||||
|            </size> | ||||
|           </property> | ||||
|          </spacer> | ||||
|         </item> | ||||
|        </layout> | ||||
|       </item> | ||||
|       <item row="1" column="1"> | ||||
|        <widget class="QPlainTextEdit" name="m_txtScript"> | ||||
|         <property name="sizePolicy"> | ||||
|          <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> | ||||
|           <horstretch>0</horstretch> | ||||
|           <verstretch>2</verstretch> | ||||
|          </sizepolicy> | ||||
|         </property> | ||||
|         <property name="placeholderText"> | ||||
|          <string>Your JavaScript-based message filtering logic</string> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|      </layout> | ||||
|     </widget> | ||||
|    </item> | ||||
|    <item row="0" column="0"> | ||||
|     <layout class="QGridLayout" name="gridLayout"> | ||||
|      <item row="0" column="0" colspan="3"> | ||||
|       <widget class="QTreeView" name="m_treeFilters"/> | ||||
|      </item> | ||||
|      <item row="1" column="2"> | ||||
|       <widget class="QPushButton" name="m_btnRemoveSelected"> | ||||
|        <property name="text"> | ||||
|  | @ -171,8 +43,276 @@ | |||
|        </property> | ||||
|       </spacer> | ||||
|      </item> | ||||
|      <item row="0" column="0" colspan="3"> | ||||
|       <widget class="QListWidget" name="m_listFilters"/> | ||||
|      </item> | ||||
|     </layout> | ||||
|    </item> | ||||
|    <item row="0" column="1"> | ||||
|     <layout class="QFormLayout" name="formLayout_3"> | ||||
|      <item row="1" column="0" colspan="2"> | ||||
|       <widget class="QTreeView" name="m_treeFeeds"> | ||||
|        <property name="minimumSize"> | ||||
|         <size> | ||||
|          <width>0</width> | ||||
|          <height>150</height> | ||||
|         </size> | ||||
|        </property> | ||||
|       </widget> | ||||
|      </item> | ||||
|      <item row="0" column="1"> | ||||
|       <widget class="QComboBox" name="comboBox"/> | ||||
|      </item> | ||||
|      <item row="0" column="0"> | ||||
|       <widget class="QLabel" name="label_9"> | ||||
|        <property name="text"> | ||||
|         <string>Account</string> | ||||
|        </property> | ||||
|        <property name="buddy"> | ||||
|         <cstring>comboBox</cstring> | ||||
|        </property> | ||||
|       </widget> | ||||
|      </item> | ||||
|     </layout> | ||||
|    </item> | ||||
|    <item row="1" column="0" colspan="2"> | ||||
|     <widget class="QGroupBox" name="m_gbDetails"> | ||||
|      <property name="title"> | ||||
|       <string>Message filter details</string> | ||||
|      </property> | ||||
|      <layout class="QFormLayout" name="formLayout"> | ||||
|       <item row="0" column="0"> | ||||
|        <widget class="QLabel" name="label"> | ||||
|         <property name="text"> | ||||
|          <string>Title</string> | ||||
|         </property> | ||||
|         <property name="buddy"> | ||||
|          <cstring>m_txtTitle</cstring> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|       <item row="0" column="1"> | ||||
|        <layout class="QHBoxLayout" name="horizontalLayout"> | ||||
|         <item> | ||||
|          <widget class="QLineEdit" name="m_txtTitle"> | ||||
|           <property name="sizePolicy"> | ||||
|            <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> | ||||
|             <horstretch>0</horstretch> | ||||
|             <verstretch>0</verstretch> | ||||
|            </sizepolicy> | ||||
|           </property> | ||||
|           <property name="maximumSize"> | ||||
|            <size> | ||||
|             <width>300</width> | ||||
|             <height>16777215</height> | ||||
|            </size> | ||||
|           </property> | ||||
|           <property name="placeholderText"> | ||||
|            <string>Title of message filter</string> | ||||
|           </property> | ||||
|          </widget> | ||||
|         </item> | ||||
|         <item> | ||||
|          <spacer name="horizontalSpacer_2"> | ||||
|           <property name="orientation"> | ||||
|            <enum>Qt::Horizontal</enum> | ||||
|           </property> | ||||
|          </spacer> | ||||
|         </item> | ||||
|        </layout> | ||||
|       </item> | ||||
|       <item row="1" column="0"> | ||||
|        <widget class="QLabel" name="label_2"> | ||||
|         <property name="text"> | ||||
|          <string>JavaScript code</string> | ||||
|         </property> | ||||
|         <property name="buddy"> | ||||
|          <cstring>m_txtScript</cstring> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|       <item row="1" column="1"> | ||||
|        <layout class="QHBoxLayout" name="horizontalLayout_3"> | ||||
|         <item> | ||||
|          <widget class="QPlainTextEdit" name="m_txtScript"> | ||||
|           <property name="sizePolicy"> | ||||
|            <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> | ||||
|             <horstretch>0</horstretch> | ||||
|             <verstretch>1</verstretch> | ||||
|            </sizepolicy> | ||||
|           </property> | ||||
|           <property name="placeholderText"> | ||||
|            <string>Your JavaScript-based message filtering logic</string> | ||||
|           </property> | ||||
|          </widget> | ||||
|         </item> | ||||
|         <item> | ||||
|          <widget class="QGroupBox" name="groupBox_2"> | ||||
|           <property name="title"> | ||||
|            <string>Sample message</string> | ||||
|           </property> | ||||
|           <layout class="QFormLayout" name="formLayout_2"> | ||||
|            <item row="0" column="0" colspan="2"> | ||||
|             <layout class="QHBoxLayout" name="horizontalLayout_4"> | ||||
|              <item> | ||||
|               <widget class="QCheckBox" name="checkBox"> | ||||
|                <property name="text"> | ||||
|                 <string>Read</string> | ||||
|                </property> | ||||
|               </widget> | ||||
|              </item> | ||||
|              <item> | ||||
|               <widget class="QCheckBox" name="checkBox_2"> | ||||
|                <property name="text"> | ||||
|                 <string>Important</string> | ||||
|                </property> | ||||
|               </widget> | ||||
|              </item> | ||||
|              <item> | ||||
|               <spacer name="horizontalSpacer_4"> | ||||
|                <property name="orientation"> | ||||
|                 <enum>Qt::Horizontal</enum> | ||||
|                </property> | ||||
|                <property name="sizeHint" stdset="0"> | ||||
|                 <size> | ||||
|                  <width>40</width> | ||||
|                  <height>20</height> | ||||
|                 </size> | ||||
|                </property> | ||||
|               </spacer> | ||||
|              </item> | ||||
|             </layout> | ||||
|            </item> | ||||
|            <item row="1" column="0"> | ||||
|             <widget class="QLabel" name="label_4"> | ||||
|              <property name="text"> | ||||
|               <string>Title</string> | ||||
|              </property> | ||||
|              <property name="buddy"> | ||||
|               <cstring>lineEdit</cstring> | ||||
|              </property> | ||||
|             </widget> | ||||
|            </item> | ||||
|            <item row="1" column="1"> | ||||
|             <widget class="QLineEdit" name="lineEdit"/> | ||||
|            </item> | ||||
|            <item row="2" column="0"> | ||||
|             <widget class="QLabel" name="label_6"> | ||||
|              <property name="text"> | ||||
|               <string>URL</string> | ||||
|              </property> | ||||
|              <property name="buddy"> | ||||
|               <cstring>lineEdit_2</cstring> | ||||
|              </property> | ||||
|             </widget> | ||||
|            </item> | ||||
|            <item row="2" column="1"> | ||||
|             <widget class="QLineEdit" name="lineEdit_2"/> | ||||
|            </item> | ||||
|            <item row="3" column="0"> | ||||
|             <widget class="QLabel" name="label_7"> | ||||
|              <property name="text"> | ||||
|               <string>Author</string> | ||||
|              </property> | ||||
|              <property name="buddy"> | ||||
|               <cstring>lineEdit_3</cstring> | ||||
|              </property> | ||||
|             </widget> | ||||
|            </item> | ||||
|            <item row="3" column="1"> | ||||
|             <widget class="QLineEdit" name="lineEdit_3"/> | ||||
|            </item> | ||||
|            <item row="4" column="0"> | ||||
|             <widget class="QLabel" name="label_8"> | ||||
|              <property name="text"> | ||||
|               <string>Created on</string> | ||||
|              </property> | ||||
|              <property name="buddy"> | ||||
|               <cstring>lineEdit_4</cstring> | ||||
|              </property> | ||||
|             </widget> | ||||
|            </item> | ||||
|            <item row="4" column="1"> | ||||
|             <widget class="QLineEdit" name="lineEdit_4"/> | ||||
|            </item> | ||||
|            <item row="5" column="0"> | ||||
|             <widget class="QLabel" name="label_5"> | ||||
|              <property name="text"> | ||||
|               <string>Contents</string> | ||||
|              </property> | ||||
|              <property name="buddy"> | ||||
|               <cstring>plainTextEdit</cstring> | ||||
|              </property> | ||||
|             </widget> | ||||
|            </item> | ||||
|            <item row="5" column="1"> | ||||
|             <widget class="QPlainTextEdit" name="plainTextEdit"/> | ||||
|            </item> | ||||
|           </layout> | ||||
|          </widget> | ||||
|         </item> | ||||
|        </layout> | ||||
|       </item> | ||||
|       <item row="2" column="1"> | ||||
|        <layout class="QHBoxLayout" name="horizontalLayout_2"> | ||||
|         <item> | ||||
|          <widget class="QPushButton" name="m_btnTest"> | ||||
|           <property name="text"> | ||||
|            <string>&Test</string> | ||||
|           </property> | ||||
|          </widget> | ||||
|         </item> | ||||
|         <item> | ||||
|          <widget class="QPushButton" name="m_btnDetailedHelp"> | ||||
|           <property name="text"> | ||||
|            <string>&Detailed &help</string> | ||||
|           </property> | ||||
|          </widget> | ||||
|         </item> | ||||
|         <item> | ||||
|          <spacer name="horizontalSpacer_3"> | ||||
|           <property name="orientation"> | ||||
|            <enum>Qt::Horizontal</enum> | ||||
|           </property> | ||||
|           <property name="sizeHint" stdset="0"> | ||||
|            <size> | ||||
|             <width>40</width> | ||||
|             <height>20</height> | ||||
|            </size> | ||||
|           </property> | ||||
|          </spacer> | ||||
|         </item> | ||||
|        </layout> | ||||
|       </item> | ||||
|       <item row="4" column="0"> | ||||
|        <widget class="QLabel" name="label_3"> | ||||
|         <property name="text"> | ||||
|          <string>Test output</string> | ||||
|         </property> | ||||
|         <property name="buddy"> | ||||
|          <cstring>m_txtErrors</cstring> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|       <item row="4" column="1"> | ||||
|        <widget class="QPlainTextEdit" name="m_txtErrors"> | ||||
|         <property name="enabled"> | ||||
|          <bool>false</bool> | ||||
|         </property> | ||||
|         <property name="sizePolicy"> | ||||
|          <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> | ||||
|           <horstretch>0</horstretch> | ||||
|           <verstretch>1</verstretch> | ||||
|          </sizepolicy> | ||||
|         </property> | ||||
|         <property name="readOnly"> | ||||
|          <bool>false</bool> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|      </layout> | ||||
|     </widget> | ||||
|    </item> | ||||
|    <item row="2" column="1"> | ||||
|     <widget class="QDialogButtonBox" name="m_buttonBox"> | ||||
|      <property name="orientation"> | ||||
|  | @ -189,12 +329,22 @@ | |||
|   </layout> | ||||
|  </widget> | ||||
|  <tabstops> | ||||
|   <tabstop>m_treeFilters</tabstop> | ||||
|   <tabstop>m_treeFeeds</tabstop> | ||||
|   <tabstop>m_listFilters</tabstop> | ||||
|   <tabstop>m_btnAddNew</tabstop> | ||||
|   <tabstop>m_btnRemoveSelected</tabstop> | ||||
|   <tabstop>comboBox</tabstop> | ||||
|   <tabstop>m_treeFeeds</tabstop> | ||||
|   <tabstop>m_txtTitle</tabstop> | ||||
|   <tabstop>m_txtScript</tabstop> | ||||
|   <tabstop>m_btnTest</tabstop> | ||||
|   <tabstop>m_btnDetailedHelp</tabstop> | ||||
|   <tabstop>checkBox</tabstop> | ||||
|   <tabstop>checkBox_2</tabstop> | ||||
|   <tabstop>lineEdit</tabstop> | ||||
|   <tabstop>lineEdit_2</tabstop> | ||||
|   <tabstop>lineEdit_3</tabstop> | ||||
|   <tabstop>lineEdit_4</tabstop> | ||||
|   <tabstop>plainTextEdit</tabstop> | ||||
|   <tabstop>m_txtErrors</tabstop> | ||||
|  </tabstops> | ||||
|  <resources/> | ||||
|  | @ -206,8 +356,8 @@ | |||
|    <slot>accept()</slot> | ||||
|    <hints> | ||||
|     <hint type="sourcelabel"> | ||||
|      <x>248</x> | ||||
|      <y>254</y> | ||||
|      <x>701</x> | ||||
|      <y>615</y> | ||||
|     </hint> | ||||
|     <hint type="destinationlabel"> | ||||
|      <x>157</x> | ||||
|  | @ -222,8 +372,8 @@ | |||
|    <slot>reject()</slot> | ||||
|    <hints> | ||||
|     <hint type="sourcelabel"> | ||||
|      <x>316</x> | ||||
|      <y>260</y> | ||||
|      <x>769</x> | ||||
|      <y>615</y> | ||||
|     </hint> | ||||
|     <hint type="destinationlabel"> | ||||
|      <x>286</x> | ||||
|  |  | |||
|  | @ -22,7 +22,7 @@ void GuiUtilities::setLabelAsNotice(QLabel& label, bool is_warning) { | |||
| } | ||||
| 
 | ||||
| void GuiUtilities::applyDialogProperties(QWidget& widget, const QIcon& icon, const QString& title) { | ||||
|   widget.setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint); | ||||
|   widget.setWindowFlags(/*Qt::MSWindowsFixedSizeDialogHint | */ Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint); | ||||
|   widget.setWindowIcon(icon); | ||||
| 
 | ||||
|   if (!title.isEmpty()) { | ||||
|  |  | |||
|  | @ -7,10 +7,10 @@ | |||
| #include "core/feedsproxymodel.h" | ||||
| #include "core/messagesmodel.h" | ||||
| #include "core/messagesproxymodel.h" | ||||
| #include "gui/dialogs/formmessagefiltersmanager.h" | ||||
| #include "miscellaneous/application.h" | ||||
| #include "miscellaneous/databasequeries.h" | ||||
| #include "miscellaneous/mutex.h" | ||||
| #include "gui/dialogs/formmessagefiltersmanager.h" | ||||
| #include "services/abstract/cacheforserviceroot.h" | ||||
| #include "services/abstract/serviceroot.h" | ||||
| #include "services/gmail/gmailentrypoint.h" | ||||
|  | @ -97,7 +97,10 @@ void FeedReader::updateFeeds(const QList<Feed*>& feeds) { | |||
| } | ||||
| 
 | ||||
| void FeedReader::showMessageFiltersManager() { | ||||
|   FormMessageFiltersManager manager(qApp->mainFormWidget()); | ||||
|   FormMessageFiltersManager manager(qApp->feedReader(), | ||||
|                                     qApp->feedReader()->feedsModel()->serviceRoots(), | ||||
|                                     qApp->mainFormWidget()); | ||||
| 
 | ||||
|   manager.exec(); | ||||
| } | ||||
| 
 | ||||
|  | @ -135,7 +138,7 @@ int FeedReader::autoUpdateInitialInterval() const { | |||
|   return m_globalAutoUpdateInitialInterval; | ||||
| } | ||||
| 
 | ||||
| void FeedReader::loadSaveMessageFilters() { | ||||
| void FeedReader::loadSavedMessageFilters() { | ||||
|   // Load all message filters from database.
 | ||||
|   // All plugin services will hook active filters to
 | ||||
|   // all feeds.
 | ||||
|  | @ -148,6 +151,17 @@ void FeedReader::loadSaveMessageFilters() { | |||
|   } | ||||
| } | ||||
| 
 | ||||
| MessageFilter* FeedReader::addMessageFilter(const QString& title, const QString& script) { | ||||
|   auto* fltr = new MessageFilter(12, this); | ||||
| 
 | ||||
|   fltr->setName(title); | ||||
|   fltr->setScript(script); | ||||
| 
 | ||||
|   // TODO: Save into database, then return.
 | ||||
| 
 | ||||
|   return fltr; | ||||
| } | ||||
| 
 | ||||
| void FeedReader::updateAllFeeds() { | ||||
|   updateFeeds(m_feedsModel->rootItem()->getSubTreeFeeds()); | ||||
| } | ||||
|  |  | |||
|  | @ -52,9 +52,9 @@ class RSSGUARD_DLLSPEC FeedReader : public QObject { | |||
|     int autoUpdateRemainingInterval() const; | ||||
|     int autoUpdateInitialInterval() const; | ||||
| 
 | ||||
|     void loadSaveMessageFilters(); | ||||
| 
 | ||||
|     void loadSavedMessageFilters(); | ||||
|     QList<MessageFilter*> messageFilters() const; | ||||
|     MessageFilter* addMessageFilter(const QString& title, const QString& script); | ||||
| 
 | ||||
|   public slots: | ||||
|     void updateAllFeeds(); | ||||
|  |  | |||
|  | @ -25,9 +25,7 @@ RootItem* AccountCheckModel::rootItem() const { | |||
| } | ||||
| 
 | ||||
| void AccountCheckModel::setRootItem(RootItem* root_item) { | ||||
| 
 | ||||
|   delete m_rootItem; | ||||
| 
 | ||||
|   m_rootItem = root_item; | ||||
| } | ||||
| 
 | ||||
|  | @ -161,23 +159,17 @@ QVariant AccountCheckModel::data(const QModelIndex& index, int role) const { | |||
|     } | ||||
|   } | ||||
|   else if (role == Qt::DecorationRole) { | ||||
|     switch (item->kind()) { | ||||
|       case RootItemKind::Category: | ||||
|       case RootItemKind::Bin: | ||||
|       case RootItemKind::Feed: | ||||
|         return item->icon(); | ||||
|     auto ic = item->icon(); | ||||
| 
 | ||||
|       default: | ||||
|         return QVariant(); | ||||
|     } | ||||
|     return ic.isNull() ? QVariant() : ic; | ||||
|   } | ||||
|   else if (role == Qt::DisplayRole) { | ||||
|     switch (item->kind()) { | ||||
|       case RootItemKind::Category: | ||||
|         return QVariant(item->data(index.column(), role).toString() + tr(" (category)")); | ||||
|         return QVariant(item->data(index.column(), role).toString() + QSL(" ") + tr("(category)")); | ||||
| 
 | ||||
|       case RootItemKind::Feed: | ||||
|         return QVariant(item->data(index.column(), role).toString() + tr(" (feed)")); | ||||
|         return QVariant(item->data(index.column(), role).toString() + QSL(" ") + tr("(feed)")); | ||||
| 
 | ||||
|       default: | ||||
|         return item->title(); | ||||
|  | @ -243,7 +235,8 @@ bool AccountCheckModel::setData(const QModelIndex& index, const QVariant& value, | |||
| } | ||||
| 
 | ||||
| Qt::ItemFlags AccountCheckModel::flags(const QModelIndex& index) const { | ||||
|   if (!index.isValid() || itemForIndex(index)->kind() == RootItemKind::Bin) { | ||||
|   if (!index.isValid() || (itemForIndex(index)->kind() != RootItemKind::Kind::Category && | ||||
|                            itemForIndex(index)->kind() != RootItemKind::Kind::Feed)) { | ||||
|     return Qt::NoItemFlags; | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -7,12 +7,12 @@ | |||
| 
 | ||||
| #include "services/abstract/rootitem.h" | ||||
| 
 | ||||
| // This is common model which displays only categories/feeds
 | ||||
| // and allows user to place checkmarks.
 | ||||
| class AccountCheckModel : public QAbstractItemModel { | ||||
|   Q_OBJECT | ||||
| 
 | ||||
|   public: | ||||
| 
 | ||||
|     // Constructors and destructors.
 | ||||
|     explicit AccountCheckModel(QObject* parent = nullptr); | ||||
|     virtual ~AccountCheckModel(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -40,7 +40,7 @@ void FormStandardImportExport::setMode(const FeedsImportExportModel::Mode& mode) | |||
|   m_ui->m_progressBar->setVisible(false); | ||||
| 
 | ||||
|   switch (mode) { | ||||
|     case FeedsImportExportModel::Export: { | ||||
|     case FeedsImportExportModel::Mode::Export: { | ||||
|       m_model->setRootItem(m_serviceRoot); | ||||
|       m_model->checkAllItems(); | ||||
|       m_ui->m_treeFeeds->setModel(m_model); | ||||
|  | @ -55,7 +55,7 @@ void FormStandardImportExport::setMode(const FeedsImportExportModel::Mode& mode) | |||
|       break; | ||||
|     } | ||||
| 
 | ||||
|     case FeedsImportExportModel::Import: { | ||||
|     case FeedsImportExportModel::Mode::Import: { | ||||
|       m_ui->m_groupFile->setTitle(tr("Source file")); | ||||
|       m_ui->m_groupFeeds->setTitle(tr("Target feeds && categories")); | ||||
|       m_ui->m_groupFeeds->setDisabled(true); | ||||
|  | @ -77,11 +77,11 @@ void FormStandardImportExport::setMode(const FeedsImportExportModel::Mode& mode) | |||
| 
 | ||||
| void FormStandardImportExport::selectFile() { | ||||
|   switch (m_model->mode()) { | ||||
|     case FeedsImportExportModel::Import: | ||||
|     case FeedsImportExportModel::Mode::Import: | ||||
|       selectImportFile(); | ||||
|       break; | ||||
| 
 | ||||
|     case FeedsImportExportModel::Export: { | ||||
|     case FeedsImportExportModel::Mode::Export: { | ||||
|       selectExportFile(); | ||||
|       break; | ||||
|     } | ||||
|  | @ -194,6 +194,7 @@ void FormStandardImportExport::selectImportFile() { | |||
|                                                           QString(), | ||||
|                                                           QMessageBox::Yes | QMessageBox::No, | ||||
|                                                           QMessageBox::Yes); | ||||
| 
 | ||||
|     parseImportFile(selected_file, answer == QMessageBox::Yes); | ||||
|   } | ||||
| } | ||||
|  | @ -227,11 +228,11 @@ void FormStandardImportExport::parseImportFile(const QString& file_name, bool fe | |||
| 
 | ||||
| void FormStandardImportExport::performAction() { | ||||
|   switch (m_model->mode()) { | ||||
|     case FeedsImportExportModel::Import: | ||||
|     case FeedsImportExportModel::Mode::Import: | ||||
|       importFeeds(); | ||||
|       break; | ||||
| 
 | ||||
|     case FeedsImportExportModel::Export: | ||||
|     case FeedsImportExportModel::Mode::Export: | ||||
|       exportFeeds(); | ||||
|       break; | ||||
| 
 | ||||
|  |  | |||
|  | @ -16,10 +16,10 @@ | |||
| #include <QStack> | ||||
| 
 | ||||
| FeedsImportExportModel::FeedsImportExportModel(QObject* parent) | ||||
|   : AccountCheckModel(parent), m_mode(Import) {} | ||||
|   : AccountCheckModel(parent), m_mode(Mode::Import) {} | ||||
| 
 | ||||
| FeedsImportExportModel::~FeedsImportExportModel() { | ||||
|   if (m_rootItem != nullptr && m_mode == Import) { | ||||
|   if (m_rootItem != nullptr && m_mode == Mode::Import) { | ||||
|     // Delete all model items, but only if we are in import mode. Export mode shares
 | ||||
|     // root item with main feed model, thus cannot be deleted from memory now.
 | ||||
|     delete m_rootItem; | ||||
|  | @ -52,10 +52,11 @@ bool FeedsImportExportModel::exportToOMPL20(QByteArray& result) { | |||
|   elem_opml_head.appendChild(elem_opml_created); | ||||
|   opml_document.documentElement().appendChild(elem_opml_head); | ||||
|   QDomElement elem_opml_body = opml_document.createElement(QSL("body")); | ||||
| 
 | ||||
|   QStack<RootItem*> items_to_process; | ||||
| 
 | ||||
|   items_to_process.push(m_rootItem); | ||||
|   QStack<QDomElement> elements_to_use; | ||||
| 
 | ||||
|   elements_to_use.push(elem_opml_body); | ||||
| 
 | ||||
|   // Process all unprocessed nodes.
 | ||||
|  | @ -146,10 +147,11 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m | |||
| 
 | ||||
|   int completed = 0, total = 0, succeded = 0, failed = 0; | ||||
|   auto* root_item = new StandardServiceRoot(); | ||||
| 
 | ||||
|   QStack<RootItem*> model_items; | ||||
| 
 | ||||
|   model_items.push(root_item); | ||||
|   QStack<QDomElement> elements_to_process; | ||||
| 
 | ||||
|   elements_to_process.push(opml_document.documentElement().elementsByTagName(QSL("body")).at(0).toElement()); | ||||
| 
 | ||||
|   while (!elements_to_process.isEmpty()) { | ||||
|  | @ -276,7 +278,6 @@ void FeedsImportExportModel::importAsTxtURLPerLine(const QByteArray& data, bool | |||
|   emit layoutChanged(); | ||||
|   int completed = 0, succeded = 0, failed = 0; | ||||
|   auto* root_item = new StandardServiceRoot(); | ||||
| 
 | ||||
|   QList<QByteArray> urls = data.split('\n'); | ||||
| 
 | ||||
|   for (const QByteArray& url : urls) { | ||||
|  |  | |||
|  | @ -9,13 +9,12 @@ class FeedsImportExportModel : public AccountCheckModel { | |||
|   Q_OBJECT | ||||
| 
 | ||||
|   public: | ||||
|     enum Mode { | ||||
|     enum class Mode { | ||||
|       Import, | ||||
|       Export | ||||
|     }; | ||||
| 
 | ||||
|     // Constructors and destructors.
 | ||||
|     explicit FeedsImportExportModel(QObject* parent = 0); | ||||
|     explicit FeedsImportExportModel(QObject* parent = nullptr); | ||||
|     virtual ~FeedsImportExportModel(); | ||||
| 
 | ||||
|     // Exports to OPML 2.0
 | ||||
|  |  | |||
|  | @ -293,14 +293,14 @@ void StandardServiceRoot::addNewCategory() { | |||
| void StandardServiceRoot::importFeeds() { | ||||
|   QScopedPointer<FormStandardImportExport> form(new FormStandardImportExport(this, qApp->mainFormWidget())); | ||||
| 
 | ||||
|   form.data()->setMode(FeedsImportExportModel::Import); | ||||
|   form.data()->setMode(FeedsImportExportModel::Mode::Import); | ||||
|   form.data()->exec(); | ||||
| } | ||||
| 
 | ||||
| void StandardServiceRoot::exportFeeds() { | ||||
|   QScopedPointer<FormStandardImportExport> form(new FormStandardImportExport(this, qApp->mainFormWidget())); | ||||
| 
 | ||||
|   form.data()->setMode(FeedsImportExportModel::Export); | ||||
|   form.data()->setMode(FeedsImportExportModel::Mode::Export); | ||||
|   form.data()->exec(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -77,7 +77,7 @@ int main(int argc, char* argv[]) { | |||
| 
 | ||||
|   qApp->loadDynamicShortcuts(); | ||||
|   qApp->hideOrShowMainForm(); | ||||
|   qApp->feedReader()->loadSaveMessageFilters(); | ||||
|   qApp->feedReader()->loadSavedMessageFilters(); | ||||
|   qApp->feedReader()->feedsModel()->loadActivatedServiceAccounts(); | ||||
|   qApp->showTrayIcon(); | ||||
|   qApp->offerChanges(); | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue