Browse Source

Improved media manager dcop interface for mount/unmount/decrypt/undecrypt methods by returning more information.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
undefined
Michele Calgaro 1 month ago
parent
commit
9ecd1aadb6
Signed by: Michele Calgaro <michele.calgaro@yahoo.it> GPG Key ID: 2A75B7CA8ADED5CF

+ 10
- 6
tdeioslave/media/mediaimpl.cpp View File

@@ -266,12 +266,16 @@ bool MediaImpl::ensureMediumMounted(Medium &medium)
266 266
 
267 267
 		DCOPRef mediamanager("kded", "mediamanager");
268 268
 		DCOPReply reply = mediamanager.call( "mount", medium.id());
269
-		if (reply.isValid())
270
-		  reply.get(m_lastErrorMessage);
271
-		else
272
-		  m_lastErrorMessage = i18n("Internal Error");
273
-		if (!m_lastErrorMessage.isEmpty())
274
-		  m_lastErrorCode = TDEIO::ERR_SLAVE_DEFINED;
269
+		TQStringVariantMap mountResult;
270
+		if (reply.isValid()) {
271
+			reply.get(mountResult);
272
+		}
273
+		if (!mountResult.contains("result") || !mountResult["result"].toBool()) {
274
+			m_lastErrorMessage = mountResult.contains("errStr") ? mountResult["errStr"].toString() : i18n("Unknown mount error.");
275
+		}
276
+		if (!m_lastErrorMessage.isEmpty()) {
277
+			m_lastErrorCode = TDEIO::ERR_SLAVE_DEFINED;
278
+		}
275 279
 		else {
276 280
 		  tqApp->eventLoop()->enterLoop();
277 281
 		}

+ 24
- 14
tdeioslave/media/mediamanager/fstabbackend.cpp View File

@@ -97,24 +97,34 @@ FstabBackend::~FstabBackend()
97 97
         KDirWatch::self()->removeFile(MTAB);
98 98
 }
99 99
 
100
-TQString FstabBackend::mount( const TQString &_udi )
100
+TQStringVariantMap FstabBackend::mount(const TQString &id)
101 101
 {
102
-    const Medium* medium = m_mediaList.findById(_udi);
103
-    if (!medium)
104
-        return i18n("No such medium: %1").arg(_udi);
105
-    TDEIO::Job* job = TDEIO::mount( false, 0, medium->deviceNode(), medium->mountPoint());
106
-    TDEIO::NetAccess::synchronousRun( job, 0 );
107
-    return TQString::null;
102
+		TQStringVariantMap result;
103
+    const Medium *medium = m_mediaList.findById(id);
104
+    if (!medium) {
105
+			result["errStr"] = i18n("No such medium: %1").arg(id);
106
+			result["result"] = false;
107
+			return result;
108
+		}
109
+    TDEIO::Job *job = TDEIO::mount(false, 0, medium->deviceNode(), medium->mountPoint());
110
+    TDEIO::NetAccess::synchronousRun(job, 0);
111
+		result["result"] = true;
112
+		return result;
108 113
 }
109 114
 
110
-TQString FstabBackend::unmount( const TQString &_udi )
115
+TQStringVariantMap FstabBackend::unmount(const TQString &id)
111 116
 {
112
-    const Medium* medium = m_mediaList.findById(_udi);
113
-    if (!medium)
114
-        return i18n("No such medium: %1").arg(_udi);
115
-    TDEIO::Job* job = TDEIO::unmount( medium->mountPoint(),  false);
116
-    TDEIO::NetAccess::synchronousRun( job, 0 );
117
-    return TQString::null;
117
+		TQStringVariantMap result;
118
+    const Medium *medium = m_mediaList.findById(id);
119
+    if (!medium) {
120
+			result["errStr"] = i18n("No such medium: %1").arg(id);
121
+			result["result"] = false;
122
+			return result;
123
+		}
124
+    TDEIO::Job *job = TDEIO::unmount(medium->mountPoint(), false);
125
+    TDEIO::NetAccess::synchronousRun(job, 0);
126
+		result["result"] = true;
127
+		return result;
118 128
 }
119 129
 
120 130
 void FstabBackend::slotDirty(const TQString &path)

+ 4
- 4
tdeioslave/media/mediamanager/fstabbackend.h View File

