~ubuntu-branches/ubuntu/wily/kid3/wily-proposed

« back to all changes in this revision

Viewing changes to src/core/model/kid3application.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2012-05-14 18:27:44 UTC
  • mfrom: (1.1.14) (2.1.16 sid)
  • Revision ID: package-import@ubuntu.com-20120514182744-4tul4661q4rao8vm
Tags: 2.1-2
Remove patch 01-gcc4.7-ftbfs, it was merged with 2.1 to another location.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <QTextCodec>
31
31
#include <QUrl>
32
32
#include <QTextStream>
 
33
#include <QNetworkAccessManager>
33
34
#ifdef CONFIG_USE_KDE
34
35
#include <kapplication.h>
35
36
#else
37
38
#endif
38
39
#ifdef HAVE_QTDBUS
39
40
#include <QDBusConnection>
 
41
#include <unistd.h>
40
42
#include "scriptinterface.h"
41
43
#endif
42
44
#include "fileproxymodel.h"
59
61
#include "discogsimporter.h"
60
62
#include "amazonimporter.h"
61
63
#include "qtcompatmac.h"
 
64
#ifdef HAVE_CHROMAPRINT
 
65
#include "musicbrainzclient.h"
 
66
#endif
62
67
#ifdef HAVE_PHONON
63
68
#include "audioplayer.h"
64
69
#endif
97
102
  m_framesV2SelectionModel(new QItemSelectionModel(m_framesV2Model, this)),
98
103
  m_framelist(new FrameList(m_framesV2Model, m_framesV2SelectionModel)),
99
104
  m_configStore(new ConfigStore),
100
 
  m_downloadClient(new DownloadClient(this)),
 
105
  m_netMgr(new QNetworkAccessManager(this)),
 
106
  m_downloadClient(new DownloadClient(m_netMgr)),
101
107
  m_textExporter(new TextExporter(this)),
102
108
  m_dirRenamer(new DirRenamer(this)),
103
109
#ifdef HAVE_PHONON
104
110
  m_player(0),
105
111
#endif
106
 
  m_downloadImageDest(ImageForSelectedFiles)
 
112
  m_downloadImageDest(ImageForSelectedFiles),
 
113
  m_musicBrainzClient(0)
