fb2utils.cpp 838 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "fb2utils.h"
  2. #include <QFile>
  3. #include <QTextStream>
  4. static QIcon loadIcon(const QString &name)
  5. {
  6. QIcon icon;
  7. icon.addFile(QString(":/24x24/%1.png").arg(name), QSize(24,24));
  8. icon.addFile(QString(":/16x24/%1.png").arg(name), QSize(16,16));
  9. return icon;
  10. }
  11. FbIcon::FbIcon(const QString &name)
  12. : QIcon(fromTheme(name, loadIcon(name)))
  13. {
  14. }
  15. namespace FB2 {
  16. QString read(const QString &filename)
  17. {
  18. // TODO: throw an exception instead of
  19. // returning an empty string
  20. QFile file( filename );
  21. if (!file.open( QFile::ReadOnly)) return QString();
  22. QTextStream in( &file );
  23. // Input should be UTF-8
  24. in.setCodec( "UTF-8" );
  25. // This will automatically switch reading from
  26. // UTF-8 to UTF-16 if a BOM is detected
  27. in.setAutoDetectUnicode( true );
  28. return in.readAll();
  29. }
  30. }