@@ -1,5 +1,5 @@
1 1
 /* This file is part of the KDE Project
2
-   Copyright (c) 2004 Kévin Ottens <ervin ipsquad net>
2
+   Copyright (c) 2004 Kévin Ottens <ervin ipsquad net>
3 3
 
4 4
    This library is free software; you can redistribute it and/or
5 5
    modify it under the terms of the GNU Library General Public
@@ -23,7 +23,7 @@
23 23
 
24 24
 #include <tqobject.h>
25 25
 #include <tqstringlist.h>
26
-#include <tqmap.h>
26
+#include <tqvariant.h>
27 27
 
28 28
 #ifdef Q_OS_FREEBSD
29 29
 #include <tqtimer.h>
@@ -42,8 +42,8 @@ public:
42 42
                           TQString &mimeType, TQString &iconName,
43 43
 	                  TQString &label);
44 44
 
45
-	TQString mount(const TQString &id);
46
-	TQString unmount(const TQString &id);
45
+	TQStringVariantMap mount(const TQString &id);
46
+	TQStringVariantMap unmount(const TQString &id);
47 47
 
48 48
 private slots:
49 49
 	void slotDirty(const TQString &path);

+ 126
- 63
tdeioslave/media/mediamanager/halbackend.cpp View File

@@ -1449,10 +1449,13 @@ TQString HALBackend::isInFstab(const Medium *medium)
1449 1449
     return TQString::null;
1450 1450
 }
1451 1451
 
1452
-TQString HALBackend::mount(const Medium *medium)
1452
+TQStringVariantMap HALBackend::mount(const Medium *medium)
1453 1453
 {
1454
-    if (medium->isMounted())
1455
-        return TQString(); // that was easy
1454
+    TQStringVariantMap result;
1455
+    if (medium->isMounted()) {
1456
+        result["result"] = true;
1457
+        return result;
1458
+    }
1456 1459
 
1457 1460
     TQString mountPoint = isInFstab(medium);
1458 1461
     if (!mountPoint.isNull())
@@ -1463,24 +1466,27 @@ TQString HALBackend::mount(const Medium *medium)
1463 1466
 
1464 1467
         kdDebug() << "triggering user mount " << medium->deviceNode() << " " << mountPoint << " " << medium->id() << endl;
1465 1468
         TDEIO::Job *job = TDEIO::mount( false, 0, medium->deviceNode(), mountPoint );
1466
-        connect(job, TQT_SIGNAL( result (TDEIO::Job *)),
1467
-                TQT_SLOT( slotResult( TDEIO::Job *)));
1469
+        connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotResult(TDEIO::Job*)));
1468 1470
         mount_jobs[job] = &data;
1469 1471
         // The caller expects the device to be mounted when the function
1470 1472
         // completes. Thus block until the job completes.
1471 1473
         while (!data.completed) {
1472 1474
             kapp->eventLoop()->enterLoop();
1473 1475
         }
1474
-        // Return the error message (if any) to the caller
1475
-        return (data.error) ? data.errorMessage : TQString::null;
1476
-
1477
-    } else if (medium->id().startsWith("/org/kde/") )
1478
-	    return i18n("Permission denied");
1479
-
1480
-    TQStringList soptions;
1476
+        if (!data.error) {
1477
+            result["result"] = true;
1478
+            return result;
1479
+        }
1480
+        else {
1481
+            result["errStr"] = data.errorMessage; // Return the error message (if any) to the caller
1482
+            result["result"] = false;
1483
+            return result;
1484
+        }
1485
+    }
1481 1486
 
1482 1487
     kdDebug() << "mounting " << medium->id() << "..." << endl;
1483 1488
 
1489
+    TQStringList soptions;
1484 1490
     TQMap<TQString,TQString> valids = MediaManagerUtils::splitOptions(mountoptions(medium->id()));
1485 1491
     if (valids["flush"] == "true")
1486 1492
         soptions << "flush";
@@ -1508,7 +1514,6 @@ TQString HALBackend::mount(const Medium *medium)
1508 1514
     if (medium->fsType() == "ntfs") {
1509 1515
         TQString fsLocale("locale=");
1510 1516
         fsLocale += setlocale(LC_ALL, "");
1511
-
1512 1517
         soptions << fsLocale;
1513 1518
     }
1514 1519
 
@@ -1549,7 +1554,6 @@ TQString HALBackend::mount(const Medium *medium)
1549 1554
        }
1550 1555
     }
1551 1556
 
1552
-
1553 1557
     const char **options = new const char*[soptions.size() + 1];
1554 1558
     uint noptions = 0;
1555 1559
     for (TQStringList::ConstIterator it = soptions.begin(); it != soptions.end(); ++it, ++noptions)
@@ -1559,13 +1563,13 @@ TQString HALBackend::mount(const Medium *medium)
1559 1563
     }
1560 1564
     options[noptions] = NULL;
1561 1565
 
1562
-    TQString qerror = i18n("Cannot mount encrypted drives!");
1563
-
1566
+    TQString qerror;
1564 1567
     if (!medium->isEncrypted()) {
1565 1568
         // normal volume
1566 1569
     	qerror = mount_priv(medium->id().latin1(), mount_point.utf8(), options, noptions, dbus_connection);
1567 1570
     } else {
1568 1571
         // see if we have a clear volume
1572
+        error = i18n("Cannot mount encrypted drives!");
1569 1573
         LibHalVolume* halVolume = libhal_volume_from_udi(m_halContext, medium->id().latin1());
1570 1574
         if (halVolume) {
1571 1575
             char* clearUdi = libhal_volume_crypto_get_clear_volume_udi(m_halContext, halVolume);
@@ -1579,45 +1583,59 @@ TQString HALBackend::mount(const Medium *medium)
1579 1583
 
1580 1584
     if (!qerror.isEmpty()) {
1581 1585
         kdError() << "mounting " << medium->id() << " returned " << qerror << endl;
1582
-        return qerror;
1586
+        result["errStr"] = qerror;
1587
+        result["result"] = false;
1588
+        return result;
1583 1589
     }
1584 1590
 
1585 1591
     medium->setHalMounted(true);
1586 1592
     ResetProperties(medium->id().latin1());
1587 1593
 
1588
-    return TQString();
1594
+    result["result"] = true;
1595
+    return result;
1589 1596
 }
1590 1597
 
1591
-TQString HALBackend::mount(const TQString &_udi)
1598
+TQStringVariantMap HALBackend::mount(const TQString &id)
1592 1599
 {
1593
-    const Medium* medium = m_mediaList.findById(_udi);
1594
-    if (!medium)
1595
-        return i18n("No such medium: %1").arg(_udi);
1596
-
1597
-    return mount(medium);
1600
+	const Medium *medium = m_mediaList.findById(id);
1601
+	if (!medium) {
1602
+		TQStringVariantMap result;
1603
+		result["errStr"] = i18n("No such medium: %1").arg(id);
1604
+		result["result"] = false;
1605
+		return result;
1606
+	}
1607
+	return mount(medium);
1598 1608
 }
1599 1609
 
1600
-TQString HALBackend::unmount(const TQString &_udi)
1610
+TQStringVariantMap HALBackend::unmount(const TQString &id)
1601 1611
 {
1602
-    const Medium* medium = m_mediaList.findById(_udi);
1612
+    TQStringVariantMap result;
1613
+
1614
+    const Medium* medium = m_mediaList.findById(id);
1603 1615
     if (!medium)
1604
-    {   // now we get fancy: if the udi is no volume, it _might_ be a device with only one
1616
+    {
1617
+        // now we get fancy: if the udi is no volume, it _might_ be a device with only one
1605 1618
         // volume on it (think CDs) - so we're so nice to the caller to unmount that volume
1606
-        LibHalDrive*  halDrive  = libhal_drive_from_udi(m_halContext, _udi.latin1());
1619
+        LibHalDrive*  halDrive  = libhal_drive_from_udi(m_halContext, id.latin1());
1607 1620
         if (halDrive)
1608 1621
         {
1609 1622
             int numVolumes;
1610 1623
             char** volumes = libhal_drive_find_all_volumes(m_halContext, halDrive, &numVolumes);
1611 1624
             if (numVolumes == 1)
1612
-                medium = m_mediaList.findById( volumes[0] );
1625
+                medium = m_mediaList.findById(volumes[0]);
1613 1626
         }
1614 1627
     }
1615 1628
 
1616
-    if ( !medium )
1617
-        return i18n("No such medium: %1").arg(_udi);
1629
+    if (!medium) {
1630
+        result["errStr"] = i18n("No such medium: %1").arg(id);
1631
+        result["result"] = false;
1632
+        return result;
1633
+    }
1618 1634
 
1619 1635
     if (!medium->isMounted())
1620
-        return TQString(); // that was easy
1636
+        result["result"] = true;
1637
+        return result;
1638
+    }
1621 1639
 
1622 1640
     TQString mountPoint = isInFstab(medium);
1623 1641
     if (!mountPoint.isNull())
@@ -1628,16 +1646,22 @@ TQString HALBackend::unmount(const TQString &_udi)
1628 1646
 
1629 1647
         kdDebug() << "triggering user unmount " << medium->deviceNode() << " " << mountPoint << endl;
1630 1648
         TDEIO::Job *job = TDEIO::unmount( medium->mountPoint(), false );
1631
-        connect(job, TQT_SIGNAL( result (TDEIO::Job *)),
1632
-                TQT_SLOT( slotResult( TDEIO::Job *)));
1649
+        connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotResult(TDEIO::Job*)));
1633 1650
         mount_jobs[job] = &data;
1634 1651
         // The caller expects the device to be unmounted when the function
1635 1652
         // completes. Thus block until the job completes.
1636 1653
         while (!data.completed) {
1637 1654
             kapp->eventLoop()->enterLoop();
1638 1655
         }
1639
-        // Return the error message (if any) to the caller
1640
-        return (data.error) ? data.errorMessage : TQString::null;
1656
+        if (!data.error) {
1657
+            result["result"] = true;
1658
+            return result;
1659
+        }
1660
+        else {
1661
+            result["errStr"] = data.errorMessage; // Return the error message (if any) to the caller
1662
+            result["result"] = false;
1663
+            return result;
1664
+        }
1641 1665
     }
1642 1666
 
1643 1667
     DBusMessage *dmesg, *reply;
@@ -1660,7 +1684,9 @@ TQString HALBackend::unmount(const TQString &_udi)
1660 1684
     }
1661 1685
     if (udi.isNull()) {
1662 1686
         kdDebug() << "unmount failed: no udi" << endl;
1663
-        return i18n("Internal Error");
1687
+        result["errStr"] = i18n("Internal error");
1688
+        result["result"] = false;
1689
+        return result;
1664 1690
     }
1665 1691
 
1666 1692
     kdDebug() << "unmounting " << udi << "..." << endl;
@@ -1670,14 +1696,18 @@ TQString HALBackend::unmount(const TQString &_udi)
1670 1696
     if (dbus_error_is_set(&error))
1671 1697
     {
1672 1698
         dbus_error_free(&error);
1673
-        return TQString();
1699
+        result["errStr"] = i18n("Unknown error");
1700
+        result["result"] = false;
1701
+        return result;
1674 1702
     }
1675 1703
 
1676 1704
     if (!(dmesg = dbus_message_new_method_call ("org.freedesktop.Hal", udi.latin1(),
1677 1705
                                                 "org.freedesktop.Hal.Device.Volume",
1678 1706
                                                 "Unmount"))) {
1679 1707
         kdDebug() << "unmount failed for " << udi << ": could not create dbus message\n";
1680
-        return i18n("Internal Error");
1708
+        result["errStr"] = i18n("Internal error");
1709
+        result["result"] = false;
1710
+        return result;
1681 1711
     }
1682 1712
 
1683 1713
     options[0] = "force";
@@ -1688,7 +1718,9 @@ TQString HALBackend::unmount(const TQString &_udi)
1688 1718
     {
1689 1719
         kdDebug() << "unmount failed for " << udi << ": could not append args to dbus message\n";
1690 1720
         dbus_message_unref (dmesg);
1691
-        return i18n("Internal Error");
1721
+        result["errStr"] = i18n("Internal error");
1722
+        result["result"] = false;
1723
+        return result;
1692 1724
     }
1693 1725
 
1694 1726
     char thisunmounthasfailed = 0;
@@ -1704,14 +1736,14 @@ TQString HALBackend::unmount(const TQString &_udi)
1704 1736
             if (qerror.isEmpty()) {
1705 1737
                 dbus_message_unref(dmesg);
1706 1738
                 dbus_error_free(&error);
1707
-                return TQString();
1739
+                result["result"] = true;
1740
+                return result;
1708 1741
             }
1709 1742
 
1710 1743
             // @todo handle unmount error message
1711 1744
         }
1712 1745
         
1713 1746
         kdDebug() << "unmount failed for " << udi << ": " << error.name << " " << error.message << endl;
1714
-        qerror = "<qt>";
1715 1747
         qerror += "<p>" + i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and "
1716 1748
                        "currently mounted at <b>%4</b> could not be unmounted. ").arg(
1717 1749
                           "system:/media/" + medium->name(),
@@ -1750,7 +1782,9 @@ TQString HALBackend::unmount(const TQString &_udi)
1750 1782
         if (thisunmounthasfailed != 0) {
1751 1783
             dbus_message_unref (dmesg);
1752 1784
             dbus_error_free (&error);
1753
-            return qerror;
1785
+            result["errStr"] = qerror;
1786
+            result["result"] = false;
1787
+            return result;
1754 1788
         }
1755 1789
     }
1756 1790
 
@@ -1766,17 +1800,25 @@ TQString HALBackend::unmount(const TQString &_udi)
1766 1800
 
1767 1801
     while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ;
1768 1802
 
1769
-    return TQString();
1803
+    result["result"] = true;
1804
+    return result;
1770 1805
 }
1771 1806
 
1772
-TQString HALBackend::decrypt(const TQString &_udi, const TQString &password)
1807
+TQStringVariantMap HALBackend::decrypt(const TQString &id, const TQString &password)
1773 1808
 {
1774
-    const Medium* medium = m_mediaList.findById(_udi);
1775
-    if (!medium)
1776
-        return i18n("No such medium: %1").arg(_udi);
1809
+    TQStringVariantMap result;
1810
+
1811
+    const Medium *medium = m_mediaList.findById(id);
1812
+    if (!medium) {
1813
+        result["errStr"] = i18n("No such medium: %1").arg(id);
1814
+        result["result"] = false;
1815
+        return result;
1816
+    }
1777 1817
 
1778 1818
     if (!medium->isEncrypted() || !medium->clearDeviceUdi().isNull())
1779
-        return TQString();
1819
+        result["result"] = true;
1820
+        return result;
1821
+    }
1780 1822
 
1781 1823
     const char *udi = medium->id().latin1();
1782 1824
     DBusMessage *msg = NULL;
@@ -1790,7 +1832,9 @@ TQString HALBackend::decrypt(const TQString &_udi, const TQString &password)
1790 1832
                                         "Setup");
1791 1833
     if (msg == NULL) {
1792 1834
         kdDebug() << "decrypt failed for " << udi << ": could not create dbus message\n";
1793
-        return i18n("Internal Error");
1835
+        result["errStr"] = i18n("Internal error");
1836
+        result["result"] = false;
1837
+        return result;
1794 1838
     }
1795 1839
 
1796 1840
     TQCString pwdUtf8 = password.utf8();
@@ -1798,7 +1842,9 @@ TQString HALBackend::decrypt(const TQString &_udi, const TQString &password)
1798 1842
     if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &pwd_utf8, DBUS_TYPE_INVALID)) {
1799 1843
         kdDebug() << "decrypt failed for " << udi << ": could not append args to dbus message\n";
1800 1844
         dbus_message_unref (msg);
1801
-        return i18n("Internal Error");
1845
+        result["errStr"] = i18n("Internal error");
1846
+        result["result"] = false;
1847
+        return result;
1802 1848
     }
1803 1849
 
1804 1850
     dbus_error_init (&error);
@@ -1813,7 +1859,9 @@ TQString HALBackend::decrypt(const TQString &_udi, const TQString &password)
1813 1859
         dbus_error_free (&error);
1814 1860
         dbus_message_unref (msg);
1815 1861
         while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ;
1816
-        return qerror;
1862
+        result["errStr"] = qerror;
1863
+        result["result"] = false;
1864
+        return result;
1817 1865
     }
1818 1866
 
1819 1867
     dbus_message_unref (msg);
@@ -1821,17 +1869,25 @@ TQString HALBackend::decrypt(const TQString &_udi, const TQString &password)
1821 1869
 
1822 1870
     while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ;
1823 1871
 
1824
-    return TQString();
1872
+    result["result"] = true;
1873
+    return result;
1825 1874
 }
1826 1875
 
1827
-TQString HALBackend::undecrypt(const TQString &_udi)
1876
+TQStringVariantMap HALBackend::undecrypt(const TQString &id)
1828 1877
 {
1829
-    const Medium* medium = m_mediaList.findById(_udi);
1830
-    if (!medium)
1831
-        return i18n("No such medium: %1").arg(_udi);
1878
+    TQStringVariantMap result;
1832 1879
 
1833
-    if (!medium->isEncrypted() || medium->clearDeviceUdi().isNull())
1834
-        return TQString();
1880
+    const Medium *medium = m_mediaList.findById(id);
1881
+    if (!medium) {
1882
+        result["errStr"] = i18n("No such medium: %1").arg(id);
1883
+        result["result"] = false;
1884
+        return result;
1885
+    }
1886
+
1887
+    if (!medium->isEncrypted() || !medium->clearDeviceUdi().isNull())
1888
+        result["result"] = true;
1889
+        return result;
1890
+    }
1835 1891
 
1836 1892
     const char *udi = medium->id().latin1();
1837 1893
     DBusMessage *msg = NULL;
@@ -1845,13 +1901,17 @@ TQString HALBackend::undecrypt(const TQString &_udi)
1845 1901
                                         "Teardown");
1846 1902
     if (msg == NULL) {
1847 1903
         kdDebug() << "teardown failed for " << udi << ": could not create dbus message\n";
1848
-        return i18n("Internal Error");
1904
+        result["errStr"] = i18n("Internal error");
1905
+        result["result"] = false;
1906
+        return result;
1849 1907
     }
1850 1908
 
1851 1909
     if (!dbus_message_append_args (msg, DBUS_TYPE_INVALID)) {
1852 1910
         kdDebug() << "teardown failed for " << udi << ": could not append args to dbus message\n";
1853 1911
         dbus_message_unref (msg);
1854
-        return i18n("Internal Error");
1912
+        result["errStr"] = i18n("Internal error");
1913
+        result["result"] = false;
1914
+        return result;
1855 1915
     }
1856 1916
 
1857 1917
     dbus_error_init (&error);
@@ -1863,7 +1923,9 @@ TQString HALBackend::undecrypt(const TQString &_udi)
1863 1923
         dbus_error_free (&error);
1864 1924
         dbus_message_unref (msg);
1865 1925
         while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ;
1866
-        return qerror;
1926
+        result["errStr"] = qerror;
1927
+        result["result"] = false;
1928
+        return result;
1867 1929
     }
1868 1930
 
1869 1931
     dbus_message_unref (msg);
@@ -1873,7 +1935,8 @@ TQString HALBackend::undecrypt(const TQString &_udi)
1873 1935
 
1874 1936
     while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ;
1875 1937
 
1876
-    return TQString();
1938
+    result["result"] = true;
1939
+    return result;
1877 1940
 }
1878 1941
 
1879 1942
 #include "halbackend.moc"

+ 5
- 5
tdeioslave/media/mediamanager/halbackend.h View File

@@ -83,11 +83,11 @@ public:
83 83
 
84 84
 	bool setMountoptions(const TQString &id, const TQStringList &options);
85 85
 
86
-	TQString mount(const TQString &id);
87
-	TQString mount(const Medium *medium);
88
-	TQString unmount(const TQString &id);
89
-	TQString decrypt(const TQString &id, const TQString &password);
90
-	TQString undecrypt(const TQString &id);
86
+	TQStringVariantMap mount(const TQString &id);
87
+	TQStringVariantMap mount(const Medium *medium);
88
+	TQStringVariantMap unmount(const TQString &id);
89
+	TQStringVariantMap decrypt(const TQString &id, const TQString &password);
90
+	TQStringVariantMap undecrypt(const TQString &id);
91 91
 
92 92
 private:
93 93
 	/**

+ 103
- 60
tdeioslave/media/mediamanager/mediamanager.cpp View File

@@ -240,76 +240,119 @@ bool MediaManager::setMountoptions(const TQString &name, const TQStringList &opt
240 240
 #endif // COMPILE_HALBACKEND
241 241
 }
242 242
 
243
-TQString MediaManager::mount(const TQString &name)
243
+TQStringVariantMap MediaManager::mount(const TQString &uid)
244 244
 {
245
-#ifdef COMPILE_HALBACKEND
246
-	if (!m_halbackend)
247
-		return i18n("Feature only available with HAL");
248
-	return m_halbackend->mount(name);
249
-#else // COMPILE_HALBACKEND
250
-	#ifdef COMPILE_TDEHARDWAREBACKEND
251
-		if (!m_tdebackend)
252
-			return i18n("Feature only available with the TDE hardware backend");
253
-		return m_tdebackend->mount(name);
254
-	#else // COMPILE_TDEHARDWAREBACKEND
255
-		if ( !m_fstabbackend ) // lying :)
256
-			return i18n("Feature only available with HAL or TDE hardware backend");
257
-		return m_fstabbackend->mount( name );
258
-	#endif // COMPILE_TDEHARDWAREBACKEND
259
-#endif // COMPILE_HALBACKEND
245
+	TQStringVariantMap result;
246
+#ifdef COMPILE_TDEHARDWAREBACKEND
247
+	if (!m_tdebackend) {
248
+		result["errStr"] = i18n("Feature only available with the TDE hardware backend");
249
+		result["result"] = false;
250
+		return result;
251
+	}
252
+	return m_tdebackend->mount(uid);
253
+#elif defined COMPILE_HALBACKEND
254
+	if (!m_halbackend) {
255
+		result["errStr"] = i18n("Feature only available with HAL");
256
+		result["result"] = false;
257
+		return result;
258
+	}
259
+	return m_halbackend->mount(uid);
260
+#else
261
+	if (!m_fstabbackend) {
262
+		result["errStr"] = i18n("Feature only available with HAL or TDE hardware backend");
263
+		result["result"] = false;
264
+		return result;
265
+	}
266
+	return m_fstabbackend->mount(uid);
267
+#endif
260 268
 }
261 269
 
262
-TQString MediaManager::unmount(const TQString &name)
270
+TQStringVariantMap MediaManager::unmount(const TQString &uid)
263 271
 {
264
-#ifdef COMPILE_HALBACKEND
265
-	if (!m_halbackend)
266
-		return i18n("Feature only available with HAL");
267
-	return m_halbackend->unmount(name);
268
-#else // COMPILE_HALBACKEND
269
-	#ifdef COMPILE_TDEHARDWAREBACKEND
270
-		if (!m_tdebackend)
271
-			return i18n("Feature only available with HAL or TDE hardware backend");
272
-		return m_tdebackend->unmount(name);
273
-	#else // COMPILE_TDEHARDWAREBACKEND
274
-		if ( !m_fstabbackend ) // lying :)
275
-			return i18n("Feature only available with HAL or TDE hardware backend");
276
-		return m_fstabbackend->unmount( name );
277
-	#endif // COMPILE_TDEHARDWAREBACKEND
278
-#endif // COMPILE_HALBACKEND
272
+	TQStringVariantMap result;
273
+#ifdef COMPILE_TDEHARDWAREBACKEND
274
+	if (!m_tdebackend) {
275
+		result["errStr"] = i18n("Feature only available with the TDE hardware backend");
276
+		result["result"] = false;
277
+		return result;
278
+	}
279
+	return m_tdebackend->unmount(uid);
280
+#elif defined COMPILE_HALBACKEND
281
+	if (!m_halbackend) {
282
+		result["errStr"] = i18n("Feature only available with HAL");
283
+		result["result"] = false;
284
+		return result;
285
+	}
286
+	return m_halbackend->unmount(uid);
287
+#else
288
+	if (!m_fstabbackend) {
289
+		result["errStr"] = i18n("Feature only available with HAL or TDE hardware backend");
290
+		result["result"] = false;
291
+		return result;
292
+	}
293
+	return m_fstabbackend->unmount(uid);
294
+#endif
279 295
 }
280 296
 
281
-TQString MediaManager::decrypt(const TQString &name, const TQString &password)
297
+TQStringVariantMap MediaManager::decrypt(const TQString &uid, const TQString &password)
282 298
 {
283
-#ifdef COMPILE_HALBACKEND
284
-	if (!m_halbackend)
285
-		return i18n("Feature only available with HAL");
286
-	return m_halbackend->decrypt(name, password);
287
-#else // COMPILE_HALBACKEND
288
-// 	#ifdef COMPILE_TDEHARDWAREBACKEND
289
-// 		if (!m_tdebackend)
290
-// 			return i18n("Feature only available with HAL or TDE hardware backend");
291
-// 		return m_tdebackend->decrypt(name, password);
292
-// 	#else // COMPILE_TDEHARDWAREBACKEND
293
-		return i18n("Feature only available with HAL");
294
-// 	#endif // COMPILE_TDEHARDWAREBACKEND
295
-#endif // COMPILE_HALBACKEND
299
+	TQStringVariantMap result;
300
+/*
301
+#ifdef COMPILE_TDEHARDWAREBACKEND
302
+	if (!m_tdebackend) {
303
+		result["errStr"] = i18n("Feature only available with the TDE hardware backend");
304
+		result["result"] = false;
305
+		return result;
306
+	}
307
+	return m_tdebackend->decrypt(uid, password);
308
+#elif defined COMPILE_HALBACKEND
309
+*/
310
+#if defined COMPILE_HALBACKEND
311
+	if (!m_halbackend) {
312
+		result["errStr"] = i18n("Feature only available with HAL");
313
+		result["result"] = false;
314
+		return result;
315
+	}
316
+	return m_halbackend->decrypt(uid, password);
317
+
318
+#else
319
+//	if (!m_fstabbackend) {
320
+		result["errStr"] = i18n("Feature only available with HAL or TDE hardware backend");
321
+		result["result"] = false;
322
+		return result;
323
+//	}
324
+//	return m_fstabbackend->decrypt(uid, password);
325
+#endif
296 326
 }
