Initial commit

master
Markus Koch 2014-10-18 18:42:15 +02:00
commit 87e8edeafb
28 changed files with 3227 additions and 0 deletions

1
.gitignore vendored 100644
View File

@ -0,0 +1 @@
*.pro.user

BIN
KonaClient 100755

Binary file not shown.

38
KonaClient.pro 100755
View File

@ -0,0 +1,38 @@
#-------------------------------------------------
#
# Project created by QtCreator 2012-09-03T13:51:11
#
#-------------------------------------------------
QT += core gui network xml
TARGET = KonaClient
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
konasearch.cpp \
konaclient.cpp \
konaimage.cpp \
flowlayout.cpp \
konapreviewimageview.cpp \
konatags.cpp \
konatag.cpp \
konarelatedtags.cpp \
imageviewer.cpp
HEADERS += mainwindow.h \
konasearch.h \
konaclient.h \
konaimage.h \
flowlayout.h \
konapreviewimageview.h \
konatags.h \
konatag.h \
konarelatedtags.h \
imageviewer.h
FORMS += mainwindow.ui \
konapreviewimageview.ui \
imageviewer.ui

404
Makefile 100644
View File

@ -0,0 +1,404 @@
#############################################################################
# Makefile for building: KonaClient
# Generated by qmake (2.01a) (Qt 4.8.3) on: Do. Mär 28 10:46:21 2013
# Project: KonaClient.pro
# Template: app
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug CONFIG+=declarative_debug -o Makefile KonaClient.pro
#############################################################################
####### Compiler, tools and options
CC = gcc
CXX = g++
DEFINES = -DQT_WEBKIT -DQT_XML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED
CFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtXml -I/usr/include/qt4 -I. -I.
LINK = g++
LFLAGS =
LIBS = $(SUBLIBS) -L/usr/lib/x86_64-linux-gnu -lQtXml -lQtGui -lQtNetwork -lQtCore -lpthread
AR = ar cqs
RANLIB =
QMAKE = /usr/bin/qmake-qt4
TAR = tar -cf
COMPRESS = gzip -9f
COPY = cp -f
SED = sed
COPY_FILE = $(COPY)
COPY_DIR = $(COPY) -r
STRIP = strip
INSTALL_FILE = install -m 644 -p
INSTALL_DIR = $(COPY_DIR)
INSTALL_PROGRAM = install -m 755 -p
DEL_FILE = rm -f
SYMLINK = ln -f -s
DEL_DIR = rmdir
MOVE = mv -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p
####### Output directory
OBJECTS_DIR = ./
####### Files
SOURCES = main.cpp \
mainwindow.cpp \
konasearch.cpp \
konaclient.cpp \
konaimage.cpp \
flowlayout.cpp \
konapreviewimageview.cpp \
konatags.cpp \
konatag.cpp \
konarelatedtags.cpp \
imageviewer.cpp moc_mainwindow.cpp \
moc_konasearch.cpp \
moc_konaclient.cpp \
moc_konaimage.cpp \
moc_konapreviewimageview.cpp \
moc_konatags.cpp \
moc_konatag.cpp \
moc_konarelatedtags.cpp \
moc_imageviewer.cpp
OBJECTS = main.o \
mainwindow.o \
konasearch.o \
konaclient.o \
konaimage.o \
flowlayout.o \
konapreviewimageview.o \
konatags.o \
konatag.o \
konarelatedtags.o \
imageviewer.o \
moc_mainwindow.o \
moc_konasearch.o \
moc_konaclient.o \
moc_konaimage.o \
moc_konapreviewimageview.o \
moc_konatags.o \
moc_konatag.o \
moc_konarelatedtags.o \
moc_imageviewer.o
DIST = /usr/share/qt4/mkspecs/common/unix.conf \
/usr/share/qt4/mkspecs/common/linux.conf \
/usr/share/qt4/mkspecs/common/gcc-base.conf \
/usr/share/qt4/mkspecs/common/gcc-base-unix.conf \
/usr/share/qt4/mkspecs/common/g++-base.conf \
/usr/share/qt4/mkspecs/common/g++-unix.conf \
/usr/share/qt4/mkspecs/qconfig.pri \
/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \
/usr/share/qt4/mkspecs/features/qt_functions.prf \
/usr/share/qt4/mkspecs/features/qt_config.prf \
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
/usr/share/qt4/mkspecs/features/default_pre.prf \
/usr/share/qt4/mkspecs/features/debug.prf \
/usr/share/qt4/mkspecs/features/default_post.prf \
/usr/share/qt4/mkspecs/features/declarative_debug.prf \
/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
/usr/share/qt4/mkspecs/features/warn_on.prf \
/usr/share/qt4/mkspecs/features/qt.prf \
/usr/share/qt4/mkspecs/features/unix/thread.prf \
/usr/share/qt4/mkspecs/features/moc.prf \
/usr/share/qt4/mkspecs/features/resources.prf \
/usr/share/qt4/mkspecs/features/uic.prf \
/usr/share/qt4/mkspecs/features/yacc.prf \
/usr/share/qt4/mkspecs/features/lex.prf \
/usr/share/qt4/mkspecs/features/include_source_dir.prf \
KonaClient.pro
QMAKE_TARGET = KonaClient
DESTDIR =
TARGET = KonaClient
first: all
####### Implicit rules
.SUFFIXES: .o .c .cpp .cc .cxx .C
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.cc.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.cxx.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.C.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
####### Build rules
all: Makefile $(TARGET)
$(TARGET): ui_mainwindow.h ui_konapreviewimageview.h ui_imageviewer.h $(OBJECTS)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
{ test -n "$(DESTDIR)" && DESTDIR="$(DESTDIR)" || DESTDIR=.; } && test $$(gdb --version | sed -e 's,[^0-9]\+\([0-9]\)\.\([0-9]\).*,\1\2,;q') -gt 72 && gdb --nx --batch --quiet -ex 'set confirm off' -ex "save gdb-index $$DESTDIR" -ex quit '$(TARGET)' && test -f $(TARGET).gdb-index && objcopy --add-section '.gdb_index=$(TARGET).gdb-index' --set-section-flags '.gdb_index=readonly' '$(TARGET)' '$(TARGET)' && rm -f $(TARGET).gdb-index || true
Makefile: KonaClient.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/unix.conf \
/usr/share/qt4/mkspecs/common/linux.conf \
/usr/share/qt4/mkspecs/common/gcc-base.conf \
/usr/share/qt4/mkspecs/common/gcc-base-unix.conf \
/usr/share/qt4/mkspecs/common/g++-base.conf \
/usr/share/qt4/mkspecs/common/g++-unix.conf \
/usr/share/qt4/mkspecs/qconfig.pri \
/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \
/usr/share/qt4/mkspecs/features/qt_functions.prf \
/usr/share/qt4/mkspecs/features/qt_config.prf \
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
/usr/share/qt4/mkspecs/features/default_pre.prf \
/usr/share/qt4/mkspecs/features/debug.prf \
/usr/share/qt4/mkspecs/features/default_post.prf \
/usr/share/qt4/mkspecs/features/declarative_debug.prf \
/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
/usr/share/qt4/mkspecs/features/warn_on.prf \
/usr/share/qt4/mkspecs/features/qt.prf \
/usr/share/qt4/mkspecs/features/unix/thread.prf \
/usr/share/qt4/mkspecs/features/moc.prf \
/usr/share/qt4/mkspecs/features/resources.prf \
/usr/share/qt4/mkspecs/features/uic.prf \
/usr/share/qt4/mkspecs/features/yacc.prf \
/usr/share/qt4/mkspecs/features/lex.prf \
/usr/share/qt4/mkspecs/features/include_source_dir.prf \
/usr/lib/x86_64-linux-gnu/libQtXml.prl \
/usr/lib/x86_64-linux-gnu/libQtGui.prl \
/usr/lib/x86_64-linux-gnu/libQtNetwork.prl \
/usr/lib/x86_64-linux-gnu/libQtCore.prl
$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug CONFIG+=declarative_debug -o Makefile KonaClient.pro
/usr/share/qt4/mkspecs/common/unix.conf:
/usr/share/qt4/mkspecs/common/linux.conf:
/usr/share/qt4/mkspecs/common/gcc-base.conf:
/usr/share/qt4/mkspecs/common/gcc-base-unix.conf:
/usr/share/qt4/mkspecs/common/g++-base.conf:
/usr/share/qt4/mkspecs/common/g++-unix.conf:
/usr/share/qt4/mkspecs/qconfig.pri:
/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri:
/usr/share/qt4/mkspecs/features/qt_functions.prf:
/usr/share/qt4/mkspecs/features/qt_config.prf:
/usr/share/qt4/mkspecs/features/exclusive_builds.prf:
/usr/share/qt4/mkspecs/features/default_pre.prf:
/usr/share/qt4/mkspecs/features/debug.prf:
/usr/share/qt4/mkspecs/features/default_post.prf:
/usr/share/qt4/mkspecs/features/declarative_debug.prf:
/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf:
/usr/share/qt4/mkspecs/features/warn_on.prf:
/usr/share/qt4/mkspecs/features/qt.prf:
/usr/share/qt4/mkspecs/features/unix/thread.prf:
/usr/share/qt4/mkspecs/features/moc.prf:
/usr/share/qt4/mkspecs/features/resources.prf:
/usr/share/qt4/mkspecs/features/uic.prf:
/usr/share/qt4/mkspecs/features/yacc.prf:
/usr/share/qt4/mkspecs/features/lex.prf:
/usr/share/qt4/mkspecs/features/include_source_dir.prf:
/usr/lib/x86_64-linux-gnu/libQtXml.prl:
/usr/lib/x86_64-linux-gnu/libQtGui.prl:
/usr/lib/x86_64-linux-gnu/libQtNetwork.prl:
/usr/lib/x86_64-linux-gnu/libQtCore.prl:
qmake: FORCE
@$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug CONFIG+=declarative_debug -o Makefile KonaClient.pro
dist:
@$(CHK_DIR_EXISTS) .tmp/KonaClient1.0.0 || $(MKDIR) .tmp/KonaClient1.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/KonaClient1.0.0/ && $(COPY_FILE) --parents mainwindow.h konasearch.h konaclient.h konaimage.h flowlayout.h konapreviewimageview.h konatags.h konatag.h konarelatedtags.h imageviewer.h .tmp/KonaClient1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp konasearch.cpp konaclient.cpp konaimage.cpp flowlayout.cpp konapreviewimageview.cpp konatags.cpp konatag.cpp konarelatedtags.cpp imageviewer.cpp .tmp/KonaClient1.0.0/ && $(COPY_FILE) --parents mainwindow.ui konapreviewimageview.ui imageviewer.ui .tmp/KonaClient1.0.0/ && (cd `dirname .tmp/KonaClient1.0.0` && $(TAR) KonaClient1.0.0.tar KonaClient1.0.0 && $(COMPRESS) KonaClient1.0.0.tar) && $(MOVE) `dirname .tmp/KonaClient1.0.0`/KonaClient1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/KonaClient1.0.0
clean:compiler_clean
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core
####### Sub-libraries
distclean: clean
-$(DEL_FILE) $(TARGET)
-$(DEL_FILE) Makefile
check: first
mocclean: compiler_moc_header_clean compiler_moc_source_clean
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
compiler_moc_header_make_all: moc_mainwindow.cpp moc_konasearch.cpp moc_konaclient.cpp moc_konaimage.cpp moc_konapreviewimageview.cpp moc_konatags.cpp moc_konatag.cpp moc_konarelatedtags.cpp moc_imageviewer.cpp
compiler_moc_header_clean:
-$(DEL_FILE) moc_mainwindow.cpp moc_konasearch.cpp moc_konaclient.cpp moc_konaimage.cpp moc_konapreviewimageview.cpp moc_konatags.cpp moc_konatag.cpp moc_konarelatedtags.cpp moc_imageviewer.cpp
moc_mainwindow.cpp: konaclient.h \
konasearch.h \
konaimage.h \
konatags.h \
konatag.h \
konarelatedtags.h \
flowlayout.h \
imageviewer.h \
mainwindow.h
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) mainwindow.h -o moc_mainwindow.cpp
moc_konasearch.cpp: konaclient.h \
konaimage.h \
konasearch.h
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) konasearch.h -o moc_konasearch.cpp
moc_konaclient.cpp: konaclient.h
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) konaclient.h -o moc_konaclient.cpp
moc_konaimage.cpp: konaclient.h \
konaimage.h
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) konaimage.h -o moc_konaimage.cpp
moc_konapreviewimageview.cpp: konaimage.h \
konaclient.h \
konapreviewimageview.h
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) konapreviewimageview.h -o moc_konapreviewimageview.cpp
moc_konatags.cpp: konatag.h \
konaclient.h \
konatags.h
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) konatags.h -o moc_konatags.cpp
moc_konatag.cpp: konatag.h
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) konatag.h -o moc_konatag.cpp
moc_konarelatedtags.cpp: konaclient.h \
konatag.h \
konarelatedtags.h
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) konarelatedtags.h -o moc_konarelatedtags.cpp
moc_imageviewer.cpp: konaimage.h \
konaclient.h \
imageviewer.h
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) imageviewer.h -o moc_imageviewer.cpp
compiler_rcc_make_all:
compiler_rcc_clean:
compiler_image_collection_make_all: qmake_image_collection.cpp
compiler_image_collection_clean:
-$(DEL_FILE) qmake_image_collection.cpp
compiler_moc_source_make_all:
compiler_moc_source_clean:
compiler_uic_make_all: ui_mainwindow.h ui_konapreviewimageview.h ui_imageviewer.h
compiler_uic_clean:
-$(DEL_FILE) ui_mainwindow.h ui_konapreviewimageview.h ui_imageviewer.h
ui_mainwindow.h: mainwindow.ui
/usr/bin/uic-qt4 mainwindow.ui -o ui_mainwindow.h
ui_konapreviewimageview.h: konapreviewimageview.ui
/usr/bin/uic-qt4 konapreviewimageview.ui -o ui_konapreviewimageview.h
ui_imageviewer.h: imageviewer.ui
/usr/bin/uic-qt4 imageviewer.ui -o ui_imageviewer.h
compiler_yacc_decl_make_all:
compiler_yacc_decl_clean:
compiler_yacc_impl_make_all:
compiler_yacc_impl_clean:
compiler_lex_make_all:
compiler_lex_clean:
compiler_clean: compiler_moc_header_clean compiler_uic_clean
####### Compile
main.o: main.cpp mainwindow.h \
konaclient.h \
konasearch.h \
konaimage.h \
konatags.h \
konatag.h \
konarelatedtags.h \
flowlayout.h \
imageviewer.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
mainwindow.o: mainwindow.cpp mainwindow.h \
konaclient.h \
konasearch.h \
konaimage.h \
konatags.h \
konatag.h \
konarelatedtags.h \
flowlayout.h \
imageviewer.h \
ui_mainwindow.h \
konapreviewimageview.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwindow.o mainwindow.cpp
konasearch.o: konasearch.cpp konasearch.h \
konaclient.h \
konaimage.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o konasearch.o konasearch.cpp
konaclient.o: konaclient.cpp konaclient.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o konaclient.o konaclient.cpp
konaimage.o: konaimage.cpp konaimage.h \
konaclient.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o konaimage.o konaimage.cpp
flowlayout.o: flowlayout.cpp flowlayout.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o flowlayout.o flowlayout.cpp
konapreviewimageview.o: konapreviewimageview.cpp konapreviewimageview.h \
konaimage.h \
konaclient.h \
ui_konapreviewimageview.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o konapreviewimageview.o konapreviewimageview.cpp
konatags.o: konatags.cpp konatags.h \
konatag.h \
konaclient.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o konatags.o konatags.cpp
konatag.o: konatag.cpp konatag.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o konatag.o konatag.cpp
konarelatedtags.o: konarelatedtags.cpp konarelatedtags.h \
konaclient.h \
konatag.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o konarelatedtags.o konarelatedtags.cpp
imageviewer.o: imageviewer.cpp imageviewer.h \
konaimage.h \
konaclient.h \
ui_imageviewer.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o imageviewer.o imageviewer.cpp
moc_mainwindow.o: moc_mainwindow.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_mainwindow.o moc_mainwindow.cpp
moc_konasearch.o: moc_konasearch.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_konasearch.o moc_konasearch.cpp
moc_konaclient.o: moc_konaclient.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_konaclient.o moc_konaclient.cpp
moc_konaimage.o: moc_konaimage.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_konaimage.o moc_konaimage.cpp
moc_konapreviewimageview.o: moc_konapreviewimageview.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_konapreviewimageview.o moc_konapreviewimageview.cpp
moc_konatags.o: moc_konatags.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_konatags.o moc_konatags.cpp
moc_konatag.o: moc_konatag.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_konatag.o moc_konatag.cpp
moc_konarelatedtags.o: moc_konarelatedtags.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_konarelatedtags.o moc_konarelatedtags.cpp
moc_imageviewer.o: moc_imageviewer.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_imageviewer.o moc_imageviewer.cpp
####### Install
install: FORCE
uninstall: FORCE
FORCE:

