Автоматическое создание novacoin.conf + кнопка для открытия novacoin.conf в Qt версии... 144/head
authorfsb4000 <fsb4000@yandex.ru>
Sat, 7 Feb 2015 11:56:24 +0000 (17:56 +0600)
committerfsb4000 <fsb4000@yandex.ru>
Sat, 7 Feb 2015 17:51:44 +0000 (23:51 +0600)
src/qt/forms/rpcconsole.ui
src/qt/guiutil.cpp
src/qt/guiutil.h
src/qt/locale/bitcoin_ru.ts
src/qt/rpcconsole.cpp
src/qt/rpcconsole.h
src/util.cpp

index afe3cd6..f5b50f6 100644 (file)
       <attribute name="title">
        <string>&amp;Information</string>
       </attribute>
-      <layout class="QGridLayout" name="gridLayout" columnstretch="0,1">
-       <property name="horizontalSpacing">
-        <number>12</number>
-       </property>
-       <item row="0" column="0">
-        <widget class="QLabel" name="label_9">
+      <layout class="QGridLayout" name="gridLayout">
+       <item row="15" column="2">
+        <widget class="QLabel" name="labelConfigfile">
          <property name="font">
           <font>
            <weight>75</weight>
           </font>
          </property>
          <property name="text">
-          <string>NovaCoin Core</string>
+          <string>Configuration file</string>
          </property>
         </widget>
        </item>
-       <item row="1" column="0">
-        <widget class="QLabel" name="label_5">
-         <property name="text">
-          <string>Client name</string>
-         </property>
-        </widget>
-       </item>
-       <item row="1" column="1">
-        <widget class="QLabel" name="clientName">
+       <item row="13" column="2">
+        <widget class="QLabel" name="lastBlockTime">
          <property name="cursor">
           <cursorShape>IBeamCursor</cursorShape>
          </property>
          </property>
         </widget>
        </item>
-       <item row="2" column="0">
-        <widget class="QLabel" name="label_6">
+       <item row="11" column="0">
+        <widget class="QLabel" name="label_3">
          <property name="text">
-          <string>Client version</string>
+          <string>Current number of blocks</string>
          </property>
         </widget>
        </item>
-       <item row="2" column="1">
-        <widget class="QLabel" name="clientVersion">
+       <item row="11" column="2">
+        <widget class="QLabel" name="numberOfBlocks">
          <property name="cursor">
           <cursorShape>IBeamCursor</cursorShape>
          </property>
          </property>
         </widget>
        </item>
-       <item row="3" column="0">
-        <widget class="QLabel" name="label_14">
-         <property name="text">
-          <string>Using OpenSSL version</string>
+       <item row="17" column="0">
+        <widget class="QLabel" name="labelCLOptions">
+         <property name="font">
+          <font>
+           <weight>75</weight>
+           <bold>true</bold>
+          </font>
          </property>
-         <property name="indent">
-          <number>10</number>
+         <property name="text">
+          <string>Command-line options</string>
          </property>
         </widget>
        </item>
-       <item row="3" column="1">
-        <widget class="QLabel" name="openSSLVersion">
-         <property name="cursor">
-          <cursorShape>IBeamCursor</cursorShape>
+       <item row="16" column="0">
+        <widget class="QPushButton" name="openDebugLogfileButton">
+         <property name="toolTip">
+          <string>Open the NovaCoin debug log file from the current data directory. This can take a few seconds for large log files.</string>
          </property>
          <property name="text">
-          <string>N/A</string>
+          <string>&amp;Open</string>
          </property>
-         <property name="textFormat">
-          <enum>Qt::PlainText</enum>
+         <property name="autoDefault">
+          <bool>false</bool>
          </property>
-         <property name="textInteractionFlags">
-          <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+        </widget>
+       </item>
+       <item row="15" column="0">
+        <widget class="QLabel" name="labelDebugLogfile">
+         <property name="font">
+          <font>
+           <weight>75</weight>
+           <bold>true</bold>
+          </font>
+         </property>
+         <property name="text">
+          <string>Debug log file</string>
          </property>
         </widget>
        </item>
