changeset 112:4bd17f36d059

* Make diff binary a settings property; some tidying
author Chris Cannam
date Fri, 26 Nov 2010 17:02:55 +0000
parents 151209bc5bd6
children 5fc7b4fc77a8
files common.cpp easyhg.pro grapher.cpp mainwindow.cpp mainwindow.h settingsdialog.cpp settingsdialog.h
diffstat 7 files changed, 54 insertions(+), 314 deletions(-) [+]
line wrap: on
line diff
--- a/common.cpp	Fri Nov 26 16:28:18 2010 +0000
+++ b/common.cpp	Fri Nov 26 17:02:55 2010 +0000
@@ -81,35 +81,6 @@
 #endif
     return name;
 }
-    
-QString getSystem()
-{
-    #ifdef Q_WS_X11
-    return QString("Linux");
-    #endif
-
-    #ifdef Q_WS_MAC
-    return QString("Mac");
-    #endif
-
-    #ifdef Q_WS_WIN
-    return QString("Windows");
-    #endif
-
-    return QString("");
-}
-
-QString getHgDirName()
-{
-    if (getSystem() == "Windows")
-    {
-        return QString(".hg\\");
-    }
-    else
-    {
-        return QString(".hg/");
-    }
-}
 
 #ifdef Q_OS_WIN32
 QString getUserRealName()
--- a/easyhg.pro	Fri Nov 26 16:28:18 2010 +0000
+++ b/easyhg.pro	Fri Nov 26 17:02:55 2010 +0000
@@ -15,7 +15,6 @@
     common.h \
     grapher.h \
     hgrunner.h \
-    settingsdialog.h \
     changeset.h \
     changesetitem.h \
     logparser.h \
@@ -40,7 +39,6 @@
     hgtabwidget.cpp \
     hgrunner.cpp \
     grapher.cpp \
-    settingsdialog.cpp \
     common.cpp \
     changeset.cpp \
     changesetitem.cpp \
--- a/grapher.cpp	Fri Nov 26 16:28:18 2010 +0000
+++ b/grapher.cpp	Fri Nov 26 17:02:55 2010 +0000
@@ -123,7 +123,7 @@
     }
 
     Changeset *cs = m_changesets[id];
-    std::cerr << "layoutCol: Looking at " << id.toStdString() << std::endl;
+//    std::cerr << "layoutCol: Looking at " << id.toStdString() << std::endl;
 
     ChangesetItem *item = m_items[id];
 
@@ -180,7 +180,7 @@
         break;
     }
 
-    std::cerr << "putting " << cs->id().toStdString() << " at col " << col << std::endl;
+//    std::cerr << "putting " << cs->id().toStdString() << " at col " << col << std::endl;
 
     m_alloc[row].insert(col);
     item->setColumn(col);
--- a/mainwindow.cpp	Fri Nov 26 16:28:18 2010 +0000
+++ b/mainwindow.cpp	Fri Nov 26 17:02:55 2010 +0000
@@ -31,7 +31,6 @@
 #include <QInputDialog>
 
 #include "mainwindow.h"
-#include "settingsdialog.h"
 #include "multichoicedialog.h"
 #include "startupdialog.h"
 #include "colourset.h"
@@ -81,6 +80,8 @@
         startupDialog();
     }
 
+    findDiffBinaryName();
+
     ColourSet *cs = ColourSet::instance();
     cs->clearDefaultNames();
     cs->addDefaultName("");
@@ -285,8 +286,8 @@
     if (ConfirmCommentDialog::confirmAndGetLongComment
         (this,
          tr("Commit files"),
-         tr("<h2>Commit files</h2><p>About to commit the following files:"),
-         tr("<h2>Commit files</h2><p>About to commit %1 files."),
+         tr("<h3>Commit files</h3><p>You are about to commit the following files:"),
+         tr("<h3>Commit files</h3><p>You are about to commit %1 files."),
          files,
          comment)) {
 
@@ -350,15 +351,17 @@
     hgIgnorePath += ".hgignore";
     
     params << hgIgnorePath;
-    
-    if ((getSystem() == "Linux"))
-    {
+
+//!!!    
+#ifdef Q_OS_LINUX
+
         editorName = "gedit";
-    }
-    else
-    {
+
+#else
+
         editorName = """C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe""";
-    }
+
+#endif
 
     HgAction action(ACT_HG_IGNORE, workFolderPath, params);
     action.executable = editorName;
@@ -366,7 +369,29 @@
     runner->requestAction(action);
 }
 