107
114
{
108
115
  setObjectName("Kid3Application");
109
116
  m_fileProxyModel->setSourceModel(m_fileSystemModel);
119
126
  ConfigStore::s_fnFormatCfg.setAsFilenameFormatter();
120
127
 
121
128
  m_importers
122
 
      << new FreedbImporter(this, m_trackDataModel)
123
 
      << new TrackTypeImporter(this, m_trackDataModel)
124
 
      << new DiscogsImporter(this, m_trackDataModel)
125
 
      << new AmazonImporter(this, m_trackDataModel)
126
 
      << new MusicBrainzReleaseImporter(this, m_trackDataModel);
 
129
      << new FreedbImporter(m_netMgr, m_trackDataModel)
 
130
      << new TrackTypeImporter(m_netMgr, m_trackDataModel)
 
131
      << new DiscogsImporter(m_netMgr, m_trackDataModel)
 
132
      << new AmazonImporter(m_netMgr, m_trackDataModel)
 
133
      << new MusicBrainzReleaseImporter(m_netMgr, m_trackDataModel);
 
134
#ifdef HAVE_CHROMAPRINT
 
135
  m_musicBrainzClient = new MusicBrainzClient(m_netMgr, m_trackDataModel);
 
136
#endif
127
137
 
128
138
#ifdef HAVE_QTDBUS
129
139
  if (QDBusConnection::sessionBus().isConnected()) {
214
224
{
215
225
  m_configStore->readFromConfig();
216
226
  if (ConfigStore::s_miscCfg.m_nameFilter.isEmpty()) {
217
 
    createFilterString(&ConfigStore::s_miscCfg.m_nameFilter);
 
227
    ConfigStore::s_miscCfg.m_nameFilter = createFilterString();
218
228
  }
219
229
  setTextEncodings();
220
230
  if (ConfigStore::s_freedbCfg.m_server == "freedb2.org:80") {
251
261
    dir = QDir(dir).absolutePath();
252
262
  }
253
263
 
254
 
  QStringList nameFilters(ConfigStore::s_miscCfg.m_nameFilter.split(' '));
 
264
  QStringList nameFilters(ConfigStore::s_miscCfg.getNameFilterPatterns().
 
265
                          split(' '));
255
266
  m_fileProxyModel->setNameFilters(nameFilters);
256
267
  m_fileSystemModel->setFilter(QDir::AllEntries | QDir::AllDirs);
257
268
  QModelIndex rootIndex = m_fileSystemModel->setRootPath(dir);
1737
1748
  return imgurl;
1738
1749
}
1739
1750
 
1740
 
#ifndef WIN32
1741
 
/**
1742
 
 * Get all combinations with lower- and uppercase characters.
1743
 
 *
1744
 
 * @param str original string
1745
 
 *
1746
 
 * @return string with all combinations, separated by spaces.
1747
 
 */
1748
 
static QString lowerUpperCaseCombinations(const QString& str)
1749
 
{
1750
 
  QString result;
1751
 
  QString lc(str.toLower());
1752
 
  QString uc(str.toUpper());
1753
 
 
1754
 
  // get a mask of all alphabetic characters in the string
1755
 
  unsigned char numChars = 0, charMask = 0, posMask = 1;
1756
 
  int numPos = lc.length();
1757
 
  if (numPos > 8) numPos = 8;
1758
 
  for (int pos = 0; pos < numPos; ++pos, posMask <<= 1) {
1759
 
    if (lc[pos] >= 'a' && lc[pos] <= 'z') {
1760
 
      charMask |= posMask;
1761
 
      ++numChars;
1762
 
    }
1763
 
  }
1764
 
 
1765
 
  int numCombinations = 1 << numChars;
1766
 
  for (int comb = 0; comb < numCombinations; ++comb) {
1767
 
    posMask = 1;
1768
 
    int combMask = 1;
1769
 
    if (!result.isEmpty()) {
1770
 
      result += ' ';
1771
 
    }
1772
 
    for (int pos = 0; pos < numPos; ++pos, posMask <<= 1) {
1773
 
      if (charMask & posMask) {
1774
 
        if (comb & combMask) {
1775
 
          result += uc[pos];
1776
 
        } else {
1777
 
          result += lc[pos];
1778
 
        }
1779
 
        combMask <<= 1;
1780
 
      } else {
1781
 
        result += lc[pos];
1782
 
      }
1783
 
    }
1784
 
  }
1785
 
 
1786
 
  return result;
1787
 
}
1788
 
#endif
1789
 
 
1790
1751
/**
1791
1752
 * Create a filter string for the file dialog.
1792
1753
 * The filter string contains entries for all supported types.
1793
1754
 *
1794
 
 * @param defaultNameFilter if not 0, return default name filter here
1795
 
 *
1796
1755
 * @return filter string.
1797
1756
 */
1798
 
QString Kid3Application::createFilterString(QString* defaultNameFilter) const
 
1757
QString Kid3Application::createFilterString() const
1799
1758
{
1800
1759
  QStringList extensions = TaggedFile::getSupportedFileExtensions();
1801
 
  QString result, allCombinations;
 
1760
  QString result, allPatterns;
1802
1761
  for (QStringList::const_iterator it = extensions.begin();
1803
1762
       it != extensions.end();
1804
1763
       ++it) {
1805
1764
    QString text = (*it).mid(1).toUpper();
1806
 
    QString lowerExt = '*' + *it;
1807
 
#ifdef WIN32
1808
 
    const QString& combinations = lowerExt;
1809
 
#else
1810
 
    QString combinations = lowerUpperCaseCombinations(lowerExt);
1811
 
#endif
1812
 
    if (!allCombinations.isEmpty()) {
1813
 
      allCombinations += ' ';
 
1765
    QString pattern = '*' + *it;
 
1766
    if (!allPatterns.isEmpty()) {
 
1767
      allPatterns += ' ';
1814
1768
    }
1815
 
    allCombinations += combinations;
 
1769
    allPatterns += pattern;
1816
1770
#ifdef CONFIG_USE_KDE
1817
 
    result += combinations;
 
1771
    result += pattern;
1818
1772
    result += '|';
1819
1773
    result += text;
1820
1774
    result += " (";
1821
 
    result += lowerExt;
 
1775
    result += pattern;
1822
1776
    result += ")\n";
1823
1777
#else
1824
1778
    result += text;
1825
1779
    result += " (";
1826
 
    result += combinations;
 
1780
    result += pattern;
1827
1781
    result += ");;";
1828
1782
#endif
1829
1783
  }
1830
1784
 
1831
1785
#ifdef CONFIG_USE_KDE
1832
 
  QString allExt = allCombinations;
 
1786
  QString allExt = allPatterns;
1833
1787
  allExt += '|';
1834
1788
  allExt += i18n("All Supported Files");
1835
1789
  allExt += '\n';
1837
1791
#else
1838
1792
  QString allExt = i18n("All Supported Files");
1839
1793
  allExt += " (";
1840
 
  allExt += allCombinations;
 
1794
  allExt += allPatterns;
1841
1795
  allExt += ");;";
1842
1796
  result = allExt + result + i18n("All Files (*)");
1843
1797
#endif
1844
1798
 
1845
 
  if (defaultNameFilter) {
1846
 
    *defaultNameFilter = allCombinations;
1847
 
  }
1848
 
 
1849
1799
  return result;
1850
1800
}
1851
1801