-       <item row="4" column="0">
-         <widget class="QLabel" name="label_berkeleyDBVersion">
-           <property name="text">
-             <string>Using BerkeleyDB version</string>
-           </property>
-           <property name="indent">
-             <number>10</number>
-           </property>
-         </widget>
+       <item row="18" column="3" rowspan="2">
+        <spacer name="horizontalSpacer">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>404</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
        </item>
-       <item row="4" column="1">
-         <widget class="QLabel" name="berkeleyDBVersion">
-           <property name="cursor">
-             <cursorShape>IBeamCursor</cursorShape>
-           </property>
-           <property name="text">
-             <string>N/A</string>
-           </property>
-           <property name="textFormat">
-             <enum>Qt::PlainText</enum>
-           </property>
-           <property name="textInteractionFlags">
-             <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
-           </property>
-         </widget>
+       <item row="19" column="1">
+        <spacer name="verticalSpacer">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>40</height>
+          </size>
+         </property>
+        </spacer>
        </item>
-       <item row="5" column="0">
-        <widget class="QLabel" name="label_12">
+       <item row="18" column="0">
+        <widget class="QPushButton" name="showCLOptionsButton">
+         <property name="toolTip">
+          <string>Show the NovaCoin-Qt help message to get a list with possible NovaCoin command-line options.</string>
+         </property>
          <property name="text">
-          <string>Build date</string>
+          <string>&amp;Show</string>
+         </property>
+         <property name="autoDefault">
+          <bool>false</bool>
          </property>
         </widget>
        </item>
-       <item row="5" column="1">
-        <widget class="QLabel" name="buildDate">
+       <item row="13" column="0">
+        <widget class="QLabel" name="label_2">
+         <property name="text">
+          <string>Last block time</string>
+         </property>
+        </widget>
+       </item>
+       <item row="7" column="0">
+        <widget class="QLabel" name="label_11">
+         <property name="font">
+          <font>
+           <weight>75</weight>
+           <bold>true</bold>
+          </font>
+         </property>
+         <property name="text">
+          <string>Network</string>
+         </property>
+        </widget>
+       </item>
+       <item row="6" column="2">
+        <widget class="QLabel" name="startupTime">
          <property name="cursor">
           <cursorShape>IBeamCursor</cursorShape>
          </property>
          </property>
         </widget>
        </item>
-       <item row="6" column="1">
-        <widget class="QLabel" name="startupTime">
+       <item row="9" column="0">
+        <widget class="QLabel" name="label_8">
+         <property name="text">
+          <string>On testnet</string>
+         </property>
+        </widget>
+       </item>
+       <item row="8" column="2">
+        <widget class="QLabel" name="numberOfConnections">
          <property name="cursor">
           <cursorShape>IBeamCursor</cursorShape>
          </property>
          </property>
         </widget>
        </item>
-       <item row="7" column="0">
-        <widget class="QLabel" name="label_11">
+       <item row="8" column="0">
+        <widget class="QLabel" name="label_7">
+         <property name="text">
+          <string>Number of connections</string>
+         </property>
+        </widget>
+       </item>
+       <item row="10" column="0">
+        <widget class="QLabel" name="label_10">
          <property name="font">
           <font>
            <weight>75</weight>
           </font>
          </property>
          <property name="text">
-          <string>Network</string>
+          <string>Block chain</string>
          </property>
         </widget>
        </item>
-       <item row="8" column="0">
-        <widget class="QLabel" name="label_7">
+       <item row="9" column="2">
+        <widget class="QCheckBox" name="isTestNet">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
          <property name="text">
-          <string>Number of connections</string>
+          <string/>
          </property>
         </widget>
        </item>
-       <item row="8" column="1">
-        <widget class="QLabel" name="numberOfConnections">
+       <item row="12" column="0">
+        <widget class="QLabel" name="label_4">
+         <property name="text">
+          <string>Estimated total blocks</string>
+         </property>
+        </widget>
+       </item>
+       <item row="12" column="2">
+        <widget class="QLabel" name="totalBlocks">
          <property name="cursor">
           <cursorShape>IBeamCursor</cursorShape>
          </property>
          </property>
         </widget>
        </item>
