# -*- coding: utf-8 -*-

import sys
import os

from PyQt4 import QtGui

from ubiquity.frontend.kde_components.PartMan import PartMan

if __name__ == "__main__":

    app = QtGui.QApplication(sys.argv)
    app.setStyle("Oxygen")

    PartMan._uidir = '../../../../gui/qt'

    styleFile = os.path.join(PartMan._uidir, "style.qss")
    sf = open(styleFile, 'r')
    app.setStyleSheet(sf.read())
    sf.close()

    win = PartMan(None)
    win.setObjectName("widgetStack")
    win.show()

    cache_order = [u'/var/lib/partman/devices/=dev=sda//',
                 u'/var/lib/partman/devices/=dev=sda//32256-8167703039',
                 u'/var/lib/partman/devices/=dev=sda//8167735296-8587192319',
                 u'/var/lib/partman/devices/=dev=sdb//',
                 u'/var/lib/partman/devices/=dev=sdb//32256-5074997759',
                 u'/var/lib/partman/devices/=dev=sdb//5075030016-5362882559',
                 u'/var/lib/partman/devices/=dev=sdc//',
                 u'/var/lib/partman/devices/=dev=sdc//32256-5074997759',
                 u'/var/lib/partman/devices/=dev=sdc//5075030016-5362882559']

    disk_cache = {u'/var/lib/partman/devices/=dev=sda//': {'dev': u'=dev=sda',
                                                         'device': '/dev/sda',
                                                         'display': u'60partition_tree__________/var/lib/partman/devices/=dev=sda//',
                                                         'label': ['msdos']},
                u'/var/lib/partman/devices/=dev=sdb//': {'dev': u'=dev=sdb',
                                                         'device': '/dev/sdb',
                                                         'display': u'60partition_tree__________/var/lib/partman/devices/=dev=sdb//',
                                                         'label': ['msdos']},
                u'/var/lib/partman/devices/=dev=sdc//': {'dev': u'=dev=sdc',
                                                         'device': '/dev/sdc',
                                                         'display': u'60partition_tree__________/var/lib/partman/devices/=dev=sdc//',
                                                         'label': ['msdos']}}

    partition_cache = {u'/var/lib/partman/devices/=dev=sda//32256-8167703039': {'can_resize': True,
                                                                              'detected_filesystem': 'ext4',
                                                                              'dev': u'=dev=sda',
                                                                              'display': u'60partition_tree__________/var/lib/partman/devices/=dev=sda//32256-8167703039',
                                                                              'id': u'32256-8167703039',
                                                                              'method_choices': [(u'25filesystem',
                                                                                                  u'ext4',
                                                                                                  u'Ext4 journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'ext3',
                                                                                                  u'Ext3 journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'ext2',
                                                                                                  u'Ext2 file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'btrfs',
                                                                                                  u'btrfs journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'reiserfs',
                                                                                                  u'ReiserFS journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'jfs',
                                                                                                  u'JFS journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'xfs',
                                                                                                  u'XFS journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'fat16',
                                                                                                  u'FAT16 file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'fat32',
                                                                                                  u'FAT32 file system'),
                                                                                                 (u'40swap',
                                                                                                  u'swap',
                                                                                                  u'swap area'),
                                                                                                 (u'70dont_use',
                                                                                                  u'dontuse',
                                                                                                  u'do not use the partition')],
                                                                              'parent': u'/dev/sda',
                                                                              'parted': {'fs': 'ext4',
                                                                                         'id': '32256-8167703039',
                                                                                         'name': '',
                                                                                         'num': '1',
                                                                                         'path': '/dev/sda1',
                                                                                         'size': '8167670784',
                                                                                         'type': 'primary'},
                                                                              'resize_max_size': 8167670784,
                                                                              'resize_min_size': 2758852608,
                                                                              'resize_pref_size': 8167670784},
                     u'/var/lib/partman/devices/=dev=sda//8167735296-8587192319': {'can_resize': True,
                                                                                   'detected_filesystem': 'linux-swap',
                                                                                   'dev': u'=dev=sda',
                                                                                   'display': u'60partition_tree__________/var/lib/partman/devices/=dev=sda//8167735296-8587192319',
                                                                                   'id': u'8167735296-8587192319',
                                                                                   'method': 'swap',
                                                                                   'method_choices': [(u'25filesystem',
                                                                                                       u'ext4',
                                                                                                       u'Ext4 journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'ext3',
                                                                                                       u'Ext3 journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'ext2',
                                                                                                       u'Ext2 file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'btrfs',
                                                                                                       u'btrfs journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'reiserfs',
                                                                                                       u'ReiserFS journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'jfs',
                                                                                                       u'JFS journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'xfs',
                                                                                                       u'XFS journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'fat16',
                                                                                                       u'FAT16 file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'fat32',
                                                                                                       u'FAT32 file system'),
                                                                                                      (u'40swap',
                                                                                                       u'swap',
                                                                                                       u'swap area'),
                                                                                                      (u'70dont_use',
                                                                                                       u'dontuse',
                                                                                                       u'do not use the partition')],
                                                                                   'parent': u'/dev/sda',
                                                                                   'parted': {'fs': 'linux-swap',
                                                                                              'id': '8167735296-8587192319',
                                                                                              'name': '',
                                                                                              'num': '5',
                                                                                              'path': '/dev/sda5',
                                                                                              'size': '419457024',
                                                                                              'type': 'logical'},
                                                                                   'resize_max_size': 419457024,
                                                                                   'resize_min_size': 4096,
                                                                                   'resize_pref_size': 419457024},
                     u'/var/lib/partman/devices/=dev=sdb//32256-5074997759': {'can_resize': True,
                                                                              'detected_filesystem': 'ext4',
                                                                              'dev': u'=dev=sdb',
                                                                              'display': u'60partition_tree__________/var/lib/partman/devices/=dev=sdb//32256-5074997759',
                                                                              'id': u'32256-5074997759',
                                                                              'method_choices': [(u'25filesystem',
                                                                                                  u'ext4',
                                                                                                  u'Ext4 journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'ext3',
                                                                                                  u'Ext3 journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'ext2',
                                                                                                  u'Ext2 file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'btrfs',
                                                                                                  u'btrfs journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'reiserfs',
                                                                                                  u'ReiserFS journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'jfs',
                                                                                                  u'JFS journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'xfs',
                                                                                                  u'XFS journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'fat16',
                                                                                                  u'FAT16 file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'fat32',
                                                                                                  u'FAT32 file system'),
                                                                                                 (u'40swap',
                                                                                                  u'swap',
                                                                                                  u'swap area'),
                                                                                                 (u'70dont_use',
                                                                                                  u'dontuse',
                                                                                                  u'do not use the partition')],
                                                                              'parent': u'/dev/sdb',
                                                                              'parted': {'fs': 'ext4',
                                                                                         'id': '32256-5074997759',
                                                                                         'name': '',
                                                                                         'num': '1',
                                                                                         'path': '/dev/sdb1',
                                                                                         'size': '5074965504',
                                                                                         'type': 'primary'},
                                                                              'resize_max_size': 5074965504,
                                                                              'resize_min_size': 223924224,
                                                                              'resize_pref_size': 5074965504},
                     u'/var/lib/partman/devices/=dev=sdb//5075030016-5362882559': {'can_resize': True,
                                                                                   'detected_filesystem': 'linux-swap',
                                                                                   'dev': u'=dev=sdb',
                                                                                   'display': u'60partition_tree__________/var/lib/partman/devices/=dev=sdb//5075030016-5362882559',
                                                                                   'id': u'5075030016-5362882559',
                                                                                   'method': 'swap',
                                                                                   'method_choices': [(u'25filesystem',
                                                                                                       u'ext4',
                                                                                                       u'Ext4 journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'ext3',
                                                                                                       u'Ext3 journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'ext2',
                                                                                                       u'Ext2 file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'btrfs',
                                                                                                       u'btrfs journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'reiserfs',
                                                                                                       u'ReiserFS journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'jfs',
                                                                                                       u'JFS journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'xfs',
                                                                                                       u'XFS journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'fat16',
                                                                                                       u'FAT16 file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'fat32',
                                                                                                       u'FAT32 file system'),
                                                                                                      (u'40swap',
                                                                                                       u'swap',
                                                                                                       u'swap area'),
                                                                                                      (u'70dont_use',
                                                                                                       u'dontuse',
                                                                                                       u'do not use the partition')],
                                                                                   'parent': u'/dev/sdb',
                                                                                   'parted': {'fs': 'linux-swap',
                                                                                              'id': '5075030016-5362882559',
                                                                                              'name': '',
                                                                                              'num': '5',
                                                                                              'path': '/dev/sdb5',
                                                                                              'size': '287852544',
                                                                                              'type': 'logical'},
                                                                                   'resize_max_size': 287852544,
                                                                                   'resize_min_size': 4096,
                                                                                   'resize_pref_size': 287852544},
                     u'/var/lib/partman/devices/=dev=sdc//32256-5074997759': {'can_resize': True,
                                                                              'detected_filesystem': 'ext4',
                                                                              'dev': u'=dev=sdc',
                                                                              'display': u'60partition_tree__________/var/lib/partman/devices/=dev=sdc//32256-5074997759',
                                                                              'id': u'32256-5074997759',
                                                                              'method_choices': [(u'25filesystem',
                                                                                                  u'ext4',
                                                                                                  u'Ext4 journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'ext3',
                                                                                                  u'Ext3 journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'ext2',
                                                                                                  u'Ext2 file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'btrfs',
                                                                                                  u'btrfs journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'reiserfs',
                                                                                                  u'ReiserFS journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'jfs',
                                                                                                  u'JFS journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'xfs',
                                                                                                  u'XFS journaling file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'fat16',
                                                                                                  u'FAT16 file system'),
                                                                                                 (u'25filesystem',
                                                                                                  u'fat32',
                                                                                                  u'FAT32 file system'),
                                                                                                 (u'40swap',
                                                                                                  u'swap',
                                                                                                  u'swap area'),
                                                                                                 (u'70dont_use',
                                                                                                  u'dontuse',
                                                                                                  u'do not use the partition')],
                                                                              'parent': u'/dev/sdc',
                                                                              'parted': {'fs': 'ext4',
                                                                                         'id': '32256-5074997759',
                                                                                         'name': '',
                                                                                         'num': '1',
                                                                                         'path': '/dev/sdc1',
                                                                                         'size': '5074965504',
                                                                                         'type': 'primary'},
                                                                              'resize_max_size': 5074965504,
                                                                              'resize_min_size': 223928320,
                                                                              'resize_pref_size': 5074965504},
                     u'/var/lib/partman/devices/=dev=sdc//5075030016-5362882559': {'can_resize': True,
                                                                                   'detected_filesystem': 'linux-swap',
                                                                                   'dev': u'=dev=sdc',
                                                                                   'display': u'60partition_tree__________/var/lib/partman/devices/=dev=sdc//5075030016-5362882559',
                                                                                   'id': u'5075030016-5362882559',
                                                                                   'method': 'swap',
                                                                                   'method_choices': [(u'25filesystem',
                                                                                                       u'ext4',
                                                                                                       u'Ext4 journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'ext3',
                                                                                                       u'Ext3 journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'ext2',
                                                                                                       u'Ext2 file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'btrfs',
                                                                                                       u'btrfs journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'reiserfs',
                                                                                                       u'ReiserFS journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'jfs',
                                                                                                       u'JFS journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'xfs',
                                                                                                       u'XFS journaling file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'fat16',
                                                                                                       u'FAT16 file system'),
                                                                                                      (u'25filesystem',
                                                                                                       u'fat32',
                                                                                                       u'FAT32 file system'),
                                                                                                      (u'40swap',
                                                                                                       u'swap',
                                                                                                       u'swap area'),
                                                                                                      (u'70dont_use',
                                                                                                       u'dontuse',
                                                                                                       u'do not use the partition')],
                                                                                   'parent': u'/dev/sdc',
                                                                                   'parted': {'fs': 'linux-swap',
                                                                                              'id': '5075030016-5362882559',
                                                                                              'name': '',
                                                                                              'num': '5',
                                                                                              'path': '/dev/sdc5',
                                                                                              'size': '287852544',
                                                                                              'type': 'logical'},
                                                                                   'resize_max_size': 287852544,
                                                                                   'resize_min_size': 4096,
                                                                                   'resize_pref_size': 287852544}}

    win.update(disk_cache, partition_cache, cache_order)
    win.update(disk_cache, partition_cache, cache_order)

    sys.exit(app.exec_())
