Browse Source

config: add [global]/image_name_prefix for inserted images

Le Tan 7 years ago
parent
commit
59efed94f3
5 changed files with 23 additions and 4 deletions
  1. 3 0
      src/resources/vnote.ini
  2. 6 3
      src/utils/vutils.cpp
  3. 3 0
      src/vconfigmanager.cpp
  4. 10 0
      src/vconfigmanager.h
  5. 1 1
      src/vwebview.cpp

+ 3 - 0
src/resources/vnote.ini

@@ -233,6 +233,9 @@ note_list_view_order=0
 ; 1 - 6
 outline_expanded_level=6
 
+; [optional] Prefix of the name of inserted images
+image_name_prefix=
+
 [export]
 ; Path of the wkhtmltopdf tool
 wkhtmltopdf=wkhtmltopdf

+ 6 - 3
src/utils/vutils.cpp

@@ -151,13 +151,16 @@ QString VUtils::generateImageFileName(const QString &path,
     // Constrain the length of the name.
     baseName.truncate(10);
 
+    baseName.prepend(g_config->getImageNamePrefix());
+
     if (!baseName.isEmpty()) {
-        baseName.prepend('_');
+        baseName.append('_');
     }
 
     // Add current time and random number to make the name be most likely unique
-    baseName = baseName + '_' + QString::number(QDateTime::currentDateTime().toTime_t());
-    baseName = baseName + '_' + QString::number(qrand());
+    baseName += QString::number(QDateTime::currentDateTime().toTime_t())
+                + '_'
+                + QString::number(qrand());
 
     QDir dir(path);
     QString imageName = baseName + "." + format.toLower();

+ 3 - 0
src/vconfigmanager.cpp

@@ -303,6 +303,9 @@ void VConfigManager::initialize()
 
     m_outlineExpandedLevel = getConfigFromSettings("global",
                                                    "outline_expanded_level").toInt();
+
+    m_imageNamePrefix = getConfigFromSettings("global",
+                                              "image_name_prefix").toString();
 }
 
 void VConfigManager::initSettings()

+ 10 - 0
src/vconfigmanager.h

@@ -520,6 +520,8 @@ public:
     int getOutlineExpandedLevel() const;
     void setOutlineExpandedLevel(int p_level);
 
+    const QString &getImageNamePrefix() const;
+
 private:
     // Look up a config from user and default settings.
     QVariant getConfigFromSettings(const QString &section, const QString &key) const;
@@ -936,6 +938,9 @@ private:
     // Expanded level of outline.
     int m_outlineExpandedLevel;
 
+    // Prefix of the name of inserted images.
+    QString m_imageNamePrefix;
+
     // The name of the config file in each directory.
     static const QString c_dirConfigFile;
 
@@ -2444,4 +2449,9 @@ inline void VConfigManager::setOutlineExpandedLevel(int p_level)
     m_outlineExpandedLevel = p_level;
     setConfigToSettings("global", "outline_expanded_level", m_outlineExpandedLevel);
 }
+
+inline const QString &VConfigManager::getImageNamePrefix() const
+{
+    return m_imageNamePrefix;
+}
 #endif // VCONFIGMANAGER_H

+ 1 - 1
src/vwebview.cpp

@@ -42,7 +42,7 @@ VWebView::VWebView(VFile *p_file, QWidget *p_parent)
 void VWebView::contextMenuEvent(QContextMenuEvent *p_event)
 {
     if (m_inPreview) {
-        QWebEngineView(p_event);
+        QWebEngineView::contextMenuEvent(p_event);
         return;
     }