195
flowlayout.cpp 100755
View File

@ -0,0 +1,195 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
** the names of its contributors may be used to endorse or promote
** products derived from this software without specific prior written
** permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtGui>
#include "flowlayout.h"
FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing)
: QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
{
setContentsMargins(margin, margin, margin, margin);
}
FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing)
: m_hSpace(hSpacing), m_vSpace(vSpacing)
{
setContentsMargins(margin, margin, margin, margin);
}
FlowLayout::~FlowLayout()
{
QLayoutItem *item;
while ((item = takeAt(0)))
delete item;
}
void FlowLayout::addItem(QLayoutItem *item)
{
itemList.append(item);
}
int FlowLayout::horizontalSpacing() const
{
if (m_hSpace >= 0) {
return m_hSpace;
} else {
return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
}
}
int FlowLayout::verticalSpacing() const
{
if (m_vSpace >= 0) {
return m_vSpace;
} else {
return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
}
}
int FlowLayout::count() const
{
return itemList.size();
}
QLayoutItem *FlowLayout::itemAt(int index) const
{
return itemList.value(index);
}
QLayoutItem *FlowLayout::takeAt(int index)
{
if (index >= 0 && index < itemList.size())
return itemList.takeAt(index);
else
return 0;
}
Qt::Orientations FlowLayout::expandingDirections() const
{
return 0;
}
bool FlowLayout::hasHeightForWidth() const
{
return true;
}
int FlowLayout::heightForWidth(int width) const
{
int height = doLayout(QRect(0, 0, width, 0), true);
return height;
}
void FlowLayout::setGeometry(const QRect &rect)
{
QLayout::setGeometry(rect);
doLayout(rect, false);
}
QSize FlowLayout::sizeHint() const
{
return minimumSize();
}
QSize FlowLayout::minimumSize() const
{
QSize size;
QLayoutItem *item;
foreach (item, itemList)
size = size.expandedTo(item->minimumSize());
size += QSize(2*margin(), 2*margin());
return size;
}
int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
{
int left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom);
QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
int x = effectiveRect.x();
int y = effectiveRect.y();
int lineHeight = 0;
QLayoutItem *item;
foreach (item, itemList) {
QWidget *wid = item->widget();
int spaceX = horizontalSpacing();
if (spaceX == -1)
spaceX = wid->style()->layoutSpacing(
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
int spaceY = verticalSpacing();
if (spaceY == -1)
spaceY = wid->style()->layoutSpacing(
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
int nextX = x + item->sizeHint().width() + spaceX;
if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
x = effectiveRect.x();
y = y + lineHeight + spaceY;
nextX = x + item->sizeHint().width() + spaceX;
lineHeight = 0;
}
if (!testOnly)
item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
x = nextX;
lineHeight = qMax(lineHeight, item->sizeHint().height());
}
return y + lineHeight - rect.y() + bottom;
}
int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
{
QObject *parent = this->parent();
if (!parent) {
return -1;
} else if (parent->isWidgetType()) {
QWidget *pw = static_cast<QWidget *>(parent);
return pw->style()->pixelMetric(pm, 0, pw);
} else {
return static_cast<QLayout *>(parent)->spacing();
}
}
void FlowLayout::insertWidgetAt(QWidget *widget, int index)
{
addWidget(widget);
this->itemList.move(this->itemList.count()-1, 0);
//this->itemList.insert(index, new QWidgetItem(widget));
}

