1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-23 17:29:42 +01:00

ifdefs--: split TomahawkUtils

This commit is contained in:
Dominik Schmidt 2011-11-20 22:34:34 +01:00
parent c63e56712e
commit d199fe5ff0
21 changed files with 40 additions and 336 deletions

View File

@ -108,6 +108,7 @@ set( libGuiSources
utils/stylehelper.cpp
utils/dropjobnotifier.cpp
utils/proxystyle.cpp
utils/tomahawkutilsgui.cpp
widgets/checkdirtree.cpp
widgets/querylabel.cpp
@ -225,6 +226,7 @@ set( libGuiHeaders
utils/rdioparser.h
utils/shortenedlinkparser.h
utils/dropjobnotifier.h
utils/tomahawkutilsgui.h
widgets/checkdirtree.h
widgets/querylabel.h

View File

@ -33,6 +33,7 @@
#include "playlist/treemodel.h"
#include "utils/stylehelper.h"
#include "utils/tomahawkutilsgui.h"
#define ANIMATION_TIME 450
#define SLIDE_TIME 350

View File

@ -33,7 +33,7 @@
#include "trackview.h"
#include "trackheader.h"
#include "utils/tomahawkutils.h"
#include "utils/tomahawkutilsgui.h"
#include "utils/logger.h"
#define PLAYING_ICON QString( RESPATH "images/now-playing-speaker.png" )

View File

@ -26,6 +26,7 @@
#include "widgets/overlaywidget.h"
#include "utils/logger.h"
#include "playlistview.h"
#include "utils/tomahawkutilsgui.h"
using namespace Tomahawk;

View File

@ -26,7 +26,7 @@
#include "query.h"
#include "result.h"
#include "utils/tomahawkutils.h"
#include "utils/tomahawkutilsgui.h"
#include "utils/logger.h"
#include "treemodelitem.h"

View File

@ -32,7 +32,7 @@
#include <QCoreApplication>
#include "utils/logger.h"
#include "utils/tomahawkutils.h"
#include "utils/tomahawkutilsgui.h"
#include "database/databasecommand_socialaction.h"
using namespace Tomahawk;

View File

@ -27,7 +27,7 @@ THE SOFTWARE.
#include <QVBoxLayout>
#include "playlist/topbar/searchlineedit.h"
#include "utils/tomahawkutils.h"
#include "utils/tomahawkutilsgui.h"
class DLLEXPORT QSearchFieldPrivate
{

View File

@ -17,22 +17,25 @@
*/
#include "config.h"
#include "tomahawkutils.h"
#include "headlesscheck.h"
#include <QtCore/QCoreApplication>
#include "tomahawksettings.h"
#include "utils/tomahawkutils.h"
#include "utils/logger.h"
#ifdef LIBLASTFM_FOUND
#include <lastfm/ws.h>
#endif
#include <QtGui/QColor>
#include <QtCore/QDateTime>
#include <QtCore/QDir>
#include <QtCore/QMutex>
#include <QtGui/QLayout>
#include <QtGui/QPainter>
#include <QtGui/QPixmap>
#include <QtNetwork/QNetworkConfiguration>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkProxy>
#include <QtCore/QCoreApplication>
#include <QtCore/QDateTime>
#include <QtCore/QDir>
#include <QtCore/QMutex>
#ifdef Q_WS_WIN
#include <windows.h>
#include <shlobj.h>
@ -43,37 +46,12 @@
#include <sys/sysctl.h>
#endif
#ifndef ENABLE_HEADLESS
#include <QtGui/QApplication>
#include <QtGui/QWidget>
#ifdef Q_WS_X11
#include <QtGui/QX11Info>
#include <libqnetwm/netwm.h>
#endif
#ifdef Q_WS_WIN
#include <windows.h>
#include <windowsx.h>
#endif
#endif
#include <tomahawksettings.h>
#include "utils/logger.h"
#include "config.h"
#ifdef LIBLASTFM_FOUND
#include <lastfm/ws.h>
#endif
namespace TomahawkUtils
{
static int s_headerHeight = 0;
static quint64 s_infosystemRequestId = 0;
static QMutex s_infosystemRequestIdMutex;
#ifdef Q_WS_MAC
QString
appSupportFolderPath()
@ -335,148 +313,6 @@ alphaBlend( const QColor& colorFrom, const QColor& colorTo, float opacity )
}
QPixmap
createDragPixmap( MediaType type, int itemCount )
{
// If more than one item is dragged, align the items inside a
// rectangular grid. The maximum grid size is limited to 5 x 5 items.
int xCount = 3;
int size = 32;
if ( itemCount > 16 )
{
xCount = 5;
size = 16;
} else if( itemCount > 9 )
{
xCount = 4;
size = 22;
}
if( itemCount < xCount )
{
xCount = itemCount;
}
int yCount = itemCount / xCount;
if( itemCount % xCount != 0 )
{
++yCount;
}
if( yCount > xCount )
{
yCount = xCount;
}
// Draw the selected items into the grid cells
QPixmap dragPixmap( xCount * size + xCount - 1, yCount * size + yCount - 1 );
dragPixmap.fill( Qt::transparent );
QPainter painter( &dragPixmap );
painter.setRenderHint( QPainter::Antialiasing );
QPixmap pixmap;
switch ( type )
{
case MediaTypeArtist:
pixmap = QPixmap( ":/data/images/artist-icon.png" ).scaledToWidth( size, Qt::SmoothTransformation );
break;
case MediaTypeAlbum:
pixmap = QPixmap( ":/data/images/album-icon.png" ).scaledToWidth( size, Qt::SmoothTransformation );
break;
case MediaTypeTrack:
pixmap = QPixmap( QString( ":/data/images/track-icon-%2x%2.png" ).arg( size ) );
break;
}
int x = 0;
int y = 0;
for( int i = 0; i < itemCount; ++i )
{
painter.drawPixmap( x, y, pixmap );
x += size + 1;
if ( x >= dragPixmap.width() )
{
x = 0;
y += size + 1;
}
if ( y >= dragPixmap.height() )
{
break;
}
}
return dragPixmap;
}
void
drawBackgroundAndNumbers( QPainter* painter, const QString& text, const QRect& figRectIn )
{
QRect figRect = figRectIn;
if ( text.length() == 1 )
figRect.adjust( -painter->fontMetrics().averageCharWidth(), 0, 0, 0 );
QPen origpen = painter->pen();
QPen pen = origpen;
pen.setWidth( 1.0 );
painter->setPen( pen );
painter->drawRect( figRect );
// circles look bad. make it an oval. (thanks, apple)
const int bulgeWidth = 8;
const int offset = 0; // number of pixels to begin, counting inwards from figRect.x() and figRect.width(). 0 means start at each end, negative means start inside the rect.
QPainterPath ppath;
ppath.moveTo( QPoint( figRect.x() + offset, figRect.y() + figRect.height() / 2 ) );
QRect leftArcRect( figRect.x() + offset - bulgeWidth, figRect.y(), 2*bulgeWidth, figRect.height() );
ppath.arcTo( leftArcRect, 90, 180 );
painter->drawPath( ppath );
ppath = QPainterPath();
ppath.moveTo( figRect.x() + figRect.width() - offset, figRect.y() + figRect.height() / 2 );
leftArcRect = QRect( figRect.x() + figRect.width() - offset - bulgeWidth, figRect.y(), 2*bulgeWidth, figRect.height() );
ppath.arcTo( leftArcRect, 270, 180 );
painter->drawPath( ppath );
painter->setPen( origpen );
#ifdef Q_WS_MAC
figRect.adjust( -1, 0, 0, 0 );
#endif
QTextOption to( Qt::AlignCenter );
painter->setPen( Qt::white );
painter->drawText( figRect.adjusted( -5, 0, 6, 0 ), text, to );
}
#ifndef ENABLE_HEADLESS
void
drawQueryBackground( QPainter* p, const QPalette& palette, const QRect& r, qreal lightnessFactor )
{
p->setPen( palette.mid().color().lighter( lightnessFactor * 100 ) );
p->setBrush( palette.highlight().color().lighter( lightnessFactor * 100 ) );
p->drawRoundedRect( r, 4.0, 4.0 );
}
void
unmarginLayout( QLayout* layout )
{
layout->setContentsMargins( 0, 0, 0, 0 );
layout->setMargin( 0 );
layout->setSpacing( 0 );
for ( int i = 0; i < layout->count(); i++ )
{
QLayout* childLayout = layout->itemAt( i )->layout();
if ( childLayout )
unmarginLayout( childLayout );
}
}
#endif
NetworkProxyFactory::NetworkProxyFactory( const NetworkProxyFactory& other )
{
m_noProxyHosts = QStringList( other.m_noProxyHosts );
@ -691,103 +527,6 @@ setNam( QNetworkAccessManager* nam, bool noMutexLocker )
}
#ifndef ENABLE_HEADLESS
QWidget*
tomahawkWindow()
{
QWidgetList widgetList = qApp->topLevelWidgets();
int i = 0;
while( i < widgetList.count() && widgetList.at( i )->objectName() != "TH_Main_Window" )
i++;
if ( i == widgetList.count() )
{
qDebug() << Q_FUNC_INFO << "could not find main Tomahawk mainwindow";
Q_ASSERT( false );
return 0;
}
QWidget *widget = widgetList.at( i );
return widget;
}
#ifndef Q_WS_MAC
void
bringToFront()
{
#if defined(Q_WS_X11)
{
qDebug() << Q_FUNC_INFO;
QWidget* widget = tomahawkWindow();
if ( !widget )
return;
widget->show();
widget->activateWindow();
widget->raise();
WId wid = widget->winId();
NETWM::init();
XEvent e;
e.xclient.type = ClientMessage;
e.xclient.message_type = NETWM::NET_ACTIVE_WINDOW;
e.xclient.display = QX11Info::display();
e.xclient.window = wid;
e.xclient.format = 32;
e.xclient.data.l[0] = 2;
e.xclient.data.l[1] = QX11Info::appTime();
e.xclient.data.l[2] = 0;
e.xclient.data.l[3] = 0l;
e.xclient.data.l[4] = 0l;
XSendEvent( QX11Info::display(), RootWindow( QX11Info::display(), DefaultScreen( QX11Info::display() ) ), False, SubstructureRedirectMask | SubstructureNotifyMask, &e );
}
#elif defined(Q_WS_WIN)
{
qDebug() << Q_FUNC_INFO;
QWidget* widget = tomahawkWindow();
if ( !widget )
return;
widget->show();
widget->activateWindow();
widget->raise();
WId wid = widget->winId();
HWND hwndActiveWin = GetForegroundWindow();
int idActive = GetWindowThreadProcessId(hwndActiveWin, NULL);
if ( AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) )
{
SetForegroundWindow( wid );
SetFocus( wid );
AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
}
}
#endif
}
#endif
#endif
QPixmap
createAvatarFrame( const QPixmap &avatar )
{
QPixmap frame( ":/data/images/avatar_frame.png" );
QPixmap scaledAvatar = avatar.scaled( frame.height() * 75 / 100, frame.width() * 75 / 100, Qt::KeepAspectRatio, Qt::SmoothTransformation );
QPainter painter( &frame );
painter.drawPixmap( (frame.height() - scaledAvatar.height()) / 2, (frame.width() - scaledAvatar.width()) / 2, scaledAvatar );
return frame;
}
void
crash()
{
@ -795,18 +534,6 @@ crash()
*a = 1;
}
int
headerHeight()
{
return s_headerHeight;
}
void
setHeaderHeight( int height )
{
s_headerHeight = height;
}
// taken from util/fileutils.cpp in kdevplatform
bool
removeDirectory( const QString& dir )

View File

@ -21,25 +21,15 @@
#include "dllmacro.h"
#include <QtCore/QObject>
#include <QtCore/QThread>
#include <QtNetwork/QNetworkProxy>
#include <QtCore/QStringList>
#include <QtCore/QRect>
#ifndef ENABLE_HEADLESS
#include <QPalette>
#endif
#define RESPATH ":/data/"
class QPainter;
class QColor;
class QDir;
class QDateTime;
class QString;
class QPixmap;
class QLayout;
class QNetworkAccessManager;
namespace TomahawkUtils
@ -89,20 +79,6 @@ namespace TomahawkUtils
DLLEXPORT QString filesizeToString( unsigned int size );
DLLEXPORT QString extensionToMimetype( const QString& extension );
DLLEXPORT QColor alphaBlend( const QColor& colorFrom, const QColor& colorTo, float opacity );
DLLEXPORT QPixmap createDragPixmap( MediaType type, int itemCount = 1 );
DLLEXPORT void drawBackgroundAndNumbers( QPainter* p, const QString& text, const QRect& rect );
#ifndef ENABLE_HEADLESS
DLLEXPORT void drawQueryBackground( QPainter* p, const QPalette& palette, const QRect& r, qreal lightnessFactor = 1 );
DLLEXPORT QWidget* tomahawkWindow();
/// Platform-specific bringing tomahawk mainwindow to front, b/c qt's activate() and such don't seem to work well enough for us
DLLEXPORT void bringToFront();
DLLEXPORT QPixmap createAvatarFrame( const QPixmap &avatar );
#endif
DLLEXPORT void unmarginLayout( QLayout* layout );
DLLEXPORT NetworkProxyFactory* proxyFactory( bool noMutexLocker = false );
DLLEXPORT QNetworkAccessManager* nam();
@ -111,9 +87,6 @@ namespace TomahawkUtils
DLLEXPORT void crash();
DLLEXPORT int headerHeight();
DLLEXPORT void setHeaderHeight( int height );
DLLEXPORT bool removeDirectory( const QString& dir );
DLLEXPORT quint64 infosystemRequestId();

View File

@ -19,15 +19,13 @@
#ifndef VIEWPAGE_H
#define VIEWPAGE_H
#include <QObject>
#include "typedefs.h"
#include "playlistinterface.h"
#include "artist.h"
#include "album.h"
#include "utils/tomahawkutils.h"
#include "dllmacro.h"
#include <QPixmap>
namespace Tomahawk
{

View File

@ -22,7 +22,7 @@
#include "Breadcrumb.h"
#include "combobox.h"
#include "utils/stylehelper.h"
#include "utils/tomahawkutils.h"
#include "utils/tomahawkutilsgui.h"
#include <QPaintEvent>
#include <QPainter>

View File

@ -23,7 +23,7 @@
#include "utils/logger.h"
#include "utils/stylehelper.h"
#include "utils/tomahawkutils.h"
#include "utils/tomahawkutilsgui.h"
static const int s_defaultFontSize = 12;

View File

@ -29,7 +29,7 @@
#include "database/databasecommand_allalbums.h"
#include "utils/stylehelper.h"
#include "utils/tomahawkutils.h"
#include "utils/tomahawkutilsgui.h"
#include "utils/logger.h"
#include "widgets/OverlayButton.h"

View File

@ -27,7 +27,7 @@
#include "artist.h"
#include "album.h"
#include "query.h"
#include "utils/tomahawkutils.h"
#include "utils/tomahawkutilsgui.h"
#include "utils/logger.h"
#define BOXMARGIN 2

View File

@ -29,7 +29,7 @@
#include "source.h"
#include "viewpage.h"
#include "utils/tomahawkutils.h"
#include "utils/tomahawkutilsgui.h"
#include "dllmacro.h"

View File

@ -20,6 +20,8 @@
#include "settingsdialog.h"
#include "config.h"
#include "utils/tomahawkutilsgui.h"
#include <QCryptographicHash>
#include <QDesktopServices>
#include <QFileDialog>
@ -417,7 +419,7 @@ SettingsDialog::testLastFmLogin()
// ensure they have up-to-date settings
lastfm::setNetworkAccessManager( TomahawkUtils::nam() );
QNetworkReply* authJob = lastfm::ws::post( query );
connect( authJob, SIGNAL( finished() ), SLOT( onLastFmFinished() ) );
@ -877,7 +879,7 @@ ProxyDialog::saveSettings()
qDebug() << Q_FUNC_INFO;
QNetworkProxy::ProxyType type = static_cast< QNetworkProxy::ProxyType>( m_backwardMap[ ui->typeBox->currentIndex() ] );
//First set settings
TomahawkSettings* s = TomahawkSettings::instance();
s->setProxyHost( ui->hostLineEdit->text() );
@ -890,7 +892,7 @@ ProxyDialog::saveSettings()
s->setProxyType( type );
s->setProxyDns( ui->checkBoxUseProxyForDns->checkState() == Qt::Checked );
s->sync();
TomahawkUtils::NetworkProxyFactory* proxyFactory = TomahawkUtils::proxyFactory();
tDebug() << Q_FUNC_INFO << "Got proxyFactory: " << proxyFactory;
if ( type == QNetworkProxy::NoProxy )

View File

@ -20,7 +20,7 @@
#include "googlewrapper.h"
#include "ui_configwidget.h"
#include "utils/tomahawkutils.h"
#include "utils/tomahawkutilsgui.h"
#include <QtPlugin>
#include <QInputDialog>

View File

@ -50,7 +50,7 @@
#endif
#include <utils/tomahawkutils.h>
#include <utils/tomahawkutilsgui.h>
#include "utils/logger.h"
SipPlugin*

View File

@ -23,7 +23,7 @@
#include "viewmanager.h"
#include "playlist.h"
#include "genericpageitems.h"
#include "utils/tomahawkutils.h"
#include "utils/tomahawkutilsgui.h"
#include "utils/logger.h"
#include "widgets/SocialPlaylistWidget.h"
#include "playlist/customplaylistview.h"

View File

@ -26,7 +26,7 @@
#include "items/categoryitems.h"
#include "items/temporarypageitem.h"
#include "utils/tomahawkutils.h"
#include "utils/tomahawkutilsgui.h"
#include "animationhelper.h"
#include "source.h"
#include "tomahawksettings.h"

View File

@ -59,7 +59,7 @@
#include "utils/xspfloader.h"
#include "utils/jspfloader.h"
#include "utils/logger.h"
#include "utils/tomahawkutils.h"
#include "utils/tomahawkutilsgui.h"
#include <lastfm/ws.h>
#include "config.h"
@ -162,7 +162,7 @@ TomahawkApp::init()
new ActionCollection( this );
connect( ActionCollection::instance()->getAction( "quit" ), SIGNAL( triggered() ), SLOT( quit() ), Qt::UniqueConnection );
#endif
tDebug( LOGINFO ) << "Setting NAM.";
// Cause the creation of the nam, but don't need to address it directly, so prevent warning
Q_UNUSED( TomahawkUtils::nam() );