]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Display the MIME type icon in the download dialog.
authorSoren Stoutner <soren@stoutner.com>
Mon, 11 Jul 2022 17:45:23 +0000 (10:45 -0700)
committerSoren Stoutner <soren@stoutner.com>
Mon, 11 Jul 2022 17:45:23 +0000 (10:45 -0700)
src/dialogs/SaveDialog.cpp
src/uis/SaveDialog.ui

index fff857d41e18679f2b61cf374152f8316ced57a8..622bc363a1ef2945338651a4774136aa3f3fa30b 100644 (file)
@@ -25,6 +25,7 @@
 #include <KLocalizedString>
 
 // Qt toolkit headers.
+#include <QDebug>
 #include <QMimeDatabase>
 #include <QPushButton>
 #include <QShortcut>
@@ -45,6 +46,7 @@ SaveDialog::SaveDialog(QWebEngineDownloadItem *downloadItemPointer)
     saveDialogUi.setupUi(this);
 
     // Get handles for the widgets.
+    QGraphicsView *mimeGraphicsViewPointer = saveDialogUi.mimeGraphicsView;
     QLabel *urlLabelPointer = saveDialogUi.urlLabel;
     QLabel *filetypeLabelPointer = saveDialogUi.fileTypeLabel;
     QLabel *mimeTypeLabelPointer = saveDialogUi.mimeTypeLabel;
@@ -55,15 +57,33 @@ SaveDialog::SaveDialog(QWebEngineDownloadItem *downloadItemPointer)
     // Get the URL and the suggested file name.
     downloadUrl = downloadItemPointer->url();
     suggestedFileName = downloadItemPointer->suggestedFileName();
-    QString mimeType = downloadItemPointer->mimeType();
+    QString mimeTypeString = downloadItemPointer->mimeType();
 
     // Get a MIME type database.
     QMimeDatabase mimeDatabase;
 
+    // Get the MIME type.
+    QMimeType mimeType = mimeDatabase.mimeTypeForName(mimeTypeString);
+
+    // Get the MIME type icon.
+    QIcon mimeTypeIcon = QIcon::fromTheme(mimeType.iconName());
+
+    // Create a graphics scene.
+    QGraphicsScene *mimeGraphicsScenePointer = new QGraphicsScene(this);
+
+    // Set the graphics scene.
+    mimeGraphicsViewPointer->setScene(mimeGraphicsScenePointer);
+
+    // Set the background of the graphics view to be the same as the window
+    mimeGraphicsViewPointer->setBackgroundRole(QPalette::Window);
+
+    // Add the MIME type icon to the scene.
+    mimeGraphicsScenePointer->addPixmap(mimeTypeIcon.pixmap(64, 64));
+
     // Populate the labels.
     urlLabelPointer->setText("<b>" + downloadUrl.toString() + "</b>");
-    filetypeLabelPointer->setText("<b>" + mimeDatabase.mimeTypeForName(mimeType).comment() + "</b>");
-    mimeTypeLabelPointer->setText("<b>" + mimeType + "</b>");
+    filetypeLabelPointer->setText("<b>" + mimeType.comment() + "</b>");
+    mimeTypeLabelPointer->setText("<b>" + mimeTypeString + "</b>");
 
     // Populate the download size label.
     if (downloadItemPointer->totalBytes() == -1)  // The file size is unknown.
index 489b8c839d918c53e96d19bca4e159ed2b45936a..b8e3dfa4b0ae95dcd1fece7f104bf1884ea7a7ef 100644 (file)
                         <string>File details</string>
                     </property>
 
-                    <!-- Labels. -->
-                    <layout class="QFormLayout">
-                        <!-- URL. -->
-                        <item row="0" column="0">
-                            <widget class="QLabel">
-                                <property name="text">
-                                    <string>URL:</string>
+                    <layout class="QHBoxLayout">
+                        <!-- Icon. -->
+                        <item>
+                            <widget class="QGraphicsView"  name="mimeGraphicsView">
+                                <property name="frameShape">
+                                    <enum>QFrame::NoFrame</enum>
                                 </property>