297 327
 
298
-TQString MediaManager::undecrypt(const TQString &name)
328
+TQStringVariantMap MediaManager::undecrypt(const TQString &uid)
299 329
 {
300
-#ifdef COMPILE_HALBACKEND
301
-	if (!m_halbackend)
302
-		return i18n("Feature only available with HAL");
303
-	return m_halbackend->undecrypt(name);
304
-#else // COMPILE_HALBACKEND
305
-// 	#ifdef COMPILE_TDEHARDWAREBACKEND
306
-// 		if (!m_tdebackend)
307
-// 			return i18n("Feature only available with HAL or TDE hardware backend");
308
-// 		return m_tdebackend->undecrypt(name);
309
-// 	#else // COMPILE_TDEHARDWAREBACKEND
310
-		return i18n("Feature only available with HAL");
311
-// 	#endif // COMPILE_TDEHARDWAREBACKEND
312
-#endif // COMPILE_HALBACKEND
330
+	TQStringVariantMap result;
331
+/*
332
+#ifdef COMPILE_TDEHARDWAREBACKEND
333
+	if (!m_tdebackend) {
334
+		result["errStr"] = i18n("Feature only available with the TDE hardware backend");
335
+		result["result"] = false;
336
+		return result;
337
+	}
338
+	return m_tdebackend->undecrypt(uid);
339
+#elif defined COMPILE_HALBACKEND
340
+*/
341
+#if defined COMPILE_HALBACKEND
342
+	if (!m_halbackend) {
343
+		result["errStr"] = i18n("Feature only available with HAL");
344
+		result["result"] = false;
345
+		return result;
346
+	}
347
+	return m_halbackend->undecrypt(uid);
348
+#else
349
+//	if (!m_fstabbackend) {
350
+		result["errStr"] = i18n("Feature only available with HAL or TDE hardware backend");
351
+		result["result"] = false;
352
+		return result;
353
+//	}
354
+//	return m_fstabbackend->undecrypt(uid);
355
+#endif
313 356
 }