-
+void MainWindow::findDiffBinaryName()
+{
+    QSettings settings;
+    QString diff = settings.value("extdiffbinary", "").toString();
+    if (diff == "") {
+        QStringList bases;
+        bases << "opendiff" << "kompare" << "kdiff3" << "meld";
+        bool found = false;
+        foreach (QString base, bases) {
+            diff = findExecutable(base);
+            if (diff != base) {
+                found = true;
+                break;
+            }
+        }
+        if (found) {
+            settings.setValue("extdiffbinary", diff);
+        } else {
+            diff = "";
+        }
+    }
+    diffBinaryName = diff;
+}
 
 void MainWindow::hgFileDiff()
 {
@@ -387,14 +412,15 @@
 
 void MainWindow::hgFolderDiff()
 {
+    if (diffBinaryName == "") return;
+
     QStringList params;
 
-    //Diff parent against working folder (folder diff)
+    // Diff parent against working folder (folder diff)
+
     params << "--config" << "extensions.extdiff=" << "extdiff" << "-p";
+    params << diffBinaryName;
 
-    params << "kompare";
-
-//    params << "kdiff3";
     runner->requestAction(HgAction(ACT_FOLDERDIFF, workFolderPath, params));
 }
 
@@ -465,8 +491,8 @@
     if (ConfirmCommentDialog::confirmDangerousFilesAction
         (this,
          tr("Revert files"),
-         tr("<h2>Revert files</h2><p>About to revert the following files to their previous committed state.  This will <b>throw away any changes</b> that you have made to these files but have not committed."),
-         tr("<h2>Revert files</h2><p>About to revert %1 files.  This will <b>throw away any changes</b> that you have made to these files but have not committed."),
+         tr("<h3>Revert files</h3><p>You are about to <b>revert</b> the following files to their previous committed state.<br><br>This will <b>throw away any changes</b> that you have made to these files but have not committed."),
+         tr("<h3>Revert files</h3><p>You are about to <b>revert</b> %1 files.<br><br>This will <b>throw away any changes</b> that you have made to these files but have not committed."),
          files)) {
         
         if (files.empty()) {
@@ -1217,7 +1243,7 @@
         workFolderExist = true;
     }
 
-    if (!localRepoDir.exists(workFolderPath + "/" + getHgDirName())) {
+    if (!localRepoDir.exists(workFolderPath + "/.hg")) {
         localRepoActionsEnabled = false;
         localRepoExist = false;
     }
@@ -1232,10 +1258,12 @@
         localRepoActionsEnabled = false;
     }
 */
+    bool haveDiff = (diffBinaryName != "");
+
     hgInitAct -> setEnabled((localRepoExist == false) && (workFolderExist==true));
     hgStatAct -> setEnabled(localRepoActionsEnabled);
-    hgFileDiffAct -> setEnabled(localRepoActionsEnabled);
-    hgFolderDiffAct -> setEnabled(localRepoActionsEnabled);
+    hgFileDiffAct -> setEnabled(localRepoActionsEnabled && haveDiff);
+    hgFolderDiffAct -> setEnabled(localRepoActionsEnabled && haveDiff);
     hgRevertAct -> setEnabled(localRepoActionsEnabled);
     hgAddAct -> setEnabled(localRepoActionsEnabled);
     hgRemoveAct -> setEnabled(localRepoActionsEnabled);
--- a/mainwindow.h	Fri Nov 26 16:28:18 2010 +0000
+++ b/mainwindow.h	Fri Nov 26 17:02:55 2010 +0000
@@ -56,7 +56,6 @@
 public slots:
     void hgQueryPaths();
     void hgStat();
-//    void tabChanged(int currTab);
     void commandCompleted(HgAction action, QString stdout);
     void commandFailed(HgAction action, QString stdout);
     void enableDisableActions();
@@ -186,11 +185,12 @@
 
     HgRunner *runner;
 
+    void findDiffBinaryName();
+    QString diffBinaryName;
+
     QFileSystemWatcher *fsWatcher;
 
-//    int             tabPage;
-//    unsigned char   initialFileTypesBits;
-    bool            justMerged;
+    bool justMerged;
 };
 
 #endif
--- a/settingsdialog.cpp	Fri Nov 26 16:28:18 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,192 +0,0 @@
-/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
-
-/*
-    EasyMercurial
-
-    Based on HgExplorer by Jari Korhonen
-    Copyright (c) 2010 Jari Korhonen
-    Copyright (c) 2010 Chris Cannam
-    Copyright (c) 2010 Queen Mary, University of London
-    
-    This program is free software; you can redistribute it and/or
-    modify it under the terms of the GNU General Public License as
-    published by the Free Software Foundation; either version 2 of the
-    License, or (at your option) any later version.  See the file
-    COPYING included with this distribution for more information.
-*/
-
-#include "settingsdialog.h"
-
-#include <QHBoxLayout>
-#include <QVBoxLayout>
-#include <QDir>
-#include <QMessageBox>
-#include <QFileDialog>
-
-SettingsDialog::SettingsDialog(QWidget *parent): QDialog(parent)
-{
-    QPushButton *okButton;
-    QPushButton *cancelButton;
-
-    mainWnd = (MainWindow *) parent;
-
-    userInfoLabel = new QLabel(tr("User info for commits, e.g. John Smith <john.smith@mail.com>"));
-    userInfoLineEdit = new QLineEdit("");//!!!mainWnd->userInfo);
-    userInfoLabel -> setBuddy(userInfoLineEdit);
-
-    remoteRepoLabel = new QLabel(tr("Remote repository path, e.g. http://192.168.1.10:8000/ or /home/mike/anotherrepo/ or c:\\anotherrepo\\"));
-    remoteRepoCombo = new QComboBox();
-    remoteRepoCombo -> insertItem(0, mainWnd->remoteRepoPath);
-/*!!!    for(int i = 0; i < NUM_PATHS_IN_MRU_LIST; i++)
-    {
-        remoteRepoCombo -> insertItem(i + 1, mainWnd -> remoteRepoMruList[i]);
-    }
-*/
-    remoteRepoCombo -> setEditable(true);
-    remoteRepoLabel -> setBuddy(remoteRepoCombo);
-    remoteRepoBrowseButton = new QPushButton(tr("Browse..."));
-
-    workFolderLabel = new QLabel(tr("Local work folder path, e.g. /home/mike/work/ or c:\\mike\\work\\"));
-    workFolderCombo = new QComboBox();
-    workFolderCombo -> insertItem(0, mainWnd -> workFolderPath);
-/*!!!    for(int i = 0; i < NUM_PATHS_IN_MRU_LIST; i++)
-    {
-        workFolderCombo -> insertItem(i + 1, mainWnd -> workFolderMruList[i]);
-    }
-*/
-    workFolderCombo -> setEditable(true);
-    workFolderLabel -> setBuddy(workFolderCombo);
-    workFolderBrowseButton = new QPushButton(tr("Browse..."));
-
-    okButton = new QPushButton(tr("Ok"));
-    cancelButton = new QPushButton(tr("Cancel"));
-
-    QHBoxLayout *btnLayout = new QHBoxLayout;
-    btnLayout -> addWidget(okButton);
-    btnLayout -> addWidget(cancelButton);
-    btnLayout -> addStretch();
-
-    QHBoxLayout *workFolderLayout = new QHBoxLayout;
-    workFolderLayout -> addWidget(workFolderCombo, 3);
-    workFolderLayout -> addWidget(workFolderBrowseButton, 1);
-
-    QHBoxLayout *remoteRepoLayout = new QHBoxLayout;
-    remoteRepoLayout -> addWidget(remoteRepoCombo, 3);
-    remoteRepoLayout -> addWidget(remoteRepoBrowseButton, 1);
-
-    QVBoxLayout *mainLayout = new QVBoxLayout;
-
-    mainLayout -> addWidget(userInfoLabel);
-    mainLayout -> addWidget(userInfoLineEdit);
-
-    mainLayout -> addWidget(remoteRepoLabel);
-    mainLayout -> addLayout(remoteRepoLayout);
-
-    mainLayout -> addWidget(workFolderLabel);
-    mainLayout -> addLayout(workFolderLayout);
-
-    mainLayout -> addLayout(btnLayout);
-
-    setLayout(mainLayout);
-
-    connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
-    connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
-    connect(workFolderBrowseButton, SIGNAL(clicked()), this, SLOT(browseWorkFolder()));
-    connect(remoteRepoBrowseButton, SIGNAL(clicked()), this, SLOT(browseRemoteRepo()));
-}
-
-#define EMPTY_DIR 2
-
-void SettingsDialog::okClicked()
-{
-    QString tmp;
-    
-//!!!    mainWnd -> firstStart = false;
-//!!!    mainWnd -> userInfo = userInfoLineEdit->text();
-
-    if (mainWnd -> remoteRepoPath  != remoteRepoCombo-> currentText())
-    {
-//!!!        insertPathToMruList(mainWnd -> remoteRepoPath, mainWnd -> remoteRepoMruList);
-        mainWnd -> remoteRepoPath = remoteRepoCombo-> currentText();
-    }
-
-    tmp = workFolderCombo -> currentText();
-    if (!tmp.endsWith(QDir::separator()))
-    {
-        tmp += QDir::separator();
-    }
-
-    if (mainWnd -> workFolderPath != tmp)
-    {
-//!!!        insertPathToMruList(mainWnd -> workFolderPath, mainWnd -> workFolderMruList);
-        mainWnd -> workFolderPath = tmp;
-    }
-
-    mainWnd -> writeSettings();
-    mainWnd -> enableDisableActions();
-    mainWnd -> hgStat();
-    mainWnd -> hgTabs -> setWorkFolderAndRepoNames(mainWnd -> workFolderPath, mainWnd -> remoteRepoPath);
-
-    QDir dir(mainWnd -> workFolderPath);
-    if (dir.exists(mainWnd -> workFolderPath))
-    {
-        uint cnt = dir.count();
-        if (cnt == EMPTY_DIR)
-        {
-            QMessageBox::information(this, tr("Todo"), tr("Your chosen workfolder is empty.\nChoose \"File/Clone from remote\"\nto download a remote repository.\nYou can also choose \"File/Init local repository\"\nto initialize repository and add files later."));
-        }
-        else
-        {
-            QString repoPath = mainWnd -> workFolderPath + getHgDirName();
-            QDir repoDir(repoPath);
-            if (!repoDir.exists())
-            {
-                QMessageBox::information(this, tr("Todo"), tr("Your chosen workfolder is not empty,\nbut does not yet contain a repository.\nChoose \"File/Init local repository\" \nto initialize repository."));
-            }
-        }
-    }
-
-
-    close();
-}
-
-
-void SettingsDialog::cancelClicked()
-{
-    close();
-}
-
-void SettingsDialog::browseDirAndSetCombo(QComboBox *combo)
-{
-    QString dir;
-    QString startDir;
-    QString system;
-
-    system = getSystem();
-    if ((system == "Linux") || (system == "Mac"))
-    {
-        startDir = QDir::homePath();
-    }
-    else
-    {
-        startDir = "c:\\";
-    }
-
-    dir =  QFileDialog::getExistingDirectory(this, tr("Open Directory"),
-        startDir,
-        QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
-
-    combo -> setItemText(0, dir + QDir::separator());
-}
-
-void SettingsDialog::browseWorkFolder()
-{
-    browseDirAndSetCombo(workFolderCombo);
-}
-
-void SettingsDialog::browseRemoteRepo()
-{
-    browseDirAndSetCombo(remoteRepoCombo);
-}
-
-
--- a/settingsdialog.h	Fri Nov 26 16:28:18 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
-
-/*
-    EasyMercurial
-
-    Based on HgExplorer by Jari Korhonen
-    Copyright (c) 2010 Jari Korhonen
-    Copyright (c) 2010 Chris Cannam
-    Copyright (c) 2010 Queen Mary, University of London
-    
-    This program is free software; you can redistribute it and/or
-    modify it under the terms of the GNU General Public License as
-    published by the Free Software Foundation; either version 2 of the
-    License, or (at your option) any later version.  See the file
-    COPYING included with this distribution for more information.
-*/
-
-#ifndef SETTINGSDIALOG_H
-#define SETTINGSDIALOG_H
-
-#include "mainwindow.h"
-
-#include <QDialog>
-#include <QLabel>
-#include <QLineEdit>
-#include <QComboBox>
-#include <QPushButton>
-
-class SettingsDialog : public QDialog
-{
-    Q_OBJECT
-
-public:
-    SettingsDialog(QWidget *parent = 0);
-
-private slots:
-    void okClicked();
-    void cancelClicked();
-    void browseWorkFolder();
-    void browseRemoteRepo();
-
-private:
-    QLabel      *userInfoLabel;
-    QLineEdit   *userInfoLineEdit;
-
-    QLabel      *remoteRepoLabel;
-    QComboBox   *remoteRepoCombo;
-    QPushButton *remoteRepoBrowseButton;
-    QHBoxLayout *remoteRepoLayout;
-
-    QLabel      *workFolderLabel;
-    QComboBox   *workFolderCombo;
-    QPushButton *workFolderBrowseButton;
-    QHBoxLayout *workFolderLayout;
-
-    QPushButton *okButton;
-    QPushButton *cancelButton;
-
-    MainWindow  *mainWnd;
-
-    void browseDirAndSetCombo(QComboBox *combo);
-};
-
-
-#endif // SETTINGSDIALOG_H