77
flowlayout.h 100755
View File

@ -0,0 +1,77 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
** the names of its contributors may be used to endorse or promote
** products derived from this software without specific prior written
** permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef FLOWLAYOUT_H
#define FLOWLAYOUT_H
#include <QLayout>
#include <QRect>
#include <QWidgetItem>
class FlowLayout : public QLayout
{
public:
FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
~FlowLayout();
void addItem(QLayoutItem *item);
int horizontalSpacing() const;
int verticalSpacing() const;
Qt::Orientations expandingDirections() const;
bool hasHeightForWidth() const;
int heightForWidth(int) const;
int count() const;
QLayoutItem *itemAt(int index) const;
QSize minimumSize() const;
void setGeometry(const QRect &rect);
QSize sizeHint() const;
QLayoutItem *takeAt(int index);
void insertWidgetAt(QWidget *widget, int index);
private:
int doLayout(const QRect &rect, bool testOnly) const;
int smartSpacing(QStyle::PixelMetric pm) const;
QList<QLayoutItem *> itemList;
int m_hSpace;
int m_vSpace;
};
#endif

200
imageviewer.cpp 100755
View File

@ -0,0 +1,200 @@
#include "imageviewer.h"
#include "ui_imageviewer.h"
#include <QWheelEvent>
#include <QDebug>
ImageViewer::ImageViewer(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::ImageViewer)
{
ui->setupUi(this);
EventFilterizer* interceptor = new EventFilterizer;
ui->centralwidget->installEventFilter(interceptor);
connect(interceptor, SIGNAL(onMove(int,int)),
this, SLOT(move(int,int)));
connect(interceptor, SIGNAL(onZoom(int)),
this, SLOT(zoom(int)));
}
ImageViewer::~ImageViewer()
{
delete ui;
}
void ImageViewer::setImage(KonaImage *Ki) { // TODO: (no todo but a notice: This function requires the image to be available locally when called!)
//ki = Ki; //TODO: <--
disconnect(Ki, SIGNAL(imageDownloaded(KonaImage*,QString)),
this, SLOT(setImage(KonaImage*)));
currentID = Ki->getId();
pix.load(Ki->getLocalImagePath());
// We're doing this a bit complicated. (It's to remove any frame from the label)
QPixmap temp = pix.scaled(this->width(), this->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
ui->imgLabel->setGeometry(0,0,this->width(), this->height());
ui->imgLabel->setPixmap(temp);
ui->imgLabel->setGeometry((ui->imgLabel->width()-temp.width()) / 2,
(ui->imgLabel->height()-temp.height()) / 2,
temp.width(), temp.height());
setWindowTitle(tr("KonaClient - Image viewer: %1 (%2x%3)").arg(QString::number(Ki->getId()),QString::number(Ki->getWidth()),QString::number(Ki->getHeight())));
}
void ImageViewer::showLoading() {
ui->imgLabel->setText("Loading image...");
setWindowTitle(tr("KonaClient - Image viewer"));
ui->imgLabel->setGeometry(0,0,this->width(),this->height());
}
void ImageViewer::move(int dx, int dy) {
ui->imgLabel->setGeometry(ui->imgLabel->x() + dx, ui->imgLabel->y() + dy, ui->imgLabel->width(),ui->imgLabel->height());
checkPos();
}
void ImageViewer::zoom(int mode) {
if (mode == ZOOM_OUT) {
ui->imgLabel->setGeometry(ui->imgLabel->x() + (pix.width()/20)/2,
ui->imgLabel->y() + (pix.height()/20)/2,
ui->imgLabel->width() - pix.width()/20,
ui->imgLabel->height() - pix.height()/20);
}
else if (mode == ZOOM_IN) {
ui->imgLabel->setGeometry(ui->imgLabel->x() - (pix.width()/20)/2,
ui->imgLabel->y() - (pix.height()/20)/2,
ui->imgLabel->width() + pix.width()/20,
ui->imgLabel->height() + pix.height()/20);
}
checkPos();
ui->imgLabel->setPixmap(pix.scaled(ui->imgLabel->width(), ui->imgLabel->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
void ImageViewer::checkPos() {
if (ui->imgLabel->width() < this->width()) {
if (ui->imgLabel->x() < 0) {
ui->imgLabel->setGeometry(0,
ui->imgLabel->y(),
ui->imgLabel->width(),
ui->imgLabel->height());
}
else if (ui->imgLabel->x() + ui->imgLabel->width() > this->width()) {
ui->imgLabel->setGeometry(this->width() - ui->imgLabel->width(),
ui->imgLabel->y(),
ui->imgLabel->width(),
ui->imgLabel->height());
}
}
else {
// if (ui->imgLabel->x() )
}
if (ui->imgLabel->height() < this->height()) {
if (ui->imgLabel->y() < 0) {
ui->imgLabel->setGeometry(ui->imgLabel->x(),
0,
ui->imgLabel->width(),
ui->imgLabel->height());
}
else if (ui->imgLabel->y() + ui->imgLabel->height() > this->height()) {
ui->imgLabel->setGeometry(ui->imgLabel->x(),
this->height() - ui->imgLabel->height(),
ui->imgLabel->width(),
ui->imgLabel->height());
}
}
else {
if (ui->imgLabel->y() + ui->imgLabel->height() < this->height()) {
ui->imgLabel->setGeometry(ui->imgLabel->x(),
this->height() - ui->imgLabel->height(),
ui->imgLabel->width(),
ui->imgLabel->height());
}
else if (ui->imgLabel->y() > 0) {
ui->imgLabel->setGeometry(ui->imgLabel->x(),
0,
ui->imgLabel->width(),
ui->imgLabel->height());
}
if (ui->imgLabel->x() + ui->imgLabel->width() < this->width()) {
ui->imgLabel->setGeometry(this->width() - ui->imgLabel->width(),
ui->imgLabel->y(),
ui->imgLabel->width(),
ui->imgLabel->height());
}
else if (ui->imgLabel->x() > 0) {
ui->imgLabel->setGeometry(0,
ui->imgLabel->y(),
ui->imgLabel->width(),
ui->imgLabel->height());
}
}
}
void ImageViewer::keyPressEvent(QKeyEvent *e) {
if (e->key() == Qt::Key_Left || e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Shift) {
emit loadPrev();
}
else if (e->key() == Qt::Key_Right || e->key() == Qt::Key_Return || e->key() == Qt::Key_Control) {
emit loadNext();
}
}
// MOUSE EVENT
EventFilterizer::EventFilterizer(QObject *parent) :
QObject(parent)
{
}
bool EventFilterizer::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::Wheel) {
QWheelEvent *wheelEvent = static_cast< QWheelEvent * >( event );
if (wheelEvent->delta() > 0) {
emit onZoom(ZOOM_IN);
}
else if (wheelEvent->delta() < 0) {
emit onZoom(ZOOM_OUT);
}
return true;
}
else if (event->type() == QEvent::MouseButtonPress) {
QMouseEvent *mouseEvent = static_cast< QMouseEvent * >( event );
lastX = mouseEvent->x();
lastY = mouseEvent->y();
return true;
}
else if (event->type() == QEvent::MouseMove) { // ONLY CALLED WHEN PRESSED
//qDebug() << "MOVE";
QMouseEvent *mouseEvent = static_cast< QMouseEvent * >( event );
emit onMove(mouseEvent->x() - lastX,
mouseEvent->y() - lastY);
lastX = mouseEvent->x();
lastY = mouseEvent->y();
return true;
}
else
{
// standard event processing
return QObject::eventFilter(obj, event);
}
}

71
imageviewer.h 100755
View File

@ -0,0 +1,71 @@
#ifndef IMAGEVIEWER_H
#define IMAGEVIEWER_H
#include <QMainWindow>
#include "konaimage.h"
#include <QDebug>
namespace Ui {
class ImageViewer;
}
class ImageViewer : public QMainWindow
{
Q_OBJECT
#define ZOOM_IN 1
#define ZOOM_OUT 2
public:
explicit ImageViewer(QWidget *parent = 0);
~ImageViewer();
void showLoading();
//void mouseMoveEvent(QMouseEvent *e);
void keyPressEvent(QKeyEvent* e);
int getCurrentId() {return currentID;}
private:
QPixmap pix;
int currentID;
public slots:
void setImage(KonaImage *Ki);
void move(int dx, int dy);
void zoom(int mode);
void checkPos();
signals:
void loadPrev();
void loadNext();
private:
Ui::ImageViewer *ui;
};
class EventFilterizer : public QObject
{
Q_OBJECT
public:
explicit EventFilterizer(QObject *parent = 0);
void setIv(ImageViewer *Iv) {iv = Iv;}
private:
ImageViewer *iv;
int lastX;
int lastY;
protected:
bool eventFilter(QObject *obj, QEvent *event);
signals:
void onMove(int, int);
void onZoom(int);
public slots:
};
#endif // IMAGEVIEWER_H

58
imageviewer.ui 100755
View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ImageViewer</class>
<widget class="QMainWindow" name="ImageViewer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="windowTitle">
<string>KonaChan - Image viewer</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: black;</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLabel" name="imgLabel">
<property name="geometry">
<rect>
<x>80</x>
<y>70</y>
<width>640</width>
<height>480</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>Loading image...</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</widget>
</widget>
<resources/>
<connections/>
<slots>
<slot>onResize()</slot>
</slots>
</ui>

46
konaclient.cpp 100755
View File

@ -0,0 +1,46 @@
#include "konaclient.h"
KonaClient::KonaClient(QString TempDir, QString CacheDir, QString ArchiveDir, QString Server)
{
// Copy info to RAM
tempDir = TempDir;
cacheDir = CacheDir;
archiveDir = ArchiveDir;
server = Server;
// Create all directories
QDir aD(archiveDir);
if (!aD.exists()) aD.mkpath(archiveDir);
QDir cD(cacheDir);
if (!cD.exists()) cD.mkpath(cacheDir);
QDir tD(tempDir);
if (!tD.exists()) tD.mkpath(tempDir);
}
KonaClient::~KonaClient()
{
// Remove temp dir
QDir tD(tempDir);
if (tD.exists()) removeDir(tempDir);
}
// Copied from http://www.qtcentre.org/threads/4166-remove-directory-empty-or-not-empty
// Removes all files and subdirectories of a specific directory.
void KonaClient::removeDir(const QString &path)
{
QFileInfo fileInfo(path);
if(fileInfo.isDir()){
QDir dir(path);
QStringList fileList = dir.entryList();
for(int i = 0; i < fileList.count(); ++i){
QFile::remove(fileList.at(i));
}
dir.rmdir(path);
}
else{
QFile::remove(path);
}
}

50
konaclient.h 100755
View File

@ -0,0 +1,50 @@
#ifndef KONACLIENT_H
#define KONACLIENT_H
#include <QObject>
#include <QDir>
// ERROR CODES
#define ERROR_TAGS_TEMPFILE 1
#define ERROR_TAGS_FORMAT 2
#define ERROR_SEARCH_TEMPFILE 1
#define ERROR_SEARCH_FORMAT 2
#define ERROR_SEARCH_XML 3
#define ERROR_SEARCH_HTTP 4
// Windows-Compatibility
#ifdef _WIN32
#define SLASH "\\"
#else
#define SLASH "/"
#endif
class KonaClient : public QObject
{
Q_OBJECT
public:
KonaClient(QString TempDir, QString CacheDir, QString ArchiveDir, QString Server = "konachan.com");
~KonaClient();
QString getTempDir() {return tempDir;}
QString getCacheDir() {return cacheDir;}
QString getArchiveDir() {return archiveDir;}
QString getServer() {return server;}
private:
QString tempDir;
QString cacheDir;
QString archiveDir;
QString server;
void removeDir(const QString &path);
};
#endif // KONACLIENT_H

208
konaimage.cpp 100755
View File

@ -0,0 +1,208 @@
#include "konaimage.h"
#include <QDebug>
KonaImage::KonaImage(KonaClient *Kc, int Id, QStringList Tags, int CreatedAt, int CreatorId, QString Author, int Change, QString Source, int Score, QString Md5, int FileSize, QString FileUrl, bool IsShownInIndex, QString PreviewUrl, int PreviewWidth, int PreviewHeight, int ActualPreviewWidth, int ActualPreviewHeight, QString SampleUrl, int SampleWidth, int SampleHeight, int SampleFileSize, QString JpegUrl, int JpegWidth, int JpegHeight, int JpegFileSize, QString Rating, bool HasChildren, int ParentID, QString Status, int Width, int Height, bool IsHeld, QString FramesPendingString, QString FramesString)
{
// Reset
previewStatusCode = 1;
imageStatusCode = 1;
jpegStatusCode = 1;
sampleStatusCode = 1;
// Copy to RAM
kc = Kc;
id = Id;
tags = Tags;
createdAt = CreatedAt;
creatorId = CreatorId;
author = Author;
change = Change;
source = Source;
score = Score;
md5 = Md5;
fileSize = FileSize;
fileUrl = FileUrl;
isShownInIndex = IsShownInIndex;
previewUrl = PreviewUrl;
previewWidth = PreviewWidth;
previewHeight = PreviewHeight;
actualPreviewWidth = ActualPreviewWidth;
actualPreviewHeight = ActualPreviewHeight;
sampleUrl = SampleUrl;
sampleWidth = SampleWidth;
sampleHeight = SampleHeight;
sampleFileSize = SampleFileSize;
jpegUrl = JpegUrl;
jpegWidth = JpegWidth;
jpegHeight = JpegHeight;
jpegFileSize = JpegFileSize;
rating = Rating;
hasChildren = HasChildren;
parentID = ParentID;
status = Status;
width = Width;
height = Height;
isHeld = IsHeld;
framesPendingString = FramesPendingString;
framesString = FramesString;
// Initialize preview file
previewFile = new QFile();
previewFile->setFileName(KONAIMAGE_PREVIEWPATH);
// Prepare preview HTTP
previewHttp = new QHttp("konachan.com"); //TODO: all these konachans.com should be Kc->getServer()
connect(previewHttp, SIGNAL(responseHeaderReceived(QHttpResponseHeader)),
this, SLOT(previewResponseHeaderReceived(QHttpResponseHeader)));
connect(previewHttp, SIGNAL(requestFinished(int,bool)),
this, SLOT(previewRequestFinished()));
// Initialize image file (highres)
imageFile = new QFile();
imageFile->setFileName(KONAIMAGE_LOCALPATH);
// Prepare image HTTP
imageHttp = new QHttp("konachan.com");
connect(imageHttp, SIGNAL(responseHeaderReceived(QHttpResponseHeader)),
this, SLOT(imageResponseHeaderReceived(QHttpResponseHeader)));
connect(imageHttp, SIGNAL(requestFinished(int,bool)),
this, SLOT(imageRequestFinished()));
// Initialize jpeg file
jpegFile = new QFile();
jpegFile->setFileName(KONAIMAGE_JPEGPATH);
// Prepare jpeg HTTP
jpegHttp = new QHttp("konachan.com");
connect(jpegHttp, SIGNAL(responseHeaderReceived(QHttpResponseHeader)),
this, SLOT(jpegResponseHeaderReceived(QHttpResponseHeader)));
connect(jpegHttp, SIGNAL(requestFinished(int,bool)),
this, SLOT(jpegRequestFinished()));
// Initialize sample file
sampleFile = new QFile();
sampleFile->setFileName(KONAIMAGE_SAMPLEPATH);
// Prepare sample HTTP
sampleHttp = new QHttp("konachan.com");
connect(sampleHttp, SIGNAL(responseHeaderReceived(QHttpResponseHeader)),
this, SLOT(sampleResponseHeaderReceived(QHttpResponseHeader)));
connect(sampleHttp, SIGNAL(requestFinished(int,bool)),
this, SLOT(sampleRequestFinished()));
}
void KonaImage::DownloadPreview(bool overwrite) {
if (previewStatusCode != 1) return; // Already in progress
if (!previewFile->exists() || overwrite) {
previewFile->open(QFile::ReadWrite);
previewStatusCode = 0;
previewHttp->get(previewUrl, previewFile);
}
else if (previewFile->exists()) {
previewStatusCode = 200; // Fake HTTP OK
previewRequestFinished();
}
}
void KonaImage::previewRequestFinished() {
//qDebug() << "PREVIEW FINISHED WITH HTTP " << previewStatusCode;
previewFile->close();
if (previewStatusCode == 200) previewStatusCode = 1;
emit previewDownloaded(this, previewFile->fileName());
}
void KonaImage::previewResponseHeaderReceived(QHttpResponseHeader resp) {
previewStatusCode = resp.statusCode();
}
// "real" image
void KonaImage::DownloadImage(bool overwrite) {
qDebug() << "Download request of real image: " << this->id;
if (imageStatusCode != 1) return; // Already in progress
if (!imageFile->exists() || overwrite) {
imageFile->open(QFile::ReadWrite);
imageStatusCode = 0;
imageHttp->get(fileUrl, imageFile);
}
else if (imageFile->exists()) {
imageFile->open(QFile::ReadWrite);
QCryptographicHash md5sum(QCryptographicHash::Md5);
md5sum.addData(imageFile->readAll());
imageFile->reset();
if (md5sum.result().toHex() == md5) {
imageStatusCode = 200; // Fake HTTP OK
imageRequestFinished();
}
else {
qDebug() << "ERROR: KonaImage: MD5 checksum verification failed!";
imageStatusCode = 0;
imageHttp->get(fileUrl, imageFile);
}
}
}
void KonaImage::imageRequestFinished() {
imageFile->close();
if (imageStatusCode == 200) imageStatusCode = 1;
emit imageDownloaded(this, imageFile->fileName());
}
void KonaImage::imageResponseHeaderReceived(QHttpResponseHeader resp) {
imageStatusCode = resp.statusCode();
}
// jpeg image
void KonaImage::DownloadJpeg(bool overwrite) {
if (jpegStatusCode != 1) return; // Already in progress
if (!jpegFile->exists() || overwrite) {
jpegFile->open(QFile::ReadWrite);
jpegStatusCode = 0;
jpegHttp->get(jpegUrl, jpegFile);
}
else if (jpegFile->exists()) {
jpegStatusCode = 200; // Fake HTTP OK
jpegRequestFinished();
}
}
void KonaImage::jpegRequestFinished() {
//qDebug() << "Jpeg FINISHED WITH HTTP " << JpegStatusCode;
jpegFile->close();
if (jpegStatusCode == 200) jpegStatusCode = 1;
emit jpegDownloaded(this, jpegFile->fileName());
}
void KonaImage::jpegResponseHeaderReceived(QHttpResponseHeader resp) {
jpegStatusCode = resp.statusCode();
}
// sample image
void KonaImage::DownloadSample(bool overwrite) {
if (sampleStatusCode != 1) return; // Already in progress
if (!sampleFile->exists() || overwrite) {
sampleFile->open(QFile::ReadWrite);
sampleStatusCode = 0;
sampleHttp->get(sampleUrl, sampleFile);
}
else if (sampleFile->exists()) {
sampleStatusCode = 200; // Fake HTTP OK
sampleRequestFinished();
}
}
void KonaImage::sampleRequestFinished() {
//qDebug() << "sample FINISHED WITH HTTP " << sampleStatusCode;
sampleFile->close();
if (sampleStatusCode == 200) sampleStatusCode = 1;
emit sampleDownloaded(this, sampleFile->fileName());
}
void KonaImage::sampleResponseHeaderReceived(QHttpResponseHeader resp) {
sampleStatusCode = resp.statusCode();
}

118
konaimage.h 100755
View File

@ -0,0 +1,118 @@
#ifndef KONAIMAGE_H
#define KONAIMAGE_H
#include <QObject>
#include <QStringList>
#include <QHttp>
#include <QFile>
#include <QCryptographicHash>
#include "konaclient.h"
#define KONAIMAGE_PREVIEWPATH kc->getCacheDir() + SLASH + "preview_" + QString::number(id) + ".jpg"
#define KONAIMAGE_LOCALPATH kc->getArchiveDir() + SLASH + QString::number(id) + fileUrl.right(4)
#define KONAIMAGE_JPEGPATH kc->getCacheDir() + SLASH + "jpeg_" + QString::number(id) + ".jpg"
#define KONAIMAGE_SAMPLEPATH kc->getCacheDir() + SLASH + "sample_" + QString::number(id) + sampleUrl.right(4)
class KonaImage : public QObject
{
Q_OBJECT
public:
KonaImage(KonaClient *kc, int Id, QStringList Tags, int CreatedAt, int CreatorId, QString Author, int Change, QString Source, int Score, QString Md5, int FileSize, QString FileUrl, bool IsShownInIndex, QString PreviewUrl, int PreviewWidth, int PreviewHeight, int ActualPreviewWidth, int ActualPreviewHeight, QString SampleUrl, int SampleWidth, int SampleHeight, int SampleFileSize, QString JpegUrl, int JpegWidth, int JpegHeight, int JpegFileSize, QString Rating, bool HasChildren, int ParentID, QString Status, int Width, int Height, bool IsHeld, QString FramesPendingString, QString FramesString);
int getId() {return id;}
int getWidth() {return width;}
int getHeight() {return height;}
QString getLocalPreviewPath() {return KONAIMAGE_PREVIEWPATH;}
QString getLocalImagePath() {return KONAIMAGE_LOCALPATH;}
QString getLocalJpegPath() {return KONAIMAGE_JPEGPATH;}
QString getLocalSamplePath() {return KONAIMAGE_SAMPLEPATH;}
private:
KonaClient *kc;
int id;
QStringList tags;
int createdAt;
int creatorId;
QString author;
int change;
QString source;
int score;
QString md5;
int fileSize;
QString fileUrl;
bool isShownInIndex;
QString previewUrl;
int previewWidth;
int previewHeight;
int actualPreviewWidth;
int actualPreviewHeight;
QString sampleUrl;
int sampleWidth;
int sampleHeight;
int sampleFileSize;
QString jpegUrl;
int jpegWidth;
int jpegHeight;
int jpegFileSize;
QString rating;
bool hasChildren;
int parentID;
QString status;
int width;
int height;
bool isHeld;
QString framesPendingString;
QString framesString;
// Eventuell fehlen noch children
// Preview image
QHttp *previewHttp;
QFile *previewFile;
int previewStatusCode;
// "real" image
QHttp *imageHttp;
QFile *imageFile;
int imageStatusCode;
// jpeg image
QHttp *jpegHttp;
QFile *jpegFile;
int jpegStatusCode;
// sample image
QHttp *sampleHttp;
QFile *sampleFile;
int sampleStatusCode;
signals:
void previewDownloaded(KonaImage *ki, QString localPath);
void imageDownloaded(KonaImage *ki, QString localPath);
void jpegDownloaded(KonaImage *ki, QString localPath);
void sampleDownloaded(KonaImage *ki, QString localPath);
public slots:
void previewRequestFinished();
void previewResponseHeaderReceived(QHttpResponseHeader resp);
void imageRequestFinished();
void imageResponseHeaderReceived(QHttpResponseHeader resp);
void jpegRequestFinished();
void jpegResponseHeaderReceived(QHttpResponseHeader resp);
void sampleRequestFinished();
void sampleResponseHeaderReceived(QHttpResponseHeader resp);
void DownloadPreview(bool overwrite = false);
void DownloadImage(bool overwrite = false);
void DownloadJpeg(bool overwrite = false);
void DownloadSample(bool overwrite = false);
};
#endif // KONAIMAGE_H

View File

@ -0,0 +1,56 @@
#include "konapreviewimageview.h"
#include "ui_konapreviewimageview.h"
#include <QDebug>
KonaPreviewImageView::KonaPreviewImageView(QWidget *parent) :
QWidget(parent),
ui(new Ui::KonaPreviewImageView)
{
ui->setupUi(this);
ui->imgLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
// ui->imgLabel->setPixmap(QPixmap ("/home/markus/Bilder/temp.jpg"));
imgReloadCounter = 0;
}
KonaPreviewImageView::~KonaPreviewImageView()
{
delete ui;
}
void KonaPreviewImageView::OpenImage()
{
emit imageClicked(ki);
}
void KonaPreviewImageView::RMB() {
qDebug() << "RMB";
}
void KonaPreviewImageView::downloadImage()
{
emit buttonClicked(ki);