314 357
 
315 358
 TQString MediaManager::nameForLabel(const TQString &label)

+ 5
- 4
tdeioslave/media/mediamanager/mediamanager.h View File

@@ -22,6 +22,7 @@
22 22
 #include <kdedmodule.h>
23 23
 #include <tqstring.h>
24 24
 #include <tqstringlist.h>
25
+#include <tqvariant.h>
25 26
 
26 27
 #include "medialist.h"
27 28
 #include "backendbase.h"
@@ -46,10 +47,10 @@ k_dcop:
46 47
 	TQStringList mountoptions(const TQString &name);
47 48
 	bool setMountoptions(const TQString &name, const TQStringList &options);
48 49
 
49
-	TQString mount(const TQString &uid);
50
-	TQString unmount(const TQString &uid);
51
-	TQString decrypt(const TQString &uid, const TQString &password);
52
-	TQString undecrypt(const TQString &uid);
50
+	TQStringVariantMap mount(const TQString &uid);
51
+	TQStringVariantMap unmount(const TQString &uid);
52
+	TQStringVariantMap decrypt(const TQString &uid, const TQString &password);
53
+	TQStringVariantMap undecrypt(const TQString &uid);
53 54
 
54 55
 	TQString nameForLabel(const TQString &label);
55 56
 	ASYNC setUserLabel(const TQString &name, const TQString &label);