-       <item row="9" column="0">
-        <widget class="QLabel" name="label_8">
+       <item row="2" column="2">
+        <widget class="QLabel" name="clientVersion">
+         <property name="cursor">
+          <cursorShape>IBeamCursor</cursorShape>
+         </property>
          <property name="text">
-          <string>On testnet</string>
+          <string>N/A</string>
          </property>
-        </widget>
-       </item>
-       <item row="9" column="1">
-        <widget class="QCheckBox" name="isTestNet">
-         <property name="enabled">
-          <bool>false</bool>
+         <property name="textFormat">
+          <enum>Qt::PlainText</enum>
          </property>
-         <property name="text">
-          <string/>
+         <property name="textInteractionFlags">
+          <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
          </property>
         </widget>
        </item>
-       <item row="10" column="0">
-        <widget class="QLabel" name="label_10">
-         <property name="font">
-          <font>
-           <weight>75</weight>
-           <bold>true</bold>
-          </font>
-         </property>
+       <item row="4" column="0">
+        <widget class="QLabel" name="label_berkeleyDBVersion">
          <property name="text">
-          <string>Block chain</string>
+          <string>Using BerkeleyDB version</string>
+         </property>
+         <property name="indent">
+          <number>10</number>
          </property>
         </widget>
        </item>
-       <item row="11" column="0">
-        <widget class="QLabel" name="label_3">
+       <item row="3" column="0">
+        <widget class="QLabel" name="label_14">
          <property name="text">
-          <string>Current number of blocks</string>
+          <string>Using OpenSSL version</string>
+         </property>
+         <property name="indent">
+          <number>10</number>
          </property>
         </widget>
        </item>
-       <item row="11" column="1">
-        <widget class="QLabel" name="numberOfBlocks">
+       <item row="3" column="2">
+        <widget class="QLabel" name="openSSLVersion">
          <property name="cursor">
           <cursorShape>IBeamCursor</cursorShape>
          </property>
          </property>
         </widget>
        </item>
-       <item row="12" column="0">
-        <widget class="QLabel" name="label_4">
-         <property name="text">
-          <string>Estimated total blocks</string>
-         </property>
-        </widget>
-       </item>
-       <item row="12" column="1">
-        <widget class="QLabel" name="totalBlocks">
+       <item row="4" column="2">
+        <widget class="QLabel" name="berkeleyDBVersion">
          <property name="cursor">
           <cursorShape>IBeamCursor</cursorShape>
          </property>
          </property>
         </widget>
        </item>
-       <item row="13" column="0">
-        <widget class="QLabel" name="label_2">
+       <item row="5" column="0">
+        <widget class="QLabel" name="label_12">
          <property name="text">
-          <string>Last block time</string>
+          <string>Build date</string>
          </property>
         </widget>
        </item>
-       <item row="13" column="1">
-        <widget class="QLabel" name="lastBlockTime">
+       <item row="5" column="2">
+        <widget class="QLabel" name="buildDate">
          <property name="cursor">
           <cursorShape>IBeamCursor</cursorShape>
          </property>
          </property>
         </widget>
        </item>
-       <item row="14" column="0">
-        <spacer name="verticalSpacer_2">
-         <property name="orientation">
-          <enum>Qt::Vertical</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>20</width>
-           <height>20</height>
-          </size>
+       <item row="2" column="0">
+        <widget class="QLabel" name="label_6">
+         <property name="text">
+          <string>Client version</string>
          </property>
-        </spacer>
+        </widget>
        </item>
-       <item row="15" column="0">
-        <widget class="QLabel" name="labelDebugLogfile">
+       <item row="0" column="0">
+        <widget class="QLabel" name="label_9">
          <property name="font">
           <font>
            <weight>75</weight>
           </font>
          </property>
          <property name="text">
