#include "ui_RequestDetailDialog.h"
#include "structs/RequestStruct.h"
-// Qt toolkit headers.
-#include <QDebug>
-
// KDE Frameworks headers.
#include <KActionCollection>
#include <KColorScheme>
+// Qt toolkit headers.
+#include <QShortcut>
+
// Construct the class.
-RequestDetailDialog::RequestDetailDialog(QWidget *parentWidgetPointer, QByteArray &requestStructByteArray) : QDialog(parentWidgetPointer)
+RequestDetailDialog::RequestDetailDialog(QWidget *parentWidgetPointer, QTableWidget *tableWidgetPointer, const int initialRow) :
+ QDialog(parentWidgetPointer), currentRow(initialRow), tableWidgetPointer(tableWidgetPointer)
+{
+ // Set the window modality.
+ setWindowModality(Qt::WindowModality::ApplicationModal);
+
+ // Instantiate the request detail dialog UI.
+ Ui::RequestDetailDialog requestDetailDialogUi;
+
+ // Setup the UI.
+ requestDetailDialogUi.setupUi(this);
+
+ // Get handles for the views.
+ dispositionLineEditPointer = requestDetailDialogUi.dispositionLineEdit;
+ urlLineEditPointer = requestDetailDialogUi.urlLineEdit;
+ requestMethodLineEditPointer = requestDetailDialogUi.requestMethodLineEdit;
+ navigationTypeLineEditPointer = requestDetailDialogUi.navigationTypeLineEdit;
+ resourceTypeLineEditPointer = requestDetailDialogUi.resourceTypeLineEdit;
+ horizontalLinePointer = requestDetailDialogUi.horizontalLine;
+ filterListLabelPointer = requestDetailDialogUi.filterListLabel;
+ filterListLineEditPointer = requestDetailDialogUi.filterListLineEdit;
+ sublistLabelPointer = requestDetailDialogUi.sublistLabel;
+ sublistLineEditPointer = requestDetailDialogUi.sublistListLineEdit;
+ appliedEntryLabelPointer = requestDetailDialogUi.appliedEntryLabel;
+ appliedEntryLineEditPointer = requestDetailDialogUi.appliedEntryLineEdit;
+ originalEntryLabelPointer = requestDetailDialogUi.originalEntryLabel;
+ originalEntryLineEditPointer = requestDetailDialogUi.originalEntryLineEdit;
+ previousButtonPointer = requestDetailDialogUi.previousButton;
+ nextButtonPointer = requestDetailDialogUi.nextButton;
+ QDialogButtonBox *dialogButtonBoxPointer = requestDetailDialogUi.dialogButtonBox;
+ QPushButton *closeButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::StandardButton::Close);
+
+ // Make the close button the default.
+ closeButtonPointer->setDefault(true);
+
+ // Get the disposition line edit palettes.
+ normalBackgroundPalette = dispositionLineEditPointer->palette();
+ negativeBackgroundPalette = normalBackgroundPalette;
+ positiveBackgroundPalette = normalBackgroundPalette;
+
+ // Modify the palettes.
+ KColorScheme::adjustBackground(negativeBackgroundPalette, KColorScheme::NegativeBackground);
+ KColorScheme::adjustBackground(positiveBackgroundPalette, KColorScheme::PositiveBackground);
+
+ // Connect the buttons.
+ connect(previousButtonPointer, SIGNAL(clicked()), this, SLOT(previous()));
+ connect(nextButtonPointer, SIGNAL(clicked()), this, SLOT(next()));
+ connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(close()));
+
+ // Create the keyboard shortcuts.
+ QShortcut *previousShortcutPointer = new QShortcut(Qt::Key_Left, this);
+ QShortcut *nextShortcutPointer = new QShortcut(Qt::Key_Right, this);
+
+ // Connect the keyboard shortcuts to the buttons.
+ connect(previousShortcutPointer, SIGNAL(activated()), previousButtonPointer, SLOT(click()));
+ connect(nextShortcutPointer, SIGNAL(activated()), nextButtonPointer, SLOT(click()));
+
+ // Populate the dialog.
+ populateDialog(currentRow);
+}
+
+void RequestDetailDialog::populateDialog(const int row)
{
+ // Set the window title.
+ setWindowTitle(i18nc("The request detail dialog window title", "Request %1 Detail", row + 1));
+
+ // Select the row in the table widget (this displays the correct row highlighted in the background of the dialog).
+ tableWidgetPointer->selectRow(row);
+
+ // Get the first table widget item in the row.
+ QTableWidgetItem *rowFirstTableWidgetItemPointer = tableWidgetPointer->item(row, 0);
+
+ // Get the data variant.
+ QVariant dataVariant = rowFirstTableWidgetItemPointer->data(Qt::UserRole);
+
+ // Get the request struct byte array from the data variant.
+ QByteArray requestStructByteArray = dataVariant.toByteArray();
+
+ // Determine if previous should be enabled.
+ bool previousEnabled = (row > 0);
+
+ // Determine if next should be enabled.
+ bool nextEnabled = (row < (tableWidgetPointer->rowCount() - 1));
+
// Create a request struct data stream reader.
QDataStream requestStructDataStreamReader(requestStructByteArray);
requestStructDataStreamReader >> requestStructPointer->sublistInt;
requestStructDataStreamReader >> requestStructPointer->urlString;
- qDebug().noquote().nospace() << "Disposition: " << requestStructPointer->dispositionInt;
- qDebug().noquote().nospace() << "Applied Entry: " << requestStructPointer->entryStruct.appliedEntry;
- qDebug().noquote().nospace() << "Original Entry: " << requestStructPointer->entryStruct.originalEntry;
- qDebug().noquote().nospace() << "Filter List: " << requestStructPointer->filterListTitle;
- qDebug().noquote().nospace() << "Request Method: " << requestStructPointer->requestMethodString;
- qDebug().noquote().nospace() << "Navigation Type: " << requestStructPointer->navigationTypeInt;
- qDebug().noquote().nospace() << "Resource Type: " << requestStructPointer->resourceTypeInt;
- qDebug().noquote().nospace() << "Sublist: " << requestStructPointer->sublistInt;
- qDebug().noquote().nospace() << "URL: " << requestStructPointer->urlString;
-
- // Set the window title.
- setWindowTitle(i18nc("The request detail dialog window title", "Request Detail"));
-
- // Set the window modality.
- setWindowModality(Qt::WindowModality::ApplicationModal);
-
- // Instantiate the request detail dialog UI.
- Ui::RequestDetailDialog requestDetailDialogUi;
-
- // Setup the UI.
- requestDetailDialogUi.setupUi(this);
-
- // Get handles for the views.
- QLineEdit *dispositionLineEditPointer = requestDetailDialogUi.dispositionLineEdit;
- QLineEdit *urlLineEditPointer = requestDetailDialogUi.urlLineEdit;
- QLineEdit *requestMethodLineEditPointer = requestDetailDialogUi.requestMethodLineEdit;
- QLineEdit *navigationTypeLineEditPointer = requestDetailDialogUi.navigationTypeLineEdit;
- QLineEdit *resourceTypeLineEditPointer = requestDetailDialogUi.resourceTypeLineEdit;
- QFrame *horizontalLinePointer = requestDetailDialogUi.horizontalLine;
- QLabel *filterListLabelPointer = requestDetailDialogUi.filterListLabel;
- QLineEdit *filterListLineEditPointer = requestDetailDialogUi.filterListLineEdit;
- QLabel *sublistLabelPointer = requestDetailDialogUi.sublistLabel;
- QLineEdit *sublistLineEditPointer = requestDetailDialogUi.sublistListLineEdit;
- QLabel *appliedEntryLabelPointer = requestDetailDialogUi.appliedEntryLabel;
- QLineEdit *appliedEntryLineEditPointer = requestDetailDialogUi.appliedEntryLineEdit;
- QLabel *originalEntryLabelPointer = requestDetailDialogUi.originalEntryLabel;
- QLineEdit *originalEntryLineEditPointer = requestDetailDialogUi.originalEntryLineEdit;
- QDialogButtonBox *dialogButtonBoxPointer = requestDetailDialogUi.dialogButtonBox;
-
// Populate the views.
dispositionLineEditPointer->setText(globalFilterListHelperPointer->getDispositionString(requestStructPointer->dispositionInt));
urlLineEditPointer->setText(requestStructPointer->urlString);
appliedEntryLineEditPointer->setText(requestStructPointer->entryStruct.appliedEntry);
originalEntryLineEditPointer->setText(requestStructPointer->entryStruct.originalEntry);
- // Get the disposition line edit palettes.
- QPalette normalBackgroundPalette = dispositionLineEditPointer->palette();
- QPalette negativeBackgroundPalette = normalBackgroundPalette;
- QPalette positiveBackgroundPalette = normalBackgroundPalette;
-
- // Modify the palettes.
- KColorScheme::adjustBackground(negativeBackgroundPalette, KColorScheme::NegativeBackground);
- KColorScheme::adjustBackground(positiveBackgroundPalette, KColorScheme::PositiveBackground);
+ // Set the button status.
+ previousButtonPointer->setEnabled(previousEnabled);
+ nextButtonPointer->setEnabled(nextEnabled);
// Modify the interface based on the disposition.
switch (requestStructPointer->dispositionInt)
{
case FilterListHelper::DEFAULT:
{
- // Hide the filter list views.
+ // Reset the disposition line edit background.
+ dispositionLineEditPointer->setPalette(normalBackgroundPalette);
+
+ // Hide the views.
horizontalLinePointer->hide();
filterListLabelPointer->hide();
filterListLineEditPointer->hide();
// Colorize the disposition line edit background.
dispositionLineEditPointer->setPalette(positiveBackgroundPalette);
+ // Show the views.
+ horizontalLinePointer->show();
+ filterListLabelPointer->show();
+ filterListLineEditPointer->show();
+ sublistLabelPointer->show();
+ sublistLineEditPointer->show();
+ appliedEntryLabelPointer->show();
+ appliedEntryLineEditPointer->show();
+ originalEntryLabelPointer->show();
+ originalEntryLineEditPointer->show();
+
break;
}
// Colorize the disposition line edit background.
dispositionLineEditPointer->setPalette(negativeBackgroundPalette);
+ // Show the views.
+ horizontalLinePointer->show();
+ filterListLabelPointer->show();
+ filterListLineEditPointer->show();
+ sublistLabelPointer->show();
+ sublistLineEditPointer->show();
+ appliedEntryLabelPointer->show();
+ appliedEntryLineEditPointer->show();
+ originalEntryLabelPointer->show();
+ originalEntryLineEditPointer->show();
+
break;
}
}
+}
- // Connect the buttons.
- connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(close()));
+void RequestDetailDialog::previous()
+{
+ // Update the current row.
+ --currentRow;
+
+ // Populate the dialog.
+ populateDialog(currentRow);
+}
+
+void RequestDetailDialog::next()
+{
+ // Update the current row.
+ ++currentRow;
+
+ // Populate the dialog.
+ populateDialog(currentRow);
}