+ 101
- 76
tdeioslave/media/mediamanager/tdehardwarebackend.cpp View File

@@ -50,15 +50,6 @@
50 50
 	(medium->isEncrypted() ? (sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt) ? "-decrypted" : "-encrypted") : "" )			\
51 51
 	)
52 52
 
53
-#define CHECK_FOR_AND_EXECUTE_AUTOMOUNT(udi, medium, allowNotification) {									\
54
-		TQMap<TQString,TQString> options = MediaManagerUtils::splitOptions(mountoptions(udi));						\
55
-		kdDebug(1219) << "automount " << options["automount"] << endl;									\
56
-		if (options["automount"] == "true" && allowNotification ) {									\
57
-			TQString error = mount(medium);												\
58
-			if (!error.isEmpty())													\
59
-			kdDebug(1219) << "error " << error << endl;										\
60
-		}																\
61
-	}
62 53
 
63 54
 /* Constructor */
64 55
 TDEBackend::TDEBackend(MediaList &list, TQObject* parent)
@@ -208,7 +199,15 @@ void TDEBackend::AddDevice(TDEStorageDevice * sdevice, bool allowNotification)
208 199
 			kdDebug(1219) << "TDEBackend::AddDevice inserted hard medium for " << sdevice->uniqueID() << endl;
209 200
 
210 201
 			// Automount if enabled
211
-			CHECK_FOR_AND_EXECUTE_AUTOMOUNT(sdevice->uniqueID(), medium, allowNotification)
202
+			TQMap<TQString,TQString> options = MediaManagerUtils::splitOptions(mountoptions(sdevice->uniqueID()));
203
+			kdDebug(1219) << "automount " << options["automount"] << endl;
204
+			if (options["automount"] == "true" && allowNotification ) {
205
+				TQStringVariantMap mountResult = mount(medium);
206
+				if (!mountResult["result"].toBool()) {
207
+					TQString error = mountResult.contains("errStr") ? mountResult["errStr"].toString() : i18n("Unknown mount error.");
208
+					kdDebug(1219) << "error " << error << endl;
209
+				}
210
+			}
212 211
 		}
213 212
 	}
214 213
 
@@ -251,7 +250,15 @@ void TDEBackend::AddDevice(TDEStorageDevice * sdevice, bool allowNotification)
251 250
 		kdDebug(1219) << "TDEBackend::AddDevice inserted optical medium for " << sdevice->uniqueID() << endl;
252 251
 
253 252
 		// Automount if enabled
254
-		CHECK_FOR_AND_EXECUTE_AUTOMOUNT(sdevice->uniqueID(), medium, allowNotification)
253
+		TQMap<TQString,TQString> options = MediaManagerUtils::splitOptions(mountoptions(sdevice->uniqueID()));
254
+		kdDebug(1219) << "automount " << options["automount"] << endl;
255
+		if (options["automount"] == "true" && allowNotification ) {
256
+			TQStringVariantMap mountResult = mount(medium);
257
+			if (!mountResult["result"].toBool()) {
258
+				TQString error = mountResult.contains("errStr") ? mountResult["errStr"].toString() : i18n("Unknown mount error.");
259
+				kdDebug(1219) << "error " << error << endl;
260
+			}
261
+		}
255 262
 	}
256 263
 
257 264
 	// Floppy & zip drives
@@ -1179,49 +1186,55 @@ void TDEBackend::slotPasswordCancel() {
1179 1186
 	m_decryptPasswordValid = true;
1180 1187
 }