-          <string>Debug log file</string>
+          <string>NovaCoin Core</string>
          </property>
         </widget>
        </item>
-       <item row="16" column="0">
-        <widget class="QPushButton" name="openDebugLogfileButton">
-         <property name="toolTip">
-          <string>Open the NovaCoin debug log file from the current data directory. This can take a few seconds for large log files.</string>
+       <item row="1" column="2">
+        <widget class="QLabel" name="clientName">
+         <property name="cursor">
+          <cursorShape>IBeamCursor</cursorShape>
          </property>
          <property name="text">
-          <string>&amp;Open</string>
-         </property>
-         <property name="autoDefault">
-          <bool>false</bool>
+          <string>N/A</string>
          </property>
-        </widget>
-       </item>
-       <item row="17" column="0">
-        <widget class="QLabel" name="labelCLOptions">
-         <property name="font">
-          <font>
-           <weight>75</weight>
-           <bold>true</bold>
-          </font>
+         <property name="textFormat">
+          <enum>Qt::PlainText</enum>
          </property>
-         <property name="text">
-          <string>Command-line options</string>
+         <property name="textInteractionFlags">
+          <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
          </property>
         </widget>
        </item>
-       <item row="18" column="0">
-        <widget class="QPushButton" name="showCLOptionsButton">
-         <property name="toolTip">
-          <string>Show the NovaCoin-Qt help message to get a list with possible NovaCoin command-line options.</string>
-         </property>
+       <item row="1" column="0">
+        <widget class="QLabel" name="label_5">
          <property name="text">
-          <string>&amp;Show</string>
-         </property>
-         <property name="autoDefault">
-          <bool>false</bool>
+          <string>Client name</string>
          </property>
         </widget>
        </item>
-       <item row="19" column="0">
-        <spacer name="verticalSpacer">
+       <item row="14" column="2">
+        <spacer name="verticalSpacer_2">
          <property name="orientation">
           <enum>Qt::Vertical</enum>
          </property>
          <property name="sizeHint" stdset="0">
           <size>
            <width>20</width>
-           <height>40</height>
+           <height>20</height>
           </size>
          </property>
         </spacer>
        </item>
+       <item row="16" column="2">
+        <widget class="QPushButton" name="openConfigurationfileButton">
+         <property name="toolTip">
+          <string>Open the NovaCoin configuration file from the current data directory.</string>
+         </property>
+         <property name="text">
+          <string>O&amp;pen</string>
+         </property>
+         <property name="autoDefault">
+          <bool>false</bool>
+         </property>
+        </widget>
+       </item>
       </layout>
      </widget>
      <widget class="QWidget" name="tab_console">
index c244c2d..6fdc5c9 100644 (file)
@@ -265,6 +265,15 @@ void openDebugLogfile()
         QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(pathDebug.string())));
 }
 
