Changeset View
Changeset View
Standalone View
Standalone View
scan/sanedialog.cpp
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 62 | if (!m_openDev.isEmpty()) { | |||
---|---|---|---|---|---|
63 | return true; | 63 | return true; | ||
64 | } | 64 | } | ||
65 | // need to select a scanner | 65 | // need to select a scanner | ||
66 | m_openDev = m_ksanew->selectDevice(nullptr); | 66 | m_openDev = m_ksanew->selectDevice(nullptr); | ||
67 | if (m_openDev.isEmpty()) { | 67 | if (m_openDev.isEmpty()) { | ||
68 | // either no scanner was found or then cancel was pressed. | 68 | // either no scanner was found or then cancel was pressed. | ||
69 | return false; | 69 | return false; | ||
70 | } | 70 | } | ||
71 | if (m_ksanew->openDevice(m_openDev) == false) { | 71 | if (!m_ksanew->openDevice(m_openDev)) { | ||
72 | // could not open the scanner | 72 | // could not open the scanner | ||
73 | KMessageBox::sorry(nullptr, i18n("Opening the selected scanner failed.")); | 73 | KMessageBox::sorry(nullptr, i18n("Opening the selected scanner failed.")); | ||
74 | m_openDev = QString(); | 74 | m_openDev = QString(); | ||
75 | return false; | 75 | return false; | ||
76 | } | 76 | } | ||
77 | 77 | | |||
78 | // restore scan dialog size and all options for the selected device if available | 78 | // restore scan dialog size and all options for the selected device if available | ||
79 | KSharedConfigPtr configPtr = KSharedConfig::openConfig("scannersettings"); | 79 | KSharedConfigPtr configPtr = KSharedConfig::openConfig("scannersettings"); | ||
80 | KWindowConfig::restoreWindowSize(windowHandle(), KConfigGroup(configPtr, "ScanDialog")); | 80 | KWindowConfig::restoreWindowSize(windowHandle(), KConfigGroup(configPtr, "ScanDialog")); | ||
81 | QString groupName = m_openDev; | 81 | QString groupName = m_openDev; | ||
82 | if (configPtr->hasGroup(groupName)) { | 82 | if (configPtr->hasGroup(groupName)) { | ||
83 | KConfigGroup group(configPtr, groupName); | 83 | KConfigGroup group(configPtr, groupName); | ||
84 | QStringList keys = group.keyList(); | 84 | QStringList keys = group.keyList(); | ||
85 | for (int i = 0; i < keys.count(); i++) | 85 | for (int i = 0; i < keys.count(); i++) { | ||
86 | m_ksanew->setOptVal(keys[i], group.readEntry(keys[i])); | 86 | m_ksanew->setOptVal(keys[i], group.readEntry(keys[i])); | ||
87 | } | 87 | } | ||
88 | } | ||||
88 | 89 | | |||
89 | return true; | 90 | return true; | ||
90 | } | 91 | } | ||
91 | 92 | | |||
92 | SaneDialog::~SaneDialog() | 93 | SaneDialog::~SaneDialog() | ||
93 | { | 94 | { | ||
94 | if (m_ksanew && !m_openDev.isEmpty()) { | 95 | if (m_ksanew && !m_openDev.isEmpty()) { | ||
95 | // save scan dialog size and all options for the selected device if available | 96 | // save scan dialog size and all options for the selected device if available | ||
96 | KSharedConfigPtr configPtr = KSharedConfig::openConfig("scannersettings"); | 97 | KSharedConfigPtr configPtr = KSharedConfig::openConfig("scannersettings"); | ||
97 | KConfigGroup group(configPtr, "ScanDialog"); | 98 | KConfigGroup group(configPtr, "ScanDialog"); | ||
98 | KWindowConfig::saveWindowSize(windowHandle(), group, KConfigGroup::Persistent); | 99 | KWindowConfig::saveWindowSize(windowHandle(), group, KConfigGroup::Persistent); | ||
99 | group = configPtr->group(m_openDev); | 100 | group = configPtr->group(m_openDev); | ||
100 | QMap<QString, QString> opts; | 101 | QMap<QString, QString> opts; | ||
101 | m_ksanew->getOptVals(opts); | 102 | m_ksanew->getOptVals(opts); | ||
102 | QMap<QString, QString>::const_iterator i = opts.constBegin(); | 103 | QMap<QString, QString>::const_iterator i = opts.constBegin(); | ||
103 | for (; i != opts.constEnd(); ++i) | 104 | for (; i != opts.constEnd(); ++i) { | ||
104 | group.writeEntry(i.key(), i.value(), KConfigGroup::Persistent); | 105 | group.writeEntry(i.key(), i.value(), KConfigGroup::Persistent); | ||
105 | } | 106 | } | ||
106 | } | 107 | } | ||
108 | } | ||||
107 | 109 | | |||
108 | void SaneDialog::imageReady(QByteArray &data, int w, int h, int bpl, int f) | 110 | void SaneDialog::imageReady(QByteArray &data, int w, int h, int bpl, int f) | ||
109 | { | 111 | { | ||
110 | /* copy the image data into img */ | 112 | /* copy the image data into img */ | ||
111 | QImage img = m_ksanew->toQImage(data, w, h, bpl, static_cast<KSaneIface::KSaneWidget::ImageFormat> (f)); | 113 | QImage img = m_ksanew->toQImage(data, w, h, bpl, static_cast<KSaneIface::KSaneWidget::ImageFormat> (f)); | ||
112 | emit finalImage(img, nextId()); | 114 | emit finalImage(img, nextId()); | ||
113 | } | 115 | } | ||
114 | 116 | | |||
115 | int SaneDialog::nextId() | 117 | int SaneDialog::nextId() | ||
116 | { | 118 | { | ||
117 | return ++m_currentId; | 119 | return ++m_currentId; | ||
118 | } | 120 | } |