1181 1188
 
1182
-TQString TDEBackend::mount(const Medium *medium)
1189
+TQStringVariantMap TDEBackend::mount(const Medium *medium)
1183 1190
 {
1191
+	TQStringVariantMap result;
1184 1192
 	if (medium->isMounted()) {
1185
-		return TQString(); // that was easy
1193
+		result["result"] = true;
1194
+		return result;
1186 1195
 	}
1187 1196
 
1188 1197
 	TQString mountPoint = isInFstab(medium);
1189
-	if (!mountPoint.isNull())
1198
+	if (!mountPoint.isEmpty())
1190 1199
 	{
1191 1200
 		struct mount_job_data data;
1192 1201
 		data.completed = false;
1193 1202
 		data.medium = medium;
1194 1203
 
1195
-		TDEIO::Job *job = TDEIO::mount( false, 0, medium->deviceNode(), mountPoint );
1196
-		connect(job, TQT_SIGNAL( result (TDEIO::Job *)), TQT_SLOT( slotResult( TDEIO::Job *)));
1204
+		TDEIO::Job *job = TDEIO::mount(false, 0, medium->deviceNode(), mountPoint);
1205
+		connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotResult(TDEIO::Job*)));
1197 1206
 		mount_jobs[job] = &data;
1198 1207
 		// The caller expects the device to be mounted when the function
1199 1208
 		// completes. Thus block until the job completes.
1200 1209
 		while (!data.completed) {
1201 1210
 			kapp->eventLoop()->enterLoop();
1202 1211
 		}
1203
-		// Return the error message (if any) to the caller
1204
-		return (data.error) ? data.errorMessage : TQString::null;
1205
-
1212
+		if (!data.error) {
1213
+			result["result"] = true;
1214
+			return result;
1215
+		}
1216
+		else {
1217
+			result["errStr"] = data.errorMessage; // Return the error message (if any) to the caller
1218
+			result["result"] = false;
1219
+			return result;
1220
+		}
1206 1221
 	}
1207 1222
 
1208 1223
 	TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
1209
-
1210
-	TDEStorageDevice * sdevice = hwdevices->findDiskByUID(medium->id());
1224
+	TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id());
1211 1225
 	if (!sdevice) {
1212
-		return i18n("Internal error");
1226
+		result["errStr"] = i18n("Internal error. Couldn't find medium.");
1227
+		result["result"] = false;
1228
+		return result;
1213 1229
 	}
1214 1230
 
1215
-	TQString diskLabel;
1216
-
1217 1231
 	TQMap<TQString,TQString> valids = MediaManagerUtils::splitOptions(mountoptions(medium->id()));
1218
-
1232
+	TQString diskLabel;
1219 1233
 	TQString mount_point = valids["mountpoint"];
1220 1234
 	if (mount_point.startsWith("/media/")) {
1221 1235
 		diskLabel = mount_point.mid(7);
1222 1236
 	}
1223
-
1224
-	if (diskLabel == "") {
1237
+	if (diskLabel.isEmpty()) {
1225 1238
 		// Try to use a pretty mount point if possible
1226 1239
 		TQStringList pieces = TQStringList::split("/", sdevice->deviceNode(), FALSE);
1227 1240
 		TQString node = pieces[pieces.count()-1];
@@ -1229,22 +1242,17 @@ TQString TDEBackend::mount(const Medium *medium)
1229 1242
 		diskLabel.replace("/", "_");
1230 1243
 	}
1231 1244
 
1232
-	TQString qerror = i18n("Cannot mount encrypted drives!");
1233
-
1245
+	TQString qerror;
1234 1246
 	if (!medium->isEncrypted()) {
1235 1247
 		// normal volume
1236 1248
 		TQStringVariantMap mountResult = sdevice->mountDevice(diskLabel, valids);
1237 1249
 		TQString mountedPath = mountResult.contains("mountPath") ? mountResult["mountPath"].toString() : TQString::null;
1238 1250
 		if (mountedPath.isEmpty()) {
1239
-			qerror = i18n("<qt>Unable to mount this device.<p>Potential reasons include:<br>Improper device and/or user privilege level<br>Corrupt data on storage device");
1251
+			qerror = i18n("Unable to mount this device.");
1240 1252
 			TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : TQString::null;
1241 1253
 			if (!errStr.isEmpty()) {
1242 1254
 				qerror.append(i18n("<p>Technical details:<br>").append(errStr));
1243 1255
 			}
1244
-			qerror.append("</qt>");
1245
-		}
1246
-		else {
1247
-			qerror = "";
1248 1256
 		}
1249 1257
 	}
1250 1258
 	else {
@@ -1275,7 +1283,9 @@ TQString TDEBackend::mount(const Medium *medium)
1275 1283
 
1276 1284
 			if (m_decryptionPassword.isNull()) {
1277 1285
 				delete m_decryptDialog;
1278
-				return TQString("Decryption aborted");
1286
+				result["errStr"] = i18n("Decryption aborted");
1287
+				result["result"] = false;
1288
+				return result;
1279 1289
 			}
1280 1290
 			else {
1281 1291
 				// Just for some added fun, if udev emits a medium change event, which I then forward, with mounted==0, it stops the MediaProtocol::listDir method dead in its tracks,
@@ -1311,17 +1321,16 @@ TQString TDEBackend::mount(const Medium *medium)
1311 1321
 						continue_trying_to_decrypt = true;
1312 1322
 					}
1313 1323
 					else {
1314
-						qerror = i18n("<qt>Unable to mount this device.<p>Potential reasons include:<br>Improper device and/or user privilege level<br>Corrupt data on storage device<br>Incorrect encryption password");
1324
+						qerror = i18n("Cannot mount encrypted drives!");
1325
+						qerror = i18n("Unable to mount this device.");
1315 1326
 						TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : TQString::null;
1316 1327
 						if (!errStr.isEmpty()) {
1317 1328
 							qerror.append(i18n("<p>Technical details:<br>").append(errStr));
1318 1329
 						}
1319
-						qerror.append("</qt>");
1320 1330
 						continue_trying_to_decrypt = false;
1321 1331
 					}
1322 1332
 				}
1323 1333
 				else {
1324
-					qerror = "";
1325 1334
 					continue_trying_to_decrypt = false;
1326 1335
 				}
1327 1336
 
@@ -1331,7 +1340,9 @@ TQString TDEBackend::mount(const Medium *medium)
1331 1340
 	}
1332 1341
 
1333 1342
 	if (!qerror.isEmpty()) {
1334
-		return qerror;
1343
+		result["errStr"] = qerror;
1344
+		result["result"] = false;
1345
+		return result;
1335 1346
 	}
1336 1347
 
1337 1348
 	ResetProperties(sdevice, false, true);
@@ -1340,29 +1351,36 @@ TQString TDEBackend::mount(const Medium *medium)
1340 1351
 		m_ignoreDeviceChangeEvents.remove(sdevice->uniqueID());
1341 1352
 	}
1342 1353
 
1343
-	return TQString();
1354
+	result["result"] = true;
1355
+	return result;
1344 1356
 }
1345 1357
 
1346
-TQString TDEBackend::mount(const TQString &_udi)
1358
+TQStringVariantMap TDEBackend::mount(const TQString &id)
1347 1359
 {
1348
-	const Medium* medium = m_mediaList.findById(_udi);
1360
+	const Medium *medium = m_mediaList.findById(id);
1349 1361
 	if (!medium) {
1350
-		return i18n("No such medium: %1").arg(_udi);
1362
+		TQStringVariantMap result;
1363
+		result["errStr"] = i18n("No such medium: %1").arg(id);
1364
+		result["result"] = false;
1365
+		return result;
1351 1366
 	}
1352
-
1353 1367
 	return mount(medium);
1354 1368
 }