+void openConfigfile()
+{
+    boost::filesystem::path pathConfig = GetConfigFile();
+
+    /* Open novacoin.conf with the associated application */
+    if (boost::filesystem::exists(pathConfig))
+        QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(pathConfig.string())));
+}
+
 ToolTipToRichTextFilter::ToolTipToRichTextFilter(int size_threshold, QObject *parent) :
     QObject(parent), size_threshold(size_threshold)
 {
index 1ff4aba..fd72668 100644 (file)
@@ -73,7 +73,8 @@ namespace GUIUtil
 
     // Open debug.log
     void openDebugLogfile();
-
+    // Open novacoin.conf
+    void openConfigfile();
     /** Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text
       representation if needed. This assures that Qt can word-wrap long tooltip messages.
       Tooltips longer than the provided size threshold (in characters) are wrapped.
index 2c25060..fdf4d09 100644 (file)
@@ -2237,6 +2237,10 @@ This label turns red, if the priority is smaller than &quot;medium&quot;.
         <translation>&amp;Открыть</translation>
     </message>
     <message>
+        <source>O&amp;pen</source>
+        <translation>О&amp;ткрыть</translation>
+    </message>
+    <message>
         <location line="+16"/>
         <source>Command-line options</source>
         <translation>Параметры командной строки</translation>
@@ -2277,11 +2281,19 @@ This label turns red, if the priority is smaller than &quot;medium&quot;.
         <translation>Отладочный лог-файл</translation>
     </message>
     <message>
+        <source>Configuration file</source>
+        <translation>Конфигурационный файл</translation>
+    </message>
+    <message>
         <location line="+7"/>
         <source>Open the NovaCoin debug log file from the current data directory. This can take a few seconds for large log files.</source>
         <translation>Открыть отладочный лог-файл NovaCoin из текущего каталога данных. Это может занять несколько секунд для больших лог-файлов.</translation>
     </message>
     <message>
+        <source>Open the NovaCoin configuration file from the current data directory.</source>
+        <translation>Открыть конфигурационный файл NovaCoin из текущего каталога данных.</translation>
+    </message>
+    <message>
         <location line="+102"/>
         <source>Clear console</source>
         <translation>Очистить консоль</translation>
index 0b9e4a5..b61cecf 100644 (file)
@@ -198,6 +198,7 @@ RPCConsole::RPCConsole(QWidget *parent) :
 
 #ifndef Q_OS_MAC
     ui->openDebugLogfileButton->setIcon(QIcon(":/icons/export"));
+    ui->openConfigurationfileButton->setIcon(QIcon(":/icons/export"));
     ui->showCLOptionsButton->setIcon(QIcon(":/icons/options"));
 #endif
 
@@ -441,6 +442,11 @@ void RPCConsole::on_openDebugLogfileButton_clicked()
     GUIUtil::openDebugLogfile();
 }
 
+void RPCConsole::on_openConfigurationfileButton_clicked()
+{
+    GUIUtil::openConfigfile();
+}
+
 void RPCConsole::scrollToEnd()
 {
     QScrollBar *scrollbar = ui->messagesWidget->verticalScrollBar();
index b523f0f..aa8c8f3 100644 (file)
@@ -36,6 +36,8 @@ private slots:
     void on_tabWidget_currentChanged(int index);
     /** open the debug.log from the current datadir */
     void on_openDebugLogfileButton_clicked();
+    /** open the novacoin.conf from the current datadir */
+    void on_openConfigurationfileButton_clicked();
     /** change the time range of the network traffic graph */
     void on_sldGraphRange_valueChanged(int value);
     /** update traffic statistics */
index 197e562..a15fa67 100644 (file)
@@ -1142,6 +1142,33 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific)
     return path;
 }
 
+string randomStrGen(int length) {
+    static string charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
+    string result;
+    result.resize(length);
+    for (int32_t i = 0; i < length; i++)
+        result[i] = charset[rand() % charset.length()];
+
+    return result;
+}
+
+void createConf()
+{
+    srand(time(NULL));
+
+    ofstream pConf;
+    pConf.open(GetConfigFile().generic_string().c_str());
+    pConf << "rpcuser=user\nrpcpassword="
+            + randomStrGen(15)
+            + "\nrpcport=8344"
+            + "\nport=7777"
+            + "\ndaemon=0 #(0=off, 1=on) Run in the background as a daemon and accept commands"
+            + "\nserver=0 #(0=off, 1=on) Accept command line and JSON-RPC commands"
+            + "\nrpcallowip=127.0.0.1"
+            + "\ntestnet=0";
+    pConf.close();
+}
+
 boost::filesystem::path GetConfigFile()
 {
     boost::filesystem::path pathConfigFile(GetArg("-conf", "novacoin.conf"));
@@ -1154,7 +1181,12 @@ void ReadConfigFile(map<string, string>& mapSettingsRet,
 {
     boost::filesystem::ifstream streamConfig(GetConfigFile());
     if (!streamConfig.good())
-        return; // No bitcoin.conf file is OK
+    {
+        createConf();
+        new(&streamConfig) boost::filesystem::ifstream(GetConfigFile());
+        if(!streamConfig.good())
+            return;
+    }
 
     set<string> setOptions;
     setOptions.insert("*");