Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Copyright: None
License: CC0-1.0

# Project file
Files: *.pro *.pri *.qrc *.ts *.sh .tx/*
Files: *.pro *.pri *.qrc *.ts *.sh .tx/* src/Printer/policy/canon*
Copyright: None
License: CC0-1.0

Expand Down
16 changes: 16 additions & 0 deletions src/Common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,3 +667,19 @@ bool isIpv4Address(const QString &str)
return reg.match(str).hasMatch();
}

int managerCanonPrinter(const QString &action, const QStringList &args)
{
QDBusInterface interface("com.deepin.printer.manager", "/com/deepin/printer/manager", "com.deepin.printer.manager", QDBusConnection::systemBus());
QDBusReply<int> ret;
if (action == "add") {
ret = interface.call("CanonPrinterInstall", args);
} else {
ret = interface.call("CanonPrinterRemove", args);
}

if (ret.isValid()) {
return ret;
}

return 0;
}
1 change: 1 addition & 0 deletions src/Common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ typedef void (*pfWriteEventLog)(const std::string &);
pfWriteEventLog getWriteEventLog();
void unloadEventLib();

int managerCanonPrinter(const QString &action, const QStringList &args);
#endif // COMMON_H
9 changes: 8 additions & 1 deletion src/Common/vendor/addprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,14 @@ int AddCanonCAPTPrinter::addPrinter()
}

qCDebug(COMMONMOUDLE) << "ppdname : " << ppd_name << "printInfo: " << printInfo;
m_proc.start("pkexec", QStringList {g_captexec, m_printer.strName, ppd_name, printInfo});
int ret = managerCanonPrinter("add", QStringList {m_printer.strName, ppd_name, printInfo});

m_proc.setProcessChannelMode(QProcess::ForwardedChannels);
if (ret != 0) {
emit m_proc.finished(ret, QProcess::CrashExit);
} else {
emit m_proc.finished(ret, QProcess::NormalExit);
}

return 1;
}
Expand Down
7 changes: 5 additions & 2 deletions src/Printer/Printer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,13 @@ dconfigfile.files = $${PWD}/logconf/org.deepin.dde.printer.json
debugconf.path = $${PREFIX}/share/deepin-debug-config/deepin-debug-config.d
debugconf.files = $${PWD}/logconf/dde-printer_debug.json

logconf.path = $${PREFIX}//share/deepin-log-viewer/deepin-log.conf.d
logconf.path = $${PREFIX}/share/deepin-log-viewer/deepin-log.conf.d
logconf.files = $${PWD}/logconf/dde-printer.json

INSTALLS += target desktop hicolor trans polkit dconfigfile debugconf logconf
canonscript.path = /opt/printer-drivers/cndrvcups-capt/
canonscript.files = $${PWD}/policy/canon*

INSTALLS += target desktop hicolor trans polkit dconfigfile debugconf logconf canonscript
}

#从debian/rules里面获取定义好的VERSION,然后转成字符串
Expand Down
36 changes: 36 additions & 0 deletions src/Printer/policy/canonadd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#! /bin/bash

# 此脚本用于添加LBP capt系列打印机,脚本自带参数为3个
# 参数1[打印机名称];参数2[打印机驱动文件路径];参数3[usb:打印机serial | net:ipaddr]

if [[ $# -eq 0 ]]; then
echo "Usage add printer: $0 printer_name ppdfile usb:serialnumber [net:ipaddr]"
echo "example:"
echo " $0 LBP2900 CNCUPSLBP2900CAPTK.ppd [usb:0000XXXX | net:192.168.0.1]"
exit 0
fi

# 如果已经添加不再添加
devinfo=${3:4}
ccpdadmin | grep -q $devinfo && exit 2

model_path=/usr/share/cups/model/

serial=""
if [[ $3 == "usb"* ]]; then
serial=/$devinfo
fi

lpadmin -p $1 -v ccp://localhost:59687$serial -P "$model_path$2" -E || exit 1
ccpdadmin | grep "invalid Spool Name" | awk '{print $3}' | while read -r name; do ccpdadmin -x $name; done

if [[ $3 == "usb"* ]]; then
ccpdadmin -p $1 -o /dev/capt/$devinfo | grep -q $1 || exit 1
else
ccpdadmin -p $1 -o $3 | grep -q $1 || exit 1
fi

systemctl restart ccpd.service
systemctl enable ccpd.service

exit 0
20 changes: 20 additions & 0 deletions src/Printer/policy/canonremove
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /bin/bash

# 此脚本用于删除LBP capt系列打印机,脚本自带参数为1个
# 参数1[打印机名称](删除对应名称的打印机)

if [[ $# -eq 0 ]]; then
echo "Usage del printer: $0 printer_name"
echo "example:"
echo " $0 LBP2900"
exit 0
fi

ccpdadmin | grep "invalid Spool Name" | awk '{print $3}' | while read -r name; do ccpdadmin -x $name; done

ccpdadmin -x $1

systemctl restart ccpd.service
systemctl enable ccpd.service

exit 0
9 changes: 4 additions & 5 deletions src/Printer/ui/dprintersshowwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@

#define FAQDOCUMENT_MESSAGE QObject::tr("Help on adding and using printers")

static const QString canonRemove = "/opt/cndrvcups-capt/remove";
static const QString canonRemove = "/opt/printer-drivers/cndrvcups-capt/canonremove";

static bool isCanonCaptPrinter(QString printerName)
static bool isCanonCaptPrinter(const QString &printerName)
{
QString printerUri = getPrinterUri(printerName.toUtf8().data());
if (printerUri.contains("ccp://")) {
Expand Down Expand Up @@ -767,9 +767,8 @@ void DPrintersShowWindow::deletePrinterClickSlot()
if (isCanonCaptPrinter(printerName)) { // 判断是否canon capt打印机
QFile file(canonRemove);
if (file.exists()) {
QProcess p;
ret = p.execute("pkexec", QStringList {canonRemove, printerName});
if (ret != 0) {
int bret = managerCanonPrinter("remove", QStringList{printerName});
if (bret != 0) {
return;
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/service/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ void Service::LaunchAutoStart(const QString &filePath)
QProcess::startDetached(scriptPath, QStringList() << "-c");
return;
}

int Service::CanonPrinterInstall(const QStringList &args)
{
m_proc->start("/opt/printer-drivers/cndrvcups-capt/canonadd", args);
m_proc->waitForFinished();
return m_proc->exitCode();
}

int Service::CanonPrinterRemove(const QStringList &args)
{
m_proc->start("/opt/printer-drivers/cndrvcups-capt/canonremove", args);
m_proc->waitForFinished();
return m_proc->exitCode();
}
2 changes: 2 additions & 0 deletions src/service/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Service : public QObject

public slots:
void LaunchAutoStart(const QString &filePath);
int CanonPrinterInstall(const QStringList &args);
int CanonPrinterRemove(const QStringList &args);

private:
QProcess *m_proc;
Expand Down