1355 1369
 
1356
-TQString TDEBackend::unmount(const TQString &_udi)
1370
+TQStringVariantMap TDEBackend::unmount(const TQString &id)
1357 1371
 {
1358
-	const Medium* medium = m_mediaList.findById(_udi);
1372
+	TQStringVariantMap result;
1359 1373
 
1360
-	if ( !medium ) {
1361
-		return i18n("No such medium: %1").arg(_udi);
1374
+	const Medium* medium = m_mediaList.findById(id);
1375
+	if (!medium) {
1376
+		result["errStr"] = i18n("No such medium: %1").arg(id);
1377
+		result["result"] = false;
1378
+		return result;
1362 1379
 	}
1363 1380
 
1364 1381
 	if (!medium->isMounted()) {
1365
-		return TQString(); // that was easy
1382
+		result["result"] = true;
1383
+		return result;
1366 1384
 	}
1367 1385
 
1368 1386
 	TQString mountPoint = isInFstab(medium);
@@ -1373,83 +1391,90 @@ TQString TDEBackend::unmount(const TQString &_udi)
1373 1391
 		data.medium = medium;
1374 1392
 
1375 1393
 		TDEIO::Job *job = TDEIO::unmount( medium->mountPoint(), false );
1376
-		connect(job, TQT_SIGNAL( result (TDEIO::Job *)), TQT_SLOT( slotResult( TDEIO::Job *)));
1394
+		connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotResult(TDEIO::Job*)));
1377 1395
 		mount_jobs[job] = &data;
1378 1396
 		// The caller expects the device to be unmounted when the function
1379 1397
 		// completes. Thus block until the job completes.
1380 1398
 		while (!data.completed) {
1381 1399
 			kapp->eventLoop()->enterLoop();
1382 1400
 		}
1383
-		// Return the error message (if any) to the caller
1384
-		return (data.error) ? data.errorMessage : TQString::null;
1401
+		if (!data.error) {
1402
+			result["result"] = true;
1403
+			return result;
1404
+		}
1405
+		else {
1406
+			result["errStr"] = data.errorMessage; // Return the error message (if any) to the caller
1407
+			result["result"] = false;
1408
+			return result;
1409
+		}
1385 1410
 	}
1386 1411
 
1387
-	TQString udi = TQString::null;
1388
-
1389 1412
 	TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
1390
-
1391
-	TDEStorageDevice * sdevice = hwdevices->findDiskByUID(medium->id());
1413
+	TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id());
1392 1414
 	if (!sdevice) {
1393
-		return i18n("Internal error");
1415
+		result["errStr"] = i18n("Internal error. Couldn't find medium.");
1416
+		result["result"] = false;
1417
+		return result;
1394 1418
 	}
1395 1419
 
1396
-	TQString qerror;
1397
-	TQString origqerror;
1398
-
1399 1420
 	// Save these for later
1400 1421
 	TQString uid = sdevice->uniqueID();
1401 1422
 	TQString node = sdevice->deviceNode();
1402 1423
 
1424
+	TQString qerror;
1403 1425
 	TQStringVariantMap unmountResult = sdevice->unmountDevice();
1404 1426
 	if (unmountResult["result"].toBool() == false) {
1405 1427
 		// Unmount failed!
1406
-		qerror = "<qt>" + i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and currently mounted at <b>%4</b> could not be unmounted. ").arg("system:/media/" + medium->name(), medium->deviceNode(), medium->prettyLabel(), medium->prettyBaseURL().pathOrURL());
1428
+		qerror = i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and currently mounted at "
1429
+		    "<b>%4</b> could not be unmounted. ").arg("system:/media/" + medium->name(), medium->deviceNode(),
1430
+		    medium->prettyLabel(), medium->prettyBaseURL().pathOrURL());
1407 1431
 		TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null;
1408 1432
 		if (!errStr.isEmpty()) {
1409 1433
 			qerror.append(i18n("<p>Technical details:<br>").append(errStr));
1410 1434
 		}
1411
-		qerror.append("</qt>");
1412
-	}
1413
-	else {
1414
-		qerror = "";
1415 1435
 	}
1416 1436
 
1417 1437
 	if (unmountResult.contains("retCode") && unmountResult["retCode"].toInt() == 1280) {
1418 1438
 		// Failed as BUSY
1419 1439
 		TQString processesUsingDev = listUsingProcesses(medium);
1420 1440
 		if (!processesUsingDev.isNull()) {
1421
-			if (KMessageBox::warningYesNo(0, i18n("<qt>The device <b>%1</b> (%2) named <b>'%3'</b> and currently mounted at <b>%4</b> can not be unmounted at this time.<p>%5<p><b>Would you like to forcibly terminate these processes?</b><br><i>All unsaved data would be lost</i>").arg("system:/media/" + medium->name()).arg(medium->deviceNode()).arg(medium->prettyLabel()).arg(medium->prettyBaseURL().pathOrURL()).arg(processesUsingDev)) == KMessageBox::Yes) {
1441
+			if (KMessageBox::warningYesNo(0, i18n("<qt>The device <b>%1</b> (%2) named <b>'%3'</b> and currently "
1442
+			    "mounted at <b>%4</b> can not be unmounted at this time.<p>%5<p><b>Would you like to forcibly "
1443
+			    "terminate these processes?</b><br><i>All unsaved data would be lost</i>").arg("system:/media/" +
1444
+			    medium->name()).arg(medium->deviceNode()).arg(medium->prettyLabel()).arg(medium->prettyBaseURL().pathOrURL())
1445
+			    .arg(processesUsingDev)) == KMessageBox::Yes) {
1422 1446
 				killUsingProcesses(medium);
1423 1447
 				unmountResult = sdevice->unmountDevice();
1424 1448
 				if (unmountResult["result"].toBool() == false) {
1425 1449
 					// Unmount failed!
1426
-					qerror = "<qt>" + i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and currently mounted at <b>%4</b> could not be unmounted. ").arg("system:/media/" + medium->name(), medium->deviceNode(), medium->prettyLabel(), medium->prettyBaseURL().pathOrURL());
1450
+					qerror = i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and currently mounted at "
1451
+					    "<b>%4</b> could not be unmounted. ").arg("system:/media/" + medium->name(), medium->deviceNode(),
1452
+					    medium->prettyLabel(), medium->prettyBaseURL().pathOrURL());
1427 1453
 					TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null;
1428 1454
 					if (!errStr.isEmpty()) {
1429 1455
 						qerror.append(i18n("<p>Technical details:<br>").append(errStr));
1430 1456
 					}
1431
-					qerror.append("</qt>");
1432
-				}
1433
-				else {
1434
-					qerror = "";
1435 1457
 				}
1436 1458
 			}
1437 1459
 		}
1438 1460
 	}
1439 1461
 
1440
-	if (qerror != "") {
1441
-		return qerror;
1462
+	if (!qerror.isEmpty()) {
1463
+		result["errStr"] = qerror;
1464
+		result["result"] = false;
1465
+		return result;
1442 1466
 	}
1443 1467
 
1444
-	// There is a possibility that the storage device was unceremoniously removed from the system immediately after it was unmounted
1445
-	// There is no reliable way to know if this happened either!
1468
+	// There is a possibility that the storage device was unceremoniously removed from the system immediately
1469
+	// after it was unmounted. There is no reliable way to know if this happened either!
1446 1470
 	// For now, see if the device node still exists
1447 1471
 	TQFileInfo checkDN(node);
1448 1472
 	if (!checkDN.exists()) {
1449 1473
 		m_mediaList.removeMedium(uid, true);
1450 1474
 	}
1451 1475
 
1452
-	return TQString();
1476
+	result["result"] = true;
1477
+	return result;
1453 1478
 }
