fb2utils.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "fb2utils.h"
  2. #include <QApplication>
  3. #include <QDir>
  4. #include <QFile>
  5. #include <QFileInfo>
  6. #include <QTextStream>
  7. static QIcon loadIcon(const QString &name)
  8. {
  9. QIcon icon;
  10. icon.addFile(QString(":/24x24/%1.png").arg(name), QSize(24,24));
  11. icon.addFile(QString(":/16x16/%1.png").arg(name), QSize(16,16));
  12. return icon;
  13. }
  14. FbIcon::FbIcon(const QString &name)
  15. : QIcon(fromTheme(name, loadIcon(name)))
  16. {
  17. }
  18. QString jScript(const QString &filename)
  19. {
  20. #ifdef QT_DEBUG
  21. QString filepath = qApp->arguments().first();
  22. #ifdef Q_OS_WIN
  23. filepath += "/..";
  24. #endif
  25. filepath += "/../../fb2edit/source/js/";
  26. filepath += filename;
  27. filepath = QDir::cleanPath(filepath);
  28. #else
  29. QString filepath = ":/js/";
  30. filepath += filename;
  31. #endif // QT_DEBUG
  32. // TODO: throw an exception instead of
  33. // returning an empty string
  34. QFile file( filepath );
  35. if (!file.open(QFile::ReadOnly)) return QString();
  36. QTextStream in( &file );
  37. // Input should be UTF-8
  38. in.setCodec( "UTF-8" );
  39. // This will automatically switch reading from
  40. // UTF-8 to UTF-16 if a BOM is detected
  41. in.setAutoDetectUnicode( true );
  42. return in.readAll();
  43. }