-                            </widget>
-                        </item>
-
-                        <item row="0" column="1">
-                            <widget class="QLabel" name="urlLabel">
-                                <property name="textFormat">
-                                    <enum>Qt::RichText</enum>
-                                </property>
-                            </widget>
-                        </item>
-
-                        <!-- File type. -->
-                        <item row="1" column="0">
-                            <widget class="QLabel">
-                                <property name="text">
-                                    <string>File type:</string>
-                                </property>
-                            </widget>
-                        </item>
-
-                        <item row="1" column="1">
-                            <widget class="QLabel" name="fileTypeLabel">
-                                <property name="textFormat">
-                                    <enum>Qt::RichText</enum>
-                                </property>
-                            </widget>
-                        </item>
-
-                        <!-- MIME type. -->
-                        <item row="2" column="0">
-                            <widget class="QLabel">
-                                <property name="text">
-                                    <string>MIME type:</string>
-                                </property>
-                            </widget>
-                        </item>
 
-                        <item row="2" column="1">
-                            <widget class="QLabel" name="mimeTypeLabel">
-                                <property name="textFormat">
-                                    <enum>Qt::RichText</enum>
+                                <property name="alignment">
+                                    <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
                                 </property>
                             </widget>
                         </item>
 
-                        <!-- Size. -->
-                        <item row="3" column="0">
-                            <widget class="QLabel">
-                                <property name="text">
-                                    <string>Size:</string>
-                                </property>
-                            </widget>
-                        </item>
-
-                        <item row="3" column="1">
-                            <widget class="QLabel" name="sizeLabel">
-                                <property name="textFormat">
-                                    <enum>Qt::RichText</enum>
-                                </property>
-                            </widget>
+                        <!-- Text. -->
+                        <item>
+                            <layout class="QFormLayout">
+                                <!-- URL. -->
+                                <item row="0" column="0">
+                                    <widget class="QLabel">
+                                        <property name="text">
+                                            <string>URL:</string>
+                                        </property>
+                                    </widget>
+                                </item>
+
+                                <item row="0" column="1">
+                                    <widget class="QLabel" name="urlLabel">
+                                        <property name="textFormat">
+                                            <enum>Qt::RichText</enum>
+                                        </property>
+                                    </widget>
+                                </item>
+
+                                <!-- File type. -->
+                                <item row="1" column="0">
+                                    <widget class="QLabel">
+                                        <property name="text">
+                                            <string>File type:</string>
+                                        </property>
+                                    </widget>
+                                </item>
+
+                                <item row="1" column="1">
+                                    <widget class="QLabel" name="fileTypeLabel">
+                                        <property name="textFormat">
+                                            <enum>Qt::RichText</enum>
+                                        </property>
+                                    </widget>
+                                </item>
+
+                                <!-- MIME type. -->
+                                <item row="2" column="0">
+                                    <widget class="QLabel">
+                                        <property name="text">
+                                            <string>MIME type:</string>
+                                        </property>
+                                    </widget>
+                                </item>
+
+                                <item row="2" column="1">
+                                    <widget class="QLabel" name="mimeTypeLabel">
+                                        <property name="textFormat">
+                                            <enum>Qt::RichText</enum>
+                                        </property>
+                                    </widget>
+                                </item>
+
+                                <!-- Size. -->
+                                <item row="3" column="0">
+                                    <widget class="QLabel">
+                                        <property name="text">
+                                            <string>Size:</string>
+                                        </property>
+                                    </widget>
+                                </item>
+
+                                <item row="3" column="1">
+                                    <widget class="QLabel" name="sizeLabel">
+                                        <property name="textFormat">
+                                            <enum>Qt::RichText</enum>
+                                        </property>
+                                    </widget>
+                                </item>
+                            </layout>
                         </item>
                     </layout>
                 </widget>