1454 1479
 
1455 1480
 void TDEBackend::slotResult(TDEIO::Job *job)

+ 5
- 5
tdeioslave/media/mediamanager/tdehardwarebackend.h View File

@@ -68,11 +68,11 @@ public:
68 68
 
69 69
 	bool setMountoptions(const TQString &id, const TQStringList &options);
70 70
 
71
-	TQString mount(const TQString &id);
72
-	TQString mount(const Medium *medium);
73
-	TQString unmount(const TQString &id);
74
-// 	TQString decrypt(const TQString &id, const TQString &password);
75
-// 	TQString undecrypt(const TQString &id);
71
+	TQStringVariantMap mount(const TQString &id);
72
+	TQStringVariantMap mount(const Medium *medium);
73
+	TQStringVariantMap unmount(const TQString &id);
74
+// 	TQStringVariantMap decrypt(const TQString &id, const TQString &password);
75
+// 	TQStringVariantMap undecrypt(const TQString &id);
76 76
 
77 77
 private:
78 78
 	/**

+ 47
- 27
tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp View File

@@ -73,15 +73,16 @@ MountHelper::MountHelper() : TDEApplication()
73 73
 	KURL url(args->url(0));
74 74
 	const Medium medium = findMedium(url);
75 75
 
76
-	if ( medium.id().isEmpty() )
76
+	if (medium.id().isEmpty())
77 77
 	{
78
-		if (m_errorStr.isEmpty())
78
+		if (m_errorStr.isEmpty()) {
79 79
 			m_errorStr+= i18n("%1 cannot be found.").arg(url.prettyURL());
80
+		}
80 81
 		TQTimer::singleShot(0, this, TQT_SLOT(error()) );
81 82
 		return;
82 83
 	}
83 84
 
84
-	if ( !medium.isMountable() && !args->isSet("e") && !args->isSet("s"))
85
+	if (!medium.isMountable() && !args->isSet("e") && !args->isSet("s"))
85 86
 	{
86 87
 		m_errorStr = i18n("%1 is not a mountable media.").arg(url.prettyURL());
87 88
 		TQTimer::singleShot(0, this, TQT_SLOT(error()) );
@@ -91,8 +92,7 @@ MountHelper::MountHelper() : TDEApplication()
91 92
 	TQString device = medium.deviceNode();
92 93
 	TQString mount_point = medium.mountPoint();
93 94
 
94
-	m_isCdrom = medium.mimeType().find("dvd")!=-1
95
-	         || medium.mimeType().find("cd")!=-1;
95
+	m_isCdrom = medium.mimeType().find("dvd") != -1 || medium.mimeType().find("cd") != -1;
96 96
 
97 97
 	if (args->isSet("d"))
98 98
 	{
@@ -127,14 +127,19 @@ MountHelper::MountHelper() : TDEApplication()
127 127
 	else if (args->isSet("u"))
128 128
 	{
129 129
 	  DCOPRef mediamanager("kded", "mediamanager");
130
-	  DCOPReply reply = mediamanager.call( "unmount", medium.id());
131
-	  if (reply.isValid())
132
-	    reply.get(m_errorStr);
133
-	  kdDebug() << "medium unmount " << m_errorStr << endl;
134
-	  if (m_errorStr.isNull())
130
+	  DCOPReply reply = mediamanager.call("unmount", medium.id());
131
+	  TQStringVariantMap unmountResult;
132
+	  if (reply.isValid()) {
133
+	    reply.get(unmountResult);
134
+    }
135
+	  if (unmountResult.contains("result") && unmountResult["result"].toBool()) {
135 136
 	    ::exit(0);
136
-	  else
137
+	  }
138
+	  else {
139
+			m_errorStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : i18n("Unknown unmount error.");
140
+		  kdDebug() << "medium unmount " << m_errorStr << endl;
137 141
 	    error();
142
+	  }
138 143
 	}
139 144
 	else if (args->isSet("s") || args->isSet("e"))
140 145
 	{
@@ -153,7 +158,11 @@ MountHelper::MountHelper() : TDEApplication()
153 158
 		{
154 159
 			DCOPReply reply = mediamanager.call( "unmount", medium.id());
155 160
 			if (reply.isValid()) {
156
-				reply.get(m_errorStr);
161
+			  TQStringVariantMap unmountResult;
162
+				reply.get(unmountResult);
163
+				if (unmountResult["result"].toBool()) {
164
+					reply.get(m_errorStr);
165
+				}
157 166
 			}
158 167
 		}
159 168
 
@@ -163,7 +172,11 @@ MountHelper::MountHelper() : TDEApplication()
163 172
 		{
164 173
 			DCOPReply reply = mediamanager.call( "undecrypt", medium.id());
165 174
 			if (reply.isValid()) {
166
-				reply.get(m_errorStr);
175
+			  TQStringVariantMap undecryptResult;
176
+				reply.get(undecryptResult);
177
+				if (undecryptResult["result"].toBool()) {
178
+					reply.get(m_errorStr);
179
+				}
167 180
 			}
168 181
 		}
169 182
 
@@ -177,13 +190,18 @@ MountHelper::MountHelper() : TDEApplication()
177 190
 	else
178 191
 	{
179 192
 	  DCOPRef mediamanager("kded", "mediamanager");
180
-	  DCOPReply reply = mediamanager.call( "mount", medium.id());
181
-	  if (reply.isValid())
182
-	    reply.get(m_errorStr);
183
-	  if (m_errorStr.isNull())
193
+	  DCOPReply reply = mediamanager.call("mount", medium.id());
194
+	  TQStringVariantMap mountResult;
195
+	  if (reply.isValid()) {
196
+	    reply.get(mountResult);
197
+	  }
198
+	  if (mountResult.contains("result") && mountResult["result"].toBool()) {
184 199
 	    ::exit(0);
185
-	  else
200
+	  }
201
+	  else {
202
+			m_errorStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : i18n("Unknown mount error.");
186 203
 	    error();
204
+	  }
187 205
 	}
188 206
 }
189 207
 
@@ -252,16 +270,18 @@ void MountHelper::slotSendPassword()
252 270
 	DCOPRef mediamanager("kded", "mediamanager");
253 271
 
254 272
 	DCOPReply reply = mediamanager.call( "decrypt", m_mediumId, dialog->getPassword() );
255
-	if (!reply.isValid()) {
256
-		m_errorStr = i18n("The TDE mediamanager is not running.");
273
+	TQStringVariantMap decryptResult;
274
+	if (reply.isValid()) {
275
+		reply.get(decryptResult);
276
+	}
277
+	if (decryptResult.contains("result") && decryptResult["result"].toBool()) {
278
+		::exit(0);
279
+	}
280
+	else {
281
+		m_errorStr = decryptResult.contains("errStr") ? decryptResult["errStr"].toString() : i18n("Unknown decrypt error.");
282
+		kdDebug() << "medium decrypt " << m_errorStr << endl;
283
+		emit signalPasswordError(m_errorStr);
257 284
 		error();
258
-	} else {
259
-		TQString errorMsg = reply;
260
-		if (errorMsg.isNull()) {
261
-			exit(0);
262
-		} else {
263
-			emit signalPasswordError(errorMsg);
264
-		}
265 285
 	}
266 286
 }
267 287
 

Loading…
Cancel
Save